var elem;
 
function Validationkeyword(theform)
 {
   if (theform.Keyword.value == "")
	 {
	   alert("Please enter your search keyword.");
	   theform.Keyword.focus();
	   return (false);
     }
	
	return (true);
 } 

function ValidateDiscountCode()
 { 
   var f = document.frmCheckout;
   
   if (f.DiscountCode.value == "") {
    alert("Please Input Discount Code.");
    f.DiscountCode.focus();
    return (false);
    }
	
	return (true);
 } 

function ProceedCheckout()
 { 
   var f = document.frmCheckout;
   var pt = f.Shipmethod;
   var ptype="";
   var i;
   
   for (i=0;i<pt.length;i++){
	   if (pt[i].checked){
		   ptype = pt[i].value;
	   }
    }
    
   if (ptype == "" && f.ShippingTo.options[f.ShippingTo.options.selectedIndex].value != "International"){
       alert("Please Select Shipping Method.");
       return (false);
       }
   else { 
       f.action.value = "Checkout";
       f.submit();
     }
 } 
  
function ValidationEmail(theForm)
{
  if (theForm.email.value == "")
  {
    alert("Please enter your email address.");
    theForm.email.focus();
    return (false);
  }
  
  if (theForm.password.value == "")
  {
    alert("Please enter your password.");
    theForm.password.focus();
    return (false);
  } 
  
    return (true);
 }   
 
 function ValidatefEmail(theform)
{
  if (theform.Email.value == "")
  {
    alert("Please enter your email address.");
    theform.Email.focus();
    return (false);
  }
    return (true);
 } 
 
function SetShipping()
{
 var f = document.frmCheckout1;
 var pt = f.SameAsShipping;
 var ptype="";
 var i;
   
 for (i=0;i<pt.length;i++){
	  if (pt[i].checked){
		  ptype = pt[i].value;
	   }
  }
 
 document.getElementById("menushipping").style.display = "block"
 
 if (ptype == "1") {
     frmCheckout1.ShipFirstName.value = frmCheckout1.BillFirstName.value;
     frmCheckout1.ShipLastName.value = frmCheckout1.BillLastName.value;
     frmCheckout1.ShipCompany.value = frmCheckout1.BillCompany.value;   
     frmCheckout1.ShipAddress1.value = frmCheckout1.BillAddress1.value;  
     frmCheckout1.ShipAddress2.value = frmCheckout1.BillAddress2.value;
     frmCheckout1.ShipCity.value = frmCheckout1.BillCity.value;
     frmCheckout1.ShipState.value = frmCheckout1.BillState.value; 
     frmCheckout1.ShipZipCode.value = frmCheckout1.BillZipCode.value;
     frmCheckout1.ShipEmail.value = frmCheckout1.BillEmail.value; 
     frmCheckout1.ShipPhone.value = frmCheckout1.BillPhone.value; 
     frmCheckout1.ShipEvening.value = frmCheckout1.BillEvening.value; 
     frmCheckout1.ShipCountry.value = frmCheckout1.BillCountry.value; 
     
     UpdateTax();
   }
 }  

function UpdateTax()
 { 
   var f = document.frmCheckout1;
   var oldstate = f.OldShipState.value;
   var zipcode = f.ShipZipCode.value;
   var state = f.ShipState.options[f.ShipState.options.selectedIndex].value;
  
   if ((oldstate == "NY" && state != "NY") || (oldstate != "NY" && state == "NY")){
        if (zipcode != "") {
           f.action.value = "Update";
           f.submit();
         }   
     }
 } 

function UpdateGiftBox() { 
   var f = document.frmCheckout1;
   f.action.value = "Update";
   f.submit();
 } 
  
function ValidateForm1()
{
  var f = document.frmCheckout1;
  
  if (f.BillFirstName.value == "") {
    alert("Please Input Billing First Name.");
    f.BillFirstName.focus();
    return (false);
  }
  
  if (f.BillLastName.value == "") {
    alert("Please Input Billing Last Name.");
    f.BillLastName.focus();
    return (false);
  }
  
  if (f.BillAddress1.value == "") {
    alert("Please Input Billing Address.");
    f.BillAddress1.focus();
    return (false);
  }
  
  if (f.BillCity.value == "") {
    alert("Please Input Billing City.");
    f.BillCity.focus();
    return (false);
  }
  
  if (f.BillState.options[f.BillState.options.selectedIndex].value == "" && (f.BillCountry.options[f.BillCountry.options.selectedIndex].value == "USA" || f.BillCountry.options[f.BillCountry.options.selectedIndex].value == "Canada")) {
     alert("Please Select Billing State.");
     f.BillState.focus();
     return (false);
  }
  
  if (f.BillZipCode.value == "") {
    alert("Please Input Billing ZipCode.");
    f.BillZipCode.focus();
    return (false);
  }
 
 if (f.BillPhone.value == "") {
    alert("Please Input Billing Day Phone.");
    f.BillPhone.focus();
    return (false);
  }
   
 if (f.BillEmail.value == "") {
    alert("Please Input Billing Email.");
    f.BillEmail.focus();
    return (false);
  }
  
  var pt = f.SameAsShipping;
  var ptype="";
  var i;
  
  for (i=0;i<pt.length;i++){
	    if (pt[i].checked){
		   ptype = pt[i].value;
	      }
    }

  if (ptype == "") {
      alert("Please Check Your Shipping Address.");
      f.BillCity.focus();
      return (false);
    }
  
  if (f.ShipFirstName.value == "") {
    alert("Please Input Shipping First Name.");
    f.ShipFirstName.focus();
    return (false);
  }
  
  if (f.ShipLastName.value == "") {
    alert("Please Input Shipping Last Name.");
    f.ShipLastName.focus();
    return (false);
  }
  
  if (f.ShipAddress1.value == "") {
    alert("Please Input Shipping Address.");
    f.ShipAddress1.focus();
    return (false);
  }
  
  if (f.ShipCity.value == "") {
    alert("Please Input Shipping City.");
    f.ShipCity.focus();
    return (false);
  }
  
  if (f.ShipState.options[f.ShipState.options.selectedIndex].value == "" && (f.ShipCountry.options[f.ShipCountry.options.selectedIndex].value == "USA" || f.ShipCountry.options[f.ShipCountry.options.selectedIndex].value == "Canada")) {
     alert("Please Select Shipping State.");
     f.ShipState.focus();
     return (false);
  }
  
  if (f.ShipZipCode.value == "") {
    alert("Please Input Shipping ZipCode.");
    f.ShipZipCode.focus();
    return (false);
  }
  
 if (f.ShipPhone.value == "") {
    alert("Please Input Shipping Day Phone.");
    f.ShipPhone.focus();
    return (false);
  }
 
 if (f.ShipEmail.value == "") {
    alert("Please Input Shipping Email.");
    f.ShipEmail.focus();
    return (false);
  }
 
 var shipcountry = f.ShipCountry.options[f.ShipCountry.selectedIndex].value;
 var shipmethod = f.ShipMethod.value;

 if ((shipcountry=="USA" || shipcountry=="Canada") && (shipmethod=="Express")) {
      alert("Please Select Correct Shipping Method or Shipping Country.");
      f.ShipCountry.focus();
      return (false);
   }
 else if (shipcountry != "USA" && shipcountry != "Canada" && shipmethod != "Express") {
      alert("Please Select Correct Shipping Method or Shipping Country.");
      f.ShipCountry.focus();
	  return false;
   }
       
 if (f.Password.value != "" && f.ConfirmPassword.value != "") {
     if (f.Password.value != f.ConfirmPassword.value) {
         alert("Confirm Password and Password should be same.");
         f.ConfirmPassword.focus();
         return (false);
      }
   }
 
 if (f.cc_name.value == "") {
     alert("Please Input Name On Card.");
     f.cc_name.focus();
     return (false);
   }
 
 if (f.cc_number.value == "") {
     alert("Please Input Credit Card Number.");
     f.cc_number.focus();
     return (false);
  }
 
 if (f.CVVNO.value == "") {
     alert("Please Input CVV#.");
     f.CVVNO.focus();
     return (false);
   }
 
     var c_month = f.cc_month.options[f.cc_month.selectedIndex].value;
     var c_year  = f.cc_year.options[f.cc_year.selectedIndex].value;
     var today_date = new Date();
     var today_month = today_date.getMonth();
     //var today_year = today_date.getYear();
     var today_year = today_date.getFullYear();
     //alert(today_year);
    
     if (c_month == "0"){
         alert ("Please Select Valid Expiration Date.");
         return (false);
       }
  
     if (c_year == today_year){
        if(c_month < (today_month + 1)){
	       alert ("Please Select Valid Expiration Date.");
	       return false;
	     }
       }
     else if (c_year < today_year){
          alert ("Please Select Valid Expiration Date.");
	      return false;
      }
         
     return (true);
 }  
 
 function SetNameOnCard() {
  var f = document.frmCheckout1;
  
  if (f.cc_name.value == "" && f.BillFirstName.value != "" && f.BillLastName.value != "") {
      f.cc_name.value = f.BillFirstName.value + " " + f.BillLastName.value;
   } 
 } 
 
function setmenushipping(){
  var f = document.frmCheckout1;
  var pt = f.SameAsShipping;
  var ptype="";
  var i;
  
  for (i=0;i<pt.length;i++){
	    if (pt[i].checked){
		   ptype = pt[i].value;
	      }
    }
  
  if (ptype == "0" || ptype == "1") {
      elem = document.getElementById("menushipping");
      elem.style.display="block";
    }
  else {
      elem = document.getElementById("menushipping");
      elem.style.display="none";
    } 
  }

function hidelayer(which) {
	if(document.getElementById(which).style.display == "block" || document.getElementById(which).style.display == "") {
	   document.getElementById(which).style.display = "none";
	   } 
	else {
	   document.getElementById(which).style.display = "block";
	  }			
 }

function displaylayer(which) {
    document.getElementById(which).style.display = "block";
 }		
 
function setGiftBox(giftbox,which) {
    if (document.getElementById(giftbox).checked == true) {
        document.getElementById(which).style.display = "block";
       }
    else {
        document.getElementById(which).style.display = "none"; 
       }
} 

function displayside(which) {
    hidesidelayers();
    document.getElementById(which).style.display = "block";
 }	

function hideside(which) {
    document.getElementById(which).style.display = "none";
 }	
  
function hidesidelayers() {
   elem = document.getElementById("layerhours");
   if(isNaN(elem)) { 
      elem.style.display="none";
    } 
   
   elem = document.getElementById("layerreturn");
   if(isNaN(elem)) { 
      elem.style.display="none";
    } 
   
   elem = document.getElementById("layersecurity");
   if(isNaN(elem)) { 
      elem.style.display="none";
    } 
    
   elem = document.getElementById("layerinternational");
   if(isNaN(elem)) { 
      elem.style.display="none";
    }
   
   elem = document.getElementById("layercheckout");
   if(isNaN(elem)) { 
      elem.style.display="none";
    }     
 }
 
 function OpenPopUp(url, width, height) {
	     var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=yes,status=no' );
	}
	
function EditShipMethod(){ 
   var f = document.frmCheckout1;
   f.action.value = "EditShip";
   f.submit();
 } 	