//var ups_fee = 26.99;
var ups_fee = 0;
var BankWireFee = 25;
var UPS_VALUE = 0;
var DUTIES_TAXES = 0;
var COUNTRY_NAME = '';
var COUNTRY_ID = 0;
var POBOX_NOT_ALLOWED = 0;
var ORIGINALPPI = 0;
var ORIGINALHANDLING = 0;
var ORIGINALSHIPPING = 0;
var PRIORITY_SHIPPING = 0;
var ORIGINAL_PRIORITY_SHIPPING = 0;
// arrDisableAllDutiesAndTaxes is the array of Partners and Countries for which Duties and Taxes are not applicable
//var arrDisableAllDutiesAndTaxes = new Array('shoenet','lilbrown','ryocigarette', 'bnbtobacco', 9, 31, 87, 141, 174, 179, 226, 239, 259, 266, 267, 278, 279);
var trDisplay = 'inline';
var tdDisplay = 'inline';
var CA_SALES_TAX = 0;
var ALL_DUTIES_TAXES = 0; // Landed Cost for LA mail
var BILLING_COUNTRY_ID = 0;
var BILLING_COUNTRY = '';
var CURRENCY_RATE = 0;
var CURRENCY_ABV = 0;
var CURRENCY_CODE = '';
var PAYMENT_OPTION = 0;
var DISABLE_DUTIES_TAXES = 0;
var DISABLE_PR_SHIPPING = 0;
var CC_TYPE = 0;
var LOGGED_IN = false;
var BILLING_COUNTRIES_LST = '';
var PREV_PAYMENT_OPTION = '0';
var SHIPPING_COUNTRIES_LST = '';
var HAZMAT_FEE = 0;
var ISHAZARDOUS = false;
var CANADA_MSG = '<p align="justify" style="padding-left:8px; padding-right:8px;"><b>STANDARD shipping to Canada includes upgraded shipping from our warehouse to your doorstep (2 - 5 business day service). Brokerage fees will not be assessed on your order but Duties and Taxes may still be due. Average Transit Time: 5 - 14 business days</b></p><p align="justify" style="padding-left:8px; padding-right:8px;"><b>PRIORITY shipping to Canada will ship from our warehouse to your doorstep in 1 - 2 business days and includes an upgrade to 2 - 3 day shipping from the store to our warehouse. Brokerage fees will not be assessed on your order but Duties and Taxes may still be due. Average Transit Time: 3 - 5 days</b></p>';
var DUTIES_TAXES_MSG = '';
if (navigator.appName == 'Netscape')
{
	trDisplay = 'table-row';
	tdDisplay = 'table-cell';
}
else if (navigator.appName == 'Opera')
{
	trDisplay = '';
}
function setFocus(obj)
{
	document.getElementById(obj).focus();	
}
function showPasswordField(show)
{
	setFocus('username');
	document.getElementById('rowEmail2').style.display = show ? 'none' : trDisplay;
	document.getElementById('rowPw2').style.display    = show ? 'none' : trDisplay;
}

function doRemActions()
{
	document.getElementById('Password').value = document.getElementById('pwd').value;
	document.getElementById('signInArea').style.display = 'none';
	//setBillingCountry();
	sendCart();
	setShipTo();
	LOGGED_IN = true;
	//doZoneEffects(document.getElementById('Zone').value);
	setPaymentOptions();
	setCountries();
	setSameAsBillingCheckBox();
	setPOBoxMsg();
}
function setPOBoxMsg()
{
	if(document.getElementById('tdPOBox'))
	{
		if(POBOX_NOT_ALLOWED == 1)
			document.getElementById('tdPOBox').style.display = tdDisplay;
		else
			document.getElementById('tdPOBox').style.display = 'none';
	}
}
function setSameAsBillingCheckBox()
{
	if(document.getElementById('trSameAsBilling'))
	{
		if(BILLING_COUNTRY_ID == COUNTRY_ID) // show same as billing checkbox
			document.getElementById('trSameAsBilling').style.display = trDisplay;
		else
		{
			document.getElementById('trSameAsBilling').style.display = 'none';
			document.getElementById('ShipToSame').checked= false;
		}
	}
}
function setCountries()
{
	if(document.getElementById('tdBillingCountry'))
		document.getElementById('tdBillingCountry').innerHTML = BILLING_COUNTRY;
	if(document.getElementById('tdShippingCountry'))
		document.getElementById('tdShippingCountry').innerHTML = COUNTRY_NAME;
}
function changeDestination()
{
	document.getElementById('Zone').value = document.getElementById('CountryShippingDD').value;
}
function showSignInArea()
{
	if (!isCartOk()) return false;
	if (!isZoneOk()) return false;
	document.getElementById('signInArea').style.display = 'inline';
	document.getElementById('beginCheckoutBtn').style.display = 'none';
	setFocus('username');
}

function continueUser()
{
	if (!isCartOk()) return false;
	if (!isZoneOk()) return false;
	if (!IsEmailOk(document.getElementById('username'))) return false;	
	if (document.getElementById('exCust').checked)
	{
		if (!IsPasswordOk(document.getElementById('pwd'))) return false;
		loginUser();
	}
	else
	{
		if (!areLoginEmailsSame()) return false;
		if (!IsPasswordOk(document.getElementById('pwd'), document.getElementById('pwV'))) return false;		
		checkUserValidity();
	}
}

function sendCart()
{
	var cartElements = new Array();
	var arrCartItems = new Array();
	var cartElements = makeCart();
	arrCartItems = cartElements[0];
	cartLength   = cartElements[1];
	sendCartInfo(arrCartItems, cartLength);
}

function makeCart()
{
	var itemRows = parseInt(document.getElementById('itemRows').value);
	var arrItems = new Array();
	var k = 0;
	var itemStore = '';
	var itemDesc = '';
	var itemProduct = '';
	var itemSize = '';
	var itemColor = '';
	var itemWeight = '';
	var itemImg = '';
	var imgHeight = 0;
	var imgWidth = 0;
	var itemQuantity = '';
	var itemPrice = '';
	var itemTotal = '';
	for (var i = 1; i <= itemRows; i++)
	{
		if (document.getElementById('trCart'+i).style.display != 'none')
		{
			itemImg = '';
			tempItemImg = '';
			storeItemImg = '';
			if(document.getElementById('itemStore'+i))
				itemStore = Trim(document.getElementById('itemStore'+i).value);
			itemDesc = Trim(document.getElementById('itemDescription'+i).value);
			itemProduct = Trim(document.getElementById('itemSKU'+i).value);
			itemSize = Trim(document.getElementById('itemSize'+i).value);
			itemColor = Trim(document.getElementById('itemColor'+i).value);
			if(document.getElementById('itemWeight'+i))									   
				itemWeight = Trim(document.getElementById('itemWeight'+i).value);
			if(document.getElementById('itemImg'+i))									   
				itemImg = Trim(document.getElementById('itemImg'+i).value);			
			if(document.getElementById('storeItemImg'+i))									   
				storeItemImg = Trim(document.getElementById('storeItemImg'+i).value);
			if(document.getElementById('itemImgHeight'+i))									   
				imgHeight = Trim(document.getElementById('itemImgHeight'+i).value);			
			if(document.getElementById('itemImgWidth'+i))									   
				imgWidth = Trim(document.getElementById('itemImgWidth'+i).value);			
			if(document.getElementById('tempItemImg'+i))									   
				tempItemImg = Trim(document.getElementById('tempItemImg'+i).value);			
			itemQuantity = Trim(document.getElementById('itemQuantity'+i).value);
			itemPrice = Trim(document.getElementById('itemPrice'+i).value);
			itemTotal = Trim(document.getElementById('itemTotal'+i).value);
			if (!(itemDesc == '' && itemQuantity == '' && itemPrice == ''))
			{
				arrItems['itemStore'+k]    = itemStore;
				arrItems['itemDesc'+k]     = itemDesc;
				arrItems['itemProduct'+k]  = itemProduct;
				arrItems['itemSize'+k]     = itemSize;
				arrItems['itemColor'+k]    = itemColor;
				arrItems['itemWeight'+k]    = itemWeight;
				arrItems['itemImg'+k]      = itemImg;
				arrItems['tempItemImg'+k]  = tempItemImg;
				arrItems['imgHeight'+k]    = imgHeight;
				arrItems['imgWidth'+k]     = imgWidth;
				arrItems['storeItemImg'+k] = storeItemImg;
				arrItems['itemQuantity'+k] = itemQuantity;
				arrItems['itemPrice'+k]    = itemPrice;
				arrItems['itemTotal'+k]    = itemTotal;
				k++;
			}
		}
	}
	return Array(arrItems, k);
}

function resetLoginForm()
{
	document.getElementById('pwd').value = '';	
	document.getElementById('pwV').value = '';
}

function changePaymentOption(value)
{
	PAYMENT_OPTION = value.split('|')[0];
	CC_TYPE = value.split('|')[1];
	hideAll("paymentOption_");
	displayAll("paymentOption_" + PAYMENT_OPTION);
	if (PAYMENT_OPTION == '3')
	{
		document.getElementById('trBWFee').style.display = trDisplay;
		document.getElementById('BankWireFee').value = Currency(BankWireFee);
	}
	else
	{
		document.getElementById('trBWFee').style.display = 'none';
		document.getElementById('BankWireFee').value = 0;
	}
	if(document.getElementById('Zone').value != '')
		calculateTotal();
}
function doZoneEffects(value)
{
	var country = '';
	if (value != '')
	{
		COUNTRY_NAME = value.split('|')[0];
		COUNTRY_ID = value.split('|')[1];
		UPS_VALUE = value.split('|')[2];
		ORIGINALSHIPPING = value.split('|')[2];
		DUTIES_TAXES = value.split('|')[3];
		POBOX_NOT_ALLOWED = value.split('|')[8];
		UPSFEE = value.split('|')[9];
		DISABLE_DUTIES_TAXES = value.split('|')[10];
		PRIORITY_SHIPPING = value.split('|')[11];
		ORIGINAL_PRIORITY_SHIPPING = value.split('|')[11];
		DISABLE_PR_SHIPPING = value.split('|')[12];
		if(UPSFEE != '')
			ups_fee = parseFloat(UPSFEE);
		else
			ups_fee = parseFloat(document.getElementById('default_upsFee').value);
		document.getElementById('tdDestMsg').innerHTML = 'Shipping to '+COUNTRY_NAME;
	}
	else
		document.getElementById('tdDestMsg').innerHTML = '';
/*
	if (document.getElementById('customerID'))
	{
		setSafTPay();
		setCountryS(COUNTRY_ID);
	}
*/	
	getCountryPPI();
	getCountryHandling();
	getCountryShipping();
	getCountryPrShipping();
	disableDuties(COUNTRY_NAME);
}
function disableDuties()
{
	document.getElementById('dutiesAndTaxesChkbx').disabled = false;
	var calTotal = true;
	if (arguments.length > 1) calTotal = arguments[1];
	var partner = document.getElementById('Partner').value;
	var priority = parseInt(document.getElementById('priority').value);
	var x;
	var disable = false;
	if(COUNTRY_ID == '266')
		var DUTIES_TAXES_MSG = 'Duties and Taxes may not be pre-paid to Nigeria. We apologize for any inconvenience';		
	else
		var DUTIES_TAXES_MSG = 'All shipments to your country will be shipped via US Post Office. Duties and taxes cannot be pre-paid.';
	var msg1 = 'Duties and Taxes may not be prepaid to your country. We apologize for any inconvenience.';
	
	var arrReturn = checkDisableVal(calTotal, DUTIES_TAXES_MSG);
	if(arrReturn[1] != '')
		DUTIES_TAXES_MSG = arrReturn[1];
	disable = arrReturn[0];
	if(disable)
	{		
		document.getElementById('dutiesAndTaxesChkbx').value = 0;
		document.getElementById('dutiesAndTaxesChkbx').disabled = true;
	}
	else
	{		
		document.getElementById('dutiesAndTaxesChkbx').value = 0;
		document.getElementById('dutiesAndTaxesChkbx').disabled = false;
	}
	
	if (priority)
	{
		checkDisablePrShipping();
		if (COUNTRY_ID == '279' || COUNTRY_ID == '278' || COUNTRY_ID == '239')
		{
			document.getElementById('dutiesAndTaxesChkbx').value = 0;
			document.getElementById('dutiesAndTaxesChkbx').disabled = true;
		}
	}
	if (disable)
	{
		document.getElementById('ExpS_standard_priority').value = 0;
		if (COUNTRY_ID == '9' || COUNTRY_ID == '226')
			showTxt(3, msg1);
		else
		{
			if(COUNTRY_ID != '267')
				showTxt(3, DUTIES_TAXES_MSG);
		}
	}
	else
	{
		if (COUNTRY_ID == '40')
		{
			showTxt(4);
		}
		else
		{
			document.getElementById('trTxt').style.display = 'none';
			document.getElementById('dvTxt').innerHTML = '&nbsp;';
		}
	}
	if (calTotal)
		calculateTotal();
}
function checkDisablePrShipping()
{
	var strCountries = document.getElementById('countryDisablePrShip').value;
	strCountries = ','+strCountries+',';
	if(strCountries.indexOf(','+COUNTRY_ID+',') >= 0)
	{
		DISABLE_PR_SHIPPING = '1';
	}
	if(DISABLE_PR_SHIPPING == '1')
		disablePriority(true);
	else
		disablePriority(false);	
}
function checkDisableVal(calTotal)
{
	var myArray = new Array(2);
	myArray[0] = false;
	myArray[1] = '';
	var strCountries = document.getElementById('countryDutiesTaxes').value;
	strCountries = ','+strCountries+',';
	if(document.getElementById('disableDutiesTaxes').value == '1')
	{
		myArray[0] = true;
		myArray[1] = 'Landingcost(Duties and Taxes) can not be prepaid for this Partner.';
		return myArray;
	}
	
	if(strCountries.indexOf(','+COUNTRY_ID+',') >= 0)
	{
		myArray[0] = true;
		myArray[1] = '';
		return myArray;
	}
	if(DISABLE_DUTIES_TAXES == '1')		
	{
		myArray[0] = true;
		myArray[1] = '';
		return myArray;
	}
	if(COUNTRY_ID == 12 && calTotal)
	{
		var audTotal = parseFloat(convCurrOtherThanCartTotal(document.getElementById('sub_total_h').value,0));
		if (audTotal < '1000')
		{
			myArray[0] = true;
			myArray[1] = 'Orders under AUD 1000 are excluded from duties and taxes in Australia.';
			return myArray;
		}
	}
	else if(COUNTRY_ID == 224 && calTotal)
	{
		var aedTotal = parseFloat(convCurrOtherThanCartTotal(document.getElementById('sub_total_h').value,0));
		if (aedTotal < '1000')
		{
			myArray[0] = true;
			myArray[1] = 'Orders under AED 1000 are excluded from duties and taxes in the UAE';
			return myArray;
		}
	}
	/*else if(COUNTRY_ID == 108 && calTotal)
	{
		var jpyTotal = parseFloat(convCurrOtherThanCartTotal(document.getElementById('sub_total_h').value,0));
		if (jpyTotal < '10000')
		{
			myArray[0] = true;
			myArray[1] = 'Orders under JPY 10,000 are excluded from duties and taxes in Japan';
			return myArray;
		}
	}*/
	else if(COUNTRY_ID == 156 && calTotal)
	{
		var nzdTotal = parseFloat(convCurrOtherThanCartTotal(document.getElementById('sub_total_h').value,0));
		if (nzdTotal < '400')
		{
			myArray[0] = true;
			myArray[1] = 'Orders under NZD 400 are excluded from duties and taxes in New Zealand';
			return myArray;
		}
	}
	else if(COUNTRY_ID == 189 && calTotal)
	{
		var sgdTotal = parseFloat(convCurrOtherThanCartTotal(document.getElementById('sub_total_h').value,0));
		if (sgdTotal < '400')
		{
			myArray[0] = true;
			myArray[1] = 'Orders under SGD 400 are excluded from duties and taxes in Singapore';
			return myArray;
		}
	}
	else if(COUNTRY_ID == 40 && calTotal)
	{
		var canadianTotal = parseFloat(convCurrOtherThanCartTotal(document.getElementById('sub_total_h').value,0));
		DUTIES_TAXES_MSG =  CANADA_MSG + '<br >';
		if (canadianTotal < '20')
		{
			DUTIES_TAXES_MSG = CANADA_MSG + '<b>Orders under CAD 20 are excluded from duties and taxes in Canada.</b>';
			myArray[0] = true;
			myArray[1] = DUTIES_TAXES_MSG;
			return myArray;
		}
	}
	return myArray;
}
function disablePriority(disable)
{	
	if (disable)
	{
		document.getElementById('ExpS_standard_priority').value = 0;
		document.getElementById('ExpS_standard_priority').disabled = true;
	}
	else
		document.getElementById('ExpS_standard_priority').disabled = false;		
}
/*
function showSafTPay(show)
{
	
	document.getElementById('tdSafTPayRadio').style.display = show ? tdDisplay : 'none';
	document.getElementById('tdSafTPayText').style.display  = show ? tdDisplay : 'none';
	if (!show)
	{
		document.getElementById('paymentTypeId1').checked = true;
		changePaymentOption(1);
	}
}
-*
/*
function setSafTPay()
{
	if(CURRENCY_ID == 3 || CURRENCY_ID == 174)
	{
		if (COUNTRY_ID != 0)
		{
			if (COUNTRY_ID == 141 || COUNTRY_ID == 168 || COUNTRY_ID == 13 || COUNTRY_ID == 174)
			{
				showSafTPay(true);
				document.getElementById('paymentTypeId4').style.display = trDisplay;
			}
			else
				showSafTPay(false);
		}
		else
			showSafTPay(false);
	}
}
*/
/*
function setCountryS(countryId)
{
	if (countryId != '')
	{
		//document.getElementById('CountryS').value = countryId;
		//document.getElementById('CountryS').value = COUNTRY_NAME;
		document.getElementById('CountryShippingDD').value = document.getElementById('Zone').value;
		if (document.getElementById('ShipToSame').checked)
		{
			document.getElementById('CountryB').value = document.getElementById('Zone').value;
		}
		document.getElementById('ShippingCountryId').value = countryId;
		document.getElementById('ShippingCountry').value = COUNTRY_NAME;
	}
}
*/
function uncheckSame()
{
	document.getElementById('ShipToSame').checked = false;
}

function setShipTo()
{
	if (document.getElementById('ShipToSame'))	
	{
		if (document.getElementById('ShipToSame').checked)
		{
/*			if (document.getElementById('CountryB') && document.getElementById('Zone'))
				document.getElementById('Zone').value = document.getElementById('CountryB').value;
			if (document.getElementById('CountryShippingDD') && document.getElementById('Zone'))
				document.getElementById('CountryShippingDD').value = document.getElementById('CountryB').value;*/
			if (document.getElementById('FirstNameS') && document.getElementById('FirstNameB')) document.getElementById('FirstNameS').value = document.getElementById('FirstNameB').value;
			if (document.getElementById('LastNameS') && document.getElementById('LastNameB')) document.getElementById('LastNameS').value = document.getElementById('LastNameB').value;
			if (document.getElementById('CompanyS') && document.getElementById('CompanyB')) document.getElementById('CompanyS').value = document.getElementById('CompanyB').value;
			if (document.getElementById('Address1S') && document.getElementById('Address1B')) document.getElementById('Address1S').value = document.getElementById('Address1B').value;
			if (document.getElementById('Address2S') && document.getElementById('Address2B')) document.getElementById('Address2S').value = document.getElementById('Address2B').value;
			if (document.getElementById('CityS') && document.getElementById('CityB')) document.getElementById('CityS').value = document.getElementById('CityB').value;
			if (document.getElementById('StateS') && document.getElementById('StateB')) document.getElementById('StateS').value = document.getElementById('StateB').value;
			if (document.getElementById('ZipS') && document.getElementById('ZipB')) document.getElementById('ZipS').value = document.getElementById('ZipB').value;
			//if (document.getElementById('CountryS')) document.getElementById('CountryS').value = COUNTRY_NAME;
			//doZoneEffects(document.getElementById('CountryB').value);
			//calculateTotal();
		}
	}
}

function calculateCartTotal()
{
	// sub_total is a cart total	
	var itemPrice, itemQuantity, qttyallitems = 0, itemTotal, sub_total = 0;
	var itemRows = parseInt(document.getElementById('itemRows').value);
	for (var i = 1; i <= itemRows; i++)
	{
		document.getElementById('itemQuantity'+i).value = Trim(document.getElementById('itemQuantity'+i).value);
		document.getElementById('itemPrice'+i).value = Trim(document.getElementById('itemPrice'+i).value);
		itemQuantity = 0;
		if (document.getElementById('itemQuantity'+i).value != '' && isDigit(document.getElementById('itemQuantity'+i).value))
			itemQuantity = parseInt(document.getElementById('itemQuantity'+i).value);
		else
			document.getElementById('itemQuantity'+i).value = '';

		itemPrice = 0;
		if (document.getElementById('itemPrice'+i).value != '' && isPrice(document.getElementById('itemPrice'+i)))
		{
			itemPrice = parseFloat(Round(document.getElementById('itemPrice'+i).value));
			document.getElementById('itemPrice'+i).value = itemPrice;
		}
		itemTotal = itemPrice * itemQuantity;

		document.getElementById('itemTotal'+i).value = Currency(itemTotal);

		sub_total += itemTotal;

		if (itemTotal != 0)
			qttyallitems += itemQuantity;
	}

	//=============== DISCOUNT  ================//
	sub_total = checkDiscount(sub_total);	
	//=============== DISCOUNT  ================//

	if (sub_total == 0)
	{
		document.getElementById('sub_total').value = '';
		document.getElementById('sub_total_h').value = '';
	}
	else
	{
		document.getElementById('sub_total').value = Currency(sub_total);
		document.getElementById('sub_total_h').value = sub_total;
	}

	//=============== ADD CA SALES TAX ================//
	CASalesTax();
	//=============== ADD CA SALES TAX ================//

	document.getElementById('qttyallitems').value = qttyallitems;
	if (document.getElementById('Zone').value != '')
	{
		var country = COUNTRY_NAME; //getCountryName(document.getElementById('Zone').value);
		disableDuties(country);
	}
	cnvtCurrency();
}
function CASalesTax()
{
	if(document.getElementById('CurrConvCountry').value != '0')
	{
		if (document.getElementById('ca_sales_tax').value != '' && document.getElementById('ca_sales_tax').value != 0)
		{
			var tax = document.getElementById('ca_sales_tax').value;
			tax = document.getElementById('sub_total_h').value * tax;
			tax = convCurrOtherThanCartTotal(tax, 0);
			document.getElementById('CAPartnerSalesTax').value = Currency(tax);
			if(document.getElementById('tdCATaxAmount'))
				document.getElementById('tdCATaxAmount').innerHTML = CURRENCY_ABV + ' ' + Currency(tax);
	//		sub_total += tax;
		}
	}
}
function checkDiscount(cartTotal)
{
	cartTotal = parseFloat(cartTotal);
	if(document.getElementById('partnerId').value == 192) // All Aboard Toys
	{		
		if(cartTotal >= 200)
		{
			cartTotal = applyDiscount(cartTotal, 10, 1);
			document.getElementById('discountOffer').innerHTML = 'A 10% discount has been applied to your order for purchasing over $200 in merchandise.';
			document.getElementById('discountOffer').style.display = 'inline';
		}
		
	}
	else
	{		
		cartTotal = applyDiscount(cartTotal, document.getElementById('discount').value, document.getElementById('discountType').value);
		if(document.getElementById('discount').value != 0)
			document.getElementById('discountOffer').style.display = 'inline';
	}
	return cartTotal;
}
function applyDiscount(cartTotal, discount, discountType)
{	
	document.getElementById('discount').value = discount; // DISCOUNT
	if(document.getElementById('discountType').value == 1)
		cartTotal = cartTotal - (cartTotal * (document.getElementById('discount').value / 100));			
	else
		cartTotal = cartTotal - discount;	
	return cartTotal;
}
function checkCountryFreeShipping()
{
	var strCountries = document.getElementById('countryFreeShipping').value;
	strCountries = ','+strCountries+',';
	if(strCountries.indexOf(','+COUNTRY_ID+',') >= 0)	
		return true;
	else
		return false;
}
function calculateTotal()
{
	var sub_total = '';
	//var	blnFreeShipping = false; // For Free Shipping in CANADA from Dr Martens.
	if (document.getElementById('sub_total_h').value != '')
		sub_total = parseFloat(document.getElementById('sub_total_h').value);
	else
		return false;
	if (!isZoneOk()) return false;
	
	var blnFreeShipping = checkCountryFreeShipping();  // For Free Shipping in selected Country against particular partner.
	document.getElementById('dutiesAndTax').value = ''; // code for new CheckoutCartCalculations
	var domShipping_std = 0;
//	var domShipping_pri = 39;
	var intHandling_min = document.getElementById('default_intHandling_min').value;
	var intHandling_percent = 0;
//	alert("PPI VALUE = "+document.getElementById('PPI').value);
	var intShipping_ppi = document.getElementById('PPI').value;
	var intShipping_pri_sur = 0; // Priority Surcharge
	var intShipping_max = 500;
	var fees_min = 0;
	
	if(blnFreeShipping)
	{
		var fees_percent = 0;
		var tax = 0;
		if (document.getElementById('fees_percent').value != '')
			fees_percent = 0;
		if (document.getElementById('ca_sales_tax').value != '')
			tax = 0;
		if (document.getElementById('intHandling_min').value != '')
			intHandling_min = 0;
		document.getElementById('PPI').value = 0;
		document.getElementById('default_cpc').value = 0;
	}
	else
	{		
		var tax = document.getElementById('default_ca_sales_tax').value;
		var fees_percent = getFeesRange();
		
		if (document.getElementById('ca_sales_tax').value != '')
			tax = document.getElementById('ca_sales_tax').value;
		if (document.getElementById('intHandling_min').value != '')
			intHandling_min = document.getElementById('intHandling_min').value;
	}
	//alert(intHandling_min);
	if (document.getElementById('ExpS_standard_priority').value == '0' && document.getElementById('dutiesAndTaxesChkbx').value == '1')
		document.getElementById('ExpShipping').value = 2;
	else if (document.getElementById('ExpS_standard_priority').value == '1' && document.getElementById('dutiesAndTaxesChkbx').value == '1')
		document.getElementById('ExpShipping').value = 3;
	else if (document.getElementById('ExpS_standard_priority').value == '1' && document.getElementById('dutiesAndTaxesChkbx').value == '0')
		document.getElementById('ExpShipping').value = 1;
	else
		document.getElementById('ExpShipping').value = 0;
	var ExpShipping = document.getElementById('ExpShipping').value;
		
	//================================= QUESTIONABLE =======================================//
	document.getElementById('Config_IntH_min').value = intHandling_min;	
	document.getElementById('Config_IntH_percent').value = intHandling_percent;	
	document.getElementById('Config_IntS_ppi').value = intShipping_ppi;
	document.getElementById('Config_IntS_pri_sur').value = intShipping_pri_sur;
	document.getElementById('Config_IntS_max').value = intShipping_max;
	document.getElementById('Config_Fees_min').value = fees_min;
	document.getElementById('Config_Fees_percent').value = fees_percent;
	document.getElementById('Config_Tax').value = tax;
	//================================= QUESTIONABLE =======================================//

	var qttyallitems = parseInt(document.getElementById('qttyallitems').value);	
	if(ExpShipping == 1 || ExpShipping == 3)
		var domShipping = PRIORITY_SHIPPING;//domShipping_pri;
	else
		var domShipping = domShipping_std;
	//alert(domShipping);
	// International Handling
	var intHandling = Round(sub_total * intHandling_percent); //sub_total * intHandling_percent;

	if (intHandling < intHandling_min) intHandling = intHandling_min;
	// International Shipping
	
	if(blnFreeShipping)
	{
		var SSurcharge = 0;
		var intShipping_min = 0;
		var intShipping = 0;
	}
	else
	{
		//var SSurcharge = document.getElementById('FreeShipping').value == 1 ? document.getElementById('default_SSurcharge').value : parseFloat(document.getElementById('SSurcharge').value);
		var SSurcharge = applySSurcharge(sub_total);		
		document.getElementById('SSurcharge').value = SSurcharge;
		var intShipping_min = parseFloat(UPS_VALUE) + parseFloat(UPS_VALUE * document.getElementById('default_fuelSurUPS').value);		
		var intShipping = parseFloat(intShipping_min) + parseFloat(SSurcharge) + parseFloat(qttyallitems) * parseFloat(intShipping_ppi);
		intShipping = Round(intShipping); // intShipping;
	}
	if (intShipping > intShipping_max) intShipping = intShipping_max;

	// IC fees
	var fees = Round(sub_total * fees_percent); // sub_total * fees_percent;
	if (fees < fees_min) fees = fees_min;
	
	//========================= FOR EXTERNAL VALUES ======================//
	var extDomShipping = 0;
	var cpcExternalDomShip = 0;
	if (document.getElementById('external_domesticshipping') && document.getElementById('external_domesticshipping').value != '' && document.getElementById('external_domesticshipping').value > 0)
	{
		extDomShipping = parseFloat(document.getElementById('external_domesticshipping').value);
		if(document.getElementById('externaldomesticshipping'))
		{
			document.getElementById('externaldomesticshipping').value = convCurrOtherThanCartTotal(extDomShipping, 1);
		}
		cpcExternalDomShip = Round(extDomShipping * parseFloat(document.getElementById('default_cpc').value));
		
		//extDomShipping = ext_dom_shipping + parseFloat(cpcExternalDomShip);
	}
	//========================= FOR EXTERNAL VALUES ======================//	
	//===================== CALCULATE CPC VALUE ====================//
	if(blnFreeShipping)
		var cpc = 0;
	else
	{
		var cpc = (parseFloat(sub_total) + parseFloat(domShipping) + parseFloat(intHandling) + parseFloat(intShipping_min) + parseFloat(SSurcharge) + parseFloat(document.getElementById('AddSSurcharge').value) + parseFloat(intShipping_ppi * qttyallitems) + parseFloat(fees)) * parseFloat(document.getElementById('default_cpc').value);
		cpc = parseFloat(cpc) + parseFloat(cpcExternalDomShip);
		//var cpc = (parseFloat(sub_total) + parseFloat(domShipping) + parseFloat(intHandling) + parseFloat(intShipping_min) + parseFloat(SSurcharge) + parseFloat(document.getElementById('AddSSurcharge').value) + parseFloat(intShipping_ppi * qttyallitems) + parseFloat(fees)) * parseFloat(document.getElementById('default_cpc').value);
	}
	document.getElementById('CPC_Mail').value = Round(cpc);

	//===================== CALCULATE CPC VALUE ====================//

	var grandTotal_before_fees = parseFloat(sub_total) + parseFloat(domShipping) + parseFloat(intHandling) + parseFloat(intShipping) + parseFloat(cpc) + parseFloat(document.getElementById('AddSSurcharge').value);
	// Display International Shipping (fees incl.)
	var shipping = parseFloat(domShipping) + parseFloat(intHandling) + parseFloat(intShipping) + parseFloat(fees) + parseFloat(cpc) + parseFloat(document.getElementById('AddSSurcharge').value);
	var shippingDutiesAndTax = 0;	
	if(ExpShipping == 2 || ExpShipping == 3)
	{
		//if(!blnFreeShipping)
		shippingDutiesAndTax = calculateDuties();		
		document.getElementById('dutiesAndTax').value = convCurrOtherThanCartTotal(shippingDutiesAndTax, 1);
		document.getElementById('Duties').value = convCurrOtherThanCartTotal(shippingDutiesAndTax, 0);
		document.getElementById('CPC_Mail').value = parseFloat(document.getElementById('CPC_Mail').value) + ALL_DUTIES_TAXES * parseFloat(document.getElementById('default_cpc').value);
	}
	else
		document.getElementById('Duties').value = 0;

	if (ExpShipping == 1 || ExpShipping == 3)
	{
		document.getElementById('Shipping_priority').value = Currency(shipping);
		document.getElementById('Shipping_standard').value = '';
	}
	else
	{
		document.getElementById('Shipping_standard').value = Currency(shipping);
		document.getElementById('Shipping_priority').value = '';
	}
	
	
			
	if(document.getElementById('CmbnDomShipHndling').value!=0)
	{
		var sumdomshp=parseFloat(shipping)+parseFloat(extDomShipping);
		document.getElementById('Shipping').value	= convCurrOtherThanCartTotal(sumdomshp, 1);
		document.getElementById('Shipping_h').value = convCurrOtherThanCartTotal(shipping, 0); //shi
	}
	else
	{
		if(blnFreeShipping == true && shipping == 0)
			document.getElementById('Shipping').value = 'Free';
		else
			document.getElementById('Shipping').value = convCurrOtherThanCartTotal(shipping, 1);
		document.getElementById('Shipping_h').value = convCurrOtherThanCartTotal(shipping, 0); //shipping;
	}
	// Grand Total
	var BankWireFee = parseFloat(undoCurrency(document.getElementById('BankWireFee').value));
	var grandTotal = grandTotal_before_fees + fees + BankWireFee + parseFloat(shippingDutiesAndTax);

	//========================= FOR EXTERNAL VALUES ======================//
	grandTotal = grandTotal + extDomShipping;
	grandTotal = convCurrOtherThanCartTotal(grandTotal, 0);
	grandTotal = Round(parseFloat(grandTotal) + parseFloat(document.getElementById('CAPartnerSalesTax').value));
	
	if(ISHAZARDOUS)
	{
		document.getElementById('hazardousFee').value = convCurrOtherThanCartTotal(document.getElementById('hazmatFee').value, 1);	
		HAZMAT_FEE = convCurrOtherThanCartTotal(document.getElementById('hazmatFee').value, 0);
		grandTotal = grandTotal + parseFloat(HAZMAT_FEE);
	}
	document.getElementById('GrandTotal').value = CURRENCY_ABV + ' ' + grandTotal.toFixed(2);
	document.getElementById('GrandTotal_h').value = grandTotal;

	// Fees breakdown for order email
	document.getElementById('DomShipping').value = domShipping;
	document.getElementById('IntHandling').value = intHandling;
	document.getElementById('IntShipping').value = intShipping;
	document.getElementById('fees').value = fees;	

	printDTMsg();
	calculateDuties();
}
function applySSurcharge(cartTotal)
{
	var SSurcharge = document.getElementById('FreeShipping').value == 1 ? document.getElementById('default_SSurcharge').value : parseFloat(document.getElementById('SSurcharge').value);
	if(document.getElementById('partnerId').value == 245 || document.getElementById('partnerId').value == 255)
	{
		if(parseFloat(cartTotal) >= 200)
			SSurcharge = 0;
	}
	return SSurcharge;
}
function chkCurrency()
{
	if(document.getElementById('CurrConvCountry').value == 0)
	{
		alert('Please Select Billing Currency.');
		document.getElementById('Zone').value = '';
		return false;
	}
	else
	{
		document.getElementById('trDutiesAndTaxes').style.display = trDisplay;
//		document.getElementById('beginCheckoutBtn').style.display = trDisplay;
		doZoneEffects(document.getElementById('Zone').value); 
		calculateTotal();
	}
	
}
function calculateDuties()
{
	var sub_total = '';
	if (document.getElementById('sub_total_h').value != '')
		sub_total = parseFloat(document.getElementById('sub_total_h').value);
	else
		return false;
	var duties_percent = parseFloat(document.getElementById('duties_percent').value);
	if (DUTIES_TAXES != '' && DUTIES_TAXES != 0)
		duties_percent = DUTIES_TAXES;
	var duties = Number(sub_total) * duties_percent + ups_fee;
	
	var cpcAmount = Round(duties * document.getElementById('default_cpc').value);
	duties += cpcAmount;
	document.getElementById('hdCPCValue').value = cpcAmount;
	ALL_DUTIES_TAXES = duties - cpcAmount;
	return duties;	
}
function setCurrencyValues()
{
	var val = document.getElementById('CurrConvCountry').value;
	if (val != '0')
	{
		var currVal = val.split('|');
		BILLING_COUNTRY_ID = parseInt(currVal[1]);
		BILLING_COUNTRY = currVal[0];
		CURRENCY_RATE = parseFloat(currVal[6]);
		CURRENCY_ABV = currVal[5];
		CURRENCY_CODE = currVal[7];
		if(document.getElementById('ddPaymentType').value != '1|VISA' && document.getElementById('ddPaymentType').value != '1|MASTER' && document.getElementById('ddPaymentType').value != '4|0')
		{
			if(document.getElementById('ddPaymentType').value != '1|JCB' || BILLING_COUNTRY_ID != '108')
			{
				CURRENCY_RATE = 1;
				CURRENCY_ABV = 'USD';
				CURRENCY_CODE = 840;
			}
		}
		txtColor = '#898593';
		currencyMsg = 'Your order will be processed in '+CURRENCY_ABV;
	}
	else
	{
		BILLING_COUNTRY_ID = 0;
		CURRENCY_RATE = 0;
		CURRENCY_ABV = 0;
		CURRENCY_CODE = '';
		BILLING_COUNTRY = '';
		txtColor = '#898593';
		currencyMsg = '';
		document.getElementById('Shipping').value = '';
		document.getElementById('Shipping_h').value = '';
		document.getElementById('GrandTotal').value = '';
		document.getElementById('GrandTotal_h').value = '';
		document.getElementById('Duties').value = '';
		document.getElementById('CurrConversion').value = '';
	}
	document.getElementById('tdSubTotalInUSD').style.color = txtColor;
	document.getElementById('sub_total').style.color = txtColor;
	document.getElementById('tdCurrencyMsg').innerHTML = currencyMsg;
}

function setPaymentOptions()
{
	if(LOGGED_IN)
	{
		if(PAYMENT_OPTION == '1') //CC
		{
			document.getElementById('paymentOption_1').style.display = tdDisplay;
			document.getElementById('paymentOption_2').style.display = 'none';
			document.getElementById('paymentOption_3').style.display = 'none';
			document.getElementById('paymentOption_4').style.display = 'none';
			document.getElementById('paymentOption_6').style.display = 'none';
			document.getElementById('tdPaymentMethod').innerHTML = 'Your Payment Method: ' + document.getElementById('ddPaymentType').options[document.getElementById('ddPaymentType').selectedIndex].text;

			//setSafTPay();
		}
		else if(PAYMENT_OPTION == '2') // Paypal
		{
			document.getElementById('paymentOption_1').style.display = 'none';
			document.getElementById('paymentOption_2').style.display = tdDisplay;
			document.getElementById('paymentOption_3').style.display = 'none';
			document.getElementById('paymentOption_4').style.display = 'none';
			document.getElementById('paymentOption_6').style.display = 'none';
		}
		else if(PAYMENT_OPTION == '3') // Bank Transfer
		{
			document.getElementById('paymentOption_1').style.display = 'none';
			document.getElementById('paymentOption_2').style.display = 'none';
			document.getElementById('paymentOption_3').style.display = tdDisplay;
			document.getElementById('paymentOption_4').style.display = 'none';
			document.getElementById('paymentOption_6').style.display = 'none';
		}
		else if(PAYMENT_OPTION == '4') // SafetyPay
		{
			document.getElementById('paymentOption_1').style.display = 'none';
			document.getElementById('paymentOption_2').style.display = 'none';
			document.getElementById('paymentOption_3').style.display = 'none';
			document.getElementById('paymentOption_4').style.display = tdDisplay;
			document.getElementById('paymentOption_6').style.display = 'none';
		}
		else if(PAYMENT_OPTION == '6') // Money Bookers
		{
			document.getElementById('paymentOption_1').style.display = 'none';
			document.getElementById('paymentOption_2').style.display = 'none';
			document.getElementById('paymentOption_3').style.display = 'none';
			document.getElementById('paymentOption_4').style.display = 'none';
			document.getElementById('paymentOption_6').style.display = tdDisplay;
		}
	}
}

function cnvtCurrency()
{
	var nVal;
	nVal = parseFloat(document.getElementById('sub_total_h').value);
	if (!nVal) return false;
	var resultV = nVal * CURRENCY_RATE;
	if (BILLING_COUNTRY_ID > 0)
	{
		document.getElementById('CurrConversion').value = CURRENCY_ABV + ' ' + Currency(resultV);
		if(document.getElementById('Zone').value != '')
			calculateTotal();
		document.getElementById('trShippingDestination').style.display = trDisplay;
		document.getElementById('trShippingMethod').style.display = trDisplay;
	}
	if (document.getElementById('ddPaymentType').value != '')
	{
		document.getElementById('trBillingCurrency').style.display = trDisplay;
	}
	else
	{
		document.getElementById('trBillingCurrency').style.display = 'none';
		document.getElementById('trShippingDestination').style.display = 'none';
		document.getElementById('trShippingMethod').style.display = 'none';
		document.getElementById('trDutiesAndTaxes').style.display = 'none';
		//document.getElementById('beginCheckoutBtn').style.display = 'none';
		document.getElementById('CurrConversion').value = '';
		document.getElementById('dutiesAndTax').value = '';
		document.getElementById('Duties').value = 0;
		document.getElementById('Shipping').value = '';
		document.getElementById('Shipping_h').value = 0;
		document.getElementById('GrandTotal').value = '';
		document.getElementById('GrandTotal_h').value = 0;
		document.getElementById('Zone').value = '';
	}
}
function convCurrOtherThanCartTotal(value, concatABV)
{	
	var nVal = parseFloat(value);
	if (!nVal) return 0;
	var resultV = Currency(nVal * CURRENCY_RATE);
	if(concatABV == 1)
		resultV = CURRENCY_ABV + ' ' + resultV;
	return resultV;
}
function isZoneOk()
{
	if (PAYMENT_OPTION == '' || PAYMENT_OPTION == '0')
	{
		alert ("Please choose your 'Payment Method'!");
		document.getElementById('ddPaymentType').focus();
		return false;
	}
	if (document.getElementById('CurrConvCountry').value == '0' || CURRENCY_ABV == '0' || BILLING_COUNTRY_ID == '0')
	{
		alert ("Please choose your 'Billing Country'!");
		document.getElementById('CurrConvCountry').focus();
		return false;
	}
	if (document.getElementById('Zone').value == '' || COUNTRY_ID == '0')
	{
		alert ("Please choose your 'Shipping Destination'!");
		//document.getElementById('Zone').focus();
		return false;
	}
	return true;
}

function isCartOk()
{
	var itemRows = parseInt(document.getElementById('itemRows').value);
	var i;
	if (document.getElementById('qttyallitems').value == 0)
	{
		alert ('There are no items in your list yet!\nPlease fill out "Store", "Item", "Price" and "Quantity" for atleast one item.');
		var flag = false;
		for (i = 1; i <= itemRows; i++)
		{
			if (document.getElementById('trCart'+i).style.display != 'none')
			{
				flag = true;
				break;
			}
		}
		if (flag)
		{
			if (Trim(document.getElementById('itemStore'+i).value) == '')
				document.getElementById('itemStore'+i).focus();
			else if (Trim(document.getElementById('itemDescription'+i).value) == '')
				document.getElementById('itemDescription'+i).focus();
			else if (Trim(document.getElementById('itemQuantity'+i).value) == '')
				document.getElementById('itemQuantity'+i).focus();
			else if (Trim(document.getElementById('itemPrice'+i).value) == '')
				document.getElementById('itemPrice'+i).focus();
		}
		else
			addRow();
		return false;
	}
	var itemRows = parseInt(document.getElementById('itemRows').value);
	for (i = 1; i <= itemRows; i++)
	{
		var store = document.getElementById('itemStore'+i);
		var description = document.getElementById('itemDescription'+i);
		var quantity = document.getElementById('itemQuantity'+i);
		var price = document.getElementById('itemPrice'+i);
		if ( !(description.value == '' && quantity.value == '' && price.value == '') )
		{
			if (Trim(description.value) == '')
			{
				alert ('Please provide Item!');
				description.focus();
				return false;
			}
			if (Trim(quantity.value) == '')
			{
				alert ('Please provide Quantity!');
				quantity.focus();
				return false;
			}
			if (!isDigit(quantity.value))
			{
				alert ('Please provide correct value for Quantity!');
				quantity.focus();
				return false;
			}
			if (Trim(price.value) == '')
			{
				alert ('Please provide Price!');
				price.focus();
				return false;
			}
			if (!isFloat(price.value))
			{
				alert ('Please provide correct value for Price!');
				price.focus();
				return false;
			}
		}
	}
	return true;
}

function addRow()
{
	var itemRows = parseInt(document.getElementById('itemRows').value) + 1;
	var objTable = document.getElementById('tblCart');
	var objRow = objTable.insertRow(-1);
	objRow.id = 'trCart'+itemRows;
	objRow.height = '10';
	var objTd1 = objRow.insertCell(0);
	//var objTd2 = objRow.insertCell(1);
	var objTd3 = objRow.insertCell(1);
	var objTd4 = objRow.insertCell(2);
	var objTd5 = objRow.insertCell(3);
	var objTd6 = objRow.insertCell(4);
	var objTd7 = objRow.insertCell(5);
	var objTd8 = objRow.insertCell(6);
	var objTd9 = objRow.insertCell(7);
	var objTd10 = objRow.insertCell(8);
	objTd1.align = 'center';
	objTd7.style.display = 'none';
	objTd8.align = 'right';
	objTd9.align = 'right';
	objTd9.className = 'tableHeading style14';
	objTd9.noWrap = true;
	objTd10.align = 'right';
	objTd10.className = 'tableHeading style14';
	objTd10.noWrap = true;
	objTd1.innerHTML = '<input type="checkbox" id="ckBoxCart'+itemRows+'" />';
	//objTd2.innerHTML = '<input type="text" name="itemStore'+itemRows+'" id="itemStore'+itemRows+'" value="'+partnerStore+'" class="clsTextBox" size="30" readonly />';
	objTd3.innerHTML = '<input type="text" name="itemDescription'+itemRows+'" id="itemDescription'+itemRows+'" class="clsTextBox" size="38" />';
	objTd4.innerHTML = '<input type="text" name="itemSKU'+itemRows+'" id="itemSKU'+itemRows+'" class="clsTextBox" size="15" />';
	objTd5.innerHTML = '<input type="text" name="itemSize'+itemRows+'" id="itemSize'+itemRows+'" class="clsTextBox" size="10" />';
	objTd6.innerHTML = '<input type="text" name="itemColor'+itemRows+'" id="itemColor'+itemRows+'" class="clsTextBox" size="10" />';
	objTd7.innerHTML = '<input type="text" name="itemWeight'+itemRows+'" id="itemWeight'+itemRows+'" class="clsTextBox" size="10" />';
	objTd8.innerHTML = '<input type="text" name="itemQuantity'+itemRows+'" id="itemQuantity'+itemRows+'" class="clsTextBox" size="5" onChange="calculateCartTotal();" />';
	objTd9.innerHTML = '&nbsp;$ <input type="text" name="itemPrice'+itemRows+'" id="itemPrice'+itemRows+'" class="clsTextBox" size="6" onChange="calculateCartTotal();" />';
	objTd10.innerHTML = '&nbsp;$ <input type="text" name="itemTotal'+itemRows+'" id="itemTotal'+itemRows+'" class="clsTextBox" size="11" readonly />';
	document.getElementById('itemDescription'+itemRows).focus();
	//document.getElementById('delCartRows').innerHTML = '<input type="button" value="Delete Items" class="clsButton" onclick="delRows();" />';
	document.getElementById('itemRows').value = itemRows;
}

function delRows()
{
	var itemRows = parseInt(document.getElementById('itemRows').value);
	var flag = false;
	var cdnDelAll = true; // Condition for all the rows deleted
	var firstTime = true;
	for (var i = 1; i <= itemRows; i++)
	{
		var objRow   = document.getElementById('trCart'+i);		// Cart Row Object
		var objCkBox = document.getElementById('ckBoxCart'+i);	// Cart Checkbox Object
		if (objRow.style.display != 'none' && objCkBox.checked)
		{
			if (firstTime)
			{
				if (confirm('Are you sure you want to delete the selected item(s)?'))
					delThisRow(i);
				else
					return false;
				firstTime = false;
			}
			else
				delThisRow(i);
			flag = true;
		}
		if (objRow.style.display != 'none')
			cdnDelAll = false;
	}
	if (cdnDelAll)
		document.getElementById('delCartRows').innerHTML = '&nbsp;';
	if (!flag)
	{
		alert ('Please select atleast one item to delete!');
		return false;
	}
}

function delThisRow(id)
{
	//document.getElementById('itemStore'+id).value = '';
	document.getElementById('itemDescription'+id).value = '';
	document.getElementById('itemSKU'+id).value = '';
	document.getElementById('itemSize'+id).value = '';
	document.getElementById('itemColor'+id).value = '';
	document.getElementById('itemWeight'+id).value = '';
	document.getElementById('itemQuantity'+id).value = '';
	document.getElementById('itemPrice'+id).value = '';
	document.getElementById('itemTotal'+id).value = '';
	document.getElementById('trCart'+id).style.display = 'none';
	document.getElementById('ckBoxCart'+id).checked = false;
	chkHazardous();
	calculateCartTotal();	
}

function MM_openBrWindow(theURL, winName, features)
{
  window.open(theURL, winName, features);
}

function isCheckoutFormOk()
{
	var form = document.getElementById('frmCheckout');
	if (!isCartOk()) return false;
	if (!isZoneOk()) return false;
	if (!IsAddressInfoOk(form)) return false;
	if (!areEmailsSame()) return false;
	if (!paymentOptionsOk()) return false;
	if (!itemOptionsOk()) return false;
	if (!document.getElementById('TermsAndConditions').checked)
	{
		alert ("Please confirm that you have read and understood our 'Terms and Conditions'!");
		document.getElementById('TermsAndConditions').focus();
		return false;
	}
	if (document.getElementById('PartnerTermsAndConditions'))
	{
		if (!document.getElementById('PartnerTermsAndConditions').checked)
		{
			alert ("Please confirm that you have read and understood our 'Terms and Conditions'!");
			document.getElementById('PartnerTermsAndConditions').focus();
			return false;
		}	
	}
	return true;
}

function validFormNSendOrder()
{
	if (!isCheckoutFormOk()) return false;
	if (confirm('Are you sure you want to place an order?'))
		sendOrder();	// This function is in js/ordersent_ajax.js
	return false;
}

function submitPaypalForm()
{
	if (!isCheckoutFormOk()) return false;
	if (confirm('Are you sure you want to place an order through PayPal?'))
		sendPaypalOrder();	// This function is in js/ordersent_ajax.js
}

function areEmailsSame()
{
	if (document.getElementById('custEmailConf'))
	{
		if (document.getElementById('custEmailConf').value == '')
		{
			alert ('Please provide Confirm Email Address!');
			document.getElementById('custEmailConf').focus();
			return false;
		}
		if (document.getElementById('custEmail').value != document.getElementById('custEmailConf').value)
		{
			alert ('Emails do not match!');
			document.getElementById('custEmailConf').focus();
			return false;
		}
	}
	return true;
}

function areLoginEmailsSame()
{
	if (document.getElementById('emailIdConf').value == '')
	{
		alert ('Please provide Confirm Email Address!');
		document.getElementById('emailIdConf').select();
		return false;
	}
	if (document.getElementById('username').value != document.getElementById('emailIdConf').value)
	{
		alert ('Emails do not match!');
		document.getElementById('emailIdConf').select();
		return false;
	}
	return true;
}

function itemOptionsOk()
{
	var QACount  = parseInt(document.getElementById('QACount').value);
	var QACountJ = parseInt(document.getElementById('QACountJ').value);
	var k = -1;
	for (var i = 0; i <= QACount; i++)
	{
		var flag = false;
		for (var j = 0; j <= QACountJ && !flag; j++)
		{
			if (document.getElementById('OrderQAs'+i+'_'+j).checked)
			{
				flag = true;
				k++;
			}
		}
	}
	if (k != QACount)
	{
		alert ('Please answer all the questions!');
		return false;
	}
	return true;
}

function paymentOptionsOk()
{
	var form = document.getElementById('frmCheckout');
	if (PAYMENT_OPTION == '1')
	{
		if (!IsCreditCardOk(form)) return false;
	}
	/*
	else if (document.getElementById('paymentTypeId4').checked)
	{
		if (!valdateSAFTPAY(form)) return false;
	}*/
	return true;
}
/*
function valdateSAFTPAY(form)
{
	if (form.CurrConvCountry.value != 3 && form.CurrConvCountry.value != 54 && form.CurrConvCountry.value != 122 && form.CurrConvCountry.value != 104)
	{		
		alert ('The currency selected is not accepted with SAF T PAY.');
		form.CurrConvCountry.focus();
		return false;
	}
	return true;
}*/
function undoCurrency(str)
{
	return str.replace(/\,/g, '');
}

function callContinueUserFunc(obj)
{
	obj.onkeypress = contUserFunc;
}

function contUserFunc(e)
{
	if (!e)
	{
		if (window.event)
			e = window.event;
		else
			return;
	}
	
	if (typeof( e.which ) == 'number')
	{
		//NS 4, NS 6+, Mozilla 0.9+, Opera
		e = e.which;
	}
	else if (typeof( e.keyCode ) == 'number')
	{
		//IE, NS 6+, Mozilla 0.9+
		e = e.keyCode;
	}
	else if (typeof( e.charCode ) == 'number')
	{
		//also NS 6+, Mozilla 0.9+
		e = e.charCode;
	}
	else
		return;
	
	if (e == 13)
		continueUser();
}

function printDTMsg()
{
	var msgInc = 'not'; // msgInc = message with duties & taxes inclusive OR not...
	//if (document.getElementById('ExpS_standard_Tax').checked || document.getElementById('ExpS_priority_Tax').checked)
	if(document.getElementById('dutiesAndTaxesChkbx').value == 1)
		msgInc = '';
	var msg = '(Duties and Taxes are ' + msgInc + ' included)';
//	document.getElementById('includeDTMsg').innerHTML = msg;
}
//----Money Booker funciton

function submitMoneyBookerForm()
{
	if (!isCheckoutFormOk()) return false;
	if (confirm('Are you sure you want to place an order through Money Boooker?'))
	   sendMoneyBookerOrder();	// This function is in js/ordersent_ajax.js
}
//google checkout

function submitGoogleCheckoutForm(){
  if (!isCheckoutFormOk()) return false;
  if (confirm('Are you sure you want to place an order through Google Checkout ?'))
	   sendGoogleCheckOutOrder();// This function is in js/ordersent_ajax.js	

}
function showTxt(cldFrm, msg)
{
	document.getElementById('trTxt').style.display = trDisplay;
 	var str = '';//'<p style="padding-right:4px;">';
	if(cldFrm == 1)
		str += 'International Checkout will get your items to your doorstep as quickly as possible.</p><br /><p align="justify" style="padding-right:4px;"><b>*STANDARD SHIPPING:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arrives to your address in approximately 8-20 business days. </p><p align="justify" style="padding-right:4px;"><b>*PRIORITY SHIPPING:</b> arrives to your address in approximately 4-10 business days.</p><p align="justify" style="padding-right:4px;">Transit times are estimated and are not guaranteed. We are not responsible for delays by customs or by the store.</p>';
	else if(cldFrm == 2)
		str += 'For your convenience, International Checkout provides the option to pre-pay Duties and Taxes.*</p><p align="justify" style="padding-right:4px;">If you choose to pre-pay Duties and Taxes, you may avoid customs delays and we guarantee that you will not be asked to pay anything when your order arrives.</p><p align="justify" style="padding-right:4px;">If you do not choose to pre-pay Duties and Taxes, you will be responsible for Duties, Taxes and any related charges when your order arrives in your country.</p><p align="justify" style="padding-right:4px;">*Duties and Taxes are calculated and charged by customs in your country.</p>';
	else if(cldFrm == 3)
		str += msg;// + '</p>';
	else if(cldFrm == 4)
		str += CANADA_MSG;
	document.getElementById('dvTxt').innerHTML = str;

}
function getCountryHandling()
{	
	if(document.getElementById('countryIntHandling').value != '')
	{
		var arr = document.getElementById('countryIntHandling').value.split(',');		
		var arrCountryHandling = new Array();
		var j = 1;
		for(i = 0; i < arr.length; i = i+2)
		{
			arrCountryHandling[arr[i]] = arr[j];
			j = j+2;
		}
		if(arrCountryHandling[COUNTRY_ID])
		{
			if(ORIGINALHANDLING == 0)
				ORIGINALHANDLING = document.getElementById('intHandling_min').value;
			document.getElementById('intHandling_min').value = arrCountryHandling[COUNTRY_ID];
		}
		else
		{
			if(ORIGINALHANDLING != 0)
				document.getElementById('intHandling_min').value = ORIGINALHANDLING;
		}
	}
}

function getCountryPPI()
{
	if(document.getElementById('countryPPI').value != '')
	{
		var arr = document.getElementById('countryPPI').value.split(',');
		var arrCountryPPI = new Array();
		var j = 1;
		for(i = 0; i < arr.length; i = i+2)
		{
			arrCountryPPI[arr[i]] = arr[j];
			j = j+2;
		}
		if(arrCountryPPI[COUNTRY_ID])
		{
			if(ORIGINALPPI == 0)
				ORIGINALPPI = document.getElementById('PPI').value;
			document.getElementById('PPI').value = arrCountryPPI[COUNTRY_ID];
		}
		else
		{
			if(ORIGINALPPI != 0)
				document.getElementById('PPI').value = ORIGINALPPI;
		}
	}
}
function getCountryShipping()
{
	if(document.getElementById('countryShipping').value != '')
	{
		var arr = document.getElementById('countryShipping').value.split(',');
		var arrShipping = new Array();
		var j = 1;
		for(i = 0; i < arr.length; i = i+2)
		{
			arrShipping[arr[i]] = arr[j];
			j = j+2;
		}
		if(arrShipping[COUNTRY_ID])
			UPS_VALUE = arrShipping[COUNTRY_ID];
		else
			UPS_VALUE = ORIGINALSHIPPING;
	}
}
function getCountryPrShipping()
{
	if(document.getElementById('priShipping').value != '' && parseFloat(document.getElementById('priShipping').value) > 0)
		PRIORITY_SHIPPING = document.getElementById('priShipping').value;
	else
		PRIORITY_SHIPPING = ORIGINAL_PRIORITY_SHIPPING;
	if(document.getElementById('countryPriShipping').value != '' && document.getElementById('countryPriShipping').value != 0)
	{
		var arr = document.getElementById('countryPriShipping').value.split(',');
		var arrPrShipping = new Array();
		var j = 1;
		for(i = 0; i < arr.length; i = i+2)
		{
			arrPrShipping[arr[i]] = arr[j];
			j = j+2;
		}
		if(arrPrShipping[COUNTRY_ID])
			PRIORITY_SHIPPING = arrPrShipping[COUNTRY_ID];
	}
}
function getFeesRange()
{
	var fees_percent = document.getElementById('default_fees_percent').value;
	if(document.getElementById('fees_percent').value != '')
		fees_percent = document.getElementById('fees_percent').value;		
	if (document.getElementById('fees_range').value != '')
	{
		var arrFeesRange = document.getElementById('fees_range').value.split(';');
		for(i=0; i < arrFeesRange.length; i++)
		{
			var arr = arrFeesRange[i].split(':');
			var range = arr[0].split('-');
			var comparison = '<=';
			if(range[1])
			{
				if (parseFloat(document.getElementById('sub_total_h').value) <= parseFloat(range[1]))
				{
					fees_percent = arr[1]/100;
					break;
				}
			}
			else
			{
				if (parseFloat(document.getElementById('sub_total_h').value) > parseFloat(range[0]))
				{
					fees_percent = arr[1]/100;
					break;
				}
			}

		}
	}
	return fees_percent;
}
function setBillingCountries()
{
	BILLING_COUNTRIES_LST = document.getElementById('dvBCntry').innerHTML;
}
function bCntrsAsPerPaymentOption()
{
	pOption = document.getElementById('ddPaymentType').value.split('|')[0];
/*	if (pOption == '4') // SafetyPay
		document.getElementById('CurrConvCountry').innerHTML = '<option value="0" selected> - Billing Country - </option>' + document.getElementById('saftpaycntryLst').value;
	else if (PREV_PAYMENT_OPTION == '4')
		document.getElementById('CurrConvCountry').innerHTML = BILLING_COUNTRIES_LST;
		*/
	if (pOption == '4') // SafetyPay
	{
		document.getElementById('dvBCntry').innerHTML = '<select name="CurrConvCountry" style="width:180px;" id="CurrConvCountry" class="clsDropDown" onChange="setSameAsBillingCheckBox();setCurrencyValues();cnvtCurrency();CASalesTax();setCountries();"><OPTION value="0" selected> - Billing Country - </OPTION>' + document.getElementById('saftpaycntryLst').value + '</select>';
		document.getElementById('rowSafetyPay').style.display = trDisplay;		
	}
	else if (PREV_PAYMENT_OPTION == '4')
	{
		document.getElementById('dvBCntry').innerHTML = BILLING_COUNTRIES_LST;
		document.getElementById('rowSafetyPay').style.display = 'none';
	}
	PREV_PAYMENT_OPTION = pOption;
}
function setShippingCountries()
{
	SHIPPING_COUNTRIES_LST = document.getElementById('dvSCntry').innerHTML;
}
function chkHazardous()
{
	ISHAZARDOUS = false;
	var itemRows = parseInt(document.getElementById('itemRows').value);	
	for (var i = 1; i <= itemRows; i++)
	{
		if (document.getElementById('trCart'+i).style.display != 'none')
		{
			if(document.getElementById('itemHazardous'+i) && document.getElementById('itemHazardous'+i).value == 1)
			{
				document.getElementById('dvSCntry').innerHTML = '<select name="Zone" style="width:180px;" id="Zone" class="clsDropDown" onChange="chkCurrency();setCountries();setSameAsBillingCheckBox();setPOBoxMsg();setSCntryCanada();"><OPTION value="0" selected> - Shipping Destination - </OPTION>' + document.getElementById('hazmatcntryLst').value + '</select>';
				//document.getElementById('Zone').innerHTML = '<OPTION value="0" selected> - Shipping Destination - </OPTION>' + document.getElementById('hazmatcntryLst').value;				
				ISHAZARDOUS = true;
				document.getElementById('trHazmatFee').style.display = trDisplay;
				break;
			}
		}
	}
	if(!ISHAZARDOUS)
	{
		document.getElementById('trHazmatFee').style.display = 'none';
		document.getElementById('dvSCntry').innerHTML = SHIPPING_COUNTRIES_LST;
		if(document.getElementById('GrandTotal_h').value != '' && document.getElementById('GrandTotal_h').value != 0)
		{
			var newVal = parseFloat(document.getElementById('GrandTotal_h').value - HAZMAT_FEE);
			document.getElementById('GrandTotal').value = CURRENCY_ABV + ' ' + Round(newVal);
		}
	}	
}
function setSCntryCanada()
{	
	/*if(document.getElementById('Zone').value.split('|')[1] == 40)
		showTxt(4);*/
}
function setUPSfee()
{
	ups_fee = parseFloat(document.getElementById('default_upsFee').value);
}