// JavaScript Document
function ajaxFunction(getVals, targetId)
{
	//alert("in");
	var browserType;
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{		
		if(xmlHttp.readyState==4 && targetId != "none")
		{
			if(targetId == "cart")
			{
				//window.location = "index.php?p=cart";
				//setTimeout("window.location.reload(true)", 30);
				window.location.reload(true);				
			}
			else
				document.getElementById(targetId).innerHTML = xmlHttp.responseText;	
		}
	}
	xmlHttp.open("GET", "functions/ajaxWork.php?"+getVals, true);
	xmlHttp.send(null);
}























function addToCart(id)

{	

	var qty = document.getElementById(id).value;



	if(qty != "" && qty != null && IsNumeric(qty))

	{		

		ajaxFunction("qty="+qty+"&id="+id, 'cart');

	}

	else

	{

		alert("Please enter a valid quantity!");	

		document.getElementById(id).value = "";

		document.getElementById(id).focus();

	}	

}















function updateCart(id)

{

	var qty = document.getElementById(id).value;

	//alert(id+" "+qty);

	if(qty == null || qty == "")

		qty = 0;

	if(IsNumeric(qty))

	{		

		ajaxFunction("qty="+qty+"&id="+id, "none");		

		return;

	}

	else

	{

		alert("Please enter a valid quantity!");

		document.getElementById(id).value = "";		

	}

}















function saveFreightRate(obj)







{







	var rate = obj.options[obj.selectedIndex].value;







	var loc = obj.options[obj.selectedIndex].innerHTML;







	if(rate != "none")







	{



		ajaxFunction("freight="+rate+"&loc="+loc, "showFreightRate");	





	}







	else







	{







		document.getElementById('showFreightRate').innerHTML = "";







		document.getElementById('showFreightLoc').innerHTML = "";







	}







	if(!IsNumeric(rate))







		rate = 0;







	//ajaxFunction("freight="+rate+"&location="+loc, "none");



	



	//setTimeout("window.location = 'index.php?p=cart'", 60);

	setTimeout("window.location.reload(true)", 60);







}































function IsNumeric(sText)







{	







	var ValidChars = "0123456789.";







	var IsNumber=true;







	var Char;







	for (i = 0; i < sText.length && IsNumber == true; i++) 







	{ 







		Char = sText.charAt(i); 







		if (ValidChars.indexOf(Char) == -1) 







		{







			IsNumber = false;







		}







	}







	return IsNumber;







}























function validateCart(type)







{







	var text;







	for(i=0; i<document.cartForm.elements.length; i++)







	{







		text = document.cartForm.elements[i].name;				







	}







	







	







	if(type == "out" && (document.getElementById('frl').value == "" || document.getElementById('fr').value == "" || document.getElementById('frl').value == "Select your region"))















	{















		alert("Please seletct your freight location!")















		return false;















	}















	return true;















}















function removeItem(id)







{







	document.getElementById(id).value = 0;







	updateCart(id);



	//setTimeout("window.location ='index.php?p=cart'", 50);

	setTimeout("window.location.reload(true)", 60);



}







function noVis(id){document.getElementById(id).style.visibility = 'hidden'}
function yesVis(id){document.getElementById(id).style.visibility = 'visible'}

function show(id){document.getElementById(id).style.display = 'block'}
function hide(id){document.getElementById(id).style.display = 'none'}

function toggleDisplay(id)
{
	var div = document.getElementById(id);
	if(div.style.display == "block")
		div.style.display = "none";
	else if(div.style.display == "none")
		div.style.display = "block";
}











