var indx = 0;

//If there any international fields have values, then disable the u.s. and canada fields
function disable_us_canada(argForm) {	
	//If either of the international fields filled out
	if(argForm.frmRegion.value != ""  || argForm.frmCountry.value != "")
	{
		argForm.frmRegionDrop.disabled = true;
		argForm.frmRegionDrop.className = "disabled";
		div1.className = "disabledorderform";
	}
	else
	{
		argForm.frmRegionDrop.disabled = false;
		argForm.frmRegionDrop.className = "enabled";
		div1.className = "orderform";
	}
}	

//If there any u.s. and canada fields have values, then disable the international fields
function disable_international(argForm)
{
	//If either of the international fields filled out
	if(argForm.frmRegionDrop.value != "")
	{	
		argForm.frmRegion.disabled = true;
		argForm.frmCountry.disabled = true;
		argForm.frmRegion.className = "disabled";
		argForm.frmCountry.className = "disabled";
		div2.className = "disabledorderform";
	}
	else
	{
		argForm.frmRegion.disabled = false;
		argForm.frmCountry.disabled = false;
		argForm.frmRegion.className = "enabled";
		argForm.frmCountry.className = "enabled";
		div2.className = "orderform";
	}
}

function disable_billing_form(the_form)
{
	var bool_val = "false";
	var enable_disable = "enabled";

	if("1" == (the_form.same_as_shipping.value))
	{
		//disable the form
		bool_val = true;
		enable_disable = "form_input disabled";
		//alert((the_form.same_as_shipping.value).toLowerCase() + "false  " + enable_disable );
	}
	else
	{
		//enable the form
		bool_val = false;
		enable_disable = "form_input enabled";
		//alert((the_form.same_as_shipping.value).toLowerCase() + "false  " + enable_disable );
	}

	the_form.billing_addressterritory.disabled = bool_val;
	the_form.billing_firstname.disabled = bool_val;
	the_form.billing_lastname.disabled = bool_val;
	
	//if this form element exists
	if(the_form.billing_organization)
		the_form.billing_organization.disabled = bool_val;
	
	the_form.billing_address.disabled = bool_val;
	the_form.billing_address2.disabled = bool_val;
	the_form.billing_city.disabled = bool_val;
	the_form.billing_region.disabled = bool_val;
	the_form.billing_country_1.disabled = bool_val;
	the_form.billing_zipcode.disabled = bool_val;
	the_form.billing_phone.disabled = bool_val;

	the_form.billing_addressterritory.className = enable_disable;
	the_form.billing_firstname.className = enable_disable;
	the_form.billing_lastname.className = enable_disable;
	
	//if this form element exists
	if(the_form.billing_organization)
		the_form.billing_organization.className = enable_disable;
	
	the_form.billing_address.className = enable_disable;
	the_form.billing_address2.className = enable_disable;
	the_form.billing_city.className = enable_disable;
	the_form.billing_region.className = enable_disable;
	the_form.billing_country_1.className = enable_disable;
	the_form.billing_zipcode.className = enable_disable;
	the_form.billing_phone.className = enable_disable;
	
}

function removeXSS(argText, argType) {
	var illegalchars = "()<>&";

	if (argType=="allow ampersand")
	{
		illegalchars = "()<>";
	}

	var output = "";
	var index = 0;
	var LimitCheck;
	var currChar;
	var blnHasIllegal = false;

	LimitCheck = argText.length;
	/** for each character, check if belongs to illegal characters */
	while (index != LimitCheck) {
		currChar = argText.charAt(index);
		if (illegalchars.indexOf(currChar) < 0)
		{
			output += currChar;
		} else {
			blnHasIllegal = true;
		}
		index = index + 1;
	}

	if (blnHasIllegal)
	{
		alert("Removing invalid characters.");
	}
	return output;
}

function submitform(the_form)
{
	the_form.submit();
}


//popup window for porchase order terms
function popup_po_terms()
{
	popupurl='/info/purchase_order_popup.html';
	popupname='popup_help';
	popupoptions='width=400,height=229,scrollbars=no, resizable=yes';
	var popUp=window.open(popupurl,popupname,popupoptions);
	popUp.focus();
}
