function btnCheckout_onClick()
{
	if (validateForm(document.InputForm)) 
	{
		var btn = document.getElementById("btnContinue");
		if(btn) btn.disabled = true;
		
		document.InputForm.submit();
	} 
	else 
	{
		alert(errMessage + "\nPlease correct the indicated fields and try again.");
    } 
}
function updateCart()
{
	if (validateForm(document.ShoppingCart)) 
	{
		document.ShoppingCart.submit();
	} 
	else 
	{
		alert(errMessage + "\nPlease correct the indicated fields and try again.");
    } 
}

function collectShippingDetails()
{
	var el = document.getElementById("_shippingAddressSameAsBillingAddress");	
	if (el.checked)
	{		
		var shipToState = document.getElementById("BillToState");
		var shipToCountry = document.getElementById("BillToCountry");
		if ((shipToCountry.value.toUpperCase() == 'US') && (shipToState.value.toUpperCase() == 'NY'))
		{
			document.getElementById("shipToFieldset").style.display = 'block';
			
			document.getElementById("ShipToCountyLabel").className = "rqrdLabel";
			document.getElementById("ShipToCounty").className = "rqrd";
			document.getElementById("ShipToCounty").disabled = false;
			document.getElementById("ShipToCountyField").style.display = 'block';
		}
		else
		{
			document.getElementById("shipToFieldset").style.display = 'none';
			document.getElementById("ShipToCountyLabel").className = "disabledText";
			document.getElementById("ShipToCounty").className = "";
			document.getElementById("ShipToCounty").disabled = true;
			document.getElementById("ShipToCountyField").style.display = 'none';
		}
	}
	else
	{
		document.getElementById("shipToFieldset").style.display = 'none';
		document.getElementById("ShipToCountyLabel").className = "disabledText";
		document.getElementById("ShipToCounty").className = "";
		document.getElementById("ShipToCounty").disabled = true;
		document.getElementById("ShipToCountyField").style.display = 'none';
	}
}

function showCounty()
{
	var shipToState = document.getElementById("ShipToState");
	var shipToCountry = document.getElementById("ShipToCountry");
	if ((shipToCountry.value.toUpperCase() == 'US') && (shipToState.value.toUpperCase() == 'NY'))
	{
		document.getElementById("ShipToCountyLabel").className = "rqrdLabel";
		document.getElementById("ShipToCounty").className = "rqrd";
		document.getElementById("ShipToCounty").disabled = false;
		document.getElementById("ShipToCountyField").style.display = 'block';
	}
	else
	{
		document.getElementById("ShipToCountyLabel").className = "disabledText";
		document.getElementById("ShipToCounty").className = "";
		document.getElementById("ShipToCounty").disabled = true;
		document.getElementById("ShipToCountyField").style.display = 'none';
	}
}
function enterFrieghtNumber(){
//Allow use of UPS freight Number

        var options = document.getElementById("_UPS_SELECT");
        
        if (document.getElementById("_freightNumber").checked){
            for(var i=0;i<options.length;i++){
                var arrOptions = options[i].value.split( "~" ); 
                options[i].value = arrOptions[0] + "~" + "4.00" + "~" + arrOptions[2];    
            }
            
            document.getElementById("FreightNumberContainer").style.display = "block";
            document.getElementById("freightNumber").className = "rqrd"; 
            
            var productTotal = new NumberFormat();
            productTotal.setNumber(document.getElementById("ProductTotal").innerText);
            
            var shipCost = new NumberFormat();
            shipCost.setCurrency(true);
            shipCost.setNumber("4.00");
            document.getElementById("ShippingAndHandling").innerHTML = "$4.00";
            document.getElementById("Shipping").value = 4.00;
            
            var total = new NumberFormat();
            total.setCurrency(true);
            total.setNumber(productTotal.toUnformatted() + shipCost.toUnformatted());
            document.getElementById("Subtotal").innerText = total.toFormatted();
        }else{
            for(var i=0;i<options.length;i++){
                var tempCost = options[i].innerHTML;
                var tempCost = tempCost.substring(tempCost.indexOf("$")+1,tempCost.indexOf(")"));   
                var arrOptions = options[i].value.split( "~" ); 
                options[i].value = arrOptions[0] + "~" + tempCost + "~" + arrOptions[2];    
            }
            var optionIndex = options.selectedIndex;  
            arrOptions = options[optionIndex].value;
            arrOptions = arrOptions.split( "~" );
            document.getElementById("ShippingAndHandling").innerHTML = "$" + arrOptions[1];
            document.getElementById("Shipping").value = arrOptions[1];
            
            document.getElementById("FreightNumberContainer").style.display = "none"; 
            document.getElementById("freightNumber").className = "optional";    
            document.getElementById("freightNumber").value = "";  
            updateShipping();
        }    
        
        
    
}
function updateShipping()
{
	var el = document.getElementById("_UPS_SELECT");     
	if (el)
	{
        
		var arrOptions = el.value.split( "~" );
        
        
		document.getElementById("ShipCode").value = arrOptions[0];
		document.getElementById("Shipping").value = arrOptions[1];
		document.getElementById("ShipMethod").value = arrOptions[2];
		
		// Update order total
		var productTotal = new NumberFormat();
		productTotal.setNumber(document.getElementById("ProductTotal").innerText);
		
		var shipCost = new NumberFormat();
		shipCost.setCurrency(true);
		shipCost.setNumber(arrOptions[1]);
		document.getElementById("ShippingAndHandling").innerText = shipCost.toFormatted();
		
		var total = new NumberFormat();
		total.setCurrency(true);
		total.setNumber(productTotal.toUnformatted() + shipCost.toUnformatted());
		document.getElementById("Subtotal").innerText = total.toFormatted();
	}
}
function enforceBusinessRules()
{
	var el = document.getElementById("_pageState");
	if (el)
	{
		var pageState = el.value;
		if (pageState == "SavePaymentInfo")
		{
			var elPO = document.getElementById("PONumber");
			if (elPO.value == '')	
			{
				document.getElementById("CardName").className = "rqrd";
				document.getElementById("_CardType").className = "rqrd";
				document.getElementById("_CardNumber").className = "rqrd";
				document.getElementById("_ExpMonth").className = "rqrd";
				document.getElementById("_ExpYear").className = "rqrd";
			}
			else
			{
				document.getElementById("CardName").className = "optional";
				document.getElementById("_CardType").className = "optional";
				document.getElementById("_CardNumber").className = "optional";
				document.getElementById("_ExpMonth").className = "optional";
				document.getElementById("_ExpYear").className = "optional";
			}
		}
	}
	return true;
}

function selectPaymentType(el)
{
	switch (el.value)
	{
		case "CC":
		{
			var elPO = document.getElementById("PONumber");
			document.getElementById("orderNumberContainer").style.display = "none";
			document.getElementById("creditCardContainer").style.display = "block";
			
			document.getElementById("PONumber").value = "";
			document.getElementById("PONumber").className = "optional";
			
			document.getElementById("CardName").className = "rqrd";
			document.getElementById("_CardType").className = "rqrd";
			document.getElementById("_CardNumber").className = "rqrd";
			document.getElementById("_ExpMonth").className = "rqrd";
			document.getElementById("_ExpYear").className = "rqrd";
			document.getElementById("_CVV2Code").className = "rqrdNumeric";
			break;
		}
		case "PO":
		{
			document.getElementById("orderNumberContainer").style.display = "block";
			document.getElementById("creditCardContainer").style.display = "none";
			
			document.getElementById("PONumber").className = "rqrd";
			
			document.getElementById("CardName").className = "optional";
			document.getElementById("_CardType").className = "optional";
			document.getElementById("_CardNumber").className = "optional";
			document.getElementById("_ExpMonth").className = "optional";
			document.getElementById("_ExpYear").className = "optional";
			document.getElementById("_CVV2Code").className = "optional";
			
			document.getElementById("CardName").value = "";
			document.getElementById("_CardType").selectedIndex = -1;
			document.getElementById("_CardNumber").value = "";
			document.getElementById("_ExpMonth").selectedIndex = 0;
			document.getElementById("_ExpYear").selectedIndex = 0;
			document.getElementById("_CVV2Code").value = "";
			break;
		}
	}
	
}