// JavaScript Document
var xmlHttp
var xmlHttp2
//alert ("loded captain");
function showCart()
{ 
	if (document.getElementById("cartpop").innerHTML == "") {	
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			{
			alert ("Your browser does not support AJAX!");
			return;
			} 
		var url="/inc/cartpopup.php";
		//url=url+"&sid="+Math.random();
		//alert(url);
		xmlHttp.onreadystatechange=function()
					{
					if(xmlHttp.readyState==4)
						{
						document.getElementById("cartpop").innerHTML=xmlHttp.responseText;
						document.getElementById("cartpop").style.display="block";
/*						x = document.getElementById("cart").style.posTop + 15;
						y = document.getElementById("cart").style.posLeft + 30;
						document.getElementById("mypopup").style.top = x + "px";
						document.getElementById("mypopup").style.left = y + "px";*/
						}
					}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} else {
		document.getElementById("cartpop").innerHTML = "";
		document.getElementById("cartpop").style.display="none";
	}
}

function addToCart(id)
{ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			{
			alert ("Your browser does not support AJAX!");
			return;
			} 
		var url="/inc/cartpopup.php?action=add&tour_id="+id;
		xmlHttp.onreadystatechange=function()
					{
					if(xmlHttp.readyState==4)
						{
						document.getElementById("cartpop").innerHTML=xmlHttp.responseText;
						document.getElementById("cartpop").style.display="block";
						refreshCartCount();
						}
					}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	return false;
}

function refreshCartCount () {
		xmlHttp=GetXmlHttpObject();
		
		if (xmlHttp==null)
			{
			alert ("Your browser does not support AJAX!");
			return;
			} 
		xmlHttp.onreadystatechange=function()
					{
					if(xmlHttp.readyState==4)
						{
/*							var tempinner;
							tempinner = xmlHttp.responseText;
							tempinner = tempinner.replace(/<div class="cart" id="cart">/gi, "");
							tempinner = tempinner.replace("</a></div>", "</a>");
							tempinner = tempinner.replace(")</div>", ")");
							tempinner = tempinner.replace("<div id=\"cartpop\" class=\"cartpopup\"></div>", "");
							document.getElementById("cart").innerHTML = tempinner;*/
							document.getElementById("cart").innerHTML=xmlHttp.responseText;							
						}
					}
		xmlHttp.open("GET","/inc/cartcount.php",true);
		xmlHttp.send(null);
}

function removeFromCart(id)
{ 
	if (confirm("Are you sure you want to delete this item from you shopping cart?")){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			{
			alert ("Your browser does not support AJAX!");
			return;
			} 
		var url="/inc/cartpopup.php?action=delete&tour_id="+id;
		xmlHttp.onreadystatechange=function()
					{
					if(xmlHttp.readyState==4)
						{
						document.getElementById("cartpop").innerHTML=xmlHttp.responseText;
						document.getElementById("cartpop").style.display="block";
						refreshCartCount();
						}
					}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		return true;
	} else {
		return false;
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}