  
   Error     = false;
   var boolDebug = false;
   var strStateCodeChanged = 'N';

function getStateCodeTax(thisForm, thisField)
{
	var strOldSelectedValue = document.forms[0].drpSalesTax[document.forms[0].drpSalesTax.selectedIndex].value;
	document.forms[0].drpSalesTax.selectedIndex = 0;
    for(i=0; i < document.forms[0].drpSalesTax.length; i++) 
	{
		if (document.forms[0].drpSalesTax[i].text.indexOf(thisField[thisField.selectedIndex].value) != -1)
		{
			document.forms[0].drpSalesTax.selectedIndex = -1;
			document.forms[0].drpSalesTax.selectedIndex = i;		
			i = 9999;
		}
	}
	
	if (strOldSelectedValue != document.forms[0].drpSalesTax[document.forms[0].drpSalesTax.selectedIndex].value)
		alert('Please note your tax has changed');
	
	strStateCodeChanged = 'Y';
	processTaxSelection(thisForm, thisField);
	strStateCodeChanged = 'N';
	return false;
}

function synchQtyLblTxt()
{
	//If refresh button is clicked, then txtQuantity shows the user input and lblQuantity shows database
	//This function sets the txt to lbl

        var varElement   = "";
		var varNamePart1 = "dgCheckoutItems__ctl";
		boolRowSelected = false;
		for(var i=0; i < 200; i++)
		{    
			j = i + 2;			
			varElement = varNamePart1 + j + "_lblQuantity";
			var myObj1 = document.getElementById(varElement);			

			varElement = varNamePart1 + j + "_txtQuantity";
			var myObj2 = document.getElementById(varElement);
			
			if (myObj1 && myObj2)
			{
				if (myObj1.innerHTML != myObj2.value)
					myObj2.value = myObj1.innerHTML;
			}		
			else
				i = 9999999;	
		}
}

function updateCartQuantity(thisField)
{
	//This cool loop will tell you all the properties associated with this object
	if (thisField.value == '')
	    thisField.value = '1';
	 
	var decQuantityNew      = parseFloat(thisField.value);
	var decQuantityOld      = 0;
	var decQuantityDifference = 0;   
	var strProcessFieldName = thisField.id.replace('txtQuantity','lblQuantity');
	var myObject = document.getElementById(strProcessFieldName);			
	if (myObject)
	{
	    decQuantityOld     = parseFloat(myObject.innerHTML);

        var decQtyOriginal  = 0;
		strProcessFieldName = thisField.id.replace('txtQuantity','hiddenQtyOriginal');
		var myObjectQO = document.getElementById(strProcessFieldName);			
		if (myObjectQO)
		{			
			decQtyOriginal  = parseFloat(myObjectQO.value);
			if (isNaN(decQtyOriginal))
    			decQtyOriginal = 0;
    	}	    
		
		strProcessFieldName = thisField.id.replace('txtQuantity','hlnkChannelItemID');
		var myObjectItem = document.getElementById(strProcessFieldName);			
		var strChannelItemID = myObjectItem.innerHTML.replace('<b><u><font color="#0000cc"></font></u></b>','');
		alert(strChannelItemID);
		if (strChannelItemID != '' && decQtyOriginal > 0 && decQtyOriginal > decQuantityNew)
		{
			alert('Quantity already purchased cannot be reduced');
			thisField.value = decQtyOriginal;	
			myObject.innerHTML = decQtyOriginal;
		}
		else
		{
			myObject.innerHTML = thisField.value;	
			decQuantityDifference = decQuantityNew - decQuantityOld;				
		}
	}

    var strPriceEach        = '';
	var strProcessFieldName = thisField.id.replace('txtQuantity','lblPriceEach');
	var myObject = document.getElementById(strProcessFieldName);
	if (myObject)
		strPriceEach = myObject.innerHTML;	

	var decPriceEach       = parseFloat(strPriceEach);
	if (isNaN(decPriceEach))
    	decPriceEach    = 0;
    
	var decQuantity       = parseFloat(thisField.value);
	if (isNaN(decQuantity))
		decQuantity    = 0;
    
    var decPriceNew = decPriceEach * decQuantity;
    var decPriceOld = 0;
    var decPriceDifference = 0;
    
	var strProcessFieldName = thisField.id.replace('txtQuantity','lblPrice');
	var myObject = document.getElementById(strProcessFieldName);
	if (myObject)
	{
		decPriceOld = parseFloat(myObject.innerHTML);
		myObject.innerHTML = (decPriceNew * 100) / 100;	
		decPriceDifference = decPriceNew - decPriceOld;	
		myObject.innerHTML = formatAmount(myObject.innerHTML);
		myObject.innerHTML = roundNumber(myObject.innerHTML);
	}

    var decSubTotalValueOld = 0;
	var myObject = document.getElementById('lblSubTotalValue');
	if (myObject)
	{
		decSubTotalValueOld = parseFloat(myObject.innerHTML);
		decSubTotalValueOld = decSubTotalValueOld + decPriceDifference;
		myObject.innerHTML = (decSubTotalValueOld * 100) / 100;
		myObject.innerHTML = formatAmount(myObject.innerHTML);	
		myObject.innerHTML = roundNumber(myObject.innerHTML);
	}

    var decSubTotalQuantity = 0;
	var myObject = document.getElementById('lblSubTotalQuantity');
	if (myObject)
	{
		decSubTotalQuantity = parseFloat(myObject.innerHTML);
		decSubTotalQuantity = decSubTotalQuantity + decQuantityDifference;
		myObject.innerHTML  = decSubTotalQuantity;	
	}

    var decShippingCostAddl = 0;    
	var myObject = document.getElementById("txtShippingCostAdditional");	
	if (myObject)
	{		
		decShippingCostAddl = parseFloat(myObject.value);		
		decShippingCostAddl = decShippingCostAddl * (decSubTotalQuantity - 1);
		decShippingCostAddl = (decShippingCostAddl * 100) / 100;
		myObject = document.getElementById("txtShippingCostAdditionalTotal");
		if (myObject)
		{
			myObject.value  = decShippingCostAddl;	
			myObject.value  = formatAmount(myObject.value);	
		}
	}
    	
    updateTotalCost("thisForm", "thisField");	
	return false;
}

function checkout_onload()
{
    var boolDebug = false;

	//If send invoice is true, then don't PaymentChannels and message to seller, instead message to buyer	
    if (document.forms[0].hiddenSendInvoice.value == "1")		
    {
		var objDiv=MM_findObj('divPaymentChannelShowHide');
		if (boolDebug) {alert("1");};
		if (objDiv)
			objDiv.style.display = 'none';
		
		var objDiv=MM_findObj('divMessageToSellerShowHide');
		if (boolDebug) {alert("2");};
		if (objDiv)
			objDiv.style.display = 'none';
		
		var objDiv=MM_findObj('divMessageToBuyerShowHide');
		if (boolDebug) {alert("3");};
		if (objDiv)
			objDiv.style.display = 'block';
		
		var objDiv=MM_findObj('divSendInvoiceCommandShowHide');
		if (boolDebug) {alert("4");};
		if (objDiv)
			objDiv.style.display = 'block';
		
		var objDiv=MM_findObj('divShippingInfoShowHide');
		if (boolDebug) {alert("5");};
		if (objDiv)
			objDiv.style.display = 'block';				

		var objDiv=MM_findObj('div3rdPartyLogosShowHide');
		if (boolDebug) {alert("62");};
		if (objDiv)
			objDiv.style.display = 'none';								
	}
	else
	{
		var objDiv=MM_findObj('divAddressBillToShowHide');
		if (objDiv)
			objDiv.style.display = 'block';
		
		var objDiv=MM_findObj('divPaymentChannelShowHide');
		if (objDiv)
			objDiv.style.display = 'block';
		
		var objDiv=MM_findObj('divMessageToSellerShowHide');
		if (objDiv)
			objDiv.style.display = 'block';		
		
		var objDiv=MM_findObj('divMessageToBuyerShowHide');
		if (objDiv)
			objDiv.style.display = 'none';

		var objDiv=MM_findObj('divSendInvoiceCommandShowHide');
		if (objDiv)
			objDiv.style.display = 'none';

		var objDiv=MM_findObj('div3rdPartyLogosShowHide');
		if (objDiv)
			objDiv.style.display = 'block';			
		
		var objDiv=MM_findObj('divShippingInfoShowHide');
		if (objDiv)
			objDiv.style.display = 'block';		

		var objDiv=MM_findObj('div3rdPartyLogosShowHide');
		if (boolDebug) {alert("61");};
		if (objDiv)
			objDiv.style.display = 'block';								
		
	}

	//Display this portion if not back from payment gateway, if error this setto -1 else set to +1.
    if (document.forms[0].hiddenPaymentStatus.value == "+1" || document.forms[0].hiddenPaymentStatus.value == "-1")		
    {
		var objDiv=MM_findObj('divPaymentReturnShowHide');
		if (boolDebug) {alert("A");};
		if (objDiv)
			objDiv.style.display = 'block';
    
		var objDiv=MM_findObj('divShippingInfoShowHide');
		if (boolDebug) {alert("B");};
		if (objDiv)
			objDiv.style.display = 'none';
		
		var objDiv=MM_findObj('divSendInvoiceCommandShowHide');
		if (boolDebug) {alert("C");};
		if (objDiv)
			objDiv.style.display = 'none';
		
		var objDiv=MM_findObj('divPaymentChannelShowHide');
		if (boolDebug) {alert("D");};
		if (objDiv)
			objDiv.style.display = 'none';		

		var objDiv=MM_findObj('divMessageToSellerShowHide');
		if (boolDebug) {alert("E");};
		if (objDiv)
			objDiv.style.display = 'none';
		
		var objDiv=MM_findObj('divMessageToBuyerShowHide');
		if (boolDebug) {alert("F");};
		if (objDiv)
			objDiv.style.display = 'none';

		var objDiv=MM_findObj('divMessageShowHide');
		if (boolDebug) {alert("G");};
		if (objDiv)
			objDiv.style.display = 'none';

		var objDiv=MM_findObj('divAddressShipToShowHide');
		if (boolDebug) {alert("H");};
		if (objDiv)
			objDiv.style.display = 'none';

		var objDiv=MM_findObj('divAddressBillToShowHide');
		if (boolDebug) {alert("I");};
		if (objDiv)
			objDiv.style.display = 'none';
		
	}

    var myObject = document.getElementById('drpShippingServiceOptions');
    if ( myObject)
    {
		if (document.forms[0].drpShippingServiceOptions.selectedIndex == -1)
			document.forms[0].drpShippingServiceOptions.selectedIndex = 0;
	}   
	setShippingFee('dummyForm', 'dummyField');
	
	if (boolDebug) {alert("END");};	
}

function checkMode(thisForm, thisField)
{
	//If not in send invoice mode, these values are not changeable
	if (document.forms[0].hiddenSendInvoice.value == '0')
	{
		document.forms[0].txtExpeditedShippingCostAdditional.focus();		
	}
	
	return true;
}

function ValidateCheckout(thisForm, thisField, strMode)
{
		var strMessage = "<BR><UL>";	
		
		if (strMode == "SendInvoice")
		{
			//Qty required
			var myObjectLabel = document.getElementById("lblSubTotalQuantity");			
			if (myObjectLabel.innerHTML == "0")
				strMessage = strMessage + "<LI>"  + arrMessages[61] +  "\n <BR> ";
			
			//Only email is required
			strMessage = strMessage + checkRequiredNew(thisForm.txtEmail  , "lblEmail"   , arrMessages[37], "Y");
		}
		else
		{
			strMessage = strMessage + checkRequiredNew(thisForm.txtPostalCodeBillTo  , "lblPostalCodeBillTo"   , arrMessages[39], "Y");

			var myObject = document.getElementById("txtStateCodeBillTo");			
			if (myObject)
				strMessage = strMessage + checkRequiredNew(thisForm.txtStateCodeBillTo   , "lblStateCodeBillTo"    , arrMessages[62], "Y");

			var myObject = document.getElementById("drpStateCodeBillTo");			
			if (myObject)
				strMessage = strMessage + checkRequiredDrpNew(thisForm.drpStateCodeBillTo   , "lblStateCodeBillTo"    , arrMessages[62], "Y");

			strMessage = strMessage + checkRequiredNew(thisForm.txtCityBillTo        , "lblCityBillTo"         , arrMessages[63], "Y");
			strMessage = strMessage + checkRequiredNew(thisForm.txtAddress1BillTo    , "lblAddress1BillTo"     , arrMessages[64], "Y");
			strMessage = strMessage + checkRequiredNew(thisForm.txtFullNameBillTo    , "lblFullNameBillTo"     , arrMessages[65], "Y");

			strMessage = strMessage + checkRequiredNew(thisForm.txtPostalCodeShipTo  , "lblPostalCodeShipTo"   , arrMessages[39], "Y");		
			
			var myObject = document.getElementById("txtStateCodeShipTo");			
			if (myObject)
				strMessage = strMessage + checkRequiredNew(thisForm.txtStateCodeShipTo   , "lblStateCodeShipTo"    , arrMessages[62], "Y");

			var myObject = document.getElementById("drpStateCodeShipTo");			
			if (myObject)
				strMessage = strMessage + checkRequiredDrpNew(thisForm.drpStateCodeShipTo   , "lblStateCodeShipTo"    , arrMessages[62], "Y");

			strMessage = strMessage + checkRequiredNew(thisForm.txtCityShipTo        , "lblCityShipTo"         , arrMessages[63], "Y");
			strMessage = strMessage + checkRequiredNew(thisForm.txtAddress1ShipTo    , "lblAddress1ShipTo"     , arrMessages[64], "Y");
			strMessage = strMessage + checkRequiredNew(thisForm.txtFullNameShipTo    , "lblFullNameShipTo"     , arrMessages[65], "Y");
			
		    strMessage = strMessage + checkRequiredNew(thisForm.txtEmail             , "lblEmail"              , arrMessages[37], "Y");			
		}
		
		var myObject = document.getElementById("divMessage");			
		if (strMessage == "<BR><UL>")
		{
	    	myObject.style.display = 'block';
			myObject.innerHTML = "Validation Successful, please wait while sending invoice" + "<BR>";
			myObject.style.display = 'block';
			myObject.style.color = 'blue';
			myObject.style.backgroundColor='white';
			myObject.style.fontWeight = 'bold';
			myObject.style.textAlign = 'center';	    	
		}
		else
		{
			if (strMode == "SendInvoice")
			{
				myObject.innerHTML = strMessage + "<BR>";
				myObject.style.display = 'block';
				myObject.style.color = 'red';			
			}
		}
		
		if (strMessage == "<BR><UL>")
		{
		    //if (!(confirm(arrMessages[59]))
		    if (document.forms[0].hiddenSendInvoice.value != '1')
			{				
				if (!(confirm("Please click OK to proceed. Once you complete the payment in PayPal, please click on Return to Merchant button !!")))
				{
					return false;
				}
				else	    		    	
		    		return true;	    
			}
	    }
	    else
			return false;		
}

function setBillToFromShipTo(thisForm, thisField)
{
		
		if (thisField.checked == true)
		{
		thisForm.txtPostalCodeBillTo.value = thisForm.txtPostalCodeShipTo.value ;
		
		var myObject = document.getElementById("txtStateCodeShipTo");
		if (myObject)	  
			thisForm.txtStateCodeBillTo.value  = thisForm.txtStateCodeShipTo.value  ;  

		var myObject = document.getElementById("drpStateCodeShipTo");
		if (myObject)	  
			thisForm.drpStateCodeBillTo.selectedIndex  = thisForm.drpStateCodeShipTo.selectedIndex  ;  
			
		thisForm.drpCountryBillTo.selectedIndex  = thisForm.drpCountryShipTo.selectedIndex  ;  
		
		thisForm.txtCityBillTo.value       = thisForm.txtCityShipTo.value       ;  
		thisForm.txtAddress1BillTo.value   = thisForm.txtAddress1ShipTo.value   ;  
		thisForm.txtFullNameBillTo.value   = thisForm.txtFullNameShipTo.value   ;  
		}
		return true;	    
		
}

function checkInvoicePassed(thisForm, thisField)
{
	if (!(thisForm.hiddenInvoiceID.value == "0"))
	{
		alert(arrMessages[55]);
		document.forms[0].txtFullNameShipTo.focus();		
	}

}

function setShippingFee(thisForm, thisField)
{
		var strSelectedText  = "";
		var strShippingCost  = "";

		var myObjectSSO       = document.getElementById("drpShippingServiceOptions");					
		if (myObjectSSO)
		{
		    if (document.forms[0].drpShippingServiceOptions.length > 0)
		    {
				strSelectedText      = document.forms[0].drpShippingServiceOptions[document.forms[0].drpShippingServiceOptions.selectedIndex].text
				var intCostStartPosn = strSelectedText.indexOf("(") + 1;
				var intCostEndPosn   = strSelectedText.indexOf(")");
				var intCostLength    = intCostEndPosn - intCostStartPosn;
				strShippingCost      = strSelectedText.substring(intCostEndPosn,intCostStartPosn);
			}
		}
				
		if (strShippingCost  == "")
		    strShippingCost  = "0";
		    
		document.forms[0].txtShippingServiceCost.value = strShippingCost;

		var intCostStartPosn = strSelectedText.indexOf(":") + 1;
		var intCostEndPosn   = strSelectedText.indexOf(" :");
		var intCostLength    = intCostEndPosn - intCostStartPosn;
		var strShippingCostAddl  = strSelectedText.substring(intCostEndPosn,intCostStartPosn);

		if (strShippingCostAddl == "")
		   strShippingCostAddl  = "0";
	
		document.forms[0].txtShippingCostAdditional.value = strShippingCostAddl;

		var strSalesTaxPercent = 0;
		var myObjectSalesTax  = document.getElementById("drpSalesTax");
		if (myObjectSalesTax)
		{			
			strSalesTaxPercent  = myObjectSalesTax[myObjectSalesTax.selectedIndex].value;			
			document.forms[0].txtSalesTaxPercent.value = strSalesTaxPercent;					
		}


		//Calculate subtotal value
		var myObjectLabel       = document.getElementById("lblSubTotalValue");				
		var strSubTotalValue    = parseFloat(myObjectLabel.innerHTML);
		if (strSubTotalValue   == "")
		    strSubTotalValue    = "0";
		
		//Calculate subtotal value
		var myObjectLabel       = document.getElementById("lblSubTotalQuantity");					
		var strSubTotalQuantity = parseFloat(myObjectLabel.innerHTML);
		if (strSubTotalQuantity   == "")
		    strSubTotalQuantity = "0";
		
		var floatstrSalesTaxPercent = parseFloat(strSalesTaxPercent);
		var strTaxAmount            = (strSubTotalValue * floatstrSalesTaxPercent)/100;
		//Since there is no real JS function to convert 10.56677 to 10.57, I multiply by 100, round and then diveide by 100
		strTaxAmount                = Math.round(parseFloat(strTaxAmount)*100)/100;

		document.forms[0].txtTaxValue.value  = roundNumber(strTaxAmount);
		
		
		//Each additional shipping cost		
		var myObjectLabel       = document.getElementById("txtShippingCostAdditional");
		if (parseInt(strSubTotalQuantity) <= 1)
		{
			var strShippingCostAddl = 0;
			myObjectLabel.style.color = "gray";
		}
		else
		{
			//var strShippingCostAddl    = document.forms[0].txtShippingCostAdditional.value;
			var strShippingCostAddlEach  = document.forms[0].txtShippingCostAdditional.value;
			if (strShippingCostAddlEach  == "")
				strShippingCostAddlEach  = "0";
									
			var floatstrSubTotalQuantity = parseFloat(strSubTotalQuantity);
			var strShippingCostAddl      = (strShippingCostAddlEach * (floatstrSubTotalQuantity -1));
		
			var myObjectLabelXX       = document.getElementById("txtShippingCostAdditionalTotal");				
			if (myObjectLabelXX)
				myObjectLabelXX.value = strShippingCostAddl;			
							
			myObjectLabel.style.color = "navy";
		}

		//Expedited shipping
		trimspaces(document.forms[0].txtExpeditedShippingCostAdditional);
		//Jun 3 2006 Take the negiative sign out.
		document.forms[0].txtExpeditedShippingCostAdditional.value = document.forms[0].txtExpeditedShippingCostAdditional.value.replace("-","");
		    
		var strExpeditedShippingCostAdditional = 0;
		if (!(document.forms[0].txtExpeditedShippingCostAdditional.value == ""))
		{
			strExpeditedShippingCostAdditional = parseFloat(document.forms[0].txtExpeditedShippingCostAdditional.value);
		}

		//alert(strShippingCost); 
		//alert(strSubTotalValue);
		//alert(strExpeditedShippingCostAdditional);
		//alert(strShippingCostAddl);
		//alert(strTaxAmount);

		//Calculate Total
		if (parseFloat(strSubTotalValue) == 0)
			var strTotal = 0;
		else
		    var strTotal        = parseFloat(strShippingCost) 
						        + parseFloat(strSubTotalValue)
		                        + parseFloat(strExpeditedShippingCostAdditional)
		                        + parseFloat(strShippingCostAddl)
		                        + parseFloat(strTaxAmount);
		    
		var myObjectLabel   = document.getElementById("lblTotalValue");					
		//Since there is no real JS function to convert 10.56677 to 10.57, I multiply by 100, round and then diveide by 100
		myObjectLabel.innerHTML = Math.round(parseFloat(strTotal)*100)/100;
				
		return true;	    		
}

function processTaxSelection(thisForm, thisField)
{
	var strSalesTaxPercent = 0;
	var myObjectSalesTax  = document.getElementById("drpSalesTax");
	if (myObjectSalesTax)
	{			
		//Make sure that the state selected for address matches the SalesTax state if any
		var myObjectStateCode  = document.getElementById("drpStateCodeShipTo");
		for(i=0; i < document.forms[0].drpSalesTax.length; i++) 
		{			
			if (myObjectStateCode)
			{
				if (document.forms[0].drpSalesTax[i].text.indexOf(myObjectStateCode[myObjectStateCode.selectedIndex].value) != -1)
				{
					document.forms[0].drpSalesTax.selectedIndex = -1;
					document.forms[0].drpSalesTax.selectedIndex = i;		
					i = 9999;
					if (strStateCodeChanged == 'N')
					{
						alert('Tax must be collected as per ship to address');
						return true;
					}	
				}
			}
		}
	
		strSalesTaxPercent  = myObjectSalesTax[myObjectSalesTax.selectedIndex].value;			
		//Since there is no real JS function to convert 10.56677 to 10.57, I multiply by 100, round and then diveide by 100
		strSalesTaxPercent  = Math.round(parseFloat(strSalesTaxPercent)*100)/100;
		thisForm.txtSalesTaxPercent.value = strSalesTaxPercent;		
	}
    
	updateTotalCost("thisForm", "thisField");	

}

function processItemSelection(thisForm, thisField, strPrice, strQuantity)
{
		
	HighlightRow(thisField);		
	
	//Expedited shipping	
	trimspaces(thisForm.txtShippingCostAdditional);
	
	var strExpeditedShippingCostAdditional = 0;
	
	//Jun 3 2006 Take the negiative sign out for non-seller login.
	document.forms[0].txtExpeditedShippingCostAdditional.value = document.forms[0].txtExpeditedShippingCostAdditional.value.replace("-","");
	
	if (!(thisForm.txtExpeditedShippingCostAdditional.value == ""))
	{
		strExpeditedShippingCostAdditional = parseFloat(thisForm.txtExpeditedShippingCostAdditional.value);
	}
	
	if (thisField.checked == true)
	{
		//Calculate subtotal value
		var myObjectLabel       = document.getElementById("lblSubTotalValue");					
		var strSubTotalValue    = parseFloat(myObjectLabel.innerHTML)  + (parseFloat(strPrice) * strQuantity);
		myObjectLabel.innerHTML = strSubTotalValue;	
		var strSubTotalValueX   = Math.round(strSubTotalValue * 100)/100;
		myObjectLabel.innerHTML = strSubTotalValueX;	
		
		
		//Calculate subtotal qty
		var myObjectLabel       = document.getElementById("lblSubTotalQuantity");					
		var strSubTotalQuantity = parseInt(myObjectLabel.innerHTML)  + parseFloat(strQuantity);
		myObjectLabel.innerHTML = strSubTotalQuantity;	
		
		updateTotalCost("thisForm", "thisField");	
	}
	else
	{	    
		//Calculate subtotal value
		var myObjectLabel       = document.getElementById("lblSubTotalValue");
		var strItemTotal        = parseFloat(strPrice) * parseInt(strQuantity);
		var strSubTotalValue    = parseFloat(myObjectLabel.innerHTML)  - strItemTotal;
		var strSubTotalValueX   = Math.round(strSubTotalValue * 100)/100;
		myObjectLabel.innerHTML = strSubTotalValueX;	
		
		//Calculate subtotal qty
		var myObjectLabel       = document.getElementById("lblSubTotalQuantity");					
		var strSubTotalQuantity = parseInt(myObjectLabel.innerHTML)  - parseFloat(strQuantity);
		myObjectLabel.innerHTML = strSubTotalQuantity;	
		
		updateTotalCost("thisForm", "thisField");
	}
}

//Invoicing only
function insuranceCostEdited(thisForm, thisField)
{
	document.forms[0].chkInsurance.checked = true;
    var myObjectIns       = document.getElementById("txtInsuranceFee");
    if (myObjectIns)
    {
	   var myObjectInsX        = document.getElementById("lblInsuranceValue");	   
       myObjectInsX.innerHTML  = myObjectIns.value;		      
    }
	updateTotalCost("thisForm", "thisField");	
	return false;   
}

function updateTotalCost(thisForm, thisField)
{	
	
	var myObjectLabel       = document.getElementById("lblSubTotalQuantity");					
	var strSubTotalQuantity = parseInt(myObjectLabel.innerHTML);

	//GCHECKOUT ONLY, not for invoicing
	if (document.forms[0].hiddenSendInvoice.value != '1')
	{
		var myObjectLabel       = document.getElementById("lblSubTotalValue");					
		if (document.forms[0].chkInsurance.checked)
			getCMaxInsuranceCost(myObjectLabel.innerHTML, "5");
	}

	//Each additional shipping cost		
	var myObjectLabel       = document.getElementById("txtShippingCostAdditional");
	if (parseInt(strSubTotalQuantity) <= 1)
		myObjectLabel.style.color = "gray";		
	else
		myObjectLabel.style.color = "navy";

	var myObjectLabelSubTotal   = document.getElementById("lblSubTotalValue");
	var myObjectLabelIns        = document.getElementById("lblInsuranceValue");
    var strShippingCost         = document.forms[0].txtShippingServiceCost.value;		
    var strShippingCostAddl     = document.forms[0].txtShippingCostAdditional.value;
    
	//Jun 3 2006 Take the negiative sign out for non-seller login.
	document.forms[0].txtExpeditedShippingCostAdditional.value = document.forms[0].txtExpeditedShippingCostAdditional.value.replace("-","");
    
    var strShippingCostExtra    = document.forms[0].txtExpeditedShippingCostAdditional.value;		
    
    var strSalesTaxPercent      = document.forms[0].txtSalesTaxPercent.value;		

	var myObjectLabel       = document.getElementById("txtShippingCostAdditional");
	if (parseInt(strSubTotalQuantity) <= 1)
	{
		var strShippingCostAddl = 0;
		myObjectLabel.style.color = "gray";
	}
	else
	{
		var strShippingCostAddl = document.forms[0].txtShippingCostAdditional.value;
		myObjectLabel.style.color = "navy";
	}

	if (parseInt(strSubTotalQuantity) <= 0)
		strShippingCost = 0;

	//GCHECKOUT-2 Oct 16 2006
	if (parseInt(strSubTotalQuantity) > 1)
	{
		var decSubTotalQuantity = parseFloat(strSubTotalQuantity);		
		var decShippingCostAddl = parseFloat(strShippingCostAddl);		
		strShippingCostAddl     = decShippingCostAddl * (decSubTotalQuantity - 1);
	}        	
	else
		document.forms[0].txtShippingCostAdditionalTotal.value = "0.0";	
	//GCHECKOUT-2 End Oct 16 2006
        
        
    //NaN means not a number, isNaN returns true if not a number
    var strSubTotal            = myObjectLabelSubTotal.innerHTML;
    if (isNaN(myObjectLabelSubTotal.innerHTML)) strSubTotal = '0';
        
    //Mar 29 2006.. moved to editable insurance
    //var strInsuranceCost        = myObjectLabelIns.innerHTML;    
    
    var strInsuranceCost  = '0';		      
    var myObjectIns       = document.getElementById("txtInsuranceFee");					
    if (myObjectIns)
       strInsuranceCost   = myObjectIns.value;		          
    
    if ((isNaN(myObjectLabelIns.innerHTML))     || (myObjectLabelIns.innerHTML == '')) strInsuranceCost     = '0';    		    
    if ((isNaN(strShippingCost))                || (strShippingCost            == '')) strShippingCost      = '0';    
    if ((isNaN(strShippingCostAddl))            || (strShippingCostAddl        == '')) strShippingCostAddl  = '0';
    if ((isNaN(strShippingCostExtra))           || (strShippingCostExtra       == '')) strShippingCostExtra = '0';
    if ((isNaN(strInsuranceCost))               || (strInsuranceCost           == '')) strInsuranceCost     = '0';
    if ((isNaN(strSalesTaxPercent))             || (strSalesTaxPercent         == '')) strSalesTaxPercent   = '0';
    
    if (strInsuranceCost > '0') (document.forms[0].chkInsurance.checked =true);
	if (!(document.forms[0].chkInsurance.checked)) strInsuranceCost = '0';   

	var floatstrSalesTaxPercent = parseFloat(strSalesTaxPercent);
	var strTaxAmount            = (parseFloat(strSubTotal) * floatstrSalesTaxPercent)/100;
	document.forms[0].txtTaxValue.value  = roundNumber(strTaxAmount);
	
	var strTotal                = parseFloat(strSubTotal) 
	                            + parseFloat(strInsuranceCost) 
	                            + parseFloat(strShippingCost)
	                            + parseFloat(strShippingCostAddl) 
	                            + parseFloat(strShippingCostExtra)
	                            + parseFloat(strTaxAmount)
	                            ;			
	                            	
	var myObjectLabelTotal      = document.getElementById("lblTotalValue");
	
	//Since there is no real JS function to convert 10.56677 to 10.57, I multiply by 100, round and then diveide by 100	
	myObjectLabelTotal.innerHTML = Math.round(parseFloat(strTotal)*100)/100;
	myObjectLabelTotal.innerHTML = formatAmount(myObjectLabelTotal.innerHTML);
}

function getInsurance(thisForm, thisField)
{
	var myObjectLabel         = document.getElementById("lblTotalValue");
	var myObjectLabelIns      = document.getElementById("lblInsuranceValue");
	
    var strInsuranceCost      = myObjectLabelIns.innerHTML;    
        
    if ((isNaN(strInsuranceCost))               || (strInsuranceCost           == '')) strInsuranceCost     = '0';
    	
    if (thisField.checked)
		var strTotal              = parseFloat(myObjectLabel.innerHTML) + parseFloat(strInsuranceCost);		
	else
		var strTotal              = parseFloat(myObjectLabel.innerHTML) - parseFloat(strInsuranceCost);			
	
	myObjectLabel.innerHTML = Math.round(parseFloat(strTotal)*100)/100;
	
	var myObjectIns       = document.getElementById("txtInsuranceFee");					
    if (myObjectIns)
       myObjectIns.value  = strInsuranceCost;
}

//
function getInsuranceDrp(thisForm, thisField)
{
   if (document.forms[0].drpInsureWith.selectedIndex == 0) //No Insurance selected
   {
      document.forms[0].txtInsuranceFee.value = "0";
      document.forms[0].txtInsuranceFee.disabled = true;
   }
   else
   {
      document.forms[0].txtInsuranceFee.disabled = false;
   }
}

//
function open2CheckoutWindow(thisForm)
{		
}

function open2CheckoutWindowX(thisForm)
{		

		//ValidateCheckout(thisForm, thisField);

		alert("A new window will open that will accept your credit card, once completed you will come back here automatically");
		
        var w = screen.width  * 0.80;
        var h = screen.height * 0.70;
		
	    //var h=650;
	    //var w=550;
	    var scroll='yes';
	    var resize='yes';
		var strPassedParam = '';
		
		var myObjectTotal   = document.getElementById("lblTotalValue");		
		
		strPassedParam = strPassedParam + '&product_id=1'
		                                + '&total='               + myObjectTotal.innerHTML
		                                + '&quantity=1'
		                                + '&card_holder_name='    + convertSpaceto20(document.forms[0].txtFullNameBillTo.value)
		                                + '&street_address='      + convertSpaceto20(document.forms[0].txtAddress1BillTo.value)
		                                + '&city='                + convertSpaceto20(document.forms[0].txtCityBillTo.value)
		                                + '&state='               + convertSpaceto20(document.forms[0].txtStateCodeBillTo.value)
		                                + '&zip='                 + document.forms[0].txtPostalCodeBillTo.value
		                                + '&country='             + document.forms[0].drpCountryBillTo.selectedValue
		                                + '&email='               + convertSpaceto20(document.forms[0].txtEmail.value)
		                                + '&phone='               + convertSpaceto20(document.forms[0].txtPhone.value)
		                                + '&cart_order_id=200'    
		                                + '&cart_id=200'          
		                                + '&ship_name='           + convertSpaceto20(document.forms[0].txtFullNameShipTo.value)
		                                + '&ship_street_address=' + convertSpaceto20(document.forms[0].txtAddress1ShipTo.value)
		                                + '&ship_city='           + convertSpaceto20(document.forms[0].txtCityShipTo.value)
		                                + '&ship_state='          + document.forms[0].txtStateCodeShipTo.value
		                                + '&ship_zip='            + document.forms[0].txtPostalCodeShipTo.value
		                                + '&ship_country=USA'     + document.forms[0].drpCountryShipTo.selectedValue
		                                + '&demo=Y'
		                                ;
		                                
		alert(strPassedParam);
		
	    var myName = '2Checkout';
	    var myPage = 'https://www2.2checkout.com/2co/buyer/purchase?sid=307499' + strPassedParam;
	    //NewWindow is a function in Common.js	    
		NewWindow(myPage, myName, w, h, scroll,resize);
		
		//Since this is called from a hyperlink, don't put return false;
		//return false;
		
}

function validateCheckoutLogin(thisForm, thisField)
{

		var strMessage = "<BR><UL>";			
		strMessage = strMessage + checkRequiredNew(thisForm.txtEmail        , "lblEmail" , arrMessages[37], "Y");

		if (thisForm.txtChannelItemID.value == "" && thisForm.txtPassword.value == "") 
		{
			strMessage = strMessage + arrMessages[107];
		}

		if (!thisForm.rdobtnlistChannels[0].checked && !thisForm.rdobtnlistChannels[1].checked) 
		{
			strMessage = strMessage + "<BR>" + "Ebay Or Overstock must be selected";
		}
		
		
		/*
		else
		{
			strMessage = strMessage + checkRequiredNew(thisForm.txtChannelItemID, "lblItemID", arrMessages[94], "Y");
			strMessage = strMessage + checkRequiredNew(thisForm.txtChannelItemID, "lblItemID", arrMessages[94], "Y");
		}
		*/
		

		var myObject = document.getElementById("MsgBoxTop");			
		if (strMessage == "<BR><UL>")
		{
	    	myObject.style.display = 'block';
			//myObject1.innerHTML = "Validation Successful, please wait while updating database .." + "<IMG height=22px src='images/Animated/Numbers.gif'>" + "<BR>" ;
			myObject.innerHTML = "please wait while validating .." + "<BR>" ;
			myObject.style.display = 'block';
			myObject.style.color = 'blue';
			myObject.style.backgroundColor='white';
			myObject.style.fontWeight = 'bold';
			myObject.style.textAlign = 'center';	    	
			return true;	
		}
		else
		{
			myObject.innerHTML = strMessage + "<BR>";
			myObject.style.display = 'block';
			myObject.style.color = 'red';
			//thisForm.imagebtnSave.focus();
			return false;	
		}
}

function getCMaxInsuranceCost(strInsuredFor, strShippedUsing)
{   	
    
	//strShippedUsing = 5  USPS
	//strShippedUsing = 20 DHL
	//strShippedUsing = 11 FedEx
	//strShippedUsing = 6  UPS

	var intInsuredFor = parseFloat(strInsuredFor);
	if (intInsuredFor > 500)
	{
		alert("Sorry!! Cannot insure above 500 USD");
		intInsuredFor = 500;
		strInsuredFor = '500';
		
		var myObject = document.getElementById('txtBIInsuredAmount');
		if (myObject)	
			myObject.value = strInsuredFor;		
	}
	
	var strCMaxCharge  = '0';
    var strShipToCountryCode = 'us';
	
	switch (strShipToCountryCode) 
  	{     
		case 'us':
		case 'cn':
		case 'US':
		case 'CN':
		
		
			if (intInsuredFor <= 50)
			{
				strCMaxCharge  = "1.35";
			}	
			else if (intInsuredFor > 50 && intInsuredFor <= 100)
			{
				strCMaxCharge  = "2.30";
			}		
			else if (intInsuredFor > 100 && intInsuredFor <= 200)
			{
				strCMaxCharge  = "3.35";
			}
			else if (intInsuredFor > 200 && intInsuredFor <= 300)
			{
				strCMaxCharge  = "4.40";
			}
			else if (intInsuredFor > 300 && intInsuredFor <= 400)
			{
				strCMaxCharge  = "5.45";
			}
			else if (intInsuredFor > 400 && intInsuredFor <= 500)
			{
				strCMaxCharge  = "6.50";
			}
			else
			{
				strXX = '1';	
			}
		
		    break;
		    
		default :
		
			//Jan 6 2007 International is opened up
			//alert('Sorry !! Cannot insure international at this time');
			//MM_showHideLayersTop('divTrackerBuyInsuranceShowHide','','hide');			
			//return false;
			//End Jan 6 2007 International is opened up
			
			if (intInsuredFor <= 50)
			{
				strCMaxCharge  = "1.95";
			}	
			else if (intInsuredFor > 50 && intInsuredFor <= 100)
			{
				strCMaxCharge  = "2.75";
			}		
			else if (intInsuredFor > 100 && intInsuredFor <= 200)
			{
				strCMaxCharge  = "3.80";
			}
			else if (intInsuredFor > 200 && intInsuredFor <= 300)
			{
				strCMaxCharge  = "4.85";
			}
			else if (intInsuredFor > 300 && intInsuredFor <= 400)
			{
				strCMaxCharge  = "5.90";
			}
			else if (intInsuredFor > 400 && intInsuredFor <= 500)
			{
				strCMaxCharge  = "6.95";
			}
			else
			{
				strXX = '1';	
			}
			
			
			break;     		
    }
        
	var myObject = document.getElementById("lblInsuranceValue");	
	
	if (myObject)
	{			
		var dblInvoiceInsuranceValue = 0;
		var myObjectHI = document.getElementById('hiddenInvoiceInsuranceFee');

		if (myObjectHI)
		{
			dblInvoiceInsuranceValue = parseFloat(myObjectHI.value);   
			if (isNaN(dblInvoiceInsuranceValue))
			   dblInvoiceInsuranceValue = 0;
		}		
		
		var dblNewInsuranceValue = 0;		
		dblNewInsuranceValue = parseFloat(strCMaxCharge);
		if (isNaN(dblNewInsuranceValue))
			dblNewInsuranceValue = 0;
		
		if (dblInvoiceInsuranceValue == 0)
			myObject.innerHTML = strCMaxCharge;		
		else
		{
		   if (dblNewInsuranceValue > dblInvoiceInsuranceValue)
			  myObject.innerHTML = strCMaxCharge;
		   else
		      myObject.innerHTML = dblInvoiceInsuranceValue;
		}			
	}	
	document.forms[0].txtInsuranceFee.value = myObject.innerHTML;
}


//GCHECKOUT
function setFocus2Next(thisForm, thisField)
{
	document.forms[0].txtExpeditedShippingCostAdditional.focus();
	return false;
}

//GCHECKOUT
function getInsuranceNew(thisForm, thisField)
{
    if (document.forms[0].chkInsurance.checked)
    {
		var myObjectLabel = document.getElementById("lblSubTotalValue");
		getCMaxInsuranceCost(myObjectLabel.innerHTML, "5");
	}
	else
	{	    
		document.forms[0].txtInsuranceFee.value = '';
		var myObject = document.getElementById("lblInsuranceValue");
		if (myObject)	
			myObject.innerHTML = '';		
	
	}
	
	updateTotalCost("thisForm", "thisField");	
	return true;
}
