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;
}

var xmlHttpc
function RemoteRequestObject()
{
	var A = false;

	try
	{
		A = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			A = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(err)
		{
			A = false;
		}
	}

	if(!A && typeof(XMLHttpRequest) != 'undefined')
		A = new XMLHttpRequest();
	
	return A;
}

function createCookie(name,value,days)
{	
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function fnpopupwindow(url,width,height)
{
	window.open('?'+url,'IMAGE','left=250,top=150,width='+width+',height='+height+',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0');
}

function reload_cart(url)
{
	xmlHttpcart = GetXmlHttpObject()
	if(xmlHttpcart == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	var url = url+"?sessid="+Math.random();
	xmlHttpcart.onreadystatechange=showcart;
	xmlHttpcart.open("GET",url,true);
	xmlHttpcart.send(null);
}

function showcart()
{
	if(xmlHttpcart.readyState == 4 || xmlHttpcart.readyState == "complete")
    { 
		document.getElementById('CART').innerHTML = xmlHttpcart.responseText;
    } 
}

function setbackground(id)
{
	if(id == 'show')
	{
		var h = (screen.height + document.documentElement.scrollTop + document.body.scrollTop);
		document.getElementById('overDiv').style.display = '';
		document.getElementById('overDiv').style.height = h+'px';
	}
	else if(id == 'hide')
	{
		document.getElementById('overDiv').style.height = '0px';
		document.getElementById('overDiv').style.display = 'none';
	}	
}

function popup(url,width,height)
{			
	window.open(url,'mywindow', 'left=120,top=150,width='+width+',height='+height+',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0');
}

function cart(url, id)
{	
	xmlHttpcCart=RemoteRequestObject()
	if(xmlHttpcCart==null)
	{
		alert("Browser does not support HTTP Request")
		return;
	} 
	var url = url;
	
	var params = "id="+id+"&sku1="+document.getElementById('sku1'+id).value+"&sku2="+document.getElementById('sku2'+id).value+"&math="+Math.random();

	xmlHttpcCart.open("POST",url,true)
	xmlHttpcCart.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpcCart.setRequestHeader("Content-length", params.length);
	xmlHttpcCart.setRequestHeader("Connection", "close");
	
	xmlHttpcCart.onreadystatechange=function()
	{		 
		if(xmlHttpcCart.readyState==4 || xmlHttpcCart.readyState=="complete")
		{ 
			var t = setTimeout("tt_HideInit()",2000);
			var t = setTimeout("setbackground('hide')",2000);			
			Tip(xmlHttpcCart.responseText, WIDTH, 195, PADDING, 15, FIX, [(screen.width/2)-100, (document.documentElement.scrollTop + document.body.scrollTop)+250]);
			window.location.reload()
		} 		
	}

	xmlHttpcCart.send(params);
	return false;
}


function cart1(cType, id)
{	
	xmlHttpcCart=RemoteRequestObject()
	if(xmlHttpcCart==null)
	{
		alert("Browser does not support HTTP Request")
		return;
	} 

	if(cType == 'update')
	{
		var url = document.getElementById('update_url').value;
	}
	else
	{
		var url = document.getElementById('remove_url').value;
	}	
	
	var params ="id="+id+"&sku1="+document.getElementById('sku1'+id).value+"&sku2="+document.getElementById('sku2'+id).value+"&math="+Math.random();

	xmlHttpcCart.open("POST",url,true)
	xmlHttpcCart.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpcCart.setRequestHeader("Content-length", params.length);
	xmlHttpcCart.setRequestHeader("Connection", "close");
	
	xmlHttpcCart.onreadystatechange=function()
	{		 
		if(xmlHttpcCart.readyState==4 || xmlHttpcCart.readyState=="complete")
		{
			right_cart()			
			var t = setTimeout("tt_HideInit()",2000);
			var t = setTimeout("setbackground('hide')",2000);
			Tip(xmlHttpcCart.responseText, WIDTH, 200, PADDING, 15, FIX, [(screen.width/2)-100, (document.documentElement.scrollTop + document.body.scrollTop)+250]);
		} 		
	}

	xmlHttpcCart.send(params);
	return false;
}

function right_cart()
{
	xmlHttpright_cart = GetXmlHttpObject()
	if(xmlHttpright_cart == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	var pn = window.location.pathname.split( '/' );
	var url = window.location.protocol + '//' + window.location.host + '/cart/right_cart?sessid='+Math.random();
	
	xmlHttpright_cart.onreadystatechange=show_right_cart;
	xmlHttpright_cart.open("GET",url,true);
	xmlHttpright_cart.send(null);
}

function show_right_cart()
{
	if(xmlHttpright_cart.readyState == 4 || xmlHttpright_cart.readyState == "complete")
    { 
		document.getElementById('RIGHT_CART').innerHTML = xmlHttpright_cart.responseText;
		
		if(xmlHttpright_cart.responseText == '&nbsp;&nbsp;&nbsp;&nbsp;No items available in cart')
		{
			document.getElementById('DIVBUTTONS').style.display = 'none';
		}
		else
		{
			document.getElementById('DIVBUTTONS').style.display = '';
		}
    } 
}

