// JavaScript Document
function clearMe(text){

if (text.defaultValue==text.value) text.value = '';

}

function change(id, newClass) {

identity=document.getElementById(id);

identity.className=newClass;

}

function swatch(attribute_ID,evt)
{

		if (document.documentElement && document.documentElement.scrollTop)
			theTop = document.documentElement.scrollTop;
		else 
			theTop = document.body.scrollTop;


		var e = (window.event) ? window.event : evt;
		document.getElementById('swatch').style.display = 'inline';
		//document.getElementById('swatch').style.top = e.clientY + document.body.scrollTop + 'px';
		//document.getElementById('swatch').style.left = e.clientX + 30 + 'px';
		document.getElementById('swatch').style.top = theTop + 10 + 'px';
		document.getElementById('swatch').style.left = 10 + 'px';
		var url="includes_root/getswatch.asp?attribute_ID=" + attribute_ID;
		//alert(url);
		xmlHttp=GetXmlHttpObject(stateChanged) 
		xmlHttp.open("GET", url , true) 
		xmlHttp.send(null) 
		
		function stateChanged() 
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				try
				{
				document.getElementById('swatch').innerHTML=xmlHttp.responseText
				}
				catch(e)
				{
				alert(xmlHttp.responseText);
				}
			} 	
		}
}		
function windowclose(divID)
	{
	document.getElementById('swatch').style.display = 'none';
	}
function swatchGridClose(divID)
	{
	document.getElementById('swatchGrid').style.display = 'none';
	}

function GetXmlHttpObject(handler)
	{ 
	var objXmlHttp=null
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work in Opera") 
		return 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
		strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
		objXmlHttp=new ActiveXObject(strName)
		objXmlHttp.onreadystatechange=handler 
		return objXmlHttp
		} 
		catch(e)
		{ 
		alert("Error. Scripting for ActiveX might be disabled") 
		return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
	objXmlHttp=new XMLHttpRequest()
	objXmlHttp.onload=handler
	objXmlHttp.onerror=handler 
	return objXmlHttp
	}
} 

function showSwatches(product_ID,option_ID,evt)
	{
		if (document.documentElement && document.documentElement.scrollTop)
			theTop = document.documentElement.scrollTop;
		else 
			theTop = document.body.scrollTop;
			
		var e = (window.event) ? window.event : evt;

		document.getElementById('swatchGrid').style.display = 'block';
		//document.getElementById('swatchGrid').style.top = e.clientY + document.body.scrollTop + 'px';
		document.getElementById('swatchGrid').style.top = theTop + 10 + 'px';
		document.getElementById('swatchGrid').style.right = '10px';	
		
		var url="includes_root/swatchgrid.asp?option_ID=" + option_ID + "&product_ID=" + product_ID;
		//alert(url);
		xmlHttp=GetXmlHttpObject(stateChanged) 
		xmlHttp.open("GET", url , true) 
		xmlHttp.send(null) 
		
		function stateChanged() 
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				try
				{
				document.getElementById('swatchGrid').innerHTML=xmlHttp.responseText
				}
				catch(e)
				{
				alert(xmlHttp.responseText);
				}
			} 	
		}
	}

function selectOption(option_ID,j)
{
	eval('document.frmAddToCart.prodoptions' + option_ID + '[' + j + '].selected=true;');
	windowclose();
	swatchGridClose();
}

function validateOptions(strValidate,iForm)
{
	if (strValidate=='')
	{
		strValidate = document.frmAddToCart.strValidate.value;
	}
	var arValidate, iLength, i, option_ID, f
	arValidate = strValidate.split(',');
	iLength = arValidate.length;
	if (parseInt(iForm) == 0)								
	{

		{
			for (i=0;i<iLength;i++){
				option_ID = arValidate[i];
				if (eval('document.frmAddToCart.prodoptions' + option_ID))
				{
					f = eval('document.frmAddToCart.prodoptions' + option_ID + '.selectedIndex');
					if (f == 0){
						alert('You must choose an option!');
						eval('document.frmAddToCart.prodoptions' + option_ID).focus();
						return false;
					}	
					else if (eval('document.frmAddToCart.prodoptions' + option_ID + '[' + f + '].value')==0)
					{
						alert('The option you have chosen is temporarily out of stock.  Please choose another.');
						eval('document.frmAddToCart.prodoptions' + option_ID).focus();
						return false;
					}
				}
			}
		}
	}
	else
	{	
		for (i=0;i<iLength;i++){
			option_ID = arValidate[i];
			if (eval('document.frmAddToCart' + iForm + '.prodoptions' + option_ID))
			{
				f = eval('document.frmAddToCart' + iForm + '.prodoptions' + option_ID + '.selectedIndex');
				if (f == 0){
					alert('You must choose an option!');
					eval('document.frmAddToCart' + iForm + '.prodoptions' + option_ID).focus();
					return false;
				}		
				else if (eval('document.frmAddToCart' + iForm + '.prodoptions' + option_ID + '[' + f + '].value')==0)
				{
					alert('The option you have chosen is temporarily out of stock.  Please choose another.');
					eval('document.frmAddToCart' + iForm + '.prodoptions' + option_ID).focus();
					return false;
				}
			}
		}
	}								
return true;
}

function showproducts(search_phrase,page,query_no)
{
		var url="http://www.home-decor-gardening.com/search_results_ajax.asp?search_phrase=" + encodeURI(search_phrase) + "&page=" + page + "&query_no=" + query_no;
		xmlHttp=GetXmlHttpObject(stateChanged) 
		xmlHttp.open("GET", url , true) 
		xmlHttp.send(null) 
		
		function stateChanged() 
		{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				try
				{
				document.getElementById('results').innerHTML=xmlHttp.responseText;
				}
				catch(e)
				{
				alert(xmlHttp.responseText);
				}
			} 
		} 	
}

function generateCap(rnd_num)
{
	var IMG = document.getElementById('captchaIMG');
	IMG.src = "http://www.home-decor-gardening.com/generate-captcha.asp?rnd_num=" + randomString();
}

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function checkUser()
{
		var url="http://www.home-decor-gardening.com/check-email.asp?email=" + document.getElementById('txtEmail').value 
		xmlHttp=GetXmlHttpObject(stateChanged) 
		xmlHttp.open("GET", url , true) 
		xmlHttp.send(null) 
		
		function stateChanged() 
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				{ 
					if (xmlHttp.responseText == "TAKEN")
					{
						alert("An account has already been established for this email address.  Please login.");
						document.getElementById('txtEmail').value = '';
						document.getElementById('UserLogin').value = document.getElementById('txtEmail').value;
						document.getElementById('UserLogin').focus();
					} 
				} 
		} 	

}

function checkavail()
{
		var url="http://www.home-decor-gardening.com/check-name.asp?name=" + document.getElementById('txtName').value 
		xmlHttp=GetXmlHttpObject(stateChanged) 
		xmlHttp.open("GET", url , true) 
		xmlHttp.send(null) 
		
		function stateChanged() 
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				{ 
					document.getElementById('nameavail').innerHTML=xmlHttp.responseText
					if (xmlHttp.responseText == "<font color=red>Name taken.</font>")
					{
						alert("This name has already been taken");
						document.getElementById('txtName').focus();
					} 
				} 
		} 	

}
		
function checkavail2()
{
		var url="http://www.home-decor-gardening.com/check-name.asp?name=" + document.getElementById('txtName').value 
		xmlHttp=GetXmlHttpObject(stateChanged) 
		xmlHttp.open("GET", url , true) 
		xmlHttp.send(null) 
		
		function stateChanged() 
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				{ 
					document.getElementById('nameavail').innerHTML=xmlHttp.responseText
				} 
		} 	

}

function sameasbilling()  
		{
		document.frmCustomer.txtShiptoFirstName.value = document.frmCustomer.txtFirstName.value;
		document.frmCustomer.txtShiptoLastName.value = document.frmCustomer.txtLastName.value;
		document.frmCustomer.txtShiptoCompany.value = document.frmCustomer.txtCompany.value;
		document.frmCustomer.txtShiptoAddress1.value = document.frmCustomer.txtAddress1.value;
		document.frmCustomer.txtShiptoAddress2.value = document.frmCustomer.txtAddress2.value;
		document.frmCustomer.txtShiptoCity.value = document.frmCustomer.txtCity.value;
		document.frmCustomer.selShiptoState.value = document.frmCustomer.selState.value;
		document.frmCustomer.txtShiptoZip.value = document.frmCustomer.txtZip.value;
		document.frmCustomer.selShiptoCountry.value = document.frmCustomer.selCountry.value;
		document.frmCustomer.txtShiptoPhone.value = document.frmCustomer.txtPhone.value;
		}

function alphaBet(startletter)
{
		var url="http://www.home-decor-gardening.com/alphabetic_product_list_AJAX.asp?startletter=" + startletter; 
		xmlHttp=GetXmlHttpObject(stateChanged) 
		xmlHttp.open("GET", url , true) 
		xmlHttp.send(null) 
		
		function stateChanged() 
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				{ 
					document.getElementById('ab_prods').innerHTML=xmlHttp.responseText
				} 
		} 	

}