/*
	Author: Mike Bommarito
	Description: Some Generic Functions
*/

function showPayType()
{
  var el = document.getElementById("ptype");
  var holder = document.getElementById("ptypeholder");
  if(el.selectedIndex=="1")
  {
    window.location.href = "./payment_per.php?pt=cc";
  }
  if(el.selectedIndex=="2")
  {
  window.location.href = "./payment_per.php?pt=oa";
  }
  if(el.selectedIndex=="0")
  {
  window.location.href = "./payment_per.php";
  }
}

var preloaded = new Array();
function preload_images() {
    for (var i = 0; i < arguments.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    };
};
preload_images(
    '../images/header/bg.jpg',
    '../images/header/bgtop.gif',
    '../images/header/header.jpg',
    '../images/header/lefthead.jpg',
    '../images/header/righthead.jpg',
    '../images/header/header2.jpg'
);


/*POPUPWINDOW*/
function popUpview(url)
{
  sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=475,height=525,left=0,top=0');
}
/*Button Over*/
function changeimg(flag,id)
{
	var imgstring = "shipimg"+id;
	if(flag=="on") document.getElementById(imgstring).src="./images/ShipToThisAddressOver.jpg";
	if(flag=="off") document.getElementById(imgstring).src="./images/ShipToThisAddress.jpg";

}

function checknewsletterForm()
{
  var theForm = document.getElementById("newsform");

  for(i=0; i<theForm.elements.length; i++){
  	 if((theForm.elements[i].type == "password" || theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea") && theForm.elements[i].getAttribute('id') != "nr" ){
         	var elname = theForm.elements[i].name;
      	 	if(theForm.elements[i].value == "" || theForm.elements[i].value == "Enter Email Address"){
      	 	theForm.elements[i].style.background = "#FFCCCC";
      	 	theForm.elements[i].focus();
      	 	theForm.elements[i].value = "";
      	 	document.getElementById("erralert2").innerHTML = "Enter Email Address";
      	 	document.getElementById("erralert2").className = "erralerton";
      	 	document.getElementById("erralert2").style.fontSize = "12px";
           document.getElementById("erralert2").style.margin = "0";
      	 	document.getElementById("erralert2").style.width = "185px";
      	 	t=1;
      	 	return false;
      	 	}else {
      	 		theForm.elements[i].style.background = "#FFFFFF";
      	 		document.getElementById("erralert2").className = "erralertoff";
      	 		}

      }
  }
   return true;
}

/*Validate Form2*/
function checkForm2(form)
{
    //var numForms = document.forms.length;

   //var theForm = document.forms[numForms-1];
  	var t=0;
   	for(i=0; i<form.elements.length; i++){

      if((theForm.elements[i].type == "password" || theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea") && theForm.elements[i].getAttribute('id') != "nr" ){
      	 	var elname = theForm.elements[i].name;
      	 	if(theForm.elements[i].value == ""){
      	 	theForm.elements[i].style.background = "#FFCCCC";
      	 	theForm.elements[i].focus();
      	 	document.getElementById("erralert").innerHTML = "Please fill in the appropriate highlighted area";
      	 	document.getElementById("erralert").className = "erralerton";
      	 	t=1;
      	 	return false;
      	 	}else {
      	 		theForm.elements[i].style.background = "#FFFFFF";
      	 		document.getElementById("erralert").className = "erralertoff";
      	 		}

      }

   }
   
   return true;
}

/*Validate Form*/
function checkForm()
{
 	var theForm = document.forms[0];
  	var t=0;
   	for(i=0; i<theForm.elements.length; i++){
      
       if(theForm.elements[i].type == "password" ){
                    	 	
              if(theForm.elements[i].value.length < 6){           
                         theForm.elements[i].style.background = "#FFCCCC";
      	 	theForm.elements[i].focus();
              	document.getElementById("erralert").innerHTML = "Password must be greater than 6 characters";
      	 	document.getElementById("erralert").className = "erralerton";           
          	return false;
            
            }
          	
            if(theForm.password2.value != theForm.password.value)
            {	
            document.getElementById("erralert").innerHTML = "Passwords do not match";
      	 	document.getElementById("erralert").className = "erralerton"; 
           theForm.elements[i].focus();
           return false;
             }
            
  
          }
      

      if((theForm.elements[i].type == "password" || theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea") && theForm.elements[i].getAttribute('id') != "nr" ){
      	 	var elname = theForm.elements[i].name;
      	 	if(theForm.elements[i].value == ""){
      	 	theForm.elements[i].style.background = "#FFCCCC";
      	 	theForm.elements[i].focus();
      	 	document.getElementById("erralert").innerHTML = "Please fill in the appropriate highlighted area";
      	 	document.getElementById("erralert").className = "erralerton";
      	 	t=1;
      	 	return false;
      	 	}else {
      	 		theForm.elements[i].style.background = "#FFFFFF";
      	 		document.getElementById("erralert").className = "erralertoff";
      	 		}

      }
      
      if(theForm.elements[i].getAttribute('id') == "ptype")
      {
        if(theForm.elements[i].value == "se")
        {
          theForm.elements[i].focus();
      	 	document.getElementById("erralert").innerHTML = "Please fill in the payment method";
      	 	document.getElementById("erralert").className = "erralerton";
          return false;
        }else
        {
          document.getElementById("erralert").className = "erralertoff";
        }
      }

   }
   return true;
}

function validateForm(theform)
{

	var errnum=0;
	for(i=0; i<document.theForm.elements.length; i++)
	{
 		if(document.theForm.elements[i].type=="hidden")
 		{
          if(document.theForm.elements[i].id=="sizeformval")
          	{if(document.theForm.elements[i].value=="") errnum=1; }
 		}
 		if(document.theForm.elements[i].name=="qty")
 		  	{if(document.theForm.elements[i].value=="") errnum=2; document.theForm.elements[i].focus();}
	}

    if(errnum!=0)
    {
    	var textval;
    	if(errnum=="2") textval="Please Enter Quantity";
    	if(errnum=="1") textval="Please Select Size";
        document.getElementById('alertholder').className="alerton";
    	document.getElementById('alertholder').innerHTML = textval;
    	return false;
    }
    else {
    	document.getElementById('alertholder').innerHTML = "";
     	document.getElementById('alertholder').className="alertoff";}
    return true;

}

/*Handle Size Click img change*/
function sizeClick(sid,hiddenval)
{
	sizeimg  = document.getElementById(sid);

	document.getElementById(hiddenval).value=sid.toUpperCase();


navRoot = document.getElementById("sizenav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
	nname = node.getAttribute('name');
	if(nname!=sid){
	document.getElementById(nname).src = "./images/buttons/"+nname+".jpg";
	}else
	{document.getElementById(nname).src = "./images/buttons/"+sid+"-selected.jpg";
      document.getElementById('sizeselected').innerHTML =  "&nbsp;&nbsp;"+sid.toUpperCase();
	}
   }
  }



	return true;
}

/*Search Boxes Text Remove/Show*/
function textBoxEdit(sid,textval)
{
	var tbox = document.getElementById(sid);
	if(tbox.value!=textval)	tbox.value = textval;
}

/*Validation Functions*/

function form_validator(theForm)

        {

        if(theForm.username.value == "") {
                 alert("Please enter your corporate email address.");
                 theForm.username.focus();
                 return(false);
        }
        if(theForm.password.value == "") {
                 alert("Please enter a password.");
                 theForm.password.focus();
                 return(false);
        }

        if(theForm.password2.value == "") {
                 alert("Please validate your password.");
                 theForm.password2.focus();
                 return(false);
        }
        if(theForm.password.value.length < 6) {
                 alert("Your password must be 6 or more characters.");
                 theForm.password.focus();
                 return(false);
        }

        if(theForm.password2.value == theForm.password.value) {
                 }
         else
                 {
                 alert("Your password validation did not match. Please re-enter your password.");
                 theForm.password.focus();
                 return(false);
        }


                if(theForm.bname.value == "") {
                 alert("Please enter your name.");
                 theForm.bname.focus();
                 return(false);
        }

        if(theForm.baddress.value == "") {
                 alert("Please enter your address.");
                 theForm.baddress.focus();
                 return(false);
        }

        if(theForm.bcity.value == "") {
                 alert("Please enter your city.");
                 theForm.bcity.focus();
                 return(false);
        }
        if(theForm.bzip.value == "") {
                 alert("Please enter your zip code.");
                 theForm.bzip.focus();
                 return(false);
        }

        if(theForm.bphone.value == "") {
                 alert("Please enter your phone number.");
                 theForm.bphone.focus();
                 return(false);
        }

        if(theForm.copy.value == "checkbox") {

                if(theForm.sname.value == "") {
                 alert("Please an attn to.");
                 theForm.sname.focus();
                 return(false);
        }

        if(theForm.saddress.value == "") {
                 alert("Please enter an address.");
                 theForm.saddress.focus();
                 return(false);
        }

        if(theForm.scity.value == "") {
                 alert("Please enter a city.");
                 theForm.city.focus();
                 return(false);
        }
        if(theForm.szip.value == "") {
                 alert("Please enter a zip code.");
                 theForm.szip.focus();
                 return(false);
        }
        if(theForm.shipid.value == "") {
                 alert("Please enter a ship-to nickname.");
                 theForm.shipid.focus();
                 return(false);
        }

        }
        return (true);

}

var ShipName = "";
var ShipCompany = "";
var ShipAddress1 = "";
var ShipAddress2 = "";
var ShipCity = "";
var ShipState = "";
var ShipStateIndex = 0;
var ShipZip = "";
var ShipCountryIndex = 0;

function ShipToBillPerson(theForm) {
if (theForm.copy.checked) {
theForm.sname.value = theForm.bname.value;
theForm.scompany.value = theForm.bcompany.value;
theForm.saddress.value = theForm.baddress.value;
theForm.saddress2.value = theForm.baddress2.value;
theForm.scity.value = theForm.bcity.value;
theForm.szip.value = theForm.bzip.value;
theForm.shipid.value = "Me";
document.theForm.scountry.selectedIndex = document.theForm.bcountry.selectedIndex;
changeListship(document.forms['theForm'].scountry)
document.theForm.sstate.selectedIndex = document.theForm.bstate.selectedIndex;
}
else {
theForm.sname.value = ShipName;
theForm.scompany.value = ShipCompany;
theForm.saddress.value = ShipAddress1;
theForm.saddress2.value = ShipAddress2;
theForm.scity.value = ShipCity;
theForm.szip.value = ShipZip;
theForm.shipid.value = "";
theForm.scountry.selectedIndex = ShipCountryIndex;
theForm.sstate.selectedIndex = ShipStateIndex;

   }
}

function helpwin(url) {
        sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=300,height=150,left=350,top=250');
}

