function getSelectValue(theSelect)
{

	if (theSelect.selectedIndex == -1)
	{
		return('');
	}else{
		return(theSelect.options[theSelect.selectedIndex].value);
	}

}

function letSelectValue(theSelect,theValue)
{

	for (var i = 0;  i < theSelect.options.length;  i++)
	{
		if (theSelect.options[i].value == theValue)
		{
			theSelect.selectedIndex = i;
			return true;
		}
	}
	
	return false;
}

function ValidateCountry()
{
	var cbytDefaultDomestic = 16;
	var cbytDefaultIntl = 27;		//Global Airmail Parcel Post
	
	var theForm = document.form1;
	var pstrDestCountry;
	var pstrShipMethod = theForm.Shipping.value;

	if (theForm.ShipFirstName.value == "")
	{
		pstrDestCountry = getSelectValue(theForm.Country);
	}
	else
	{
		pstrDestCountry = getSelectValue(theForm.ShipCountry);
	}

	if (pstrDestCountry  == "")	//Exit gracefully so form validation can take over
	{
	return true;
	}
	
	if (pstrShipMethod == "")
	{
	alert("Please select a shipping method using the /View Rates/ button.");
	return false;
	}
	
	if (pstrDestCountry != 'US')
	{
		if (pstrShipMethod == cbytDefaultIntl)	
		{
			return true;
		}
		else
		{
			alert("We use Global Airmail Parcel Post for all non-U.S. orders.");
//			theForm.Shipping.value = cbytDefaultIntl;
//			return true;
			letSelectValue(theForm.Shipping,cbytDefaultIntl);
			theForm.Shipping.focus();
			return false;
		}
	}
	else
	{
		if (pstrShipMethod == cbytDefaultIntl)
		{
			alert("Global Airmail Parcel Post cannot be used for U.S. orders. \n Please reselect your shipping method.");
			letSelectValue(theForm.Shipping,cbytDefaultDomestic);
			theForm.Shipping.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
	
}

function GetRates(strDisplayType)
{
var pstrZip;
var pstrDestCountry;
var pstrURL;

var theForm = document.form1;
var p_blnShip = (theForm.ShipFirstName.value != "");

	if (p_blnShip)
	{
		pstrZip = theForm.ShipZip.value;
		pstrDestCountry = getSelectValue(theForm.ShipCountry);
	}else{
		pstrZip = theForm.Zip.value;
		pstrDestCountry = getSelectValue(theForm.Country);
	}

	if (pstrDestCountry  == "")
	{
		alert("Please select a Country to ship to.");
		if (p_blnShip){theForm.ShipCountry.focus()}else{theForm.Country.focus()}
		return false
	}

	if (((pstrDestCountry == "US") || (pstrDestCountry == "CA")) && (pstrZip == ""))
	{
		alert("Please enter a ZIP code.");
		if (p_blnShip){theForm.ShipZip.focus()}else{theForm.Zip.focus()}
		return false
	}

	pstrURL = "ShippingRates.asp?DestinationZip=" + pstrZip + "&DestinationCountry=" + pstrDestCountry  + "&DisplayStyle=" + strDisplayType
	PreView=window.open(pstrURL,"Preview","toolbar=0,location=0,directories=0,status=0,menubar=No,copyhistory=0,scrollbars=1,width=400,height=300");
}


function ssValidateCountrySelection(theForm)
{
// this function returns true in the event of an invalid selection

	var pstrBillToCountry = getSelectValue(theForm.Country);
	var pstrShipToCountry = getSelectValue(theForm.ShipCountry);

	if (pstrBillToCountry != "")
	{
		var pstrBillToState = getSelectValue(theForm.State);
		if ((pstrBillToCountry == "US") || (pstrBillToCountry == "CA"))
		{
			if ((pstrBillToState == "NA") || (pstrBillToState == ""))
			{
				alert("Please select a state");
				theForm.State.focus();
				return true;
			}
		}else{
			if (pstrBillToState != "NA")
			{
				letSelectValue(theForm.State,"NA");
				return false;
			}
		}
	}

	if (pstrShipToCountry != "")
	{
		var pstrShipToState = getSelectValue(theForm.ShipState);
		if ((pstrShipToCountry == "US") || (pstrShipToCountry == "CA"))
		{
			if ((pstrShipToState == "NA") || (pstrShipToState == ""))
			{
				alert("Please select a state");
				theForm.ShipState.focus();
				return true;
			}
		}else{
			if (pstrShipToState != "NA")
			{
				letSelectValue(theForm.ShipState,"NA");
				return false;
			}
		}
	}

return false;
	
}
