
var s_current = "sdpx";
var f_current = "fdpx";
var ff_current = "ffd";
var fs_current = "fsd";
var fsbold_flag = "off";
var fsitalic_flag = "off";



function normalAll()
{
   changeFontSize('','d','d');
   changeFontFace('','d');
   document.bgColor = "";
   window.document.getElementById("gba").style.color = "";

   fsbold_flag = "off";
   window.document.getElementById("fsb").style.color = "#0088ff";
   window.document.getElementById("gba").style.fontWeight = "";

   fsitalic_flag = "off";
   window.document.getElementById("fsi").style.color = "#0088ff";
   window.document.getElementById("gba").style.fontStyle = "";

   window.document.colorselect.bgcolorbox.value = "";
   window.document.colorselect.fontcolorbox.value = "";
   setColors();
}

function changeFontSize(newsize,PX,FN)
{
   window.document.getElementById(s_current).style.color = "#0088ff";
   s_current = "s" + PX + "px";
   window.document.getElementById(s_current).style.color = "#ee0000";

   window.document.getElementById(f_current).style.color = "#0088ff";
   f_current = "f" + PX + "px";
   window.document.getElementById(f_current).style.color = "#ee0000";

   window.document.getElementById("gba").style.fontSize = newsize;

   setColors();
}

function changeFontFace(newface,NUM)
{
   window.document.getElementById(ff_current).style.color = "#0088ff";
   ff_current = "ff" + NUM;
   window.document.getElementById(ff_current).style.color = "#ee0000";

   window.document.getElementById("gba").style.fontFamily = newface;

   setColors();
}



function fsBold()
{
   if(fsbold_flag == "off")
   {
      window.document.getElementById("fsb").style.color = "#ee0000";
      window.document.getElementById("gba").style.fontWeight = "bold";
      fsbold_flag = "on";
   }
   else if(fsbold_flag == "on")
   {
      window.document.getElementById("fsb").style.color = "#0088ff";
      window.document.getElementById("gba").style.fontWeight = "";
      fsbold_flag = "off";
   }

   setColors();
}

function fsItalic()
{
   if(fsitalic_flag == "off")
   {
      window.document.getElementById("fsi").style.color = "#ee0000";
      window.document.getElementById("gba").style.fontStyle = "italic";
      fsitalic_flag = "on";
   }
   else if(fsitalic_flag == "on")
   {
      window.document.getElementById("fsi").style.color = "#0088ff";
      window.document.getElementById("gba").style.fontStyle = "";
      fsitalic_flag = "off";
   }

   setColors();
}




function setColors()
{
   var A = window.document.colorselect.bgcolorbox.value;
   var B = window.document.colorselect.fontcolorbox.value;
   var errflag = 0;
   if(testHexCode(A) == "good")
   {
      document.bgColor = "#" + A;
   }
   else
   {
      if(A != "") { errflag += 1; }
   }

   if(testHexCode(B) == "good")
   {
      window.document.getElementById("gba").style.color = "#" + B;
   }
   else
   {
      if(B != "") { errflag += 2; }
   }

   if(errflag == 1)
   {
      alert("The background color you entered is invalid. Please enter a valid 6 character hex code.");
   }
   else if(errflag == 2)
   {
      alert("The font color you entered is invalid. Please enter a valid 6 character hex code.");
   }
   else if(errflag == 3)
   {
      alert("The background color and font color you entered are invalid. Please enter valid 6 character hex codes.");
   }

   if(A == "") { document.bgColor = ""; }
   if(B == "") { window.document.getElementById("gba").style.color = ""; }
}

function testHexCode(UserCode)
{
   if(UserCode.length == 6)
   {
      var hexArray = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','A','B','C','D','E','F')
      var flag = 0;
      for (var n = 0; n < 6; n++)
      {

         for (var i = 0; i < 22; i++)
         {
            if(hexArray[i] == UserCode.charAt(n))
            {
               flag = flag + 1;
            }
         }
      }
   }

   if(flag == 6) { return "good"; } else { return "bad"; }
}
