// initilize variables from current url
var riid = 0;
var sid;
var fnm = "";
var sbl = "empty";
var pid;
var sqty = 0;
var getVars = new Array();
var slist = ( window.location.href.indexOf( "?" ) + 1 ) ? window.location.href.substr( window.location.href.indexOf( "?" ) + 1 ) : "";
slist = slist.split( "&" );
for ( var x = 0; x < slist.length; x++ )
{
   var slistvar = slist[x].split( "=" );
   getVars[ unescape( slistvar[0] ) ] = unescape( slistvar[1] );
   if (slistvar[0] == "ri")
   {
      riid = getVars[unescape(slistvar[0])];
   }
   else if (slistvar[0] == "fnm")
   {
      fnm = getVars[unescape(slistvar[0])];
   }
   else if (slistvar[0] == "sid")
   {
      sid = getVars[unescape(slistvar[0])];
   }
   else if (slistvar[0] == "pid")
   {
      pid = getVars[unescape(slistvar[0])];
   }
   else if (slistvar[0] == "li1" || slistvar[0] == "oqty")
   {
      sbl = getVars[unescape(slistvar[0])];
      if (slistvar[0] == "oqty")
	 sqty += parseInt(getVars[unescape(slistvar[0])]);
   }
   else if (slistvar[0].charAt(0) == "l" && slistvar[0].charAt(1) == "q")
   {
      sqty += parseInt(getVars[unescape(slistvar[0])]);
   }
}

function popUp(URL)
{
   day = new Date();
   id = day.getTime();

   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,location=0,scrollbars=1,statusbar=0,menubar=0,resizable=1,width=650,height=500');");
}
var NS = (navigator.appName=="Netscape")?true:false;
function rszwin()
{
   iWidth = (NS)?window.innerWidth:document.body.clientWidth;
   iHeight = (NS)?window.innerHeight:document.body.clientHeight;
   iWidth = document.images[0].width - iWidth + 50;
   iHeight = document.images[0].height - iHeight + 120;
   window.resizeBy(iWidth, iHeight);
   self.focus();
}

var haveerrors = false;
function showText(boxname, text, errors)
{
   if (boxname == 'errheader')
      document.getElementById(boxname).innerHTML = "<font face='Arial,Helvetica' size=2 color='red'><b>"+text+"</b></font>";
   else if (boxname == 'errtrailer')
      document.getElementById(boxname).innerHTML = "";
   else document.getElementById(boxname).innerHTML = "<font face='Arial, Helvetica' color='red' size=2>"+text+"</font>";
   if (!haveerrors && errors && boxname != 'errheader' && boxname != 'errtrailer')
      haveerrors = errors;
}

function validateForm(f)
{
   haveerrors = 0;

   str = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
   var cflg = 0;
   for(i=0; i < f.bm.value.length ;i++)
   {
      if (str.indexOf(f.bm.value.charAt(i))<0)
      {
	 cflg = 1; break;
      }
   }

   var len = f.bm.value.length;
   var dflg = 0;
   if (f.bm.value.charAt(len-3) != "." && f.bm.value.charAt(len-4) != "." && f.bm.value.charAt(len-5) != ".")
      dflg = 1;

   var mflg = 1;
   for(i=1; i < f.bm.value.length - 4 ;i++)
   {
      if (f.bm.value.charAt(i) == "@")
      {
	 mflg = 0; break
      }
   }

   if (f.bm.value.length < 1 || cflg == 1 || dflg == 1 || mflg == 1)
      showText("emailerror","<LI>Please enter a valid email address",true);
   else showText("emailerror","",false);

   (f.bp.value.length < 1) ? showText("pwderror","<LI>Please choose a password (6-8 digits)",true) : showText("pwderror","",false);
   (f.bn.value.length < 1) ? showText("nameerror","<LI>Please enter your name",true) : showText("nameerror","",false);
   (f.b1.value.length < 1) ? showText("addrerror","<LI>Please enter your address",true) : showText("addrerror","",false);
   (f.bc.value.length < 1) ? showText("cityerror","<LI>Please enter a city",true) : showText("cityerror","",false);
   (f.bz.value.length < 1) ? showText("ziperror","<LI>Please enter a zip/postal code",true) : showText("ziperror","",false);
   (f.be.value.length < 1) ? showText("areaerror","<LI>Please enter a area code",true) : showText("areaerror","",false);
   (f.bt.value.length < 1) ? showText("phnerror","<LI>Please enter a phone number",true) : showText("phnerror","",false);
   if (haveerrors == true)
   {
      showText("errheader","Sorry, some required fields are missing<br>", true);
      showText("errtrailer","",true);
   }
   return (!haveerrors);
}

function popUp_gift(URL)
{
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,location=0,scrollbars=1,statusbar=0,menubar=0,resizable=0,width=640,height=320');");
}

function popUp(URL)
{
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,location=0,scrollbars=1,statusbar=0,menubar=0,resizable=1,width=650,height=500');");
}

function showgmb(citm)
{
   if (citm.style.display=='none') citm.style.display='';
   else citm.style.display='none';
}
function textCounter(text,cnt,max)
{
   if (text.value.length > max)
      text.value = text.value.substring(0, max);
   else cnt.value = max - text.value.length;
}
