<!-- IR_Javascript.js -->

var windowname, windowname2, con_qty, con_price, con_tot;
var dge=document.getElementById;

// ***** Load functions ******
function loadDefault()
{

	var defaultAt, lenURL, theLoc;

	// Tested with IR site

	theLoc = window.parent.location.toString();


	lenURL = theLoc.length;


	defaultAt = theLoc.lastIndexOf('default.html',lenURL);

	//	alert(defaultAt);


	if (defaultAt < 0)
	{  
	//	alert("reloading");
	//	window.parent.location = "default.html";
		ChangePage("default.html");
	}


}
function ChangePage(Pg)
{
	document.location = Pg;
}
function StockFrame(Pg)
{


	var frames, framename, parent;

	// Tested with IR site

	//alert(Pg + " should appear in frame");

	parent = window.parent;

	frames = parent.length;

	//alert(frames);

	//alert(parent.frames[2]);

	framename = parent.frames[2];

	//alert(framename);

	framename.document.location=Pg;
	
}
function OpenOrderPage(Pg)
{

	var instr, theURL, theName;

	// Tested with IR site

	theURL = "Order_Form.html";
	theName = "Order_Form";


	instr = "toolbar=no,location=no,directories=no,status=no,";
	instr = instr + "menubar=yes,scrollbars=yes,resizable=yes,";
	instr = instr + "copyhistory=no,width=600,height=400";

	//alert(instr);

	windowname = window.open(theURL,theName,instr);

	windowname.focus();

}
function OpenShippingRef(Pg)
{

	var instr, theURL, theName;

	// Tested with IR site

	theURL = "Shipping.html";
	theName = "Shipping_Reference";

	instr = "toolbar=no,location=no,directories=no,status=no,";
	instr = instr + "menubar=no,scrollbars=yes,resizable=yes,";
	instr = instr + "copyhistory=no,width=600,height=400";

	//alert(instr);

	windowname = window.open(theURL,theName,instr);

	windowname.focus();

}
function OpenReferenceChart(Pg,PgTitle)
{

	var instr, theURL, theName;

	// Tested with IR site

	theURL = "DioramaRef.html";
	theName = "Diorama_Reference";

	instr = "toolbar=no,location=no,directories=no,status=no,";
	instr = instr + "menubar=no,scrollbars=yes,resizable=yes,";
	instr = instr + "copyhistory=no,width=600,height=400";

	// alert(instr);

	windowname2 = window.open(theURL,theName,instr);

	windowname2.focus();

}
function SubmitForm(FormIn)
{

	var x,strForm;
	
	strForm = "document.forms['" + FormIn + "']";
	
	x = eval(strForm);
	
	x.submit();

}
//**** Expandable List Functions *****
function cl_expcol(a)
{
	// Copied from http://webpageworkshop.co.uk/main/article11
	// following has to be globally defined: var dge=document.getElementById;
	  if(!dge)return;
	    document.getElementById(a).style.display = 
	      (document.getElementById(a).style.display=='none')?
	      'block':'none';
      
}
function cl_colall()
{
  if(!dge)return;
  for(i=1;document.getElementById('ex'+i);i++){
    document.getElementById('ex'+i).style.display='none';
  }
}

// ****** Calculation Functions for Order Form ******
function pasteItem(code,desc,price)
{

var lnno,q,qtyT,codeT,priceT,descT,lineT,qtyT2,fdV,pstHr,nst,fld,tURL,tNm,x;

	tURL = "Order_Form.html";
	tNm = "Order_Form";


	nst = "toolbar=no,location=no,directories=no,status=no,";
	nst = nst + "menubar=yes,scrollbars=yes,resizable=yes,";
	nst = nst + "copyhistory=no,width=600,height=400";

	//alert(nst);
	
	windowname = window.open(tURL,tNm,nst);
	
	if(windowname.document.forms['OrderForm']==null)
	{
		return;
	}

	windowname.focus();

	//self.focus();

	//alert(windowname.document.forms.length);
	


	if (confirm("Add " + desc + " to Printable Order Form?"))
	{

	x = "windowname.document.forms['OrderForm'].elements['";
	
	//alert(x.name);

	pstHr = true;


	//alert(code + desc + price);
	
	for (lnno=1; lnno <= 8; lnno++)
	{
	
		qtyT="n_qty" + parseInt(lnno);
		codeT="code" + parseInt(lnno);
		priceT="n_pri" + parseInt(lnno);
		descT="desc" + parseInt(lnno);
		lineT="n_ln" + parseInt(lnno);
		qtyT2="n_qty" + parseInt(lnno+1);

		q=1;

		fld=eval(x + qtyT + "']");
		if((fld==null)||(fld==undefined))
		{
			return;
		}
		fdV=fld.value;
		//alert(fld.name);
		if(fdV!="")
		{
			//alert(fdV);
			pstHr = false;
			if(isNaN(fdV)==false)
			{
				q = parseInt(fdV);
				//alert(q);
			}
		}

		fld=eval(x + codeT + "']");
		fdV=fld.value;
		//alert(fld.name);
		if(fdV!="")
		{
			//alert(fdV);
			pstHr = false;
		}
		
		fld=eval(x + priceT + "']");
		fdV=fld.value;
		//alert(fld.name);
		if(fdV!="")
		{
			//alert(fdV);
			pstHr = false;
		}
		
		fld=eval(x + descT + "']");
		fdV=fld.value;
		//alert(fld.name);
		if(fdV!="")
		{
			//alert(fdV);
			pstHr = false;
		}
		if(fdV==desc)
		{
			if(isNaN(q)==false)
			{
				q = q+1;
			}
			//alert(q);
			pstHr = true;
		}
		//fld=eval(x + lineT + "']");
		//fdV=fld.value;
		//alert(fld.name);
		//if(fdV!="")
		//{
		//	//alert(fdV);
		//	pstHr = false;
		//}
		if(pstHr==true)
		{
			//alert("paste here at " + qtyT);
			fld=eval(x  +  qtyT + "']");
			fld.value = OutputQuantity(String(q));
			fld=eval(x  +  codeT + "']"); 
			fld.value = code;
			fld=eval(x  +  priceT + "']");
			fld.value = OutputCurrency(price);
			fld=eval(x  +  descT + "']");
			fld.value = desc;
			//fld=eval(x  +  lineT + "']");
			//fld.value = OutputCurrency(price);
			break;
		}
		else
		{
			if(lnno==8)
			{	
				alert("Sorry, no more room on Order Form.");
			}
			pstHr = true;
		}

	} //end for
	
	

	windowname.focus();
	//Recalculate();


	} //end confirm
	
}
function CalcPastePriceTimesQuantity()
{

	var x,fld,qtyT,priceT,lineT,qtyV,priceV,lineV,lnno;
	
	//windowname.focus();
	
	x = document.forms['OrderForm'];
	
	for (lnno=1; lnno <= 8; lnno++)
	{
	

		fld="n_qty" + parseInt(lnno);
		qtyT=x.elements[fld];
		qtyV=qtyT.value;


		fld="n_pri" + parseInt(lnno);
		priceT=x.elements[fld];  
		priceV=priceT.value;
		

		fld="n_ln" + parseInt(lnno);
		lineT=x.elements[fld]; 
		lineV=lineT.value;
		
		

		if(((qtyV!="")&&(qtyV!=null)) && ((priceV!="")&&(priceV!=null)))
		{	
			if((isNaN(qtyV)==false)&&(isNaN(priceV)==false))
			{
			//alert("I am pasting CalcPastePriceTimesQuantity");
				lineT.value = OutputCurrency(qtyV * priceV);
			}
		}
		if(((qtyV=="")||(qtyV==null)) || ((priceV=="")||(priceV==null)))
		{	
			lineT.value = "";
		}


	} //end for
	


}
function CalcPasteShipping()
{
	var x,fld,sbTtAmt,sbTtFld,osShipFld,shpTtFld,shpTtAmt,sfFld,sfAmt;

	x = document.forms['OrderForm'];
	
	fld="n_subtot_";
	sbTtFld=x.elements[fld]; 
	sbTtAmt = sbTtFld.value;
	if((isNaN(sbTtAmt)==false))
	{
		sbTtAmt=parseFloat(sbTtAmt);
	}
	
	//alert(sbTtAmt);
	
	
	fld="n_qtyCat_";
	sfFld=x.elements[fld]; 
	sfAmt = sfFld.value;
	if((sfAmt!="")&&(isNaN(sfAmt)==false))
	{
		sfAmt = parseInt(sfAmt);
		sfAmt = sfAmt * 5;
		sbTtAmt = sbTtAmt - sfAmt;
	}
	
	//alert(sbTtAmt);
	

	fld="ckb_overseas_";
	osShipFld=x.elements[fld]; 

	fld="n_shiptot_";
	shpTtFld=x.elements[fld]; 
	shpTtAmt = 0;
	
	if(isNaN(sbTtAmt)==false)
	{
		if(osShipFld.checked==true)
		{
			shpTtAmt = sbTtAmt * .20;
			//Minimum for overseas shipping is $8
			if (shpTtAmt < 8){
				shpTtAmt=8;
			}
		}
		if(osShipFld.checked==false)
		{
			shpTtAmt = GetDomesticShipping(sbTtAmt);
		}
	}
	
	shpTtFld.value = OutputCurrency(shpTtAmt);

}
function CalculateSalesTaxTotal()
{

	var x,fld,stFld,stAmt,stxFld,stxRt,stxrFld,stxRes,sfFld,sfAmt;

	x = document.forms['OrderForm'];

	fld="n_subtot_";
	stFld=x.elements[fld]; 
	stAmt = stFld.value;
	if((isNaN(stAmt)==false))
	{
		stAmt = parseFloat(stAmt);
	}
	
	//alert(stAmt);
	
	fld="n_qtyCat_";
	sfFld=x.elements[fld]; 
	sfAmt = sfFld.value;
	if((sfAmt!="")&&(isNaN(sfAmt)==false))
	{
		sfAmt = parseInt(sfAmt);
		sfAmt = sfAmt * 5;
		stAmt = stAmt - sfAmt;
	}
	
	//alert(stAmt);

	fld = "n_selrate_";
	stxFld=x.elements[fld]; 
	stxRt = stxFld.value;
	if((isNaN(stxRt)==false))
	{
		stxRt = parseFloat(stxRt);
	}
	
	//alert(stxRt);

	fld = "n_taxrate_";
	stxrFld=x.elements[fld]; 
	stxRes= 0;
	
	if((stxRt!="")&&(stxRt!=null))
	{
		if((isNaN(stAmt)==false) && (isNaN(stxRt)==false))
		{
			
			stxRes = (stAmt * stxRt)/100;
		}
	}
	
	stxrFld.value = OutputCurrency(stxRes);

}
function CalcPasteSubTotal()
{
	var x,fld,lineT,lineVal,sbTtFld,sbTtAmt,lnno;

	x = document.forms['OrderForm'];

	sbTtAmt = 0;
	
	fld="n_subtot_";
	sbTtFld=x.elements[fld];

	for (lnno=1; lnno <= 8; lnno++)
	{
		fld="n_ln" + parseInt(lnno);
		lineT=x.elements[fld]; 
		lineVal=parseFloat(lineT.value);
		
		if((isNaN(lineVal)==false))
		{
			sbTtAmt = sbTtAmt + lineVal;
		}


	} //end for
	
	fld="n_qtyCat_";
	lineT=x.elements[fld];
	
	//alert(isNaN(lineT.value));
	
	if((lineT.value!="")&&(lineT.value!=null)&&(isNaN(lineT.value)==false))
	{
		lineVal=parseInt(lineT.value);
		
		//alert(lineVal);
		
		if ((lineVal!=null)||(lineVal!=0))
		{
			sbTtAmt = sbTtAmt + (lineVal * 5);
		}
	}

	sbTtFld.value = OutputCurrency(sbTtAmt);

}
function CalcPasteTotalTotal()
{
	// sub-Total plus sales tax plus shipping

	var x,fld,ttFld,TtAmt,sbTtFld,sbTtAmt,slsTxFld,slsTxAmt,shpTtFld,shpTtAmt;

	x = document.forms['OrderForm'];
	
	TtAmt = 0; 
	
	fld="n_subtot_";
	sbTtFld=x.elements[fld];
	sbTtAmt = sbTtFld.value;
	if(isNaN(sbTtAmt)==false)
	{
		sbTtAmt=parseFloat(sbTtAmt);
	}

	fld="n_taxrate_";
	slsTxFld=x.elements[fld];
	slsTxAmt = slsTxFld.value;
	if(isNaN(slsTxAmt)==false)
	{
		slsTxAmt=parseFloat(slsTxAmt);
	}

	fld="n_shiptot_";
	shpTtFld=x.elements[fld];
	shpTtAmt = shpTtFld.value;
	if(isNaN(shpTtAmt)==false)
	{
		shpTtAmt=parseFloat(shpTtAmt);
	}

	fld="n_tottot_";
	ttFld=x.elements[fld];


	if (isNaN(sbTtAmt)==false)
	{
		TtAmt = TtAmt + sbTtAmt;
	}
	if (isNaN(slsTxAmt)==false)
	{
		TtAmt = TtAmt + slsTxAmt;
	}
	if (isNaN(shpTtAmt)==false)
	{
		TtAmt = TtAmt + shpTtAmt;
	}

	ttFld.value = OutputCurrency(TtAmt);
	

}
function Recalculate()
{
	
	CalcPastePriceTimesQuantity();
	CalcPasteSubTotal();
	CalculateSalesTaxTotal();
	CalcPasteShipping();
	CalcPasteTotalTotal();

}
function OKRecalc(fldname)
{
	var x,chkFld,chkAmt;

	x = document.forms['OrderForm'];
	
	if(x.elements[fldname]==null)
	{
		//alert(fldname + " is not an element");
		return;
	}

	chkFld = x.elements[fldname];
	chkAmt = chkFld.value;


	if (checkNumerical(chkAmt)==true)
	{
		if (fldname.substring(0,5)=="n_qty")
		{
			chkFld.value = OutputQuantity(chkFld.value);
		}
		if (fldname.substring(0,5)=="n_pri")
		{
			chkFld.value = OutputCurrency(chkFld.value);
		}
		
		Recalculate();
		return;
	}
	if (checkNumerical(chkAmt)!=true)
	{
		chkFld.value = "";
		return;
	}

}
// ****** Output Formatting Functions ********
function OutputCurrency(amtIn)
{
	var amtOut,thedot;
	
	if(isNaN(amtIn)==false)
	{
		amtOut = parseFloat(amtIn);
	}
	if(isNaN(amtOut)==true)
	{
		amtOut = "";
		return amtOut;
	}

	amtOut= amtOut * 100;
	amtOut= Math.round(amtOut);
	amtOut= amtOut / 100;

	amtOut = amtOut.toString();

	thedot = 0
	thedot = amtOut.lastIndexOf('.',amtOut.length);

	//	alert("the amount is " + amtOut);
	//	alert("the dot " + thedot);
	//	alert("the length is " + amtOut.length);

	if (thedot < 0)
	{
		amtOut = amtOut.concat('.00');
	}
	thedot = amtOut.lastIndexOf('.',amtOut.length);
	if (amtOut.length < (thedot + 3))
	{
		amtOut= amtOut.concat('0');
	}
	if (amtOut.length < (thedot + 2))
	{
		amtOut= amtOut.concat('0');
	}
	if (thedot > 3)
	{
		amtOut= amtOut.substr(0,thedot + 3);
	}

	return amtOut;
}
function OutputQuantity(amtIn)
{

	var amtOut,thedot;
	
	if(isNaN(amtIn)==false)
	{
		amtOut = parseFloat(amtIn);
	}
	if(isNaN(amtOut)==true)
	{
		amtOut = "";
		return amtOut;
	}

	amtOut= amtOut * 100;
	amtOut= Math.round(amtOut);
	amtOut= amtOut / 100;

	//alert(amtOut);

	amtOut = amtOut.toString();

	thedot = amtOut.lastIndexOf('.',amtOut.length);

	if(thedot>0)
	{
		//alert("getting substring");
		amtOut = amtOut.substr(0,thedot);
	}

	return amtOut;
	
}
// ****** Calculation Functions for Both Forms ******
function PasteValueToField(formname,valueFld,pasteFld,clearFld)
{
	var x, tempFld;

	// Tested with IR site

	x = document.forms[formname];
	valueFld = x.elements[valueFld];
	pasteFld = x.elements[pasteFld];
	clearFld = x.elements[clearFld];

	clearFld.value = "";
	tempFld = valueFld.value;
	//alert(tempFld);
	
	if(tempFld.lastIndexOf(':',tempFld.length)!=0)
	{
		pasteFld.value = tempFld.substring(4,tempFld.length);
	}
	if(tempFld.lastIndexOf(':',tempFld.length)<0)
	{
		pasteFld.value=tempFld;
	}


}
function CalculateSalesTaxPct(formname,totalamount,pctrate,amount)
{

	// This should always take the totalamount and pctrate from 
	// the form,  calculate, and paste result to amount field.

	var x, thedot;

	// Tested with IR site

	x = document.forms[formname];
	amount = x.elements[amount];
	pctrate = x.elements[pctrate];
	totalamount = x.elements[totalamount];


	amount.value = (pctrate.value/100) * totalamount.value;

	amount.value = OutputCurrency(amount.value);

}
function GetDomesticShipping(TotAmt)
{

	var USShip;

	USShip = 0;

	if ((TotAmt < 10.01)&&(TotAmt>0)){
		USShip = 6.00;}
	else if (TotAmt < 20.01 && TotAmt >= 10.01){
		USShip = 7.00;}
	else if (TotAmt < 50.01 && TotAmt >= 20.01){
		USShip = 8.00;}
	else if (TotAmt < 75.01 && TotAmt >= 50.01){
		USShip = 9.00;}
	else if (TotAmt >= 75.01){
		USShip = 11.00;}

	return USShip;
}
//  ****** Calculation Functions for Shipping Page *****
function CalculateShipping(formname,ttlamt,amnt,ttlOSShp,srchrgpct,themin,domamt)
{

	var x, totAmt, pctAmt, pplAmt, pplAmtDisplay, USShip, thedot,msg;

	// Tested with IR site

	x = document.forms[formname];
	amnt = x.elements[amnt];
	ttlamt = x.elements[ttlamt];
	ttlOSShp = x.elements[ttlOSShp];
	srchrgpct = x.elements[srchrgpct];
	themin = x.elements[themin];
	domamt = x.elements[domamt];	
	msg = "";

	totAmt = ttlamt.value;
	pctAmt = srchrgpct.value.valueOf();
	//	pctAmt = pctAmt/100;
	minAmt = themin.value.valueOf();

	//	alert(pctAmt);
	//	alert(minAmt);
	
	//reset displaying values
	domamt.value = OutputCurrency(0);
	amnt.value = OutputCurrency(0);
	ttlOSShp.value = OutputCurrency(0);


	USShip = 0;


	if ((totAmt==null) || (totAmt=="") || (isNaN(totAmt)==true))
	{
		return false;
	}
	if (totAmt < 0)
	{
		alert("Cannot do calculation on a negative number: " + totAmt);
		return false;
	}
	if ((totAmt.substring(0,3)=="US$")||(totAmt.substring(0,3)=="us$"))
	{
		totAmt=totAmt.substring(3,totAmt.length);
	}
	if (isNaN(totAmt.charAt(0))==true)
	{
		totAmt=totAmt.substring(1,totAmt.length);
	}
	if (isNaN(totAmt)==true)
	{
		alert("Please enter the dollar total as a number.");
		return false;
	}
	if ((totAmt==null) || (totAmt==""))
	{
		alert("Please enter the U.S. dollar total as a number.");
		return false;
	}

	totAmt = Math.round(totAmt);

	pplAmt = totAmt*(pctAmt/100);
	pplAmt = pplAmt*100;
	pplAmt = Math.round(pplAmt);
	pplAmt = pplAmt / 100;

	//	alert(pplAmt);

	// Following should be generatable from Domestic Shipping Rates table

	USShip=GetDomesticShipping(totAmt)


	msg = "";
	msg = msg + "Paypal automatically adds $";
	msg = msg + USShip;
	msg = msg + " domestic shipping. ";
	msg = msg + pctAmt ;
	msg = msg + "% of $";
	msg = msg + OutputCurrency(totAmt);
	msg = msg + " is $";
	msg = msg + OutputCurrency(pplAmt);
	msg = msg + ".";

	alert(msg);


	domamt.value = OutputCurrency(USShip);

	pplAmt = pplAmt - USShip;
	pplAmt = pplAmt*100;
	pplAmt = Math.round(pplAmt);
	
	
	pplAmt = pplAmt / 100;

	
	if (pplAmt + USShip >= minAmt){	
		ttlOSShp.value = OutputCurrency(pplAmt + USShip);
	}
	if (pplAmt + USShip < minAmt){
		alert("The minimum overseas shipping charge is $" + minAmt + ".");
		pplAmt = (minAmt - USShip);
		ttlOSShp.value = OutputCurrency(minAmt);
	}
	
	
	amnt.value = OutputCurrency(pplAmt);
		
	
	if (pplAmt > 0)
	{
		msg = "";
		msg = msg + "Thank you. The adjustment amount of $";
		msg = msg + amnt.value;
		msg = msg + " can be added to the Paypal shopping cart.";

		alert(msg);

		return true;
	}
	else
	{
		msg = "";
		msg = msg + "No adjustment needed.  $";
		msg = msg + minAmt;
		msg = msg + " minimum is met by regular charge.";
		alert(msg);
		return false;
	}

}
function PaypalVerify(formname,description,minimum)
{

	var x, pplAmt, msg;
	x = document.forms[formname];

	pplAmt = x.amount.value;



	if ((pplAmt==null) || (pplAmt==""))
	{
		return false;
	}
	if (pplAmt < 0)
	{
		alert("Cannot sent a negative number: " + pplAmt);
		return false;
	}
	if ((pplAmt.substring(0,3)=="US$")||(pplAmt.substring(0,3)=="us$"))
	{
		pplAmt=pplAmt.substring(3,pplAmt.length);
	}
	if (isNaN(pplAmt.charAt(0))==true)
	{
		pplAmt=pplAmt.substring(1,pplAmt.length);
	}
	if (isNaN(pplAmt)==true)
	{
		alert("Please enter the dollar total as a number.");
		return false;
	}
	if ((pplAmt==null) || (pplAmt==""))
	{
		alert("Please enter the U.S. dollar total as a number.");
		return false;
	}
	if ((minimum > 0) &&((pplAmt + GetDomesticShipping(TotAmt))  < minimum))
	{
		alert("Minimum " + description + " is $" + minimum + ".");
		pplAmt = minimum;
		x.amount.value = pplAmt;
		return false;
	}

		pplAmt = pplAmt*100;
		pplAmt = Math.round(pplAmt);
		pplAmt = pplAmt / 100;
		//alert(pplAmt);
		x.amount.value = pplAmt;
	
	if (pplAmt > 0)
	{
		return true;
	}
	else
	{

		return false;
	}

}
// ****** Verification Functions ******
function checkNumerical(pplAmt)
{

	if ((pplAmt==null) || (pplAmt==""))
	{
		return true;
	}
	if (pplAmt < 0)
	{
		alert("Negative number not valid: " + pplAmt);
		return false;
	}
	if (isNaN(pplAmt)==true)
	{
		alert(pplAmt + " is not a number.");
		return false;
	}

	
	if (pplAmt > 0)
	{
		return true;
	}
	else
	{

		return false;
	}


}
// **** Cookie Save Functions ******
function createCookie(name,value,days)
{
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	if(name.substring(0,4)=="n_ln")
	{
		return;
	}
	if (value.substring(0,1)==" ")
	{
		alert("first char is a blank, removing it.");
		value = value.substring(1,value.length);
	}
	if (value.substring(0,1)=="=")
	{
		alert("first char is an equal sign, removing it.");
		value = value.substring(1,value.length);
	}
	
	if (name.substring(0,2)=="o_")
	{
		//alert(value);
		//alert(escape(value));
	}

	value = escape(value);
	
//	if(value!="")
//	{
		//alert(name + " is " + value+expires+"; path=/");
		document.cookie = name+"="+value+expires+"; path=/";
//	}

}
function PasteOrderFormField(fieldin,content)
{
	//var line;

	//line = ":" + fieldin + ":";
	//line = line + content;

	//document.cookie = document.cookie + line;
	
	createCookie(fieldin,content,0);

}
function newSaveOrderForm()
{

	var x, fldno, fldnm, theField, mkr, code, price, desc, qty, eleLen;

	x = document.forms['OrderForm'];

	document.cookie = "";

	eleLen = x.elements.length;

	for (fldno=0; fldno<=eleLen; fldno++)
	{

		if(fldno == eleLen)
		{
			//document.cookie = document.cookie + ":EOF:";
			//createCookie("EOF","EOF",0);
			return;
		}
		theField = x.elements[fldno];
		mkr = theField.name;
		
		setFieldVal(mkr);
	}

}
function setFieldVal(mkr)
{

	fldnm = eval("document.forms['OrderForm']." + mkr);

	if(mkr.indexOf("n_")==0)
	{
		tf = checkNumerical(fldnm.value);
		if(tf==true)
		{
		//	alert(mkr + " is a number");
			PasteOrderFormField(mkr,fldnm.value);
			return;
		}
		else
		{
			PasteOrderFormField(mkr,"");
			return;
		}
	}
	if(mkr.indexOf("ckb_")==0)
	{
		tf = fldnm.checked;
		//alert(mkr + " is a checkbox");
		if(tf==true)
		{
			//alert(" and it is checked");
			PasteOrderFormField(mkr,fldnm.value);
			return;
		}
		else
		{
			//alert(" but it is not checked");
			PasteOrderFormField(mkr,"");
			return;
		}
	}


	PasteOrderFormField(mkr,fldnm.value);

}
// ***** Cookie Load Functions ******
function ReadCookie()
{

	//This function is only used to test setting the cookie
	//alert(document.cookie);
	
	//createCookie('Test','Success',0);
	//createCookie('NewTest','Success',0);
	

	alert(document.cookie);
	

}
function parseCookie(mkr,ckString)
{
	var retval, idxln, startAt, strmsg;
	
	retval = "";
	
	startAt = 0;

	startAt = ckString.indexOf(mkr,startAt);
	
	if(startAt<0)
	{
		//alert(mkr + " does not appear to be a cookie.");
		return retval;
		
	}
	
	startAt = startAt + mkr.length;

	//idxln = ckString.indexOf(nextmkr,startAt);
	
	idxln = ckString.indexOf(";",startAt);
	


	//if (idxln<0)
	//{
	//	idxln = ckString.indexOf(nextmkr,startAt);
	//	idxln = idxln - 1;
	//}
	if (idxln<0)
	{
		idxln = ckString.length;
		//idxln = idxln - 2;
	}
	//if (mkr=="EOF")
	//{
	//	retval="EOF";
	//	return retval;
	//}
	if (mkr.substring(0,4)=="n_ln")
	{
		retval = "";
		return retval;
	}
	
	

	retval = ckString.substring(startAt + 1,idxln);
	
	retval = unescape(retval);
	
	if(retval.substring(0,1)=="=")
	{
		retval = retval.substring(1,retval.length);
	}
	if(retval.substring(0,1)==";")
	{
		retval = retval.substring(1,retval.length);
	}	
	
	
	if(retval!="")
	{
		//alert("parseCookie mkr,retval: " + mkr + " " + retval);
	}


	
	return retval;
}
function getFieldVal(f1)
{

	var fldnm, fieldval;


	fldnm = eval("document.forms['OrderForm']." + f1);

	fieldval = parseCookie(f1, document.cookie);

	if(f1.indexOf("ckb_")==0)
	{
		//alert(f1 + " is a checkbox");
		if(fieldval=="Yes")
		{
			//alert(" and it is checked");
			fldnm.checked = true;
			return;
		}
		else
		{
			//alert(" but it is not checked");
			fldnm.checked = false;
			return;
		}
	}
	else
	{
		fldnm.value = fieldval;	
	}


}
function newCookieLoad()
{

	var x, fieldcnt, f1, f2, f0, theField, eleLen;

	x = document.forms['OrderForm'];
	

	//f0 = "EOF";

	eleLen = x.elements.length;

	for (fieldcnt=0; fieldcnt <= eleLen; fieldcnt++)
	{

		theField = x.elements[fieldcnt];
	
		f1 = theField.name;

		if (fieldcnt==eleLen-1)
		{
			//alert(f1 + " " + f0);
			getFieldVal(f1);
			break;
		}
		if (fieldcnt!=eleLen)
		{
			//f2 = x.elements[fieldcnt + 1].name;
			//alert(f1 + " " + f2);
			getFieldVal(f1); 
		}
	
	}
	
	Recalculate();

}
