function blank_shipping_ecouncil() {
this.price=0;
this.nicknames='';
this.text='';
}

function shipping_ecouncil(table,codeqtys) {
var ret={result:-1,price:0,nicknames:'',text:''};
var solution=[];
	function countprovision(p,code) {
	for (var i in p) {
		if (p[i].code!=code) continue;
		return p[i].qty;
	}
	return 0;
	}
	function addtosolution(dest,code,qty) {
	for (var i in table) {
		var count,q=countprovision(table[i].provides,code);
		if (!q) continue;
		count=Math.ceil(qty/q);
		for (;count>0;count--) dest.push(i);
	}
	}
	function findsolution(sol) {
	for (var i in codeqtys) {
		if (addtosolution(sol,codeqtys[i].code,codeqtys[i].qty))
			return -1;
	}
	return 0;
	}
	function subtractprovision(ex,cqs) {
	for (var j in cqs) {
		var cq=cqs[j];
		if (typeof(ex[''+cq.code])=='undefined') ex[''+cq.code]=0;
		ex[''+cq.code]-=cq.qty;
	}
	}
	function addprovision(ex,cqs) {
	for (var j in cqs) {
		var cq=cqs[j];
		if (typeof(ex[''+cq.code])=='undefined') ex[''+cq.code]=0;
		ex[''+cq.code]+=cq.qty;
	}
	}
	function findexcess(sol) {
	var ex=[];
	subtractprovision(ex,codeqtys);
	for (var i in sol) addprovision(ex,table[sol[i]].provides);
	return ex;
	}
	function isnotremovable(ex,cqs) {
	for (var i in cqs) {
		var j=ex[''+cqs[i].code];
		if (typeof(j)=='undefined') return 1;
		if (j<cqs[i].qty) return 1;
	}
	return 0;
	}
	function aclone(obj) {
	var i,o=[];
	for (i in obj) o[i]=obj[i];
	return o;
	}
	function walksolutions(solns,sol,ex,start) {
	// recursive
	var i;
	for (i=start;i<sol.length;i++) {
		var sc,ec;
		if (isnotremovable(ex,table[sol[i]].provides)) continue;
		sc=aclone(sol);
		ec=aclone(ex);
		subtractprovision(ec,table[sol[i]].provides);
		sc.splice(i,1);
		walksolutions(solns,sc,ec,i);
	}
	solns.push(new function() { this.price=0; this.solution=sol });
	}
	function trimexcess(sol,ex) {
	var solns=[];
	walksolutions(solns,sol,ex,0);
	for (var i in solns) {
		var s=solns[i];
		for (var j in s.solution) s.price+=table[s.solution[j]].price;
	}
	solns.sort(function(a,b) { if (a.price < b.price) return -1; return 1});
	return solns[0].solution;
	}
	function optimizesolution(sol) {
	var ex,os;
	ex=findexcess(sol);
	os=trimexcess(sol,ex);
	return os;
	}
if (findsolution(solution)) return ret;
solution=optimizesolution(solution);
ret.result=0;
{
	var j,nickobj={},nickarr=[];
	for (var i in solution) {
		var te=table[solution[i]];
		ret.price+=te.price;
		nickobj[te.nickname]=1;
		ret.text+=(ret.text?', ':'')+te.text;
	}
	for (j in nickobj) nickarr.push(j);
	nickarr.sort();
	if (nickarr.length==2) ret.nicknames=nickarr[0]+' and '+nickarr[1];
	else for (j=0;j<nickarr.length;j++) {
		ret.nicknames+=(j?', ':'')+(j&&(j+1==nickarr.length)?' and ':'')+nickarr[j];
	}
}
return ret;
}
function cart_ecouncil(jsname,locations,products,href,debug,savecartcgi) {
	function errout(t) { setTimeout(function(){throw(t)},1000) }
	function findid(a){return document.getElementById(a);}
	function sethtml(i,t){var e=findid(i);if(e.innerHTML!=t)e.innerHTML=t;}
	function getselect(e){return(e.selectedIndex<0)?'':e.options[e.selectedIndex].value;}
	function expirestring(days) {var d=new Date();d.setDate(d.getDate()+days);return 'expires='+d.toGMTString();}
	function savecookie(t) { document.cookie='EMBED='+escape(t)+'; '+expirestring(365); }
	function he(t) {t=t+'';t=t.replace(/&/g,'&amp;');t=t.replace(/</g,'&lt;');t=t.replace(/>/g,'&gt;');t=t.replace(/\"/g,'&quot;');return t;}
	function handler_httppost(obj,req,callback) {
	if (req.readyState!=4) return;
	if ((req.status!=200)||(req.responseText!='Success')) {
		if (obj.debug) eval(callback);
		else alert('There was an error contacting the server.\n\n'
			+'Please try again, and if the problem persists, '
			+'please wait a few minutes before trying again.\n'
			+'Thank you for your patience.\n\n'
			+'Code: '+req.status+'\n'
			+'Response: '+req.responseText);
	} else {
		eval(callback);
	}
	}
	function httppost(obj,u,p,c) {
	var req;
	try {req=new XMLHttpRequest();} catch (err) {
		try {req=new ActiveXObject('Microsoft.XMLHTTP');} catch (err) {
			alert('Couldn\'t create http request');
			return;
		}
	}

	req.open('POST',u);
	req.onreadystatechange=function() { handler_httppost(obj,req,c) }
	req.send(p);
	}

	this.clearinputdefault=function(f,n,t) {
	var o=document.forms[f][n];
	if (o.value==t) o.value='';
	}

	this.savescroll=function(id) {
	var v=0; 
	if (typeof(window.pageYOffset)=='number') v=window.pageYOffset;
	else if (typeof(document.documentElement.scrollTop)=='number') v=document.documentElement.scrollTop;
	else if (typeof(document.body.scrollTop)=='number') v=document.body.scrollTop;
	this.scrolls[''+id]=v
	}

	this.loadscroll=function(id) {var v=parseInt(this.scrolls[''+id]);if (isNaN(v)) v=0;window.scroll(0,v)}


	this.updatecookie=function() {
	var i,t='',inputs='',items='';
	
	this.formcache['SHIPLOCATION']=this.curlocation;

	for (i in this.formcache) {
		inputs+=escape(i)+','+escape(this.formcache[i])+',';
	}
	for (i=0;i<this.items.length;i++) {
		var it=this.items[i];
		items+=it.p.id+','+it.qty+','+it.color+',';
	}
	t='FC='+escape(inputs)+',ITEMS='+escape(items);
	savecookie(t);
	}

	this.loadcookie=function() {
		var i,t,a,fc,its;
		t=document.cookie;
		if (t=='') return;
		a=t.split(';');
		a=a[0].split('=');
		a=unescape(a[1]);
		a=a.split(',');
		a[0]=unescape(a[0]);
		a[1]=unescape(a[1]);
		fc=a[0].split('=');
		if (fc.length==1) fc[1]='';
		fc=fc[1].split(',');
		for (i=0;i+1<fc.length;i+=2) {
			this.formcache[unescape(fc[i])]=unescape(fc[i+1]);
		}
		its=a[1].split('=');
		if (its.length==1) its[1]='';
		its=its[1].split(',');
		for (i=0;i+2<its.length;i+=3) {
			var it;
			it=new new_item_cart(this.findproduct(its[i]));
			it.qty=parseInt(its[i+1]);
			it.color=parseInt(its[i+2]);
			this.items.push(it);
		}
		if (this.curlocation<0) {
			i=this.formcache['SHIPLOCATION'];
			if (typeof(i)!=='undefined') {
				i=parseInt(i);
				if ((i>=0)&&(i<this.locations.length)) this.curlocation=i;
			}
		}
	}

	function additem_cart() {
	var i,p,t='';
	p=this.products;
	t+='<p>Select the product you\'d like to add and press the <i>Add</i> button next to it. Press the <i>Go back</i> button to return to your shopping cart without making a selection.</p>';
	t+='<form name=CARTFORM onsubmit="return false">';
	for (i=0;i<p.length;i++) {
		t+='<div style="float:left;position:relative;width:400px;height:125px;border:1px solid black;margin:1em;">';
		t+='<div style="position:absolute;top:0px;left:0px;height:125px;width:125px"><img src="'+p[i].icon+'" width=125 height=125></div>';
		t+='<div style="position:absolute;top:0px;left:130px;height:30px;width:275px;font-weight:bold">'+p[i].name+'</div>';
		t+='<div style="position:absolute;top:30px;left:130px;height:70px;width:265px;overflow:auto">'+p[i].text+'</div>';
		t+='<div style="position:absolute;top:103px;left:130px;height:25px;width:75px"><nobr>'+this.formatprice(p[i].price)+'</nobr></div>';
		t+='<div style="position:absolute;top:100px;left:205px;"><input type=button onclick="'+this.jsname+'.savescroll(1);'+this.jsname+'.additem('+p[i].id+')" value="Add"></div>';
		t+='</div>';
	}
	t+='<div style="clear:both"><input type=button onclick="'+this.jsname+'.savescroll(1);'+this.jsname+'.drawcart()" value="Go back"></div>';
	t+='</form>';
	this.draw(t);
	this.loadscroll(1);
	}

	this.fc=function (n) {
	var t,v;
	v=typeof(this.formcache[n]);
	if (v==='undefined') {
		v=this.formcache[n]='';
	}
	return ' name="'+n+'"';
	}

	this.getfc=function (n) {
	if (typeof(this.formcache[n])==='undefined') return '';
	return this.formcache[n];
	}

	function checkship_cart() {
	var v=document.forms.CARTFORM.SHIPISBILL.checked;
	for (var i in document.forms.CARTFORM) {
		if (i.slice(0,2)=='S_') document.forms.CARTFORM[i].disabled=v;
	}
	
	}

	function revieworder_cart() {
	var t='';
	var fns=['FNAME','First name','MNAME','Middle','LNAME','Last name',
		'ADD1','Address line 1','ADD2','Address line 2','CITY','City',
		'STATE','State','ZIP','Zip code','EMAIL','Email address',
		'PHONE','Phone number'];
	t+='<p>Total price estimate: <b>'+this.formatprice(this.prices.totalprice)+'</b>';
	t+=' <i>(this may vary after shipping/handling)</i>';
	t+='<p>Please review your order below and press the <i>Finish order</i> button when done.</p>';
	t+='<table cellspacing=0 cellpadding=5>';
	t+='<tr><td colspan=2><b>Billing Information</b>';
	for (var i=0;i+1<fns.length;i+=2) {
		t+='<tr><td align=right valign=bottom><nobr><i><font size=-1>'+fns[i+1]+'</font></i></nobr><td>'+he(this.getfc('B_'+fns[i]));
	}
	if (this.formcache['SHIPISBILL']==1) {
		t+='<tr><td colspan=2><b>Shipping address is the same as billing</b>';
	} else {
		t+='<tr><td colspan=2>&nbsp;';
		t+='<tr><td colspan=2><b>Shipping Information</b>';
		for (var i=0;i+1<fns.length;i+=2) {
			t+='<tr><td align=right valign=bottom><nobr><i><font size=-1>'+fns[i+1]+'</font></i></nobr><td>'+he(this.getfc('S_'+fns[i]));
		}
	}
	t+='<tr><td colspan=2>&nbsp;';
	t+='<tr><td><b>Items</b><td>&nbsp;';
	for (var i=0;i<this.items.length;i++) {
		var it=this.items[i];
		t+='<tr><td valign=top align=right><b>'+(i+1)+'.</b><td>'+it.p.name;
		t+=', <nobr>color: '+it.p.colors[it.color]+'</nobr>';
		if (it.qty>1) t+=', <nobr>unit price '+this.formatprice(it.p.price)+',</nobr> <nobr>qty '+it.qty+'</nobr>';
		t+=', <nobr>price '+this.formatprice(it.price)+'</nobr>';
	}
	t+='<tr><td>Tax<td>'+this.formatprice(this.prices.tax);
	t+='<tr><td>Shipping<td>'+this.shippingdetail.nicknames;
	t+='<tr><td><nobr>Shipping price</nobr><td>'+this.formatprice(this.prices.shipping);
	t+='<tr><td>Total price<td>'+this.formatprice(this.prices.totalprice);
	t+='</table>';
	t+='<form name=CARTFORM onsubmit="return false">';
	t+='<p><b>Instructions</b>';
	t+='<br><textarea cols=40 rows=5 '+this.fc('NOTES')+' onfocus="'+this.jsname+'.clearinputdefault(\'CARTFORM\',\'NOTES\',\'You can enter special instructions for this order here.\')">';
	if (this.formcache['NOTES']=='') this.formcache['NOTES']='You can enter special instructions for this order here.';
	t+='</textarea>';
	t+='<p><input type=button onclick="'+this.jsname+'.savescroll(3);'+this.jsname+'.update_formcache();'+this.jsname+'.getcontact()" value="Go back"> ';
	t+='<input type=button onclick="'+this.jsname+'.savescroll(3);'+this.jsname+'.update_formcache();'+this.jsname+'.submitcart()" value="Finish order">';
	t+='</form>';
	this.draw(t);
	this.loadscroll(3);
	this.fill_formcache();
	}

	this.checkcontact=function() {
		this.update_formcache();
		var str=this.getfc('B_PHONE')+this.getfc('B_EMAIL');
		if (str=='') {
			alert('Please enter either a phone number or an email address so we can contact you.');
			return;
		}
		this.savescroll(2);
		this.revieworder();
	}

	function getcontact_cart() {
	var t='';
	t+='<p>Total price estimate: <b>'+this.formatprice(this.prices.totalprice)+'</b>';
	t+=' <i>(this may vary after shipping/handling)</i>';
	t+='<p>Please enter your contact information below and press the <i>Continue</i> button when finished.</p>';
	t+='<form name=CARTFORM onsubmit="return false">';
	t+='<table bgcolor="#eeeeee" cellspacing=0 width=95%>';
	t+='<tr><td colspan=3 align=center style="border:1px solid black;background:#eee"><b>Billing address</b><td rowspan=14 bgcolor=white>&nbsp;<td colspan=3 align=center style="border:1px solid black;background:#ddd"><b>Shipping address</b>';
	t+='<tr><td style="border-left:1px solid black;border-right:1px solid black" colspan=3>&nbsp;<td style="border-left:1px solid black;border-right:1px solid black" colspan=3>';
		t+='<input id="SHIPISBILL" tabindex=3 type=checkbox '+this.fc('SHIPISBILL')+' onclick="'+this.jsname+'.clickship()" checked> ';
		t+='<label for="SHIPISBILL">Shipping information is the same</label>'
	t+='<tr><td style="border-left:1px solid black;padding-left:.3em;">First name<td>Middle<td style="border-right:1px solid black">Last name';
	t+='<td style="border-left:1px solid black;padding-left:.3em">First name<td>Middle<td style="border-right:1px solid black">Last name';
	t+='<tr><td style="border-left:1px solid black;padding-left:.7em"><input tabindex=2 size=10'+this.fc('B_FNAME')+'><td style="padding-left:.4em"><input tabindex=2 size=3'+this.fc('B_MNAME')+'><td style="border-right:1px solid black;padding-left:.4em"><input tabindex=2 size=10'+this.fc('B_LNAME')+'>';
	t+='<td style="border-left:1px solid black;padding-left:.7em"><input tabindex=3 size=10'+this.fc('S_FNAME')+'><td style="padding-left:.4em"><input tabindex=3 size=3'+this.fc('S_MNAME')+'><td style="border-right:1px solid black;padding-left:.4em"><input tabindex=3 size=10'+this.fc('S_LNAME')+'>';
	t+='<tr><td style="border-left:1px solid black;border-right:1px solid black;padding-left:.3em" colspan=3>Street address';
	t+='<td style="border-left:1px solid black;border-right:1px solid black;padding-left:.3em" colspan=3>Street address';
	t+='<tr><td style="border-left:1px solid black;border-right:1px solid black;padding-left:.7em" colspan=3><nobr>1. <input tabindex=2 size=40'+this.fc('B_ADD1')+'></nobr>';
	t+='<td style="border-left:1px solid black;border-right:1px solid black;padding-left:.7em" colspan=3><nobr>1. <input tabindex=3 size=40'+this.fc('S_ADD1')+'></nobr>';
	t+='<tr><td style="border-left:1px solid black;border-right:1px solid black;padding-left:.7em" colspan=3><nobr>2. <input tabindex=2 size=40'+this.fc('B_ADD2')+'></nobr>';
	t+='<td style="border-left:1px solid black;border-right:1px solid black;padding-left:.7em" colspan=3><nobr>2. <input tabindex=3 size=40'+this.fc('S_ADD2')+'></nobr>';
	t+='<tr><td style="border-left:1px solid black;padding-left:.3em">City<td>State/Prov.<td style="border-right:1px solid black">Zip code';
	t+='<td style="border-left:1px solid black;padding-left:.3em">City<td>State/Prov.<td style="border-right:1px solid black">Zip code';
	t+='<tr><td style="border-left:1px solid black;padding-left:.7em"><input tabindex=2'+this.fc('B_CITY')+'><td style="padding-left:.4em"><input tabindex=2 size=3'+this.fc('B_STATE')+'><td style="border-right:1px solid black;padding-left:.4em"><input tabindex=2 size=10'+this.fc('B_ZIP')+'>';
	t+='<td style="border-left:1px solid black;padding-left:.7em"><input tabindex=3'+this.fc('S_CITY')+'><td style="padding-left:.4em"><input tabindex=3 size=3'+this.fc('S_STATE')+'><td style="border-right:1px solid black;padding-left:.3em"><input tabindex=3 size=10'+this.fc('S_ZIP')+'>';
	t+='<tr><td style="border-left:1px solid black;border-right:1px solid black;padding-left:.3em" colspan=3>Email address';
	t+='<td style="border-left:1px solid black;border-right:1px solid black;padding-left:.3em" colspan=3>Email address';
	t+='<tr><td style="border-left:1px solid black;border-right:1px solid black;padding-left:.7em" colspan=3><input tabindex=2 size=40'+this.fc('B_EMAIL')+'>';
	t+='<td style="border-left:1px solid black;border-right:1px solid black;padding-left:.7em" colspan=3><input tabindex=3 size=40'+this.fc('S_EMAIL')+'>';
	t+='<tr><td style="border-left:1px solid black;border-right:1px solid black;padding-left:.3em" colspan=3>Phone number';
	t+='<td style="border-left:1px solid black;border-right:1px solid black;padding-left:.3em" colspan=3>Phone number';
	t+='<tr><td style="border-left:1px solid black;border-right:1px solid black;padding-left:.7em" colspan=3><input tabindex=2 size=40'+this.fc('B_PHONE')+'>';
	t+='<td style="border-left:1px solid black;border-right:1px solid black;padding-left:.7em" colspan=3><input tabindex=3 size=40'+this.fc('S_PHONE')+'>';
	t+='<tr><td style="border-left:1px solid black;border-bottom:1px solid black;border-right:1px solid black;" colspan=3>&nbsp;';
	t+='<td style="border-left:1px solid black;border-bottom:1px solid black;border-right:1px solid black;" colspan=3>&nbsp;';
	t+='</table>';
	t+='<p><input type=button tabindex=3 onclick="'+this.jsname+'.savescroll(2);'+this.jsname+'.update_formcache();'+this.jsname+'.drawcart()" value="Go back"> ';
	t+='<input type=button tabindex=3 onclick="'+this.jsname+'.checkcontact()" value="Continue">';
	t+='</form>';
	this.draw(t);
	this.loadscroll(2);
	this.fill_formcache();
	checkship_cart();
	}
	function drawcart_cart() {
	var i,items=this.items;
	var t;

	t='<form name=CARTFORM onsubmit="return false">';
	t+='<p><b>Shopping cart</b></p>';
	t+='<p>Please review your order and press the <i>Continue</i> button to proceed.</p>';
	t+='<table cellspacing=0 width=95%>';
	for (i=0;i<items.length;i++) {
		var p=items[i].p;
		if (i) t+='<tr><td colspan=4>&nbsp;';
		t+='<tr><td style="padding-left:.5em;border-left:1px solid black;border-top:1px solid black" align=left">Item '+(i+1);
		t+='<td style="font-weight:bold;border-top:1px solid black">'+p.name;
		t+='<td style="border-top:1px solid black" align=right>'
		if (p.colors.length) {
			var j;
			t+='Color: ';
			t+='<select name=COLORS'+i+' onchange="'+this.jsname+'.deltaopts('+i+')">';
			for (j=0;j<p.colors.length;j++) {
				t+='<option '+(j==items[i].color?'selected ':'')+'value="'+j+'">'+p.colors[j];
			}
			t+='</select>';
		} else t+='&nbsp;';

		t+='<td style="border-top:1px solid black" align=right><nobr>Item price</nobr><td style="border-top:1px solid black;border-right:1px solid black">'+this.formatprice(p.price);

		t+='<tr><td style="padding:.5em;border-left:1px solid black;border-bottom:1px solid black" rowspan=3 align=center><img height=200 width=200 style="width:10em;height:10em" src="'+p.icon+'">';
		t+='<td style="border-bottom:1px solid black" colspan=2 rowspan=3 valign=top>'+p.text;
		t+='<td align=right>Quantity<td style="border-right:1px solid black">';
		t+='<nobr><input type=button onclick="'+this.jsname+'.savescroll(0);'+this.jsname+'.deltaqty('+i+',-1);'+this.jsname+'.drawcart()" value="-"> ';
		t+=items[i].qty;
		t+=' <input type=button onclick="'+this.jsname+'.savescroll(0);'+this.jsname+'.deltaqty('+i+',1);'+this.jsname+'.drawcart()" value="+"></nobr>';
		t+='<tr><td align=right><nobr>Total price</nobr><td style="border-right:1px solid black">'+this.formatprice(items[i].price);
		t+='<tr><td style="border-bottom:1px solid black">&nbsp;<td style="border-right:1px solid black;border-bottom:1px solid black">';
		t+='<input type=button onclick="'+this.jsname+'.savescroll(0);'+this.jsname+'.items.splice('+i+',1);'+this.jsname+'.drawcart()" value="Remove">';
	}
	t+='</table>';
	if (!items.length) {
		t+='<p>There are currently no items in your shopping cart. Click the <i>Add another item</i> button below to add an item.</p>';
	}

	t+='<p><input type=button onclick="'+this.jsname+'.savescroll(0);'+this.jsname+'.additemgui()" value="Add another item"></p>';

	t+='<table><tr><td>Shipping estimate<td align=right><nobr>'+this.formatprice(this.prices.shipping)+'</nobr>';
	if (this.shippingdetail.nicknames) t+='<td><nobr>'+this.shippingdetail.nicknames+'</nobr>';

	t+='<td><select name=LOCATION onchange="'+this.jsname+'.savescroll(0);'+this.jsname+'.checklocation()">';
	t+='<option value="">Select shipping location';
	for (i=0;i<this.locations.length;i++) {
		var loc=this.locations[i];
		t+='<option value='+i+(i==this.curlocation?' selected':'')+'>'+loc.name;
	}
	t+='</select>';

	if (this.prices.tax) t+='<tr><td>Tax estimate<td align=right><nobr>'+this.formatprice(this.prices.tax)+'</nobr>';
	t+='<tr><td>Total price estimate<td align=right><nobr>'+this.formatprice(this.prices.totalprice)+'</nobr>';
	t+='</table>';
	t+='<br><input id="CONTBUTTON" type=button disabled onclick="'+this.jsname+'.savescroll(0);'+this.jsname+'.getcontact()" value="Continue"></p>';
	t+='</form>';
	this.draw(t);
	if (this.prices.totalprice) document.forms.CARTFORM.CONTBUTTON.disabled=0;
	this.loadscroll(0);
	}

	function new_item_cart(p) {
	this.p=p;
	this.price=0;
	this.qty=1;
	this.color=0;
	}
	function calculateprice_cart() {
	var sum=0,tax=0,shipping=0,a=this.items;
	var codeqtys=[];
	var s=new blank_shipping_ecouncil();
	for (var i in a) {
		a[i].price=a[i].qty*a[i].p.price;
		sum+=a[i].price;
		codeqtys.push(new function() { this.code=a[i].p.shipcode; this.qty=a[i].qty });
	}
	if (this.curlocation>=0) {
		var loc=this.locations[this.curlocation];
		s=shipping_ecouncil(loc.shiptable,codeqtys);
		shipping=s.price;
		if (loc.taxrate!==0) tax=Math.round((sum+shipping)*loc.taxrate);
	}
	this.shippingdetail=s;
	this.prices.tax=tax;
	this.prices.shipping=shipping;
	this.prices.totalprice=sum+tax+shipping;
	}
	this.finish_cart=function() {
	var t;
	t='<div>Thank you for your order. Someone will contact you soon '
		+'to confirm your order and to discuss payment options.</div>';
	this.items.length=0;
	this.formcache['NOTES']='';
	this.updatecookie();
	this.draw(t);
	this.loadscroll(4);
	}
	this.cartastext=function() {
	var i,t='Order from cart.js\r\n';
	var fns=['FNAME','First name','MNAME','Middle name','LNAME','Last name',
		'ADD1','Address line 1','ADD2','Address line 2','CITY','City',
		'STATE','State','ZIP','Zip code','EMAIL','Email address',
		'PHONE','Phone number'];
	t+='Special instructions from the customer\r\n';
	t+='\t'+this.formcache['NOTES']+'\r\n';
	t+='Billing address\r\n';
	for (i=0;i+1<fns.length;i+=2) {
		t+='\t'+fns[i+1]+': '+this.formcache['B_'+fns[i]]+'\r\n';
	}
	if (this.formcache['SHIPISBILL']==1) {
		t+='Shipping address is the same as billing\r\n';
	} else {
		t+='Shipping address\r\n';
		for (i=0;i+1<fns.length;i+=2) {
			t+='\t'+fns[i+1]+': '+this.formcache['S_'+fns[i]]+'\r\n';
		}
	}
	t+='Item count: '+this.items.length+'\r\n';
	t+='Tax: '+this.formatprice(this.prices.tax)+'\r\n';
	t+='Shipping price: '+this.formatprice(this.prices.shipping)+'\r\n';
	t+='Shipping description: '+this.shippingdetail.text+'\r\n';
	t+='Total price: '+this.formatprice(this.prices.totalprice)+'\r\n';
	for (i=0;i<this.items.length;i++) {
		var it=this.items[i];
		t+='Item '+(i+1)+':\r\n';
		t+='\tId: '+it.p.id+'\r\n';
		t+='\tName: '+it.p.name+'\r\n';
		if (it.qty>1) t+='\tUnit price: '+this.formatprice(it.p.price)+'\r\n';
		if (it.qty) t+='\tPrice: '+this.formatprice(it.price)+'\r\n';
		if (it.qty!=1) t+='\tQuantity: '+it.qty+'\r\n';
		if (it.qty) if (it.p.colors.length) t+='\tColor: '+it.p.colors[it.color]+'\r\n';
	}
	if (this.debug)
		alert('This message would have been sent via email:\r\n\r\n'+t);
	return t;
	}
	this.checklocation_cart=function() {
	var v,loc;
	v=getselect(document.forms.CARTFORM.LOCATION);
	if (v=='') v='-1';
	this.curlocation=parseInt(v);
	}
	function submit_cart() {
	var t='';
	t=this.cartastext();
	this.draw('Please wait... uploading order to our server');
	this.loadscroll(4);
	var qs='?'+this.getfc('B_PHONE')+this.getfc('B_EMAIL');
	httppost(this,this.savecartcgi+qs,t,this.jsname+'.finish_cart()');
	}
	this.update_formcache_cart=function() {
	for (var i in this.formcache) {
		var s=document.forms.CARTFORM[i];
		if (typeof(s)=='object') {
			if ((s.type=='textarea')||(s.type=='text')) {
				this.formcache[i]=s.value;
			} else if (s.type=='checkbox') {
				this.formcache[i]=s.checked;
			}
		} 
	}
	}
	this.fill_formcache=function () {
	for (var i in this.formcache) {
		var s;
		s=document.forms.CARTFORM[i];
		if (typeof(s)=='object') {
			if ((s.type=='textarea')||(s.type=='text')) {
				s.value=this.formcache[i];
			} else if (s.type=='checkbox') {
				var v=this.formcache[i];
				if (v!=='') {
					s.checked=eval(v);
				}
			}
		}
	}
	}

this.jsname=jsname;
this.divid='W';
this.debug=debug;
this.savecartcgi=savecartcgi;
this.locations=locations;
this.products=products;
this.curlocation=-1;
this.items=[];
this.shippingdetail=new blank_shipping_ecouncil();
this.prices={totalprice:0,shipping:0,tax:0};
this.formcache=[];
this.scrolls=[];
this.draw=function(t) {sethtml(this.divid,t)}
this.findproduct=function(id) {for (var i in this.products) if (this.products[i].id==id) return this.products[i]; return ''}
this.additem=function(id) {this.items.push(new new_item_cart(this.findproduct(id)));this.drawcart()}
this.drawcarttext=drawcart_cart;
this.calculateprice=calculateprice_cart;
this.drawcart=function() { this.calculateprice(); this.updatecookie(); this.drawcarttext() }
this.formatprice=function(c) { if (!c) return '$ 0' ; c=''+c; return '$ '+c.slice(0,c.length-2)+'.'+c.substr(c.length-2,2) }
this.deltaqty=function(id,d) { this.items[id].qty+=d; if (this.items[id].qty<0) this.items[id].qty=0 }
this.deltaopts=function(id) { this.items[id].color=getselect(document.forms.CARTFORM['COLORS'+id]) ; this.updatecookie() }
this.getcontact=getcontact_cart;
this.revieworder=revieworder_cart;
this.additemgui=additem_cart;
this.submitcart=submit_cart;
this.checklocation=function() {this.checklocation_cart();this.drawcart() }
this.update_formcache=function() {this.update_formcache_cart();this.updatecookie()}
this.clickship=function() {checkship_cart();this.update_formcache()}

	this.loadcookie();
	{
		var i;

		i=href.indexOf('?');
		if (i>=0) {
			var id;
			id=href.slice(i,href.length);
			if (id.slice(0,4)=='?id=')
				this.items.push(new new_item_cart(this.findproduct(id.slice(4,id.length))));
		}
	}
};

