function cartError(str)
{
	document.getElementById("error_box_cart").style.display="block";
	document.getElementById("error_box_cart").getElementsByTagName("p")[0].innerHTML=str;
}

function duh()
{
	document.getElementById("ccChanged").value='1';
	document.getElementById("CC_Name").value='Test';
	document.getElementById("CC_Number").value='4111111111111111';
	document.getElementById("CC_Exp_Month").options[5].selected=true;
	document.getElementById("CC_Exp_Year").options[5].selected=true;
}

function noThanks()
{
	// didnt want the discount - send back to step 3
	lightWindowSubmitAjax();
	lwTimeoutPass();
	updateCheckoutLightbox('/store/?action=cart.dsp_step3&resetCouponCode=1');
}

var _lwTimeout=null;
var _lwTimeoutOnce=false;
var _lwTimeoutDelay=30000; // 60 total seconds triggers action
var _lwDoEval=true;
function lwTimeout()
{
	// check in XX ms if the checkout lw has loaded
	window.clearTimeout(_lwTimeout);
	_lwTimeoutOnce=false;
	_lwDoEval=true;
	_lwTimeout=window.setTimeout("lwTimeoutCheck()",_lwTimeoutDelay);
}

function lwTimeoutCheck()
{
	if(_lwTimeoutOnce==false)
	{
		_lwTimeout=window.setTimeout("lwTimeoutCheck()",_lwTimeoutDelay);
		_lwTimeoutOnce=true;
	}
	else
	{
		lwTimeoutAction();
	}
}

function lwTimeoutPass()
{
	window.clearTimeout(_lwTimeout);
	_lwTimeoutOnce=false;
	_lwDoEval=true;
}

function lwTimeoutAction()
{
	xmlhttp_checkout.onreadystatechange=function(){return false}
	_lwDoEval=false;
	myLightWindow.deactivate();
	document.getElementById("error_box").getElementsByTagName("p")[0].innerHTML="Your submission took too long to complete.<br>Please try again.";
	document.getElementById("error_box").style.display="block";
}


var xmlhttp_checkout;
function checkout_1(nextStep)
{
	xmlhttp_checkout=null;
	if(xmlhttp_checkout=getAjaxObj())
	{
		xmlhttp_checkout.onreadystatechange=function()
		{
			if (xmlhttp_checkout.readyState==4)
			{
				// 4 = "loaded"
				if (xmlhttp_checkout.status==200)
				{
					// 200 = OK
					lwTimeoutPass();
					if(_lwDoEval==true)
					{
						eval(xmlhttp_checkout.responseText);
					}
				}
				else
				{
					//alert("Problem getting XML data - checkout_1("+nextStep+")\n\nRe-Sending");
					checkout_1(nextStep);
				}
			}
		};

		var frm=document.getElementById("cartForm");



		var params="nextStep="+nextStep;
		params+="&checkoutType="+frm.checkoutType.value;
		params+="&email="+frm.email.value;
		params+="&password="+frm.password.value;
		params+="&Remember="+((document.getElementById("Remember").checked)?"1":"0");

		if(document.getElementById('checkingOut')!=null)
		{
			params+="&checkingOut=1";
		}
		//alert(params);

		xmlhttp_checkout.open("POST","/store/?action=cart.act_step1",true);
		xmlhttp_checkout.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_checkout.setRequestHeader("Content-length", params.length);
		xmlhttp_checkout.setRequestHeader("Connection", "close");
		xmlhttp_checkout.send(params);

		lightWindowSubmitAjax();
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function checkout_2(nextStep)
{
	xmlhttp_checkout=null;
	var val;
	var name;
	var inps;
	var errors=0;

	var params="nextStep="+nextStep;
	var frm=document.getElementById("cartForm");

	var arr=new Array(frm.getElementsByTagName("input"),frm.getElementsByTagName("select"));

	var msg=""
	for(var y=0;y<arr.length;y++)
	{
		inps=arr[y];
		for(var x=0;x<inps.length;x++)
		{
			if(inps[x].tagName=="select")
				val=inps[x].options[inps[x].options.selectedIndex].value;
			else
				val=inps[x].value;

			name=inps[x].name;
			if(val=="" && document.getElementById("required_"+name)!=null)
			{
				document.getElementById("required_"+name).className="required";
				msg="Please complete all required fields.<br>";
				errors++;
			}
			else
			{
				params+="&"+name+"="+val;
				if(document.getElementById("required_"+name)!=null)
					document.getElementById("required_"+name).className="";
			}
		}
	}

	if(document.getElementById("password")!=null)
	{
		if(document.getElementById("password").value!=document.getElementById("confirm_password").value)
		{
			document.getElementById("required_password").className="required";
			document.getElementById("required_confirm_password").className="required";
			msg+="Password and Confirm Password do not match.";
			errors++;
		}
		else
		{
			if(document.getElementById("password").value!="")
			{
				document.getElementById("required_password").className="";
			}
			if(document.getElementById("confirm_password").value!="")
			{
				document.getElementById("required_confirm_password").className="";
			}
		}

	}

	if(errors==0)
	{
		document.getElementById("error_box_cart").style.display="none";

		if(xmlhttp_checkout=getAjaxObj())
		{
			xmlhttp_checkout.onreadystatechange=function()
			{
				if (xmlhttp_checkout.readyState==4)
				{
					// 4 = "loaded"
					//alert(xmlhttp_checkout.responseText);
					//clipboardData.setData("text",xmlhttp_checkout.responseText);
					if (xmlhttp_checkout.status==200)
					{
						// 200 = OK
						lwTimeoutPass();						
						if(_lwDoEval==true)
						{
							eval(xmlhttp_checkout.responseText);
						}
					}
					else
					{
						//alert("Problem getting XML data - checkout_2("+nextStep+")\n\nRe-Sending");
						//alert(xmlhttp_checkout.responseText);
						checkout_2(nextStep);
					}
				}
			};

			params+="&checkingOut=1";
			xmlhttp_checkout.open("POST","/store/?action=cart.act_step2",true);
			xmlhttp_checkout.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp_checkout.setRequestHeader("Content-length", params.length);
			xmlhttp_checkout.setRequestHeader("Connection", "close");
			xmlhttp_checkout.send(params);

			lightWindowSubmitAjax();
		}
		else
		{
			alert("Your browser does not support AJAX.");
		}
	}
	else
	{
		document.getElementById("error_box_cart").style.display="block";
		document.getElementById("error_box_cart").getElementsByTagName("p")[0].innerHTML=msg;
	}
}

function checkout_3(nextStep,removeCoupon)
{
	xmlhttp_checkout=null;
	var val;
	var name;
	var inps;

	var frm=document.getElementById("cartForm");
	var arr=new Array(frm.getElementsByTagName("input"),frm.getElementsByTagName("select"));
	var params="";

	if(nextStep!=null)
	{
		params+="nextStep="+nextStep;
	}
	if(removeCoupon!=null)
	{
		params+="&removeCoupon=1";
	}
	if(document.getElementById("selectedCoupon_3")!=null)
	{
		params+="&selectedCoupon="+document.getElementById("selectedCoupon_3").options[document.getElementById("selectedCoupon_3").options.selectedIndex].value;
	}
	if(document.getElementById("prizeProduct_3")!=null)
	{
		params+="&prizeProduct="+document.getElementById("prizeProduct_3").options[document.getElementById("prizeProduct_3").options.selectedIndex].value;
	}


	for(var y=0;y<arr.length;y++)
	{
		inps=arr[y];
		for(var x=0;x<inps.length;x++)
		{
			if(inps[x].tagName=="select")
				val=inps[x].options[inps[x].options.selectedIndex].value;
			else
				val=inps[x].value;

			name=inps[x].name;
			params+="&"+name+"="+val;
		}
	}


	if(xmlhttp_checkout=getAjaxObj())
	{
		xmlhttp_checkout.onreadystatechange=function()
		{
			if (xmlhttp_checkout.readyState==4)
			{
				// 4 = "loaded"
				if (xmlhttp_checkout.status==200)
				{
					// 200 = OK
					lwTimeoutPass();
					if(_lwDoEval==true)
					{
						eval(xmlhttp_checkout.responseText);
					}
				}
				else
				{
					//alert("Problem getting XML data - checkout_3("+nextStep+")\n\nRe-Sending");
					checkout_3(nextStep);
				}
			}
		};

		params+="&checkingOut=1";
		xmlhttp_checkout.open("POST","/store/?action=cart.act_step3",true);
		xmlhttp_checkout.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_checkout.setRequestHeader("Content-length", params.length);
		xmlhttp_checkout.setRequestHeader("Connection", "close");
		xmlhttp_checkout.send(params);

		lightWindowSubmitAjax();

	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function checkout_4(nextStep,nextStepRedirect,removeCoupon)
{
	xmlhttp_checkout=null;
	if(xmlhttp_checkout=getAjaxObj())
	{
		xmlhttp_checkout.onreadystatechange=function()
		{
			if (xmlhttp_checkout.readyState==4)
			{
				// 4 = "loaded"
				if (xmlhttp_checkout.status==200)
				{
					// 200 = OK
					lwTimeoutPass();
					if(_lwDoEval==true)
					{
						eval(xmlhttp_checkout.responseText);
					}
				}
				else
				{
					//alert(xmlhttp_checkout.responseText);
					//alert("Problem getting XML data - checkout_4("+nextStep+","+nextStepRedirect+")\n\nRe-Sending");
					checkout_4(nextStep,nextStepRedirect,removeCoupon);
				}
			}
		};

		var frm=document.getElementById("cartForm");

		var params="";

		if(nextStep!=null)
		{
			params+="nextStep="+nextStep;
			if(nextStepRedirect!=null)
			{
				params+="&nextStepRedirect="+nextStepRedirect;
			}
		}


		if(removeCoupon!=null)
		{
			params+="&removeCoupon=1";
		}
		if(document.getElementById("selectedCoupon_4")!=null)
		{
			params+="&selectedCoupon="+document.getElementById("selectedCoupon_4").options[document.getElementById("selectedCoupon_4").options.selectedIndex].value;
		}
		if(document.getElementById("prizeProduct_4")!=null)
		{
			params+="&prizeProduct="+document.getElementById("prizeProduct_4").options[document.getElementById("prizeProduct_4").options.selectedIndex].value;
		}

		params+="&checkingOut=1";
		xmlhttp_checkout.open("POST","/store/?action=cart.act_step4",true);
		xmlhttp_checkout.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_checkout.setRequestHeader("Content-length", params.length);
		xmlhttp_checkout.setRequestHeader("Connection", "close");
		xmlhttp_checkout.send(params);

		lightWindowSubmitAjax();
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}


function updateCheckoutLightbox(page)
{

	if(page.indexOf("dsp_step1")!=-1)
	{
		var h=425;
	}
	else if(page.indexOf("dsp_step2")!=-1)
	{
		var h=650;
	}
	else if(page.indexOf("dsp_step3")!=-1)
	{
		var h=800;
	}
	else if(page.indexOf("dsp_step4")!=-1)
	{
		var h=750;
	}
	else if(page.indexOf("dsp_forgotPass")!=-1)
	{
		var h=425;
	}
	else if(page.indexOf("dsp_stepFreeProduct")!=-1)
	{
		var h=360;
	}
	page+="&checkingOut=1";


	document.getElementById("nextStepButton").parentNode.width=850;
	document.getElementById("nextStepButton").parentNode.height=h;
	document.getElementById("nextStepButton").parentNode.href=page;
	document.getElementById("nextStepButton").parentNode.type='page';
	myLightWindow.submitForm("nextStepButton");
}

function lightWindowSubmitAjax()
{
	var loadDiv=document.getElementById("lightwindow_loading");
	if(loadDiv!=null)
	{
		loadDiv.parentNode.removeChild(loadDiv);
	}
	$('lightwindow_contents').setStyle({overflow: 'hidden'});
	myLightWindow._addLoadingWindowMarkup();
	window.scrollTo(0,0);
	document.getElementById("lightwindow_loading").scrollIntoView(true);

	lwTimeout();
}

var outOfStock=false;
function addToCart(redeemFree,postAddAction)
{
	if(allAttributesSelected())
	{
		if(outOfStock)
		{
			document.getElementById("message_box").getElementsByTagName("p")[0].innerHTML="This item is currently out of stock.";
			document.getElementById("message_box").style.display="block";
			messageFade("message_box");
		}
		else
		{
			if(xmlhttp_atc=getAjaxObj())
			{
				xmlhttp_atc.onreadystatechange=function()
				{
					if (xmlhttp_atc.readyState==4)
					{
						// 4 = "loaded"
						if (xmlhttp_atc.status==200)
						{
							// 200 = OK
							eval(xmlhttp_atc.responseText);
						}
						else
						{
							//alert("Problem getting XML data - updateMainCart();");
							//updateMainCart();
						}
					}
				};

				xmlhttp_atc.open("GET","/store/?action=cart.act_addToCart&id="+productToAddToCart+((postAddAction==null)?"&goToCart=1":"&nextPage="+postAddAction)+((redeemFree==1)?"&redeemFree=1":""));
				xmlhttp_atc.send(null);
			}
		}
	}
	else
	{
		doSelectAttributes();
	}
}

function saveForLater()
{
	if(allAttributesSelected() ||  productToAddToCart!=null)
	{
		if(_customer_id==0)
		{
			myLightWindow.activateWindow({href:'/store/?action=cart.dsp_step1&afterLogin=saveForLater()&afterLoginTitle=Please log in.',title:'',caption:'',width:850,height:425,type:'page'});
		}
		else
		{
			runAjaxCall('/store/?action=cart.act_addToWishList&id='+productToAddToCart+'&skipRefresh=1');
			document.getElementById("message_box").getElementsByTagName("p")[0].innerHTML="This product has been added to your wish list.";
			document.getElementById("message_box").style.display="block";
			messageFade("message_box");
			myLightWindow.deactivate();
			updateMainCart();
		}
	}
	else
	{
		doSelectAttributes();
	}
}

function updateMainCart()
{
	if(xmlhttp_umc=getAjaxObj())
	{
		xmlhttp_umc.onreadystatechange=function()
		{
			if (xmlhttp_umc.readyState==4)
			{
				// 4 = "loaded"
				if (xmlhttp_umc.status==200)
				{
					// 200 = OK
					eval(xmlhttp_umc.responseText);
				}
				else
				{
					//alert("Problem getting XML data - updateMainCart();");
					updateMainCart();
				}
			}
		};

		xmlhttp_umc.open("GET","/store/?action=cart.act_updateMainCart",true);
		xmlhttp_umc.send(null);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}


function addToCartProductPage(redeemFree)
{
	if(allAttributesSelected() ||  productToAddToCart!=null)
	{
		if(outOfStock)
		{
			document.getElementById("message_box").getElementsByTagName("p")[0].innerHTML="This item is currently out of stock.";
			document.getElementById("message_box").style.display="block";
			messageFade("message_box");
		}
		else
		{
			if(xmlhttp_atc=getAjaxObj())
			{
				xmlhttp_atc.onreadystatechange=function()
				{
					if (xmlhttp_atc.readyState==4)
					{
						// 4 = "loaded"
						if (xmlhttp_atc.status==200)
						{
							// 200 = OK
							eval(xmlhttp_atc.responseText);
						}
						else
						{
							addToCartProductPage(redeemFree)
						}
					}
				};

				xmlhttp_atc.open("GET","/store/?action=cart.act_addToCart&id="+productToAddToCart+"&goToCart=1"+((redeemFree==1)?"&redeemFree=1":""));
				xmlhttp_atc.send(null);
			}
		}
	}
	else
	{
		doSelectAttributes();
	}
}

function doSelectAttributes()
{
	var tbl=document.getElementById("attributesSelectTable");
	if(tbl==null)
	{
		// no attributes are setup up this product - means no skus are selectable
		document.getElementById("message_box").style.display="none";
		document.getElementById("error_box").getElementsByTagName("p")[0].innerHTML="There are no skus for this product at this time.<br/>Please check back later.";
		document.getElementById("error_box").style.display="block";
		messageFade("error_box");
	}
	else
	{
		var str="You must select your ";
		var arr=new Array();
		for(var x=0;x<tbl.rows.length;x++)
		{
			var sel=tbl.rows[x].cells[1].getElementsByTagName("select")[0];
			if(sel.options[sel.options.selectedIndex].value=="_choose_")
			{
				arr[arr.length]=tbl.rows[x].cells[0].getElementsByTagName("div")[0].innerHTML;
			}
		}
		if(arr.length==1)
		{
			str+=arr[0];
		}
		else if(arr.length==2)
		{
			str+=arr[0]+" and "+arr[1];
		}
		else
		{
			for(var x=0;x<arr.length-2;x++)
			{
				str+=arr[x]+", ";
			}
			str+=arr[arr.length-2]+" and "+arr[arr.length-1];
		}
		document.getElementById("message_box").getElementsByTagName("p")[0].innerHTML=str;
		document.getElementById("message_box").style.display="block";
		messageFade("message_box");
	}
}

function allAttributesSelected()
{
	var tbl=document.getElementById("attributesSelectTable");
	if(tbl==null)
	{
		// no attributes are setup up this product - means no skus are selectable
		if(productToAddToCart!=null)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		var arr=new Array();
		for(var x=0;x<tbl.rows.length;x++)
		{
			var sel=tbl.rows[x].cells[1].getElementsByTagName("select")[0];
			if(sel.options[sel.options.selectedIndex].value=="_choose_")
			{
				arr[arr.length]=tbl.rows[x].cells[0].getElementsByTagName("div")[0].innerHTML;
			}
		}
		return arr.length==0;
	}
}

function setCurrent(obj,y)
{
	var li=document.getElementById("productViewsUl").getElementsByTagName("li");
	for(var x=0;x<li.length;x++)
	{
		if(li[x].getElementsByTagName("a")[0]==obj)
		{
			li[x].getElementsByTagName("a")[0].id="current";
			ProductImages["current"].src=ProductImages[y].src;
		}
		else
		{
			li[x].getElementsByTagName("a")[0].id="";
		}
	}
}

var productToAddToCart=null;

var xmlhttp_att_update=new Array();
var xmlhttp_att_update_counter=0;

function filterAttributes(obj,product_id,isPrizeProduct,query_string)
{
	if(document.getElementById("out_of_stock")!=null)
		document.getElementById("out_of_stock").style.display="none";

	var mbox=document.getElementById("message_box");
	if(mbox!=null){
		document.getElementById("message_box").getElementsByTagName("p")[0].innerHTML="";
		document.getElementById("message_box").style.display="none";
	}

	var tbl=document.getElementById("attributesSelectTable");
	var sel=new Array();
	for(var x=0;x<tbl.rows.length;x++)
	{
		sel[x]=tbl.rows[x].cells[1].getElementsByTagName("select")[0];
	}


	var params="product_id="+product_id;
	var nextSel=null;

	for(var x=0;x<sel.length;x++)
	{
		if(sel[x]==obj)
		{
			var index=x;
		}
	}


	for(var x=0;x<sel.length;x++)
	{
		if(x>index)
		{
			//sel[x].disabled=true;
			$(sel[x].name+'_image_cell').innerHTML='';
			for(var y=1;y<sel[x].options.length;y++)
			{
				sel[x].removeChild(sel[x].options[y]);
				y--;
			}
		}
		else
		{
			//sel[x].disabled=false;
			params+="&"+sel[x].name+"="+manualEscape(sel[x].options[sel[x].options.selectedIndex].value);
		}

		if(typeof sel[index+1]!="undefined")
		{
			nextSel=sel[index+1].name;
		}
	}
	
	if(obj.getAttribute("firstSel")=="1" && obj.options[obj.options.selectedIndex].value=="_choose_") {
		nextSel=null;
	}

	if(obj.options[obj.options.selectedIndex].value=="_choose_")
	{
		$(obj.name+'_image_cell').innerHTML='';
	}

	xmlhttp_att_update_counter++;
	if(xmlhttp_att_update[xmlhttp_att_update_counter]=getAjaxObj())
	{
		xmlhttp_att_update[xmlhttp_att_update_counter].onreadystatechange=function()
		{
			if (xmlhttp_att_update[xmlhttp_att_update_counter].readyState==4)
			{
				// 4 = "loaded"
				//alert(xmlhttp_att_update[xmlhttp_att_update_counter].responseText);
				if (xmlhttp_att_update[xmlhttp_att_update_counter].status==200)
				{
					// 200 = OK
					//clipboardData.setData("Text",xmlhttp_att_update[xmlhttp_att_update_counter].responseText);
					//alert(xmlhttp_att_update[xmlhttp_att_update_counter].responseText);
					eval(xmlhttp_att_update[xmlhttp_att_update_counter].responseText);
				}
				else
				{

					//alert("Problem getting XML data");
					//filterAttributes(obj,product_id)
				}
			}
		};

		if(nextSel!=null)
		{
			params+="&nextSel="+nextSel;
		}


		params+="&curSel="+obj.name;
		params+="&isPrizeProduct="+isPrizeProduct;
		
		if(query_string){
			params+=query_string;
		}
		
		xmlhttp_att_update[xmlhttp_att_update_counter].open("POST","/store/?action=products.act_filterAttributes",true);

		if(obj.options[obj.options.selectedIndex].value!="_choose_" || obj.getAttribute("firstSel"))
		{
			xmlhttp_att_update[xmlhttp_att_update_counter].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp_att_update[xmlhttp_att_update_counter].setRequestHeader("Content-length", params.length);
			xmlhttp_att_update[xmlhttp_att_update_counter].setRequestHeader("Connection", "close");
			xmlhttp_att_update[xmlhttp_att_update_counter].send(params);
		}

		if(obj.options[obj.options.selectedIndex].value!="_choose_")
		{
			document.getElementById(obj.name+"_image_cell").innerHTML='<img width="13" height="13" src="'+((document.location.toString().indexOf("cart.")!=-1)?smallLoadingWhiteBG.src:smallLoading.src)+'"/>';
		}

	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function reset_to_fitted(product_id,isPrizeProduct,query_string){
	
	
	try{
		var opt=document.getElementById("first_selected_option");
		opt.selected=true;
		if(query_string) {
			filterAttributes(opt.parentNode,product_id,isPrizeProduct,query_string);
		} 
		else {
			filterAttributes(opt.parentNode,product_id,isPrizeProduct);
		}
		
	}catch(e){;}
	/*
	var tbl=document.getElementById("attributesSelectTable");
	if(tbl!=null){
		if(tbl.rows.length>0){			
			var sel=tbl.rows[0].cells[1].getElementsByTagName("select")[0];
			sel.options[0].selected=true;
			filterAttributes(sel,product_id,isPrizeProduct);
		}
	}
	*/
}

var smallLoading=new Image();
smallLoading.src='/images/ajax-loading-small.gif';

var smallLoadingWhiteBG=new Image();
smallLoadingWhiteBG.src='/images/ajax-loading-small-white-bg.gif';

function manualEscape(str)
{
	str=str.replace(/\+/g,"%2B");
	str=str.replace(/&quot;/g,"_QUOTE_");
	str=str.replace(/&deg;/g,"_DEGREE_");
	return str;
}

function submitNotify(id,upcoming_product)
{
	var inp=document.getElementById("notifyEmail");
	var isMatch=false;
	if(inp.value!="")
	{
		if(inp.value.match( /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i))
		{
			isMatch=true;
		}
	}
	if(isMatch)
	{
		if(xmlhttp_notify=getAjaxObj())
		{
			xmlhttp_notify.onreadystatechange=function()
			{
				if (xmlhttp_notify.readyState==4)
				{
					// 4 = "loaded"
					//alert(xmlhttp_notify.responseText);
					if (xmlhttp_notify.status==200)
					{
						// 200 = OK
						eval(xmlhttp_notify.responseText);
					}
					else
					{

						//alert("Problem getting XML data");
						//submitNotify(id)
					}
				}
			};



			params="id="+id;
			params+="&email="+inp.value;
			if(upcoming_product==1)
			{
				params+="&upcoming_product=1";
			}
			xmlhttp_notify.open("POST","/store/?action=products.act_notifyMeLater",true);

			xmlhttp_notify.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp_notify.setRequestHeader("Content-length", params.length);
			xmlhttp_notify.setRequestHeader("Connection", "close");
			xmlhttp_notify.send(params);

			var loadDiv=document.getElementById("lightwindow_loading");
			if(loadDiv!=null)
			{
				loadDiv.parentNode.removeChild(loadDiv);
			}
			$('lightwindow_contents').setStyle({overflow: 'hidden'});
			myLightWindow._addLoadingWindowMarkup();
			window.scrollTo(0,0);
			document.getElementById("lightwindow_loading").scrollIntoView(true);

		}
		else
		{
			alert("Your browser does not support AJAX.");
		}
	}
	else
	{

	}
}

var animatedMessages=new Array();
var animLookup=new Array();
function messageFade(box_id)
{
	setTimeout("startMessageFade('"+box_id+"')",5000);
}

function startMessageFade(box_id)
{
	animatedMessages[box_id]=100;
	animLookup[box_id]=setInterval("doMessageFade('"+box_id+"')",10);
}

function doMessageFade(box_id)
{
	animatedMessages[box_id]-=2;
	var opacity=animatedMessages[box_id];
	var obj=document.getElementById(box_id);

	obj.style.opacity = (opacity / 100);
	obj.style.KhtmlOpacity = (opacity / 100);

	obj.style.MozOpacity = (opacity / 100);
	obj.style.filter = "alpha(opacity=" + opacity + ")";

	if(animatedMessages[box_id]<=0)
	{
		clearInterval(animLookup[box_id]);
		obj.style.display="none";
		opacity=100;

		obj.style.KhtmlOpacity = null;
		obj.style.opacity = null;

		obj.style.MozOpacity = null;
		obj.style.filter = null;
	}
}

function addToWishList(id)
{
	if(_customer_id==0)
	{
		myLightWindow.activateWindow({href:'/store/?action=cart.dsp_step1&afterLogin=addToWishList('+id+')&afterLoginTitle=Please log in.',title:'',caption:'',width:850,height:425,type:'page'});
	}
	else
	{
		runAjaxCall('/store/?action=cart.act_addToWishList&id='+id+'&removeFromCart=1&quantity='+document.getElementById('qty_'+id).value);
	}
}

function accountCreateFormValidate(frm)
{
	var val;
	var name;
	var inps;
	var errors=0;

	var arr=new Array(frm.getElementsByTagName("input"),frm.getElementsByTagName("select"));

	var msg=""
	for(var y=0;y<arr.length;y++)
	{
		inps=arr[y];
		for(var x=0;x<inps.length;x++)
		{
			if(inps[x].tagName=="select")
				val=inps[x].options[inps[x].options.selectedIndex].value;
			else
				val=inps[x].value;

			name=inps[x].name;
			if(val=="" && document.getElementById("required_"+name)!=null)
			{
				document.getElementById("required_"+name).className="required";
				msg="Please complete all required fields.<br>";
				errors++;
			}
			else
			{
				if(document.getElementById("required_"+name)!=null)
					document.getElementById("required_"+name).className="";
			}
		}
	}

	if(document.getElementById("password")!=null)
	{
		if(document.getElementById("password").value!=document.getElementById("confirm_password").value)
		{
			document.getElementById("required_password").className="required";
			document.getElementById("required_confirm_password").className="required";
			msg+="Password and Confirm Password do not match.";
			errors++;
		}
		else
		{
			if(document.getElementById("password").value!="")
			{
				document.getElementById("required_password").className="";
			}
			if(document.getElementById("confirm_password").value!="")
			{
				document.getElementById("required_confirm_password").className="";
			}
		}

	}

	if(errors==0)
	{
		return true;
	}
	else
	{
		document.getElementById("error_box").style.display="block";
		document.getElementById("error_box").getElementsByTagName("p")[0].innerHTML=msg;
		return false;
	}
}

function updateLightBoxCart()
{
	if(xmlhttp_ulbc=getAjaxObj())
	{
		xmlhttp_ulbc.onreadystatechange=function()
		{
			if (xmlhttp_ulbc.readyState==4)
			{
				// 4 = "loaded"
				if (xmlhttp_ulbc.status==200)
				{
					// 200 = OK
					eval(xmlhttp_ulbc.responseText);
				}
				else
				{
					//alert("Problem getting XML data - updateLightBoxCart();");
					updateLightBoxCart();
				}
			}
		};

		xmlhttp_ulbc.open("GET","/store/?action=cart.act_updateLightBoxCart");
		xmlhttp_ulbc.send(null);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function updateTotalDspCart(checkout)
{
	var frm=document.getElementById("cartFormHome");
	var inps=frm.getElementsByTagName("input");
	var params="";
	if(checkout==1)
	{
		params+="checkout=1";
	}
	for(var x=0;x<inps.length;x++)
	{
		var	val=inps[x].value;
		var name=inps[x].name;
		params+=((params=="")?"":"&")+name+"="+val;
	}



	if(xmlhttp_tdc=getAjaxObj())
	{
		xmlhttp_tdc.onreadystatechange=function()
		{
			if (xmlhttp_tdc.readyState==4)
			{
				// 4 = "loaded"
				if (xmlhttp_tdc.status==200)
				{
					// 200 = OK
					eval(xmlhttp_tdc.responseText);
				}
				else
				{
					//alert("Problem getting XML data - updateTotalDspCart("+checkout+");");
					updateTotalDspCart(checkout);
				}
			}
		};

		xmlhttp_tdc.open("POST","/store/?action=cart.act_updateTotalDspCart",true);
		xmlhttp_tdc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_tdc.setRequestHeader("Content-length", params.length);
		xmlhttp_tdc.setRequestHeader("Connection", "close");
		xmlhttp_tdc.send(params);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function doLoadingFade()
{
	Effect.Fade('lightwindow_loading', {
	duration: 0.75,
	delay: 1.0,
	afterFinish: function() {
		// Just in case we need some scroll goodness (myLightWindow also avoids the swiss cheese effect)
		if (myLightWindow.windowType != 'image' && myLightWindow.windowType != 'media' && myLightWindow.windowType != 'external') {
			$('lightwindow_contents').setStyle({
				overflow: 'auto'
			});
		}
		myLightWindow._handleNavigation(myLightWindow.activeGallery);
		myLightWindow._defaultGalleryAnimationHandler();
		myLightWindow._setStatus(false);
	}.bind(myLightWindow),
	queue: {position: 'end', scope: 'lightwindowAnimation'}
	});
}

function useBillingAddress(nextStep)
{
	var frm=document.getElementById("cartForm");

	var arr=new Array(frm.getElementsByTagName("input"),frm.getElementsByTagName("select"));

	for(var y=0;y<arr.length;y++)
	{
		var inps=arr[y];
		for(var x=0;x<inps.length;x++)
		{
			var tmp=inps[x].name.split("_");
			if(tmp[0]=="billing")
			{
				if(inps[x].tagName=="select")
					document.getElementById("shipping_"+tmp[1]).options[inps[x].options.selectedIndex].selected=true;
				else
					document.getElementById("shipping_"+tmp[1]).value=inps[x].value
			}
		}
	}
	checkout_2(nextStep);
}

function forgotPassword()
{
	if(xmlhttp_fp=getAjaxObj())
	{
		xmlhttp_fp.onreadystatechange=function()
		{
			if (xmlhttp_fp.readyState==4)
			{
				// 4 = "loaded"
				if (xmlhttp_fp.status==200)
				{
					// 200 = OK
					//alert(xmlhttp_fp.responseText);
					eval(xmlhttp_fp.responseText);
				}
				else
				{
					//alert(xmlhttp_fp.responseText);
					forgotPassword();
				}
			}
		};
		var params="email="+document.getElementById("forgotPass").email.value;
		xmlhttp_fp.open("POST","/store/?action=cart.act_forgotPass",true);
		xmlhttp_fp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_fp.setRequestHeader("Content-length", params.length);
		xmlhttp_fp.setRequestHeader("Connection", "close");
		xmlhttp_fp.send(params);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function selectFitting(id, customer_id)
{
	if(xmlhttp_sf=getAjaxObj())
	{		
		xmlhttp_sf.onreadystatechange=function()
		{
			if (xmlhttp_sf.readyState==4)
			{
				// 4 = "loaded"
				
				if (xmlhttp_sf.status==200)
				{
					// 200 = OK
					//alert("rtext="+xmlhttp_sf.responseText);
					eval(xmlhttp_sf.responseText);
				}
				else
				{					
					selectFitting(id, customer_id);
				}
			}
		};
		var params="id="+id+"&customer_id"+customer_id;
		xmlhttp_sf.open("POST","/store/?action=myaccount.act_fittingdefault",true);
		xmlhttp_sf.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_sf.setRequestHeader("Content-length", params.length);
		xmlhttp_sf.setRequestHeader("Connection", "close");
		xmlhttp_sf.send(params);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

var Tmp=new Array();

function getMatchPercent(product_id)   {
	if(Tmp[product_id]=getAjaxObj())
	{
		 Tmp[product_id].onreadystatechange=function()
		{
			if (Tmp[product_id].readyState==4)
			{
				// 4 = "loaded"
				if (Tmp[product_id].status==200)
				{
					// 200 = OK
					// eval(xmlhttp_fp.responseText);
					var div=document.getElementById("match_percent_"+ Tmp[product_id].responseText.split("|||")[0].replace(/ /g,""));
					div.innerHTML = Tmp[product_id].responseText.split("|||")[1];
				}
				else
				{
					getMatchPercent(product_id);
				}
			}
		};
		var params="product_id="+product_id;
		Tmp[product_id].open("POST","/store/?action=main.act_matchpercent",true);
		Tmp[product_id].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		Tmp[product_id].setRequestHeader("Content-length", params.length);
		Tmp[product_id].setRequestHeader("Connection", "close");
		Tmp[product_id].send(params);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function selectedFitting()   {
	document.getElementById('message_box_p').innerHTML = "Your profile has been updated with the selected fitting."
	document.getElementById('message_box').style.display = "block";
	messageFade("message_box");
	// document.getElementById('message_box').style.display = "none";
}



function displaySpecs(index)
{
	var arr=new Array();
	var divs=document.getElementById("specsDiv").getElementsByTagName("div");
	for(var x=0;x<divs.length;x++)
	{
		if(divs[x].className=="specs_div")
		{
			arr[arr.length]=divs[x];
		}
	}

	var as=document.getElementById("specs_header").getElementsByTagName("a");
	for(var x=0;x<arr.length;x++)
	{
		if(x==index)
		{
			arr[x].style.display="block";
			as[x].getElementsByTagName("img")[0].src=as[x].getElementsByTagName("img")[0].getAttribute("onsrc");
		}
		else
		{
			arr[x].style.display="none";
			as[x].getElementsByTagName("img")[0].src=as[x].getElementsByTagName("img")[0].getAttribute("offsrc");
		}


	}
}

function runAjaxCall(page,test)
{
	var ajaxObj;
	if(ajaxObj=getAjaxObj())
	{
		ajaxObj.onreadystatechange=function()
		{
			if (ajaxObj.readyState==4)
			{
				// 4 = "loaded"
				if (ajaxObj.status==200)
				{
					// 200 = OK
					if(ajaxObj.responseText!="")
					{
						if(test==1)
							alert(ajaxObj.responseText)
						else
							eval(ajaxObj.responseText)
					}
				}
				else
				{
					//alert("Problem getting XML data - runAjaxCall("+page+","+test+");");
					runAjaxCall(page,test);
				}
			}
		};
		ajaxObj.open("GET",page,true);
		ajaxObj.send(null);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function getAjaxObj()
{
	var xmlhttp=false;
	if(window.XMLHttpRequest)
	{
		// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

function resetFitting(fitting_id)   {
	if(xmlhttp_sf=getAjaxObj())
	{		
		xmlhttp_sf.onreadystatechange=function()
		{
			if (xmlhttp_sf.readyState==4)
			{
				// 4 = "loaded"
				
				if (xmlhttp_sf.status==200)
				{
					// 200 = OK
					eval(xmlhttp_sf.responseText);
				}
				else
				{					
					resetFitting(fitting_id);
				}
			}
		};
		var params="fitting_id="+fitting_id;
		xmlhttp_sf.open("POST","/store/?action=myaccount.act_fittingreset",true);
		xmlhttp_sf.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_sf.setRequestHeader("Content-length", params.length);
		xmlhttp_sf.setRequestHeader("Connection", "close");
		xmlhttp_sf.send(params);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}
