var elem;
var flagShipmentCoutry = false;
var shipCountry = "";
 
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.PromoCode.value == "") {
       alert("Please enter a Promo code.");
       f.PromoCode.focus();
       return (false);
    }
	
	return (true);
 } 
 
function displayWindow(url, width, height) {
   var url1 = 'bigimage.asp?pic=' + url + '&height=460&width=500';
   var Win = window.open(url1,"",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=no' );
 }
	
function ProceedCheckout(opt)
 { 
   var f = document.frmCheckout;
   var total = f.subtotal.value;
   //var pt = f.Shipmethod;
   var ptype="";
   var i;
   
   if (opt == 1){ 
      if (total < 200) {
         alert("For wholesale checkout, Your minimum order is $200.00.");
         return (false);
      }
    }
   /*
   for (i=0;i<pt.length;i++){
	   if (pt[i].checked){
		   ptype = pt[i].value;
	   }
    }
    */
   //if (ptype == ""){
   if (false) {
       alert("Please Select Shipping Method.");
       document.getElementById("sel_ship_td").style.backgroundColor = "#CC0000";
       document.getElementById("sel_ship_txt").style.color = "#FFFFFF";
       return (false);
       }
   else { 
       f.action.value = "Checkout";
       f.submit();
     }
 } 
function paypalcheckout(opt){	var f = document.frmCheckout;
   var total = f.subtotal.value;
   //var pt = f.Shipmethod;
   var ptype="";
   var i;
   
   if (opt == 1){ 
      if (total < 200) {
         alert("For wholesale checkout, Your minimum order is $200.00.");
         return (false);
      }
    }
   
  /* for (i=0;i<pt.length;i++){
	   if (pt[i].checked){
		   ptype = pt[i].value;
	   }
    }
    */
    
    ptype = f.ppShipPrice.value;
    
   if (ptype == ""){
       alert("Please Select Shipping Method.");
       document.getElementById("sel_ship_td").style.backgroundColor = "#CC0000";
       document.getElementById("sel_ship_txt").style.color = "#FFFFFF";
       //return (false);
       }
   else { 
       //f.action.value = "Checkout";
       //f.submit();
       f.ppcheckout.value = "1";
       f.submit();
       //self.location.href="cart.asp?ppcheckout=1"
     }}
function checkGiftWrap(chkBox)
{
	var form = chkBox.form;
	//GiftB
	var num = chkBox.name;
	num = num.substr(5);
	
	var objGiftSec;
		if (chkBox.checked)	{		if (document.getElementById("span_gift_message" + num) != null)
		{
			objGiftSec = document.getElementById("span_gift_message" + num);			objGiftSec.style.display = "";
			objGiftSec.style.visibility = "visible";
		}	}	else	{		if (document.getElementById("span_gift_message" + num) != null)
		{
			objGiftSec = document.getElementById("span_gift_message" + num);			objGiftSec.style.display = "none";
			objGiftSec.style.visibility = "hidden";
		}	}		form.submit();	
}  function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
function ChangeAction(actionv) {document.frmPerson.Action.value = actionv;return true;
}

function textlength() {var f = window.document.frmPerson;
var e;
var s;
var temp;
var textlen="";
   
   for(var i=0; i < f.elements.length; i++) {
      e = f.elements[i];
      
      if (e.type == "text" && e.name != "Comments" && e.value != "") {
         s = e.value;
         while (s.indexOf(" ") > -1)
         s = s.replace(" ","");
         temp = e.name + "=" + s.length;
         textlen = textlen + temp + ";";
         }
      }
 
 f.ptext.value = textlen; 
 return true;    }

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.SameAsBilling;
 var ptype="";
 var i;
   
 for (i=0;i<pt.length;i++){
	  if (pt[i].checked){
		  ptype = pt[i].value;
	   }
  }
 
 if (ptype == "1") {
     f.ShipFirstName.value = f.BillFirstName.value;
     f.ShipLastName.value = f.BillLastName.value;
     f.ShipCompany.value = f.BillCompany.value;
     f.ShipAddress1.value = f.BillAddress1.value;  
     f.ShipAddress2.value = f.BillAddress2.value;
     f.ShipCity.value = f.BillCity.value;
     f.ShipState.value = f.BillState.value; 
     f.ShipZipCode.value = f.BillZipCode.value;
     f.ShipEmail.value = f.BillEmail.value; 
     f.ShipPhone.value = f.BillPhone.value; 
     f.ShipEvening.value = f.BillEvening.value; 
     f.ShipCountry.value = f.BillCountry.value; 
    }
  
  if (f.ShipState.options[f.ShipState.options.selectedIndex].value == "NY") {
      setTax();
    } 
  else {
      setNoTax();
    }     
 }  


function ValidateForm1()
{
  var f = document.frmCheckout1;
  
  if (f.BillFirstName.value == "") {
    alert("Please enter Billing First Name.");
    f.BillFirstName.focus();
    return (false);
  }
  
  if (f.BillLastName.value == "") {
    alert("Please enter Billing Last Name.");
    f.BillLastName.focus();
    return (false);
  }
  
  if (f.BillAddress1.value == "") {
    alert("Please enter Billing Address.");
    f.BillAddress1.focus();
    return (false);
  }
  
  if (f.BillCity.value == "") {
    alert("Please enter 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")) {
  if (f.BillState.options[f.BillState.options.selectedIndex].value == "" && (f.BillCountry.options[f.BillCountry.options.selectedIndex].value == "United States" || f.BillCountry.options[f.BillCountry.options.selectedIndex].value == "Canada")) {
     alert("Please Select Billing State.");
     f.BillState.focus();
     return (false);
  }
  
  if (f.BillZipCode.value == "" && (f.BillCountry.options[f.BillCountry.options.selectedIndex].value == "United States" || f.BillCountry.options[f.BillCountry.options.selectedIndex].value == "Canada")) {
    alert("Please enter Billing ZipCode.");
    f.BillZipCode.focus();
    return (false);
  }
 
 if (f.BillPhone.value == "") {
    alert("Please enter Billing Day Phone.");
    f.BillPhone.focus();
    return (false);
  }
   
 if (f.BillEmail.value == "") {
    alert("Please enter Billing Email.");
    f.BillEmail.focus();
    return (false);
  }
  
  var pt = f.SameAsBilling;
  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.BillPhone.focus();
      return (false);
    }
  
  if (f.ShipFirstName.value == "") {
    alert("Please enter Shipping First Name.");
    f.ShipFirstName.focus();
    return (false);
  }
  
  if (f.ShipLastName.value == "") {
    alert("Please enter Shipping Last Name.");
    f.ShipLastName.focus();
    return (false);
  }
  
  if (f.ShipAddress1.value == "") {
    alert("Please enter Shipping Address.");
    f.ShipAddress1.focus();
    return (false);
  }
  
  if (f.ShipCity.value == "") {
    alert("Please enter 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")) {
  if (f.ShipState.options[f.ShipState.options.selectedIndex].value == "" && (f.ShipCountry.options[f.ShipCountry.options.selectedIndex].value == "United States" || f.ShipCountry.options[f.ShipCountry.options.selectedIndex].value == "Canada")) {
     alert("Please Select Shipping State.");
     f.ShipState.focus();
     return (false);
  }
  
  if (f.ShipZipCode.value == "" && (f.BillCountry.options[f.BillCountry.options.selectedIndex].value == "United States" || f.BillCountry.options[f.BillCountry.options.selectedIndex].value == "Canada")) {
    alert("Please enter Shipping ZipCode.");
    f.ShipZipCode.focus();
    return (false);
  }
  
 if (f.ShipPhone.value == "") {
    alert("Please enter Shipping Day Phone.");
    f.ShipPhone.focus();
    return (false);
  }
 
 if (f.ShipEmail.value == "") {
    alert("Please enter Shipping Email.");
    f.ShipEmail.focus();
    return (false);
  }
 
 var shipcountry = f.ShipCountry.options[f.ShipCountry.selectedIndex].value;
 var shippingto = f.ShippingTo.value;
 /*
 //if  (shippingto=="International" && (shipcountry=="USA" || shipcountry=="Canada")) {
 if  (shippingto=="International" && (shipcountry=="United States" || shipcountry=="Canada")) {
      alert("you selected a shipping method which does not work with the address you selected, check the following; change the country or select a shipping method that is suitable for your address.");
      f.ShipCountry.focus();
      return (false);
   }
 else if (shipcountry!=shippingto && shippingto!="International" && shipcountry!="") {
      alert("you selected a shipping method which does not work with the address you selected, check the following; change the country or select a shipping method that is suitable for your address.");
      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);
      }
   }
 */
 var paytype = "";
 var i = 0;
 for (i = 0 ; i < f.PaymentType.length ; i++)
 {
	if (f.PaymentType[i].checked)
		paytype = f.PaymentType[i].value;
 }
 if (paytype != "CHECK")
 {
 
 if (f.cc_name.value == "") {
     alert("Please enter Name On Card.");
     f.cc_name.focus();
     return (false);
   }
 
 if (f.cc_number.value == "") {
     alert("Please enter Credit Card Number.");
     f.cc_number.focus();
     return (false);
  }
 
 if (f.CVVNO.value == "") {
     alert("Please enter 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" || c_year == "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;
      }
   }  //if (paytype != "CHECK")
         
     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 setTax(){
return;
 var elem;
 elem = document.getElementById("menunotax");
 elem.style.display="none";
 
 elem = document.getElementById("menutax");
 elem.style.display="block";
}

function setNoTax(){
return;
 var elem;
 elem = document.getElementById("menutax");
 elem.style.display="none";
 
 elem = document.getElementById("menunotax");
 elem.style.display="block";
}

function setTaxDisplay(){
return;
 var f = document.frmCheckout1;
 
 if (f.ShipState.options[f.ShipState.options.selectedIndex].value == "NY") {
     setTax();
   } 
 else {
     setNoTax();
   }   
}

function CheckShippingTo() {
return;
  var f = document.frmCheckout1;
  var shipcountry = f.ShipCountry.options[f.ShipCountry.selectedIndex].value;
  var shippingto = f.ShippingTo.value;

  //if (shippingto=="International" && (shipcountry=="USA" || shipcountry=="Canada")) {
  if (shippingto=="International" && (shipcountry=="United States" || shipcountry=="Canada")) {
      //alert("you selected a shipping method which does not work with the address you selected, check the following; change the country or select a shipping method that is suitable for your address.");
      //f.ShipCountry.focus();
      showShippingMessage(shipcountry);
    }
  else if (shipcountry!=shippingto && shippingto!="International" && shipcountry!="") {
      //alert("you selected a shipping method which does not work with the address you selected, check the following; change the country or select a shipping method that is suitable for your address.");
      //f.ShipCountry.focus();
      showShippingMessage(shipcountry);
	}
 }

function showeditshipping()
{
	var objtag1 = document.getElementById("shipwrong1");
	var objtag2 = document.getElementById("shipwrong2");
	var objtag3 = document.getElementById("layer2");
	
	//objtag1.style.display = "";
	//objtag1.style.visibility = "visible";
	//objtag2.style.display = "";
	//objtag2.style.visibility = "visible";
	objtag3.style.display = "";
	objtag3.style.visibility = "visible";
}

function showShippingMessage(sCountry)
{
	var objtag1 = document.getElementById("shipwrong1");
	var objtag2 = document.getElementById("shipwrong2");
	var objtag3 = document.getElementById("layer2");
	
	objtag1.style.display = "";
	objtag1.style.visibility = "visible";
	objtag2.style.display = "";
	objtag2.style.visibility = "visible";
	objtag3.style.display = "";
	objtag3.style.visibility = "visible";
	
	var f = document.frmShippingUpdate;
	
	if (sCountry == "USA" || sCountry == "United States")
		f.ShippingTo.selectedIndex = 1;
	else if (sCountry == "Canada")
		f.ShippingTo.selectedIndex = 2;
	else
		f.ShippingTo.selectedIndex = 3;
	
	clearall(1);
	
	//divlayer.style.display = "";
	//divlayer.style.visibility = "visible";
	//divlayer.style.display = "none";
	//divlayer.style.visibility = "hidden";
}

function OpenPopUp(url, width, height) {
	     var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=yes,status=no' );
	}
	

function clearall(){
   return;
   elem = document.getElementById("USA");
   if(isNaN(elem)) { 
      elem.style.display="none";
     } 
   
   elem = document.getElementById("Canada");
   if(isNaN(elem)) { 
      elem.style.display="none";
     } 
   
   elem = document.getElementById("International");
   if(isNaN(elem)) { 
      elem.style.display="none";
     }   
   if (arguments.length > 0)
	var f = window.document.frmShippingUpdate;
   else
	var f = window.document.frmCheckout;
   var shippingto = f.ShippingTo.options[f.ShippingTo.selectedIndex].value;
   
   elem = document.getElementById(shippingto);
   if(isNaN(elem)) { 
      elem.style.display="block";
     }   
 }		
 


