function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadwebready() { //v3.0
  var d=document; if(d.webready){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadwebready.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openPopupNone(theUrl, height, width)
{
	var features = "toolbar=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height;
	myWindow = window.open(theUrl, 'NewWindow', features);
	myWindow.focus();
}

function openPopupAll(theUrl, height, width)
{
	var features = "toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height;
	myWindow = window.open(theUrl, 'NewWindow', features);
	myWindow.focus();
}


var gIntID = 0;
var fieldNumbers = new Array();
	
function insertRow() {
	gIntID = gIntID + 1;
	fieldNumbers.push(gIntID);
	
	var tbody = document.getElementById("table1").getElementsByTagName("tbody")[0]; 
	var row = document.createElement("tr");
	row.setAttribute("valign", "top");
	
	// cell for the hghlights inputs
	var cell_h = document.createElement("td"); 
	cell_h.setAttribute("nowrap", "true");

	// highlight color input
	var ctrl_h = document.createElement("INPUT");	
	ctrl_h.setAttribute("type","text");
	ctrl_h.name = "Highlight_" + gIntID;
	ctrl_h.setAttribute("id","Highlight_"+gIntID);
	ctrl_h.setAttribute("value","");
	ctrl_h.setAttribute("size","75");

	// assemble highlight input cell content
	cell_h.appendChild(ctrl_h);


	var cell_remove = document.createElement("td");
	var removeLink = document.createElement("a");
	removeLink.setAttribute("href", "#");
	var hrefValue = new Function("DeleteRow(this)");
	removeLink.onclick = hrefValue;
	removeLink.innerHTML = "Remove";
	cell_remove.appendChild(removeLink);

	// assemble cells of row
	row.appendChild(cell_h);
	row.appendChild(cell_remove);
	tbody.appendChild(row);
}

function DeleteRow(x)
{
	while (x.tagName.toLowerCase() !='tr') {
		if (x.parentElement)
			x=x.parentElement;
		else if (x.parentNode)
			x=x.parentNode;
		else
			return;
	}
    
	var rowNum=x.rowIndex;
    
	while (x.tagName.toLowerCase() !='table') {
		if (x.parentElement)
			x=x.parentElement;
		else if (x.parentNode)
             x=x.parentNode;
		else
			return;
	}

	x.deleteRow(rowNum);  
}

// function used on custinfo to fill in the shipping info with the billing info
function fillShip() {
	document.info.ShipLastName.value = document.info.BillLastName.value;
	document.info.ShipFirstName.value = document.info.BillFirstName.value;
	document.info.ShipEmail.value = document.info.BillEmail.value;
	document.info.ShipAddress1.value = document.info.BillAddress1.value;
	document.info.ShipAddress2.value = document.info.BillAddress2.value;
	document.info.ShipCity.value = document.info.BillCity.value;
	document.info.ShipZipCode.value = document.info.BillZipCode.value;
	document.info.ShipState.options[document.info.BillState.selectedIndex].selected = true;
	document.info.ShipTelephone.value = document.info.BillTelephone.value;
	
	checkStateForTax();
}

function emptyShip() {
	document.info.ShipLastName.value = "";
	document.info.ShipFirstName.value = "";
	document.info.ShipEmail.value = "";
	document.info.ShipAddress1.value = "";
	document.info.ShipAddress2.value = "";
	document.info.ShipCity.value = "";
	document.info.ShipZipCode.value = "";
	document.info.ShipState.options[0].selected = true;
	document.info.ShipTelephone.value = "";
	
	checkStateForTax();
}

// function used on custinfo to double check the form before submission
function checkForm() {
	var mySelectedState = "";

	if (document.info.billShipInfoSame[0].checked) {
		fillShip();
		mySelectedState = document.info.BillState.options[document.info.BillState.selectedIndex].value;
	} else {
		mySelectedState = document.info.ShipState.options[document.info.ShipState.selectedIndex].value;		
	}

	var errorMsg = "";

	if (mySelectedState.indexOf("Select") > -1)
		errorMsg = errorMsg + "Please specify the shipping state.\n";	
	
	if (errorMsg == "")
		return true;
	else {
		alert(errorMsg);
		return false;
	}
}