

function initLoginSuccessHTML()
{
	
	var div = document.getElementById("DATA-TABLE");

	if (div)
	{	
		var form = div.childNodes[findTag(div,"form")];
			
		if(form)
		{ 
			var table = form.childNodes[findTag(form,"table")].tBodies[0]; 

			if(table)
			{			
				var currenttable, savedtable, currentvalue, savedvalue;
				
				// alter table
				for (var i=0; i<table.rows.length; i++)
				{
					var ni = -1;
					var ti = findTag(table.rows[i].cells[0],"input");	// tag index of radio button
					
					if (ti > -1)
					 { ni = findNextNodeType(table.rows[i].cells[0].childNodes[ti],3); }		// node index of text label	
			
					if (ni > -1)
					{
	//					alert(table.rows[i].cells[0].childNodes[ni].nodeValue);						
						if ((table.rows[i].cells[0].childNodes[ni].nodeValue) && (table.rows[i].cells[0].childNodes[ni].nodeValue.search("Saved") > -1))
						{ 
							savedvalue = table.rows[i].cells[0].childNodes[ti].value;
	//						alert(savedvalue);
							savedtable = table.rows[i].cells[1].childNodes[ti];
							table.rows[i].cells[0].childNodes[ni].nodeValue = " Saved Cart"; 					
						}
						else if ((table.rows[i].cells[0].childNodes[ni].nodeValue) && (table.rows[i].cells[0].childNodes[ni].nodeValue.search("Last") > -1))
						 { table.rows[i].cells[0].childNodes[ni].nodeValue = " Last Order"; }
						else if ((table.rows[i].cells[0].childNodes[ni].nodeValue) && (table.rows[i].cells[0].childNodes[ni].nodeValue.search("Current") > -1))
						{ 
							currentvalue = table.rows[i].cells[0].childNodes[ti].value;
	//						alert(currentvalue);
							currenttable = table.rows[i].cells[1].childNodes[ti];
							table.rows[i].cells[0].childNodes[ni].nodeValue = " Current Cart"; 
						}
						else
						 { table.rows[i].cells[0].childNodes[ni].nodeValue = " Empty Cart"; }								
					}
				}
				
				if ((currentvalue) && (savedvalue))
				{
					currentvalue = currentvalue.replace(";","");
					currentvalue += savedvalue.replace("basket=","");
	//				alert(currentvalue);
					var tabledata = getTableData([currenttable,savedtable]);
					if (tabledata)
					 { table.rows[0],newTR(tabledata[0],tabledata[1],tabledata[2],tabledata[3],table,currentvalue); }
				}

				// style the table
				for (var i=0; i<table.rows.length; i++)
				{
					table.rows[i].cells[0].className = "input-head";
					if (findTag(table.rows[i].cells[1],"table") > -1)
					 { table.rows[i].cells[1].childNodes[findTag(table.rows[i].cells[1],"table")].className = "inner-table"; }
					
					table.rows[i].cells[1].className = "input-col no-pad";													
				}
			}
	
		
			// style button
			form.removeChild(form.childNodes[findTag(form,"center")]);
			
			var button = document.createElement("input");
	
			if (button)	
			{
				button.type = "submit";
				button.className = "submit";
				button.name = "setbasket";
				button.alt = "Use This Cart";
				button.value = "Use This Cart";
				setStyle(button,"display:block; margin:auto;");
				form.appendChild(button);			
			}
		}
		else
		{	
			var table = div.childNodes[findTag(div,"table")].tBodies[0];
			
			setStyle(div,"float:right; margin-right:50px;");
			
			if (table)
			{	
				setStyle(table,"float:right; width:400px;");
				table.width=400;		
				for (var i=0; i<table.rows.length; i++)
				{
					table.rows[i].cells[0].className = "input-col no-pad";
					if (findTag(table.rows[i].cells[0],"table") > -1)
					 { table.rows[i].cells[0].childNodes[findTag(table.rows[i].cells[0],"table")].className = "inner-table"; }													
				}
				
				table = table.rows[0].cells[0].childNodes[findTag(table.rows[0].cells[0],"table")].tBodies[0]
				if (table)
				{	
					setStyle(table, "width:400px;");
					table.width=400;
					for (var i=0; i<table.rows.length; i++)
					{
						if(table.rows[i].cells.length == 2)
						{														
							setStyle(table.rows[i].cells[0], "width:50px;");
							setStyle(table.rows[i].cells[1], "width:350px;");
							table.rows[i].cells[0].width=50;
							table.rows[i].cells[1].width=350;
						}
					}
				}
			}
		}
	}
}


function getTableData(table)
{
	var cartQty = new Array();
	var cartDesc = new Array();
	var cartWeight = new Array();
	var numCartItems = 0;
	
	for (i=0; i<2; i++)
	{
		if (table[i].rows.length > 2)
		{
			//alert(table[i].rows.length);	
			for (var j=2; j<table[i].rows.length; j++)
			{
				if (table[i].rows[j].cells.length == 2)
				{
					cartQty[numCartItems] = table[i].rows[j].cells[0].childNodes[0].nodeValue;
					//alert(cartQty[numCartItems]);
					cartDesc[numCartItems] = table[i].rows[j].cells[1].childNodes[0].nodeValue;
					//alert(cartDesc[numCartItems]);
					cartWeight[numCartItems] = table[i].rows[++j].cells[1].childNodes[0].nodeValue;
					//alert(cartWeight[numCartItems]);
					numCartItems++;
				}
			}
		}
		else
		 { return false; }
	}
	return [cartQty,cartDesc,cartWeight,numCartItems];
}


function newTR(cartQty, cartDesc, cartWeight, numCartItems, mainTable, buttonValue) {
	var table,tr,td,elem;
	
	var newtr = mainTable.insertRow(0);	
	td = newtr.appendChild(document.createElement("td"));
		
		elem = document.createElement("input")
		elem.type = "radio";
		elem.name = "SelectedBasket";
		elem.value = buttonValue;
		td.appendChild(elem);
			
		td.appendChild(document.createTextNode(" Combined Cart"));
	td = newtr.appendChild(document.createElement("td"));
		table = td.appendChild(document.createElement("table"));
			setStyle(table,"cell-padding:1px; width:100%;");
			tr = table.insertRow(table.rows.length);
				td = tr.appendChild(document.createElement("td"));
					td.colSpan = "2";
					setStyle(td,"text-align:center; font-style:italic;");
					td.appendChild(document.createTextNode("Current Cart + Saved Cart"));
	/*			td = tr.appendChild(document.createElement("td"));
					td.width = "50";
					td.align = "center";
					td.appendChild(document.createElement("b"));
						td.childNodes[0].appendChild(document.createTextNode("Qty"));
				td = tr.appendChild(document.createElement("td"));
					td.width = "200";
					td.appendChild(document.createElement("b"));
						td.childNodes[0].appendChild(document.createTextNode("Description"));
			tr = table.insertRow(table.rows.length);
				td = tr.appendChild(document.createElement("td"));
					td.colSpan = "2";				
					td.appendChild(document.createElement("hr"));

			for(var i=0; i<numCartItems; i++)
			{
			tr = table.insertRow(table.rows.length);
				td = tr.appendChild(document.createElement("td"));
					td.setAttribute("valign","middle");
					td.appendChild(document.createTextNode(cartQty[i]));
				td = tr.appendChild(document.createElement("td"));
					td.appendChild(document.createTextNode(cartDesc[i]));
			tr = table.insertRow(table.rows.length);
				td = tr.appendChild(document.createElement("td"));
				td = tr.appendChild(document.createElement("td"));
					td.appendChild(document.createTextNode(cartWeight[i]));				
			}
	*/
}

function initOrderDetailHTML(formid)
{
	var div = document.getElementById("DATA-TABLE");
	
	if (div)
	{	
		var table = div.childNodes[findTag(div,"table")].tBodies[0];
		
		if(table)
		{
			var data = new Array();
			
			// read in table data for reorder form			
			for (var i=4, j=0; ((table.rows[i].cells[0].childNodes[0].tagName != "HR") && (i<table.rows.length)); i++,j++)
			{
				data[j] = new Array;
								
				if ((table.rows[i].cells[0]) && (table.rows[i].cells[0].hasChildNodes()) && (table.rows[i].cells[0].childNodes[0].nodeType == 3)
				 && (table.rows[i].cells[1]) && (table.rows[i].cells[1].hasChildNodes()) && (table.rows[i].cells[1].childNodes[0].tagName == "A"))
				{
					data[j][0] = table.rows[i].cells[0].childNodes[0].nodeValue;
					data[j][1] = getSKU(table.rows[i].cells[1].childNodes[0].href);			
				}
			}
			
			// add basket data for the reorder form
			var basketField = document.getElementById("BASKET-DATA");
			var basketValue = "basket=";
			
			for (var i=0; i<data.length; i++)
			 { basketValue += ("|" + data[i][1] + ',' + data[i][0]); }
			basketValue += ';';
			
			basketField.value = basketValue;
			
			// reformat date strings
			for (var i=0; i<table.rows.length; i++)
			{
				for (var j=0; j<table.rows[i].cells.length; j++)
				{
					if (table.rows[i].cells[j].hasChildNodes())
					{
						for(var k=0; k<table.rows[i].cells[j].childNodes.length; k++)
						{
							if (table.rows[i].cells[j].childNodes[k].nodeType == 3)
							{
								var theNodeValue = table.rows[i].cells[j].childNodes[k].nodeValue;
								var theDate = findDateTime(theNodeValue);
								if (theDate)
								 {	
								 	table.rows[i].cells[j].childNodes[k].nodeValue = theNodeValue.replace(getDateTimeString(theNodeValue),theDate.toDateString() + ' - ' + timeToString(theDate)); 
								 }
							}
						}
					}
				}
			}
			// rearrange table data
			for (var i=1; i<table.rows.length; i++)
			{}
		}		
	}	
	
	var theform = document.getElementById(formid);	
}


function getSKU(theHREF)
 { return theHREF.substring(theHREF.lastIndexOf("key=")+4); }
 
 
function initOrderHistoryHTML()
{
	var div = document.getElementById("DATA-TABLE");
	
	if (div)
	{	
		var table = div.childNodes[findTag(div,"table")].tBodies[0];
		
		if(table)
		{
			var data = new Array();
			
			// remove rows with <hr>'s
			for (var i=1; i<table.rows.length; i++)
			{
				if (table.rows[i].cells[0].childNodes[0].tagName == "HR")
				 { table.removeChild(table.rows[i]); }
			}
			table.removeChild(table.rows[1]);
			// read in table data			
			for (var i=0; i<table.rows.length; i++)
			{
				data[i] = new Array;
				
				for (var j=0; j<table.rows[0].cells.length; j++)
				{
					if (table.rows[i].cells[j]) {
					data[i][j] = table.rows[i].cells[j].childNodes[0].nodeValue;
					
					//alert(data[i][j] + " " + i + " " + j);
					}
				}
			}
		
			// rearrange table data
			for (var i=1; i<table.rows.length; i++)
			{
				var str1, str2, strind;
				var theDate = new Date();
					
				table.rows[i].cells[3].childNodes[0].nodeValue = '$' + table.rows[i].cells[3].childNodes[0].nodeValue;
				
				strind = table.rows[i].cells[4].childNodes[0].nodeValue.search(/\d{4}\D{1}\d{1,2}\D{1}\d{1,2}/);
				str1 = table.rows[i].cells[4].childNodes[0].nodeValue.substring(0,strind);
				str2 = table.rows[i].cells[4].childNodes[0].nodeValue.substring(strind);
				//str2 = str2.replace("T"," @ ");
				
				theDate = findDateTime(str2);
				str2 = str2.replace(getDateTimeString(str2),theDate.toDateString() + ' - ' + timeToString(theDate));
				
				table.rows[i].cells[4].childNodes[0].nodeValue = str1;
				table.rows[i].cells[4].appendChild(document.createElement("br"));
				table.rows[i].cells[4].appendChild(document.createTextNode(str2));
/*
				table.rows[i].cells[4].appendChild(document.createElement("br"));
				table.rows[i].cells[4].appendChild(document.createElement("br"));
				table.rows[i].cells[4].appendChild(document.createTextNode("Date:  "));			
				table.rows[i].cells[4].appendChild(document.createTextNode(data[i][1]));
				table.rows[i].cells[4].appendChild(document.createElement("br"));
				table.rows[i].cells[4].appendChild(document.createElement("br"));
				table.rows[i].cells[4].appendChild(document.createTextNode("Shipping:  "));			
				table.rows[i].cells[4].appendChild(document.createTextNode(data[i][5]));
*/
				table.rows[i].removeChild(table.rows[i].cells[1]);
				table.rows[i].removeChild(table.rows[i].cells[4]);

				table.rows[i].cells[0].className = "input-col";
				setStyle(table.rows[i].cells[0],"font-weight:bold;");
				table.rows[i].cells[1].className = "input-col";
				table.rows[i].cells[2].className = "input-col";
				table.rows[i].cells[3].className = "input-col";
				table.rows[i].cells[4].className = "input-col";
			}
			table.rows[0].removeChild(table.rows[0].cells[1]);
			table.rows[0].removeChild(table.rows[0].cells[4]);					
			// set up headers
			table.rows[0].cells[0].className = "input-head";
			table.rows[0].cells[1].className = "input-head";
			//setStyle(table.rows[0].cells[1],"width:75px;");
			table.rows[0].cells[2].className = "input-head";
			table.rows[0].cells[3].className = "input-head";
			table.rows[0].cells[4].className = "input-head";
		}		
	}	
	
	var inputs = document.getElementsByTagName("input");
	
	for (var i=0; i<inputs.length; i++)
	{
		if ((inputs[i].type.toLowerCase() == "submit") && (!inputs[i].className))
		 { inputs[i].className = "submit"; setStyle(inputs[i],"margin:10px 5px;");}
	}
}


function timeToString(theDate)
{
	var ampm = "am";
	var thehour = theDate.getHours()+1;
	
	if (thehour > 12)
	 { ampm = "pm"; thehour -= 12; }
	
	return (thehour + ':' + theDate.getMinutes() + ampm);
}


function splitDateTime(str)
{
	if (str)
	{
		str = str.replace(":","-");
		str = str.replace(":","-");
		str = str.replace("T","-");
		return str.split("-");
	}
	else
	 { return null; }
}


function getDateTimeString(str)
{
	var datestr = str.match(/\d{4}-{1}\d{2}-{1}\d{2}T{1}\d{1,2}:{1}\d{2}:{1}\d{2}/);
	if (datestr)
	 { return datestr.toString(); }
	else
	 { return null; }
}

function findDateTime(str)
{
	var theDate = new Date();
	var datedata = splitDateTime(getDateTimeString(str));
	
	if (datedata)
	{
		theDate.setFullYear(datedata[0],--datedata[1],datedata[2]);
		theDate.setHours(datedata[3]);
		theDate.setMinutes(datedata[4]);
		theDate.setMilliseconds(datedata[5]);
	
		return theDate;
	}
	else
	 { return null; }
}

function findTag(elem, tagname)
{
	if (elem) {
		if (elem.hasChildNodes())
		{			
			for (var i=0; i<elem.childNodes.length; i++)
			{	
				if (elem.childNodes[i].tagName == tagname.toUpperCase())
				 {	return i; } // success
			}
		}
	}
	else
	 { alert("elem doesn't exist in function 'findTag(elem, tagname);'"); }
	return -1; // fail	
}

function findNextNodeType(elem, type)
{
	var doSearch = false;
	
	if (elem) {
		if (elem.parentNode)
		{			
			for (var i=0; i<elem.parentNode.childNodes.length; i++)
			{		
				if (doSearch)
				{
					if (elem.parentNode.childNodes[i].nodeType == type)
					 {	return i; } // success
				}
				else	
				 { if (elem.parentNode.childNodes[i] == elem)  { doSearch = true; }  }
			}
		}
	}
	else
	 { alert("elem doesn't exist in function 'findNodeType(elem, type);'"); }
	return -1; // fail	
}

// >>UserUpdate.HTML>>
function initUserUpdateHTML(formid)
{
	var theform = document.getElementById(formid);
	var theSelectBox = document.getElementById(formid).contactsel;
	
	theform.Concountry.onchange = function()  { adjustState(theform.Constate,theform.Concountry); };
	theform.Constate.onchange = function()  { adjustCountry(theform.Constate,theform.Concountry); };
	theform.contactsel.onchange = function() 
	{   
		eval("setcontact"+theSelectBox[theSelectBox.selectedIndex].value+"();");
				
		if (theform.Constate.selectedIndex > 0)	// fix glitch in PDG software that causes wrong state to be displayed
		 { theform.Constate.selectedIndex -= 1; }
	};
	
/*******
	for (var i=0; i<theSelectBox.length; i++)	// remove the stupid 'friendly' name
	{ 	
		if (theSelectBox[i].text.substring(0,3) == "***")
		 { theSelectBox[i].text = theSelectBox[i].text.substring(5); }		
	}
*******/
		 
	adjustLocationReqs(theform.Constate,theform.Concountry,theform.Conzip);
}

function adjustUserUpdateReqs(formid,action)
{
	var theform = document.getElementById(formid);
	var elem = theform.elements;
	
	/*theform.Confriendlyname.value="***";	// use to remove 'friendly' name */
	
	for (var i=0; i<elem.length; i++)
	 { elem[i].setAttribute("class",""); elem[i].setAttribute("errortext",""); }
	 
	switch(action) {
		case "updatecustomer": //validate:customer;
			if ((theform.contactpass.value) || (theform.contactpass2.value))
			{
				theform.contactpass.setAttribute("class", "requiredfield"); 
				theform.contactpass2.setAttribute("class", "requiredfield");
			}
			else
			 { theform.contactemail.setAttribute("class", "requiredfield"); }
			break;
			
		case "updatecontact": //validated:contact;
			if(theform.contactsel[theform.contactsel.selectedIndex].text == "Add New Contact")
			{			
				theform.contactsel.setAttribute("class", "requiredfield");
				theform.contactsel.setAttribute("errortext", "You must select a contact to update.");
				break;
			}
			
		case "addcontact":
				theform.Confirstname.setAttribute("class", "requiredfield");
				theform.Conlastname.setAttribute("class", "requiredfield");
				theform.Constreet1.setAttribute("class", "requiredfield");
				theform.Concity.setAttribute("class", "requiredfield");
				theform.Conphone1.setAttribute("class", "requiredfield");
				theform.Confriendlyname.setAttribute("class", "requiredfield");
				adjustLocationReqs(theform.Constate, theform.Concountry, theform.Conzip);
			break;			

			
		case "removecontact": // validate:contact-select;
			if(theform.contactsel[theform.contactsel.selectedIndex].text == "Add New Contact")
			{
				theform.contactsel.setAttribute("class", "requiredfield");
				theform.contactsel.setAttribute("errortext", "You must select a contact to remove.");
			}
			break;
	}
	
	return elem;	
}

// >>Basket.HTML>>
function initBasketHTML(formid)
{
	var theform = document.getElementById(formid);
	
	theform.onsubmit = function() {
		adjustBasketReqs(this);
		return validateForm(this);
	};
	
	theform.shipcountry.onchange = function()  { adjustState(theform.shipstate,theform.shipcountry); };
	theform.shipstate.onchange = function()  { adjustCountry(theform.shipstate,theform.shipcountry); };
	
	adjustBasketReqs(theform);
}

function adjustBasketReqs(theform)
{
	if ((theform.shipcountry.options[theform.shipcountry.selectedIndex].text == "United States of America")		// If Country is US or Canada, require State and Zip Code otherwise require neither.
	 || (theform.shipcountry.options[theform.shipcountry.selectedIndex].text == "Canada")) 
	{
		theform.shipstate.setAttribute("class", "requiredfield");
		theform.shipzip.setAttribute("class", "requiredfield");
	} 
	else 
	{
		theform.shipstate.setAttribute("class", "");
		theform.shipzip.setAttribute("class", "");
	}
}

// >>SearchResult.HTML>>
function initSearchResultHTML(formid)
{
	var inputs = document.getElementsByTagName("input");

	for(var i=0; i<inputs.length; i++)
	{
		if(inputs[i].name.match("madd"))
		 { inputs[i].setAttribute("id",getId(inputs[i].name)); }		
	}
}

// >>Sample-Item.HTML>>
function initSampleItemHTML(crumb)
{ 
	highlightThumb(document.getElementById('item-image'));
	
	var anchors = document.getElementsByTagName('a');
	
	for(var i=0; i<anchors.length; i++)
	 { if (anchors[i].className == "inactive")  { anchors[i].href = "javascript:void(0);"; }  }
	 
	// hide "Product Images" tab if there is only one image available
	if (countNodeType(document.getElementById("thumb-frame"),1) <= 2) // there are two children, <a> and <br>, for each image
	 { setStyle(document.getElementById("imagesLI"),"display:none;"); }
	
	addCrumb(crumb);
	document.getElementById("Sample-Item").realtimeprice.setAttribute("size","8"); 
}

function initItemTemp_DefaultHTML(desc)
{
	if (!desc)
	 { 
		 setStyle(document.getElementById("general-infoLI"),"display:none;");
		 setStyle(document.getElementById("General-Info"),"display:none;"); 
	 }
}

function countNodeType(elem,type)
{
	var count = -1;

	if ((elem) && (elem.hasChildNodes()))
	{
		for (var i=0,count=0; i<elem.childNodes.length; i++)
		{
			if (elem.childNodes[i].nodeType == type)
			 { count++; }
		}
	}
	
	return count;
}

// ^^initSampleItemHTML^^
function addCrumb(crumb)
{
	var crumbtrail = document.getElementById("crumb_nav");
	
	crumbtrail.appendChild(document.createTextNode('>> '));													// '>> '
	
	crumbtrail.appendChild(document.createElement('a'));													// <a>
	crumbtrail.lastChild.href = "https://bindingtape.com/cgi-bin/commerce.cgi?preadd=action&key=" + crumb;	// href=""
	
	crumbtrail.lastChild.appendChild(document.createTextNode(crumb));										// crumb
}

// >>Error.HTML>>
function initErrorHTML()
{
	var text = document.getElementById("errortext");
	
	// I've only identified two type of error messages generated. This code will properly highlight
	// the error text in those types of messages. If another type exists this may either highlight 
	// the wrong information or too much information
	if (text.childNodes[1])					// if a second <P> element exists
	  { setStyle(text.childNodes[1],"color: red;"); }		// use it
	else									// else	
	  { setStyle(text.childNodes[0],"color: red;"); }	  	// use the first
}
function disableVerifySubmits()
{
	document.getElementById('buyit1').disabled=true;
	document.getElementById('buyit2').disabled=true;
}	

function enableVerifySubmits()
{
	document.getElementById('buyit1').disabled=false;
	document.getElementById('buyit2').disabled=false;
	return false;
}

// >>Verify.HTML>>
function initVerifyHTML()
{
	document.getElementById('VerifyForm').onsubmit = function() {
		disableVerifySubmits();
		adjustVerifyReqs();
		return (validateForm(this)) ? true : enableVerifySubmits();		
	};
	
	adjustVerifyReqs(); // Initializes all reqs based on 'billmethod' selection.
}

// ^^initVerifyHTML()^^
function adjustVerifyReqs()
{
	var theform = document.getElementById('VerifyForm');
		
	if (theform.billmethod.options[theform.billmethod.selectedIndex].text == "Credit Card")
	{
		theform.cardtype.setAttribute("class", "requiredfield");		// Set as a required field.
		theform.cardnumber.setAttribute("class", "requiredfield");
		theform.cardexpmonth.setAttribute("class", "requiredfield");
		theform.cardexpyear.setAttribute("class", "requiredfield");
		theform.ccv2.setAttribute("class", "requiredfield");
	}
	else
	{
		theform.cardtype.setAttribute("class", "");		// Set as not required field.
		theform.cardnumber.setAttribute("class", "");
		theform.cardexpmonth.setAttribute("class", "");
		theform.cardexpyear.setAttribute("class", "");
		theform.ccv2.setAttribute("class", "");
	}
}

// >>Register.HTML>>
function initRegisterHTML()
{
	var theform = document.getElementById('RegisterForm');

	theform.onsubmit = function() { 
		initBillShipReqs(theform);
		return validateForm(this); 
	}; 
	
	theform.contactname.setAttribute("class", "requiredfield");		// Set as a required field.
	theform.contactpass.setAttribute("class", "requiredfield");
	theform.contactpass2.setAttribute("class", "requiredfield");
	theform.contactemail.setAttribute("class", "requiredfield");
	theform.billphone1.setAttribute("class", "requiredfield");

	initBillShipSelectBoxes(theform);
	initBillShipReqs(theform);
}

// >>Checkout.HTML>>
function initCheckoutHTML()
{
	var theform = document.getElementById('CheckoutForm');
	
	theform.onsubmit = function() { 
		initBillShipReqs(theform);
		return validateForm(this); 
	}; 
	
	theform.contactname.setAttribute("class", "requiredfield");		// Set as a required field.
	theform.contactemail.setAttribute("class", "requiredfield");
	theform.phone1.setAttribute("class", "requiredfield");

	initBillShipSelectBoxes(theform);
	initBillShipReqs(theform);
}

// ^^initCheckoutHTML()^^
function initBillShipSelectBoxes(theform)
{
	theform.billcountry.onchange = function()  { adjustState(theform.billstate,theform.billcountry); };
	theform.billstate.onchange = function()  { adjustCountry(theform.billstate,theform.billcountry); };
	theform.shipcountry.onchange = function()  { adjustState(theform.shipstate,theform.shipcountry); };
	theform.shipstate.onchange = function()  { adjustCountry(theform.shipstate,theform.shipcountry); };
}

// ^^initCheckoutHTML()^^
function initBillShipReqs(theform)
{
	theform.billfirstname.setAttribute("class", "requiredfield");	// Set as a required field
	theform.billlastname.setAttribute("class", "requiredfield");
	theform.billstreet1.setAttribute("class", "requiredfield");
	theform.billcity.setAttribute("class", "requiredfield");
	theform.billcountry.setAttribute("class", "requiredfield");
	
	adjustLocationReqs(theform.billstate,theform.billcountry,theform.billzip);		// Initializes billstate/billzip and all shipping reqs.

	if ((!theform.shiptobilladdr) 														// If "Ship to tbe Billing Address" box is checked, don't require shipping info.
	 || (!theform.shiptobilladdr.checked))
	{ 
		adjustLocationReqs(theform.shipstate,theform.shipcountry,theform.shipzip); // Initializes billstate/billzip and all shipping reqs.
		theform.shipcountry.setAttribute("class", "requiredfield");
		theform.shipstreet1.setAttribute("class", "requiredfield");
		theform.shipcity.setAttribute("class", "requiredfield");
	}
	else
	{
		theform.shipcountry.setAttribute("class", "");
		theform.shipstreet1.setAttribute("class", "");
		theform.shipcity.setAttribute("class", "");
		theform.shipstate.setAttribute("class", "");
		theform.shipzip.setAttribute("class", "");
	}
}

// ^^initCheckoutReqs()^^	>>custom.js:validateForm()>>
function adjustLocationReqs(theState,theCountry,theZip)
{	
	if ((theCountry.options[theCountry.selectedIndex].text == "United States of America")		// If Country is US or Canada, require State and Zip Code otherwise require neither.
	 || (theCountry.options[theCountry.selectedIndex].text == "Canada")) 
	{
		theState.setAttribute("class", "requiredfield");
		theZip.setAttribute("class", "requiredfield");
	} 
	else 
	{
		theState.setAttribute("class", "");
		theZip.setAttribute("class", "");
	}
}

// >>Head.HTML>>
function initLinks()
{
	for (var a=0; a<document.links.length; a++)
	{
		if ((document.links[a].href == 'https://bindingtape.com/') || (document.links[a].href == 'https://www.bindingtape.com/')
		 || (document.links[a].href == 'http://bindingtape.com/')  || (document.links[a].href == 'http://www.bindingtape.com/'))
		{	
			document.links[a].href = 'https://bindingtape.com/cgi-bin/commerce.cgi?listcategories';
			
			if ((document.links[a].childNodes[0]) && (document.links[a].childNodes[0].nodeValue == "Top")
			 && (document.links[a].parentNode.id == "crumb_nav"))			 
			  { document.links[a].childNodes[0].nodeValue = "Products"; }
		}	
	}
}

// >>Head.HTML>>
function initImages()
{	
	for (var a=0; a<document.images.length; a++)
	{
		if(!document.images[a].onerror)
		  { document.images[a].onerror = function() { onImgErrorSmall(this); };	}
	}
}
