function CloseChange() {
	div = document.getElementById('change');
	div.style.visibility = 'hidden';
	var finish = ""; var fabric = ""; var laminate = "";
	if(eval("fin = document.getElementById('finish')"))	{ finish   = fin.innerHTML; }
	if(eval("fab = document.getElementById('fabric')"))	{ fabric   = fab.innerHTML; }
	if(eval("lam = document.getElementById('laminate')"))	{ laminate = lam.innerHTML; }
	var sku = document.getElementById('sku').innerHTML;
	var prc = document.getElementById('price');
	var http    = null;
	var newDate = new Date;
	var url = "/getprice.htm?nc="+newDate.getTime()+"&finish="+finish+"&fabric="+fabric+"&sku="+sku+"&laminate="+laminate;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET",url,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			myArray = http.responseText.split(':');
			prc.innerHTML = "$"+myArray[0];
			if(oldprc = document.getElementById('old_price')) {
				oldprc.innerHTML = "\$"+myArray[1]+"";
			}
			add = document.getElementById('addtocart');
			add.style.visibility = 'visible';
		}
	}
	http.send(null);
	return true;
}

function Select(name,what) {
	div = document.getElementById(what);
	div.innerHTML = name;
	add = document.getElementById('addtocart');
	add.style.visibility = 'hidden';
	CloseChange();
}

function Change(id,what) {
	// get the height and width of the main div so we can cover it up...
	mn = document.getElementById('main');
	var width  = mn.offsetWidth;
	var height = mn.offsetHeight;
	div = document.getElementById('change');
	div.style.width  = width;
	div.style.height = height;
	div.style.overflow='auto';
	div.style.backgroundColor='#FFFFFF';
	div.innerHTML='';
	div.style.visibility = 'visible';
	
	eval("document.getElementById('dropshadow').focus()");

	var http    = null;
	var newDate = new Date;
	var url = "/selects.htm?"+what+"="+newDate.getTime()+"&id="+id+"&width="+width;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET",url,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			div.innerHTML = http.responseText;
		}
	}
	http.send(null);
	return false;
}

function GetShipping(zip,sid) {
	zip = zip.replace(/\D+/g,"");
	if(zip.length != 5) {
		alert('Error: the zip code you entered is not in the correct format. Please return and check your zip code again.');
		return false;
	}
	var http = null;
	var newDate = new Date;
	var url = "/get_shipping.htm?nc="+newDate.getTime()+"&zip="+zip;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET",url,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			div = document.getElementById('shipping');
			div.innerHTML = http.responseText;
		}
	}
	http.send(null);
}

function AddCart(tbl,pid,sid) {
	var qty = 1;  if(eval("document.getElementById('qty')"))	{ qty=document.getElementById('qty').value; }
	var sku = ""; if(eval("document.getElementById('sku')"))	{ sku=document.getElementById('sku').innerHTML; }
	var fin = ""; if(eval("document.getElementById('finish')"))	{ fin=document.getElementById('finish').innerHTML; }
	var fab = ""; if(eval("document.getElementById('fabric')"))	{ fab=document.getElementById('fabric').innerHTML; }
	var lam = ""; if(eval("document.getElementById('laminate')"))	{ lam=document.getElementById('laminate').innerHTML; }
	var prc = ""; if(eval("document.getElementById('price')"))	{ prc=document.getElementById('price').innerHTML; }

	crt = document.getElementById('cart2');
	add = document.getElementById('cart3');
	var http = null;
	var newDate = new Date;
	var url = "/addcart.htm?nc="+newDate.getTime()+"&qty="+qty+"&sid="+sid+"&tbl="+tbl+"&pid="+pid+"&sku="+sku+"&fin="+fin+"&fab="+fab+"&lam="+lam+"&prc="+prc;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET",url,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			add.innerHTML = http.responseText;
			myArray = http.responseText.split('|||');
			var items = myArray[1] || '0';
			var sssss = myArray[2] || 's';
			var total = myArray[3] || '0.00';
			crt.style.backgroundColor='#006633';
			crt.innerHTML = "<a class=carton href=/cart.htm>Shopping Cart: "+items+" Item"+sssss+" $"+total+"</a>";
		}
	}

	http.send(null);
	add.style.visibility='visible';
	window.setTimeout("add.style.visibility='hidden'",10000);

	if(tbl=='fabrics') {
		// remove the add to cart button if this is a fabric
		div = document.getElementById('add_to_cart');
		div.innerHTML="This swatch has been added to your cart.";
	}
}

function ShowHighResImage() {
	img = document.getElementById('dropshadow');
	var id = img.src.match(/(\d+)-300.jpg$/);
	window.open("/pics/db/products/"+id[1]+"-600.jpg","_new","width=620,height=620");
}

function ShowProductImage(id) {
	img = document.getElementById('dropshadow');
	img.src = "/pics/db/products/"+id+"-300.jpg";
}

function Filters(obj) {
	qrys = new Array(3); qrys["fc"]=''; qrys["fs"]=''; qrys["fr"]='';
	filters = new Array('fc','fs','fr');
	for(f=0; f<=3; f++) {
		for(i=1; i<=20; i++) {
			var key = filters[f]+""+i;
			img = eval(document.getElementById(key));
			if(img) {
				// switch the state if the obj matches...
				if(obj==key) {
					if(img.src.match("cb_of.gif")) {
						img.src = '/pics/cb_on.gif';
					} else {
						img.src = '/pics/cb_of.gif';
					}
				}
				// now check the state and save the ones that are "on"...
				if(img.src.match("cb_on.gif")) {
					var k = filters[f];
					qrys[k]+=i+":";
				}
			}
		}
	}

	var newDate = new Date;
	var url = "/products.htm?js="+newDate.getTime()+"&fc="+qrys['fc']+"&fs="+qrys['fs']+"&fr="+qrys['fr'];
	div = document.getElementById('main');
	if((qrys['fc']=="") && (qrys['fs']=="") && (qrys['fr']=="")) {
		div.innerHTML="<h1>No Matches</h1>Please select a collection and room from the menu to the left.";
		return 1;
	}
	div.innerHTML="<img src=/pics/loading.gif width=48 height=47 hspace=300 vspace=50 alt='Loading...'>";

	var http = null;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET",url,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			div.innerHTML = http.responseText;
		}
	}
	http.send(null);
}

function BillingShipping(checked) {
	div = document.getElementById('shipping');
	if(checked == false) {
		div.style.visibility='hidden';
		div.style.overflow='hidden';
		div.style.height='1px';
	} else {
		div.style.visibility='visible';
		div.style.overflow='visible';
		div.style.height='100%';
	}
}

function Row(col,id,on) {
	divback = document.getElementById(col+"r"+id);
	divlink = document.getElementById(col+"l"+id);
	if(on=='on') {
		divback.style.background='#F4E8DB';
		divlink.style.color='#000000';
		divback.style.cursor='pointer';
	} else {
		divback.style.background='#006633';
		divlink.style.color='#FFFFFF';
	}
}

function ShowDiv(id) {
	tb = document.getElementById("tb"+id);
	tl = document.getElementById("tl"+id);
	tl.style.color='#FFFFFF';
	tb.style.background='#006633';
	if(sb = document.getElementById("sb"+id)) {
		sb.style.visibility='visible';
	}
}

function HideDiv(id,on) {
	tb = document.getElementById("tb"+id);
	tl = document.getElementById("tl"+id);
	if(on=='off') {
		tb.style.background='#F4E8DB';
		tb.style.backgroundImage="url('pics/tback.gif')";
		tl.style.color='#006633';
	}
	if(sb = document.getElementById("sb"+id)) {
		sb.style.visibility='hidden';
	}
}
