/*
	This file contains the functions that change and modifys the Character Stat
fields in the form.

   The First function:  swapOptions(the_array_name)
      loads the array into the Stat fields.  This includes Edu, Con, Dex, Power,
      Points Left, and Template Skill List.

   The Second function:  Change_Stats()
      runs all the "dynamic" Stat changes for the Move, Sanity, Wound and Move
      Stats.

   The Third function:  UpdateSKLPts()
      transferes the Skill Points across all the tables.

   The Fourth function:  Math_Add(Number_In)
      runs when the + button is clicked next to one of the stats.  It uses a ++
      to add one point to the Stat and ueses a -- to reduce the points.  It then
      checks to see if the stat exceeds 20.  If it exceeds 20 it then uses a --
      to reduce the stat and a ++ to increase the Points.

   The Fifth function:  MathSub(Number_In)
      runs when the - button is clicked next to one of the stats.  It uses a --
      to reduce one point to the Stat and ueses a ++ to add the points.  It then
      checks to see if the stat is less than 3.  If it less than 3 it then uses
      a ++ to increase the stat and a -- to reduce the Points.

   The Sixth and Seventh: Math_Add_EDU(Number_In) and MathSub_EDU(Number_In)
      are identical to #4 and #5 except that they also take care of adding and
      subtracting the Skill points when the EDU skill is changed.   

*/


/* 
   First function
   Processes the Player Templates request.  Places the Template data into the approate fields,
   runs the math functions and clears the skill check scetion. 
*/

function swapOptions(the_array_name)
	{
      var the_array=eval(the_array_name);
      window.document.PSTPChars.Edu2.value=the_array[0];
      window.document.PSTPChars.Con2.value=the_array[1];
      window.document.PSTPChars.Dex2.value=the_array[2];
      window.document.PSTPChars.Power2.value=the_array[3];
      window.document.PSTPChars.Points2.value=the_array[4];
      window.document.PSTPChars.Skils2.value=the_array[5];
      window.document.PSTPChars.SkillPTS.value=window.document.PSTPChars.Points2.value;
      Change_Stats();
      UpdateSKLPts(); 
      ChangeStatFalse();
   }

/*
   Second function
   Checks the stats and fills in the Sanity, Magic, Wound, and Move fields.
*/
function Change_Stats()
	{
      window.document.PSTPChars.Sanity2.value=window.document.PSTPChars.Power2.value*5;
      window.document.PSTPChars.Magic2.value=window.document.PSTPChars.Power2.value;
      window.document.PSTPChars.Wound2.value=window.document.PSTPChars.Con2.value;
      if (window.document.PSTPChars.Dex2.value<=3)
      	{
      		window.document.PSTPChars.Move2.value=5;
         }
      if ((window.document.PSTPChars.Dex2.value>=4)&&(window.document.PSTPChars.Dex2.value<=5))
      	{
      		window.document.PSTPChars.Move2.value=6;
         }
      if ((window.document.PSTPChars.Dex2.value>=6)&&(window.document.PSTPChars.Dex2.value<=7))
      	{
      		window.document.PSTPChars.Move2.value=7;
         }
      if ((window.document.PSTPChars.Dex2.value>=8)&&(window.document.PSTPChars.Dex2.value<=12))
      	{
      		window.document.PSTPChars.Move2.value=8;
         }
      if ((window.document.PSTPChars.Dex2.value>=13)&&(window.document.PSTPChars.Dex2.value<=15))
      	{
      		window.document.PSTPChars.Move2.value=9;
         }
      if ((window.document.PSTPChars.Dex2.value>=16)&&(window.document.PSTPChars.Dex2.value<=17))
      	{
      		window.document.PSTPChars.Move2.value=10;
         }
      if ((window.document.PSTPChars.Dex2.value>=18)&&(window.document.PSTPChars.Dex2.value<=19))
      	{
      		window.document.PSTPChars.Move2.value=11;
         }
      if (window.document.PSTPChars.Dex2.value==25)
      	{
      		window.document.PSTPChars.Move2.value=12;
         }

   }

/* 
   Third function
   Updates the all the Skill point locations in each table
*/
function UpdateSKLPts()
{
   window.document.PSTPChars.SkillPTS1.value=window.document.PSTPChars.SkillPTS.value;
   window.document.PSTPChars.SkillPTS2.value=window.document.PSTPChars.SkillPTS.value;
   window.document.PSTPChars.SkillPTS3.value=window.document.PSTPChars.SkillPTS.value;
   window.document.PSTPChars.SkillPTS4.value=window.document.PSTPChars.SkillPTS.value;
/*
   window.document.PSTPChars.SkillPTS5.value=window.document.PSTPChars.SkillPTS.value;
*/
   return;
}

/* 
   Fourth function
   The math function that adds to the stat and subtrcts from the points left.
*/
function Math_Add(Number_In)
	{
     	Number_In++;
		window.document.PSTPChars.Points2.value--;
   	if ((window.document.PSTPChars.Points2.value<0)||(Number_In>25))
			{
		     	Number_In--;
				window.document.PSTPChars.Points2.value++;
				Change_Stats();
            return Number_In;
         }
		Change_Stats();

      return Number_In;
   }


/*
   Fifth function
   The math function that subtracts from the stat and adds to the points left
*/
function MathSub(Number_In)
	{
   	Number_In--;
  	  	window.document.PSTPChars.Points2.value++;
      if (Number_In<1)
      {
        	Number_In++;
   	  	window.document.PSTPChars.Points2.value--;
			Change_Stats();
  	   	return Number_In;
   	}
		Change_Stats();

   	return Number_In;
   }

/* 
   Sixth function 
   The math function that adds to the stat and subtrcts from the points left.
   It also adds points to all the Skill Points fields 
*/
function Math_Add_EDU(Number_In)
	{
     	Number_In++;
		window.document.PSTPChars.Points2.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;


   	if ((window.document.PSTPChars.Points2.value<0)||(Number_In>25))
			{
		     	Number_In--;
				window.document.PSTPChars.Points2.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
				Change_Stats();
            UpdateSKLPts();
            return Number_In;
         }
		Change_Stats();
      UpdateSKLPts();
      return Number_In;
   }


/*
   Seventh function 
   The math function that subtracts from the stat and adds to the points left
   It also subtracts points to all the Skill Points fields 
*/
function MathSub_EDU(Number_In)
{
	Number_In--;
  	  	window.document.PSTPChars.Points2.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      window.document.PSTPChars.SkillPTS.value++;
      	if (Number_In<1)
      	{
        	Number_In++;
   	  	window.document.PSTPChars.Points2.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
			Change_Stats();
         UpdateSKLPts();
  	   	return Number_In;
      	}
      	if (window.document.PSTPChars.SkillPTS.value<0)
      	{
        	Number_In++;
   	  	window.document.PSTPChars.Points2.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
      window.document.PSTPChars.SkillPTS.value--;
		Change_Stats();
        UpdateSKLPts();
        alert("Illeagal User Input.\n\n You must remove a skill to do this.");
  		return Number_In;
   	}
	Change_Stats();
      	UpdateSKLPts();
   	return Number_In;
}


