function addToCart(event, id){
   var url = "/ajax/addtocart.asp?itemversionid=" + id + "&amount=" + document.getElementById("amount_" + id).value;
   sendRequestToDiv(url, "leftColCart");
   if(getCookie('showCartPop') != 'No'){
      showCartPop(event);
   }
}

function addToResellerCart(event, id){
   if(!(isNaN(document.getElementById("amount_" + id).value))){
      var url = "/ajax/addtocart.asp?itemversionid=" + id + "&amount=" + document.getElementById("amount_" + id).value;
      sendRequestToDiv(url, "leftColCart");
      if(getCookie('showCartPop') != 'No'){
         showCartPop(event);
      }
   }
}


function setCookie(c_name,value,expiredays)
{
   var exdate=new Date();
   exdate.setDate(exdate.getDate()+expiredays);
   
   document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function showNoCart(){
   if(document.getElementById("showNoCartPop").checked){
      setCookie('showCartPop', 'No', null);
   }
   else{
      setCookie('showCartPop', 'Yes', null);
   }
}


function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset:ISO-8859-1');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

function sendRequestToDiv(url,divName, postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset:ISO-8859-1');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		
                if (req.status == 200){
                   var myDiv = document.getElementById(divName);
                   myDiv.innerHTML = req.responseText;
                }
	}
	if (req.readyState == 4) return;
	req.send(postData);
}


var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}
