function PopUp(w,f){
	var newwin = window.open(w,'',f);
	if (!newwin) document.location = "/Frames?" + w;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
	var newwin = window.open(theURL,winName,features);
	if (!newwin) document.location = "/Frames?" + theURL;
}
function BillToShip(strField) {
	// Copy data from Billing field into the shipping field
	var bName="Billing_" + strField;
	var sName="Shipping_" + strField;
	var bEl = document.address_form[bName];
	var sEl = document.address_form[sName];
	if (strField=="address_line2" && 
			document.address_form["Billing_address_line1"].value!=
			document.address_form["Shipping_address_line1"].value)
		return;
	if (!(sEl.value) || document.address_form["ship_same_as_bill"].checked) 
		sEl.value=bEl.value;
	if (bEl.selectedIndex)
		if (!(sEl.selectedIndex) || document.address_form["ship_same_as_bill"].checked) 
			sEl.selectedIndex=bEl.selectedIndex;
}
function BillToShipSelect() {
	var bSel=document.address_form["Billing_region_name"];
	var sSel=document.address_form["Shipping_region_name"];
	if (sSel.selectedIndex==0) sSel.selectedIndex=bSel.selectedIndex;
}
function SetShipDisabled() {
	// This function doesn't work in Netscape, but it doesn't throw any errors, either.
	var el=document.address_form.elements;
	var x=15;
	var bDisabled = el["ship_same_as_bill"].checked
	for (x=0;x<el.length;x++) 
		if (el[x].name.substring(0,9)=="Shipping_") 
			el[x].disabled = bDisabled;
}

function FixAddress(strAddressType,strCity,strState,strZip,strAddress1,strAddress2) {
	document.address_form[strAddressType + "city"].value = strCity;
	document.address_form[strAddressType + "region_name"].value = strState;
	document.address_form[strAddressType + "postal_code"].value = strZip;
	if (strAddress1!="") {
		document.address_form[strAddressType + "address_line1"].value = strAddress1;
		document.address_form[strAddressType + "address_line2"].value = strAddress2;
	}
	
	document.address_form[strAddressType + "Invalid_Address"].checked = true;
	document.address_form[strAddressType + "Invalid_Address"].disabled = true;

	if ((strAddressType=="Billing_") && (document.address_form["ship_same_as_bill"].checked))
		FixAddress("Shipping_",strCity,strState,strZip,strAddress1,strAddress2);
}

function TransferOption(strFrom,strTo,strTrackOpts){
	var selFrom = document.address_form[strFrom];
	var selTo = document.address_form[strTo];
	var elTrackOpts = document.address_form[strTrackOpts];
	var aFromText = new Array();
	var aFromValues = new Array();
	var x;
	for (x=0;x<selFrom.length;x++){
		if (selFrom.options[x].selected) {
			selTo.options[selTo.length] = new Option(selFrom.options[x].text,selFrom.options[x].value);
			if (elTrackOpts.value.indexOf("*,*" + selFrom.options[x].value + "*,*")>-1) {
				elTrackOpts.value = elTrackOpts.value.replace("*,*" + selFrom.options[x].value + "*,*","*,*");
			} else {
				elTrackOpts.value = elTrackOpts.value + selFrom.options[x].value + "*,*";
			}			
		} else {
			aFromText[aFromText.length] = selFrom.options[x].text;
			aFromValues[aFromValues.length] = selFrom.options[x].value;
		}
	}
	selFrom.length = 0;
	for (x=0;x<aFromText.length;x++){
		selFrom.options[x] = new Option(aFromText[x],aFromValues[x]);
	}
}

function waitPopup(strMessage, strImg)
{
	var wWait;
	var html;
	if (!strImg || strImg=='') strImg='/images/progress.gif';
	
	
	html="<html><head><title>" + strMessage + "</title></head>";
	html += "<body bgcolor=#e3e0b7 text=#02195d background='" + strImg + "' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>&nbsp;</body></html>";

	HideSubmit();
	
	var height = screen.height;
	var width = screen.width;
	var top = (height / 2) - 50;
	var left = (width / 2) - 200;

	wWait = window.open("","wait","width=306,height=100,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,directories=0");
	if (wWait) {
		wWait.document.write(html);
		wWait.moveTo(left,top);
	}
}

function waitPopupClose()
{
	var wWait;
	wWait = window.open("","wait","width=306,height=84,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,directories=0");
	if (wWait)
		wWait.close();
}

function HideSubmit()
{
	var x;
	for (x=0;x<document.forms.length;x++) 
		document.forms[x].style.visibility ="Hidden";
}

function RedirectOpener(strUrl,bClose){
	if (window.opener) {
		window.opener.document.location = strUrl;
		if (bClose) window.close();
	} else {
		document.location = strUrl;
	}
}

function htmlDecode(str) {
	// Simple client side HTML decoding.
	str=str.replace(/&quot;/gi,'"');
	str=str.replace(/&nbsp;/gi,' ');
	//str=str.replace(/<br>/gi,'\n');
	str=str.replace(/&gt;/gi,'>');
	str=str.replace(/&lt;/gi,'<');
	str=str.replace(/&amp;/gi,'&');
	return str
}

function docWrite(str) {
	// Useful if you need to write a swf file, that needs to work in IE.
	document.write(str);
}
