var xmlhttp;

var yScroll = 0;

function Add2Cart(item,qty,desc){
	xmlhttp=GetXmlHttpObject();
	
	if(desc == undefined){desc = "";}
	
	if (xmlhttp==null){
		//document.getElementById("ptResults").style.display = "block";
		//document.getElementById("ptResults").innerHTML="Your browser does not support XMLHTTP!";
		return;
	}
	
	//Pulse("A2C:"+qty+","+item);
	
	var url="/include/AJAX/add2cart.php";
	url=url+"?itm="+item;
	url=url+"&qty="+qty;
	url=url+"&desc="+desc;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=Add2Cart_SC;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	
	
}

function Add2Cart_SC(){
	if (xmlhttp.readyState==4){
		lb = document.getElementById('light');
		lb.innerHTML=xmlhttp.responseText;
		
		LightBox(true);
	}
}

function GetXmlHttpObject(){
	if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	
	if (window.ActiveXObject){ // code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return null;
}

function LBMove(){
	lb = document.getElementById('light');
	fb = document.getElementById('fade');
	
	lb.style.top = ((fb.offsetHeight/2)-(lb.offsetHeight/2) + yScroll);
	lb.style.left = ((fb.offsetWidth/2)-(lb.offsetWidth/2));
}

function LightBox(on){
	lb = document.getElementById('light');
	fb = document.getElementById('fade');
	
	if(on){
		document.body.style.overflow = 'hidden';
		lb.style.display='block';
		fb.style.display='block';
		
		// --------------
		if (self.pageYOffset){
			yScroll = self.pageYOffset;
		}else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop; 
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}
		
		fb.style.top = yScroll;
		LBMove();
		// --------------
		
	}else{
		lb.style.display='none';
		fb.style.display='none';
		document.body.style.overflow = 'auto';
		window.scrollTo(0, yScroll);
	}
	
}