function menuClick(fileName)
{
    window.location=fileName;
}

function check_email(e) {
	ok ="1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
	if(ok.indexOf(e.charAt(i))<0){ 
		return (false);
		}	
	} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);
		} 
	}
}

if (document.images)
{
    preload_image_object = new Image();
    // set image url
    image_url = new Array();
    image_url[0] = "Images/Template/GetItNow_btn.jpg";
    image_url[1] = "Images/Template/GetItNow_btn_Hover.jpg";
    image_url[2] = "Images/Template/BuyIcon.jpg";
    image_url[3] = "Images/Template/BuyIcon_Hover.jpg";
    image_url[4] = "Images/Template/Home_Btn.jpg";
    image_url[5] = "Images/Template/Home_Btn_Hover.jpg";

    for(i=0; i<=image_url.length; i++) 
        preload_image_object.src = image_url[i];
}

function onHoverImage(objName,imageUrlId)
{
    if (imageUrlId==4)
    {
        document.getElementById(objName).style.backgroundColor="#e98117";
        document.getElementById(objName).style.backgroundImage="url("+image_url[imageUrlId]+")";
    }
    else if (imageUrlId==5)
    {
        document.getElementById(objName).style.backgroundColor="#a8c223";
        document.getElementById(objName).style.backgroundImage="url("+image_url[imageUrlId]+")";
    }
    else
        document.getElementById(objName).src=image_url[imageUrlId];
}

fleaTrapPriceOne = 39.99;
fleaTrapPriceTwo = 74.99;
fleaTrapSheetsBonus=2;
sheetsPriceOne=5.99;
sheetsPriceFive=24.99;
boxPrice = 449.99;
adaptorPrice = 9.90;
upsPrice=5.86;
boxSheetsBonus = 32;
ShippingPriceAlaskaHawai = 19.99;
adaptorShippingPrice = 8.69;
ShippingPriceStr = "$ shipping price";
freeShippingPrice = "Free Shipping";
extraShippingCost = false;

function ChangeQty(objId,dir,price)
{
    obj=document.getElementById(objId);
    objHF=document.getElementById(objId+"HF");
   
    if (dir=='up')
    {
        if (obj.value<99)
        {
            obj.value++;
            objHF.value++;
        }
    }
    else
    {
        if (obj.value>0)
        {
            obj.value--;
            objHF.value--;
        }
    }

    if ((objId == "sheetsQty") && ((obj.value>0) && (obj.value<3))) {
        if (dir == 'up') {
            obj.value = 3;
            objHF.value = 3;
        }
        else {
            obj.value = 0;
            objHF.value = 0;
        }
    }

    UpdateBuyData();
}
function ChangeQtyAlt(objId,dir,price)
{
    obj=document.getElementById(objId);
    objHF=document.getElementById(objId+"HF");
   
    if (dir=='up')
    {
        if (obj.value<99)
        {
            obj.value++;
            objHF.value++;
        }
    }
    else
    {
        if (obj.value>0)
        {
            obj.value--;
            objHF.value--;
        }
    }

    if ((objId == "sheetsQty") && ((obj.value>0) && (obj.value<3))) {
        if (dir == 'up') {
            obj.value = 3;
            objHF.value = 3;
        }
        else {
            obj.value = 0;
            objHF.value = 0;
        }
    }

    UpdateBuyDataAlt();
	
}

function UpdateBuyDataAlt() {
	
	totalPriceObj=document.getElementById("totalPrice");
	
    totalPriceHFObj=document.getElementById("totalPriceHF");
	
	myFleaTrapQtyObj = document.getElementById("myFleaTrapQty").value;
    sheetsQtyObj = document.getElementById("sheetsQty").value;
    boxQtyObj = document.getElementById("boxQty").value;
    adaptorQtyObj = document.getElementById("adaptorQty").value;

    myFleaTrapTotalHFObj = document.getElementById("myFleaTrapTotalHF");
    sheetsTotalHFObj = document.getElementById("sheetsTotalHF");
    boxTotalHFObj = document.getElementById("boxTotalHF");
    adaptorTotalHFObj = document.getElementById("adaptorTotalHF");
    bonusSheetsHFObj = document.getElementById("bonusSheetsHF");
    shippingPriceHFObj = document.getElementById("shippingPriceHF");
    adaptorShippingPriceHFObj = document.getElementById("adaptorShippingPriceHF");
	


    UpsCbObj = document.getElementById("UpsCb");
    
    myFleaTrapPrice=(Math.floor(myFleaTrapQtyObj/2)*fleaTrapPriceTwo)+((myFleaTrapQtyObj%2)*fleaTrapPriceOne);
    sheetsQtyObjPrice=(Math.floor(sheetsQtyObj/5)*sheetsPriceFive)+((sheetsQtyObj%5)*sheetsPriceOne);
    boxQtyObjPrice = boxQtyObj * boxPrice;
    adaptorQtyObjPrice = adaptorQtyObj * adaptorPrice;
    adaptorTotalHFObj.value = adaptorQtyObjPrice.toFixed(2);

    if (myFleaTrapQtyObj == 0 && sheetsQtyObj == 0 && boxQtyObj == 0 && adaptorQtyObj > 0) {
        adaptorQtyObjPrice = adaptorQtyObjPrice + adaptorShippingPrice;
        adaptorShippingPriceHFObj.value = adaptorShippingPrice;
    }
    else
        adaptorShippingPriceHFObj.value = 0;

    AdditionalShippingPrice = 0;
	
	
	 if ((document.getElementById("ShippingCountry").value == "US" & document.getElementById("ShippingState").value != '') | document.getElementById("ShippingCountry").value == "CA")
	 {
		 if (document.getElementById("ShippingCountry").value == "US" && (document.getElementById("ShippingState").value == "AK" | document.getElementById("ShippingState").value == "HI"))
			{
				extraShippingCost=true;
				AdditionalShippingPrice = AdditionalShippingPrice + ShippingPriceAlaskaHawai;
			}
	 }
	 else if  (document.getElementById("Country").value == "US" && (document.getElementById("State").value == "AK" | document.getElementById("State").value == "HI"))
	    {
				extraShippingCost=true;
				AdditionalShippingPrice = AdditionalShippingPrice + ShippingPriceAlaskaHawai;
		}
	
	if (UpsCbObj.checked)
	    AdditionalShippingPrice = AdditionalShippingPrice + upsPrice;

    myFleaTrapTotalHFObj.value = myFleaTrapPrice;
    sheetsTotalHFObj.value = sheetsQtyObjPrice;
    boxTotalHFObj.value = boxQtyObjPrice;
	
	totalPriceObj.innerHTML = (myFleaTrapPrice + sheetsQtyObjPrice + boxQtyObjPrice + adaptorQtyObjPrice + AdditionalShippingPrice).toFixed(2);
    totalPriceHFObj.value=totalPriceObj.innerHTML;
	
	$("#shipping").val((myFleaTrapPrice + sheetsQtyObjPrice + boxQtyObjPrice + adaptorQtyObjPrice + AdditionalShippingPrice).toFixed(2));
    
    bonusSum=boxQtyObj*boxSheetsBonus;
    document.getElementById("bonusSheets").innerHTML = bonusSum;
    bonusSheetsHFObj.value = bonusSum;
	document.getElementById("sheetsQtyHF").value = parseInt(document.getElementById("sheetsQty").value) + bonusSum;

    var ShippingPrice = document.getElementById("ShippingPrice");

    if (myFleaTrapQtyObj == 0 && sheetsQtyObj == 0 && boxQtyObj == 0 && adaptorQtyObj > 0) {
        ShippingPrice.innerHTML = (Number(adaptorShippingPrice) + Number(AdditionalShippingPrice)).toFixed(2) + ShippingPriceStr;
        shippingPriceHFObj.value = (Number(adaptorShippingPrice) + Number(AdditionalShippingPrice)).toFixed(2) + ShippingPriceStr;
    }
    else {
        ShippingPrice.innerHTML = (AdditionalShippingPrice == 0 ? freeShippingPrice : Number(AdditionalShippingPrice).toFixed(2) + ShippingPriceStr);
        shippingPriceHFObj.value = (AdditionalShippingPrice == 0 ? freeShippingPrice : Number(AdditionalShippingPrice).toFixed(2) + ShippingPriceStr);
    }
	
	//PAYPAL
	
	if($("#ShippingAddress").val() == "")
	{
		$("#paypal_address1").val($("#Address").val());
	} else {
		$("#paypal_address1").val($("#ShippingAddress").val());
	}
	if($("#ShippingCity").val() == "")
	{
		$("#paypal_city").val($("#City").val());
	} else {
		$("#paypal_city").val($("#ShippingCity").val());
	}
	if($("#ShippingCountry").val() == "")
	{
		$("#paypal_country").val($("#Country").val());
	} else {	
		$("#paypal_country").val($("#ShippingCountry").val());
	}
	if($("#ShippingState").val() == "")
	{
		$("#paypal_state").val($("#State").val());
	} else {
		$("#paypal_state").val($("#ShippingState").val());	
	}
	if($("#ShippingState").val() == "")
	{
		$("#paypal_zip").val($("#Zip").val());
	} else {	
		$("#paypal_zip").val($("#ShippingZip").val());
	}
	$("#paypal_first_name").val($("#firstName").val());
	$("#paypal_last_name").val($("#lastName").val());
	$("#paypal_email").val($("#Email").val());
	
	//SIMPLE
	$("#simple_firstname").val($("#firstName").val());
	$("#simple_lastname").val($("#lastName").val());
	$("#simple_email").val($("#Email").val());
	
	if (document.getElementById("promoCb").checked)
	    $("#simple_promoCb").val($("#promoCb").val());
	else
	    $("#simple_promoCb").val("");
	    
	if (UpsCbObj.checked)
	    $("#simple_UpsCb").val($("#UpsCb").val());
	else
	    $("#simple_UpsCb").val("");
	
		//Billing Address
	$("#simple_address").val($("#Address").val());
	$("#simple_city").val($("#City").val());
	$("#simple_zip").val($("#Zip").val());
	$("#simple_country").val($("#Country").val());
	$("#simple_state").val($("#State").val());
		//Shipping Address
	$("#simple_shippingaddress").val($("#ShippingAddress").val());
	$("#simple_shippingcity").val($("#ShippingCity").val());
	$("#simple_shippingzip").val($("#ShippingZip").val());
	$("#simple_shippingcountry").val($("#ShippingCountry").val());
	$("#simple_shippingstate").val($("#ShippingState").val());
	
	$("#simple_addresstype").val($("#AddressType").val());
	
	
	//PAYPAL
	itemCount = 0;	
	$("#paypalOutput").html("");
	if(myFleaTrapQtyObj > 0)
	{
		itemCount++;
		addItemToPaypal("myFleaTrap",myFleaTrapQtyObj,(myFleaTrapPrice/myFleaTrapQtyObj).toFixed(2),itemCount);
	}
	if(sheetsQtyObj > 0)
	{
		itemCount++;
		addItemToPaypal("Adhesive Sheets",sheetsQtyObj,(sheetsQtyObjPrice/sheetsQtyObj).toFixed(2),itemCount);
	} 
	if(boxQtyObj>0)
	{
		itemCount++;
		addItemToPaypal("myFleaTrap Box",boxQtyObj,boxPrice,itemCount);
	} 
	if(adaptorQtyObj>0)
	{
		itemCount++;		
		addItemToPaypal("Switching AC adaptor 6V",adaptorQtyObj,adaptorPrice,itemCount);
	} 
	if(extraShippingCost)
	{
		itemCount++;		
		addItemToPaypal("Shipping to Alaska or Hawaii",1,ShippingPriceAlaskaHawai,itemCount);
	}
	if (UpsCbObj.checked)
	{
		itemCount++;		
		addItemToPaypal("UPS Shipping",1,upsPrice,itemCount);
	}
	return true;
}
function addItemToPaypal(name,quantity,amount,index)
{
	$("#paypalOutput").append('<input type="hidden" name="item_name_'+index+'" value="'+name+'"/>');
	$("#paypalOutput").append('<input type="hidden" name="amount_'+index+'" value="'+amount+'"/>');
	$("#paypalOutput").append('<input type="hidden" name="quantity_'+index+'" value="'+quantity+'"/>');
}

function UpdateBuyData() {
	totalPriceObj=document.getElementById("totalPrice");
    totalPriceHFObj=document.getElementById("totalPriceHF");
	
	myFleaTrapQtyObj = document.getElementById("myFleaTrapQty").value;
    sheetsQtyObj = document.getElementById("sheetsQty").value;
    boxQtyObj = document.getElementById("boxQty").value;
    adaptorQtyObj = document.getElementById("adaptorQtyObj").value;

    myFleaTrapTotalHFObj = document.getElementById("myFleaTrapTotalHF");
    sheetsTotalHFObj = document.getElementById("sheetsTotalHF");
    boxTotalHFObj = document.getElementById("boxTotalHF");
    adaptorTotalHFObj = document.getElementById("adaptorTotalHF");
    bonusSheetsHFObj = document.getElementById("bonusSheetsHF");
    shippingPriceHFObj = document.getElementById("shippingPriceHF");
    adaptorShippingPriceHFObj = document.getElementById("adaptorShippingPriceHF");

    UpsCbObj = document.getElementById("UpsCb");
    
    myFleaTrapPrice=(Math.floor(myFleaTrapQtyObj/2)*fleaTrapPriceTwo)+((myFleaTrapQtyObj%2)*fleaTrapPriceOne);
    sheetsQtyObjPrice=(Math.floor(sheetsQtyObj/5)*sheetsPriceFive)+((sheetsQtyObj%5)*sheetsPriceOne);
    boxQtyObjPrice = boxQtyObj * boxPrice;
    adaptorQtyObjPrice = adaptorQtyObj * adaptorPrice;
    adaptorTotalHFObj.value = adaptorQtyObjPrice.toFixed(2);

    if (myFleaTrapQtyObj == 0 && sheetsQtyObj == 0 && boxQtyObj == 0 && adaptorQtyObj > 0) {
        adaptorQtyObjPrice = adaptorQtyObjPrice + adaptorShippingPrice;
        adaptorShippingPriceHFObj.value = adaptorShippingPrice;
    }
    else
        adaptorShippingPriceHFObj.value = 0;

    AdditionalShippingPrice = 0;
	
	if ((document.getElementById("ShippingCountry").value == "US" & document.getElementById("ShippingState").value != '') | document.getElementById("ShippingCountry").value == "Canada")
	{
		if (document.getElementById("ShippingCountry").value == "US" && (document.getElementById("ShippingState").value == "Alaska" | document.getElementById("ShippingState").value == "Hawaii"))
			AdditionalShippingPrice = AdditionalShippingPrice + ShippingPriceAlaskaHawai;
	}
	else if  (document.getElementById("Country").value == "US" && (document.getElementById("State").value == "Alaska" | document.getElementById("State").value == "Hawaii"))
	    AdditionalShippingPrice = AdditionalShippingPrice + ShippingPriceAlaskaHawai;
	
	if (UpsCbObj.checked)
	    AdditionalShippingPrice = AdditionalShippingPrice + upsPrice;

    myFleaTrapTotalHFObj.value = myFleaTrapPrice;
    sheetsTotalHFObj.value = sheetsQtyObjPrice;
    boxTotalHFObj.value = boxQtyObjPrice;
	
	totalPriceObj.innerHTML = (myFleaTrapPrice + sheetsQtyObjPrice + boxQtyObjPrice + adaptorQtyObjPrice + AdditionalShippingPrice).toFixed(2);
    totalPriceHFObj.value=totalPriceObj.innerHTML;
    
    bonusSum=boxQtyObj*boxSheetsBonus;
    document.getElementById("bonusSheets").innerHTML = bonusSum;
    bonusSheetsHFObj.value = bonusSum;
	document.getElementById("sheetsQtyHF").value = parseInt(document.getElementById("sheetsQty").value) + bonusSum;

    var ShippingPrice = document.getElementById("ShippingPrice");

    if (myFleaTrapQtyObj == 0 && sheetsQtyObj == 0 && boxQtyObj == 0 && adaptorQtyObj > 0) {
        ShippingPrice.innerHTML = (Number(adaptorShippingPrice) + Number(AdditionalShippingPrice)).toFixed(2) + ShippingPriceStr;
        shippingPriceHFObj.value = (Number(adaptorShippingPrice) + Number(AdditionalShippingPrice)).toFixed(2) + ShippingPriceStr;
    }
    else {
        ShippingPrice.innerHTML = (AdditionalShippingPrice == 0 ? freeShippingPrice : Number(AdditionalShippingPrice).toFixed(2) + ShippingPriceStr);
        shippingPriceHFObj.value = (AdditionalShippingPrice == 0 ? freeShippingPrice : Number(AdditionalShippingPrice).toFixed(2) + ShippingPriceStr);
    }
}

function CountryHandler(obj, cbId) {
  return true;
}

function checkFormConfirm() {
        document.getElementById("SendForm").submit();
}
function checkForm() {
    if (document.getElementById("firstName").value == "") {
        alert("Insert first name");
        FocusAndSelectFieldOnError("firstName");
    }
    else if (document.getElementById("lastName").value == "") {
        alert("Insert last name");
        FocusAndSelectFieldOnError("lastName");
    }
    else if (document.getElementById("Email").value == "") {
        alert("Insert email");
        FocusAndSelectFieldOnError("Email");
    }
    else if (document.getElementById("Address").value == "") {
        alert("Insert address");
        FocusAndSelectFieldOnError("Address");
    }
    else if (document.getElementById("City").value == "") {
        alert("Insert city");
        FocusAndSelectFieldOnError("City");
    }
    else if (document.getElementById("Zip").value == "") {
        alert("Insert zip");
        FocusAndSelectFieldOnError("Zip");
    }
    else if ((document.getElementById("Country").value == "US") && (document.getElementById("State").value == "")) {
        alert("Insert state");
        FocusAndSelectFieldOnError("State");
    }
    else if (document.getElementById("CardNumber").value == "") {
        alert("Insert card number");
        FocusAndSelectFieldOnError("CardNumber");
    }
    else
        document.getElementById("SendForm").submit();
}
function checkFormAlt() {
	if (document.getElementById("firstName").value == "") {
        alert("Insert first name");
        FocusAndSelectFieldOnError("firstName");
    }
    else if (document.getElementById("lastName").value == "") {
        alert("Insert last name");
        FocusAndSelectFieldOnError("lastName");
    }
    else if (document.getElementById("Email").value == "") {
        alert("Insert email");
        FocusAndSelectFieldOnError("Email");
    }
    else if (document.getElementById("Address").value == "") {
        alert("Insert address");
        FocusAndSelectFieldOnError("Address");
    }
    else if (document.getElementById("City").value == "") {
        alert("Insert city");
        FocusAndSelectFieldOnError("City");
    }
    else if (document.getElementById("Zip").value == "") {
        alert("Insert zip");
        FocusAndSelectFieldOnError("Zip");
    }
    else if ((document.getElementById("Country").value == "US") && (document.getElementById("State").value == "")) {
        alert("Insert state");
        FocusAndSelectFieldOnError("State");
    }
    else
	{
		UpdateBuyDataAlt();
		
        document.getElementById("SendForm").submit();
		return true;
	}
	return false;
}
function submitFormPaypal()
{
	
	if (document.getElementById("firstName").value == "") {
        alert("Insert first name");
        FocusAndSelectFieldOnError("firstName");
    }
    else if (document.getElementById("lastName").value == "") {
        alert("Insert last name");
        FocusAndSelectFieldOnError("lastName");
    }
    else if (document.getElementById("Email").value == "") {
        alert("Insert email");
        FocusAndSelectFieldOnError("Email");
    }
    else if (document.getElementById("Address").value == "") {
        alert("Insert address");
        FocusAndSelectFieldOnError("Address");
    }
    else if (document.getElementById("City").value == "") {
        alert("Insert city");
        FocusAndSelectFieldOnError("City");
    }
    else if (document.getElementById("Zip").value == "") {
        alert("Insert zip");
        FocusAndSelectFieldOnError("Zip");
    }
    else if ((document.getElementById("Country").value == "US") && (document.getElementById("State").value == "")) {
        alert("Insert state");
        FocusAndSelectFieldOnError("State");
    }
    else
	{
		UpdateBuyDataAlt();
		if($("#quantity_1").val() <= 0)
		{
			$("#quantity_1").remove();
		}
		if($("#quantity_2").val() <= 0)
		{
			$("#quantity_2").remove();
		}
		if($("#quantity_3").val() <= 0)
		{
			$("#quantity_3").remove();
		}
		if($("#quantity_4").val() <= 0)
		{
			$("#quantity_4").remove();
		}
		if($("#UpsCb").val() != 1)
		{
			$("#upsShippingName").remove();
			$("#upsShipping").remove();
			if(extraShippingCost)
			{
				$("#shippingName").attr( "name", "item_name_5" );
				$("#shippingAmount").attr( "name", "amount_5" );
			} else {		
				$("#shippingName").remove();
				$("#shippingAmount").remove();
			}
		} else {
			if(!extraShippingCost) {		
				$("#shippingName").remove();
				$("#shippingAmount").remove();
			}
		}	
		document.getElementById("SendFormPaypal").submit();
		return true;
	}
	return false;
}

function FocusAndSelectFieldOnError(FieldName) {
    try {
        document.getElementById(FieldName).focus();
        document.getElementById(FieldName).select();
    }
    catch (err) { };
}
