function EnlargeImage(iCode,iPID,nImg){
  window.open("/EnlargeImage.asp?ProdID="+ iPID + "&Code=" + iCode + "&Img=" + nImg,"","toolbar=no,menubar=0,resizable=0,scrollbars=no,width=200,height=200"); 
}

function Size(swImg){
var i = new Image();
i.src=swImg;
window.resizeTo(i.width + 30,i.height + 160);
}

function OpenParent(cadena){

  var Open = opener.window.parent.closed;
  if (Open == false) {
    opener.window.location.href = cadena;
  }else
  {
  	window.open(cadena);
  }
  window.close();
}


function AddProductF(frmProduct){
document.getElementById(frmProduct).Target.value="ADD";
document.getElementById(frmProduct).submit();
}
function AddProduct(){
document.frmProduct.Target.value="ADD";
document.frmProduct.submit();
}

function AddProduct2(zProdID){
	window.location.href = "/AddProduct.asp?Target=ADD&ProdID=" +zProdID;
}

function DetailSet(iCode){
  var sw = document.all("TD"+iCode).style.display;
  if (sw == "") {
     document.all("TD"+iCode).style.display = "none";
     document.all("ID"+iCode).style.display = "";
     document.all("IH"+iCode).style.display = "none";
  }else{
     document.all("TD"+iCode).style.display = "";
     document.all("ID"+iCode).style.display = "none";
     document.all("IH"+iCode).style.display = "";
  }
}

function DeleteItem(iCode){
  document.frmOrder.Target.value= "DELETE";
  document.frmOrder.DItem.value = iCode;
  document.frmOrder.submit();
}

function DeletePage(iCode,Page){
	document.frmOrder.Target.value= "DELETE_PAGE";
  document.frmOrder.DItem.value = iCode;
  document.frmOrder.Page.value = Page;
  document.frmOrder.submit();
}

function Recalculate(iCode){
  var sw = true;
  for (i=1; i<=iCode; i++){
    //if (!isNumber(document.all("Qty"+i).value)) sw = false;
      //alert(document.getElementById("Qty"+i));
    if (!isNumber(document.getElementById("Qty"+i).value)) sw = false;
    if (document.getElementById("Qty"+i).value=="0") sw = false;
    //if (document.all("Qty"+i).value == "0") sw = false;
  }
  if (sw) {
  document.frmOrder.Target.value= "CALC";
  document.frmOrder.DItem.value = iCode;
  document.frmOrder.submit();
  }else{
    alert("Please enter valid values for the quantity items!.");
  }
}


function isNumber(value) {
	for (var i=0; i < value.length; i++) {
		a = parseInt(value.charAt(i));
		if (isNaN(a)) {
			return false;			
			break;
		}
	}
	return true;
}

function ApplyCoupon(){
  if (document.frmCoupon.CouponCode.value == ""){
    alert("You must fill the Coupon Code fields!");
  }else{
    document.frmCoupon.Target.value = "ADDCOUPON";
    document.frmCoupon.submit();
  }
}

function DeleteCoupon(){
  document.frmOrder.Target.value= "DELETECOUPON";
  document.frmOrder.DItem.value = 0;
  document.frmOrder.submit();
}

function CheckOut(sCad){
  document.frmOrder.Target.value="";
  if (sCad == "")  document.frmOrder.action = "secure/Customer.asp";
  else{document.frmOrder.action = sCad + "/Customer.asp"; }
  
  document.frmOrder.method = "post"
  document.frmOrder.submit();
}
function CheckOut2(sCad){
  document.frmOrder.Target.value="";
  if (sCad == "")  document.frmOrder.action = "/secure/Customer.asp";
  else{document.frmOrder.action = sCad + "/Customer.asp"; }
  
  document.frmOrder.method = "post"
  document.frmOrder.submit();
}

function RetrievePassword(){
  window.open("Password.asp","","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=352,height=202");
}

function CreateAccount(){
  window.location.href="Customer.asp?Target=new";
}

function SameON(){
  //document.all("SInfo").disabled = true
  document.frmCustomer.csFName.disabled = true;
  document.frmCustomer.csMI.disabled = true;
  document.frmCustomer.csLName.disabled = true;
  document.frmCustomer.csCompany.disabled = true;
  document.frmCustomer.csAddr1.disabled = true;
  document.frmCustomer.csAddr2.disabled = true;
  document.frmCustomer.csCity.disabled = true;
  document.frmCustomer.csZip.disabled = true;
  document.frmCustomer.csPhone.disabled = true;
  document.frmCustomer.csFax.disabled = true;
  document.frmCustomer.csEmail.disabled = true;
  document.frmCustomer.csState.disabled = true;
  document.frmCustomer.csCountry.disabled = true;
          
}


function SameOFF(){
 // document.all("SInfo").disabled = false
  document.frmCustomer.csFName.disabled = false;
  document.frmCustomer.csMI.disabled = false;
  document.frmCustomer.csLName.disabled = false;
  document.frmCustomer.csCompany.disabled = false;
  document.frmCustomer.csAddr1.disabled = false;
  document.frmCustomer.csAddr2.disabled = false;
  document.frmCustomer.csCity.disabled = false;
  document.frmCustomer.csZip.disabled = false;
  document.frmCustomer.csPhone.disabled = false;
  document.frmCustomer.csFax.disabled = false;
  document.frmCustomer.csEmail.disabled = false;
  document.frmCustomer.csState.disabled = false;
  document.frmCustomer.csCountry.disabled = false;
  
}


function SaveCustomer(){
var sOutB = "";
var sOutS = "";
var sOutP = "";

if (document.frmCustomer.cFName.value == "") sOutB += "\t\t- First Name\n";
if (document.frmCustomer.cLName.value == "") sOutB += "\t\t- Last Name\n";
if (document.frmCustomer.cAddr1.value == "") sOutB += "\t\t- Address\n";
if (document.frmCustomer.cCity.value == "") sOutB += "\t\t- City\n";
//alert(document.frmCustomer.elements.length);

if (document.frmCustomer.cCountry.selectedIndex == 0) sOutB += "\t\t- Country\n";
//alert("AQUI->" + document.frmCustomer.cState.value);
if (document.frmCustomer.cState.selectedIndex == 0) sOutB += "\t\t- State\n";
//if(document.getElementById("cState").value=="NN"){
//sOutB += "\t\t- State\n";
//{alert("EXISTE->"+document.getElementById("cState").value);
//}else{
//document.frmCustomer.cState.value=document.getElementById("cState").value;
//alert("AQUI->"+document.frmCustomer.cState.value);
//}
//if (document.frmCustomer.cCountry.selectedIndex == "") sOutB += "\t\t- Country\n";
if (document.frmCustomer.cZip.value == "") sOutB += "\t\t- Zip Code\n";
if (document.frmCustomer.cPhone.value == "") sOutB += "\t\t- Phone Number\n";
if (document.frmCustomer.cEmail.value == "") sOutB += "\t\t- Email Address\n";

if (!document.frmCustomer.cShippSame[0].checked) {

if (document.frmCustomer.csFName.value == "") sOutS += "\t\t- First Name\n";
if (document.frmCustomer.csLName.value == "") sOutS += "\t\t- Last Name\n";
if (document.frmCustomer.csAddr1.value == "") sOutS += "\t\t- Address\n";
if (document.frmCustomer.csCity.value == "") sOutS += "\t\t- City\n";
//if (document.frmCustomer.csState.selectedIndex == 0) sOutS += "\t\t- State\n";
//if (document.frmCustomer.csCountry.selectedIndex == 0) sOutS += "\t\t- Country\n";
if (document.frmCustomer.csZip.value == "") sOutS += "\t\t- Zip Code\n";
if (document.frmCustomer.csPhone.value == "") sOutS += "\t\t- Phone Number\n";
if (document.frmCustomer.csEmail.value == "") sOutS += "\t\t- Email Address\n";

}

if (document.frmCustomer.cPass1.value != document.frmCustomer.cPass2.value) sOutP += "\tYour password confirmation is wrong."

if ((sOutB == "") && (sOutS == "") && (sOutP == "")) {
  document.frmCustomer.Target.value="SAVE";
  document.frmCustomer.submit();
}else{
  var sError = "";
  sError += "SORRY\nWe cannot process this form. You must fill in the follow fields first:\n";
  sError += "---------------------------------------------------------------------------------\n";
  if (sOutB != "") sError += "Billing Information:\n" + sOutB;
  if (sOutS != "") sError += "Shipping Information:\n" + sOutS;
  if (sOutP != "") sError += "Returning Information:\n" + sOutP;
  alert(sError);
}
 
}

function Login(){
  var sw = true;
  if (document.frmLogin.User.value == "") sw = false;
  if (document.frmLogin.Password.value == "") sw = false;
  if (!sw) {
    alert("You must fill all fields to continue.");
   } else {
     document.frmLogin.Target.value = "LOGIN";
     document.frmLogin.submit();
   }
}

function SetShipping(){
  var iIndex = -1;
  for (var i=0; i<=document.frmShipping.nItems.value; i++){
    //alert("entro" + i);
    if (document.frmShipping.nItems.value != 0){
    	if (document.frmShipping.sShipMethod[i].checked) {
     		//alert(document.all("smethod"+i).checked + " - " + document.all("smethod"+i).value);
     		iIndex = i;
    	}
    }else{
        //alert("volvio" + i);
    	iIndex = i;
    }
  }
  if (iIndex == -1){
    alert("Please select a shipping method to continue.");
  }else{
    document.frmShipping.ShipIndex.value = iIndex;
    document.frmShipping.Target.value="SAVE";
    document.frmShipping.submit();
  }
}

function RemoveOASRP(){
  if (confirm("Do you want to remove this O.A.S.R.P. Value?")){
    window.location.href= "Payments.asp?SetExtra=DEL";
  }
}

function PayOption(){
  var index = document.frmPayments.sPayMethod.selectedIndex;
  var index2 = document.frmPayments.sPayMethod.options[index].text;
  if (index2=="PayPal") {
    document.all("Pay01").style.display = "none";
    document.all("Pay02").style.display = "none";
    document.all("Pay03").style.display = "";
    document.all("Pay04").style.display = "none";
    document.all("Pay05").style.display = "none";
  }
  if (index2=="Credit Card") {
    document.all("Pay01").style.display = "";
    document.all("Pay02").style.display = "none";
    document.all("Pay03").style.display = "none";
    document.all("Pay04").style.display = "none";
    document.all("Pay05").style.display = "none";
  }
  if (index2=="PhoneFax") {
    document.all("Pay01").style.display = "none";
    document.all("Pay02").style.display = "";
    document.all("Pay03").style.display = "none";
    document.all("Pay04").style.display = "none";
    document.all("Pay05").style.display = "none";
  }
  if (index2=="Value Partner") {
    document.all("Pay01").style.display = "none";
    document.all("Pay02").style.display = "none";
    document.all("Pay03").style.display = "none";
    document.all("Pay04").style.display = "none";
    document.all("Pay05").style.display = "";
  }
  if (index2=="eCheck") {
    document.all("Pay01").style.display = "none";
    document.all("Pay02").style.display = "none";
    document.all("Pay03").style.display = "none";
    document.all("Pay04").style.display = "";
    document.all("Pay05").style.display = "none";
  }
}

function OpenWindowCC(){

 window.open("/CCard.html","","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600");

}

function SetOASRP(){
  var iH = document.all("OASRP").value;
  if (!isNumber(iH)){
    document.all("OASRP").value = "";
    alert("Please insert a valid value.");
  }else{
    window.location.href= "Payments.asp?SetExtra=SET&iEXTRA=" + iH;
  } 
  //alert("AQY");
}

function PlaceOrder(){
  var index = document.frmPayments.sPayMethod.selectedIndex;
  var index2 = document.frmPayments.sPayMethod.options[index].text;
  var CadError = "";
  if ((index2=="Credit Card")) {
    if (isCardNumValid(document.frmPayments.sCardNumber.value)) {
       CadError = "Credit Card invalid!";
       document.frmPayments.sCardNumber.value = "";
    }else{
       if (document.frmPayments.sCardNumber.value=="") CadError += "\nCard Number";
       if (document.frmPayments.sCardName.value=="") CadError += "\nCard Name Holder";
       if (document.frmPayments.sCardType.selectedIndex == 0) CadError += "\nCard Type";
       if (document.frmPayments.sCardMonth.selectedIndex == 0) CadError += "\nCard Month Expitarion";
       if (document.frmPayments.sCardYear.selectedIndex == 0) CadError += "\nCard Year Expitarion";
       if (document.frmPayments.sCardCode.value=="") CadError += "\nCard Code";
       //if (document.frmPayments.Terms.status!=true) CadError += "\nAccept the terms and conditions";
    }
  }
  if (index2== "PhoneFax"){
    var c = false;
    var iII = 0;
    for (var i=0; i<document.frmPayments.elements.length;i++)
    {
    var e = document.frmPayments.elements[i];
    if (e.type == 'radio'){
      iII++;
      if (e.checked){
        c = true;
      }
    }
    }
    if (!c) {
      if (iII != 0) {
        CadError += "\nPayment Method";
      }
    }
  }
  
  if (index2 == "eCheck"){ 
    if (document.frmPayments.sBankName.value == "") CadError += "\nBank Name";
    if (document.frmPayments.sAccountNumber.value == "") CadError += "\nAccount Number";
    if (document.frmPayments.sRoutingNumber.value == "") CadError += "\nRouting Number";
    if (document.frmPayments.sCheckNumber.value == "") CadError += "\nCheck Number";
  }

  if (index2 == "Value Partner") {
     if (document.frmPayments.sPartnerLogin.value == "") CadError += "\nPartner Login";
     if (document.frmPayments.sPartnerPassword.value == "") CadError += "\nPartner Password";
   }
  
	//CadError="";
  if (CadError == "") {
     document.frmPayments.Target.value = "PLACE";
     document.frmPayments.submit();
  }else{
    if (CadError  == "Credit Card invalid!") {
       alert(CadError);
    }else{
       var sError = "";
       sError += "SORRY\nWe cannot process this form. You must fill in the follow fields first:\n";
       sError += "---------------------------------------------------------------------------------\n";
       alert(sError + CadError);
    }
  }
  
}

function isCardNumValid(num) {
	var num1, num2, tempNum;
	if (!isNumber(num)) {
		return true;
	}
	num1 = ""
	if (!(num.length%2==0)) {
		for(var j=0; j < num.length; j++) {
			if ((j+1)%2==0){
				tempNum = 2 * num.charAt(j);
			}
			else {
				tempNum = 1 * num.charAt(j);
			}
			num1 = num1 + tempNum.toString();
		}
	}else{
		for(var j=0; j < num.length; j++){
			if ((j+1)%2==0){
				tempNum = 1 * num.charAt(j);
			}
			else{
				tempNum = 2 * num.charAt(j);
			}
			num1 = num1 + tempNum.toString();
		}
	}
	num2 = 0;
	for (var j = 0; j < num1.length; j++) {
		num2 = num2 + parseInt(num1.charAt(j));
	}
	if (num2%10==0) {
		return false;
	}
	else {
		return true;
	}
}

function CreatePhoneFaxForm(iOrderID){
  var sURL = "orderprint.asp?OrderID=" + iOrderID + "&Target=Form";
  window.open(sURL,"","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=600");
}



function PrintFriendly(iOrderID){
  var sURL = "orderprint.asp?OrderID=" + iOrderID;
  window.open(sURL,"","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=600");
}

function Category(){
  if (document.frmResults.sCate.selectedIndex == 0){
  }else{
    var Resp = document.frmResults.sCate.value;
    var sS = document.frmResults.Cate.options[document.frmResults.Cate.selectedIndex].value;
    if (Resp == ""){
      sOut = "catid=" + sS;
    }else{
      sOut = Resp + "&catid=" + sS
    }
    sRedir = "/results.asp?" + sOut;
    window.location = sRedir;
    
  }
   
}

function Sort(){
  if (document.frmResults.PSort.selectedIndex == 0){
  }else{
    var Resp = document.frmResults.SSort.value;
    var sS = document.frmResults.PSort.options[document.frmResults.PSort.selectedIndex].value;
    var sOut = "";
    if (Resp == ""){
      sOut = "orderby=" + sS;
    }else{
      sOut = Resp + "&orderby=" + sS;
    }
    sRedir = "/results.asp?" + sOut
    window.location = sRedir;
   
  }
}

function Page(iPage){
  var Resp = document.frmResults.SPage.value;
  var sOut = "";
  if (Resp==""){
    sOut = "page=" + iPage;
  }else{
    sOut = Resp + "&page=" + iPage;
  }
  sRedir = "/results.asp?" + sOut;
  window.location = sRedir;
}

function SubMit(){
  document.frmAgain.submit();
}

function HidePass(){
	if (document.getElementById("Password").style.display == "")
		document.getElementById("Password").style.display = "none";
	else
		document.getElementById("Password").style.display = "";
	if (document.getElementById("Password1").style.display == "")
		document.getElementById("Password1").style.display = "none";
	else
		document.getElementById("Password1").style.display = "";
   }
   
   function VerifiPass(){
   		clave1 = document.FPass.NewPass.value 
   		clave2 = document.FPass.ConPass.value
		if ((clave1 == "") || (clave2 == ""))
			alert("Su Password no debe ser una cadena vacia");
		else {
    	if (clave1 == clave2) 
       		document.FPass.submit();
    	else 
			alert("Los Password qur introdujo son distintos\nPor favor verifique y vuelva a intentarlo");
		}
   }
function ShowSetOS(iREL){
     var sw = document.getElementById("T"+iREL).style.display;
     if (sw == ""){
        document.getElementById("T"+iREL).style.display = "none";
        document.getElementById("ON"+iREL).style.display = "";
        document.getElementById("OFF"+iREL).style.display = "none";
     }else{
        document.getElementById("T"+iREL).style.display = "";
        document.getElementById("ON"+iREL).style.display = "none";
        document.getElementById("OFF"+iREL).style.display = "";
     }
   }

function OpenOS(URL,Altura){
window.open(URL,'Dashboard', 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=538,height= '+ Altura);
}


function EmailFriend(iPID){
  window.open("/EmailFriend.asp?ProdID="+ iPID,"","toolbar=no,menubar=0,resizable=0,scrollbars=no,width=662,height=404"); 
}


function DoNothing(){

}


function SelectTemplate(xPID,xPOS){
  var xP = document.frmProduct.all("ATT"+xPOS).value;
  document.location.href='ProductDetail.asp?PID='+ xPID + "&ATT=" + xP;
}

function ChangeColor(a, iCode){
  a.className = iCode;
}

