var xmlhttp=false;
var xmlhttp1=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.

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

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

@end @*/

//xml 0
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

//xml 1
if (!xmlhttp1 && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp1 = new XMLHttpRequest();
	} catch (e) {
		xmlhttp1=false;
	}
}
if (!xmlhttp1 && window.createRequest) {
	try {
		xmlhttp1 = window.createRequest();
	} catch (e) {
		xmlhttp1=false;
	}
}

function sendReceiveCartStatus(cId, sesid) {
  if (xmlhttp) {
		xmlhttp.open("GET", "/cart_check.php?cid="+cId+"&PHPSESSID=" + sesid,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
			  returectBrowser(xmlhttp.responseText);
			}
		}
		xmlhttp.send(null);
	}
	return 0;
}
function getLastCID(cId, sesid) {
  if (xmlhttp) {
		xmlhttp.open("GET", "/cart_check.php?getCid=1&PHPSESSID=" + sesid,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {

        var lastCID = '&hrdsw=1';

			  if (xmlhttp.responseText > 0) {
          lastCID = '&cvid=' + xmlhttp.responseText;
				}

        var cartLinks=document.getElementsByName("cartLink");

        if (cartLinks) {
					for (var n=0; n<cartLinks.length; n++) {
		        cartLinks[n].href = cartLinks[n].href + '' + lastCID;
					}
				}

			}
		}
		xmlhttp.send(null);
	}
	return 0;
}

function sendReceivePageStatus(cId, dbl, sesid) {
  if (xmlhttp1) {
		xmlhttp1.open("GET", "/cart_check.php?notcart=1&cid="+cId+"&PHPSESSID=" + sesid,true);
		xmlhttp1.onreadystatechange=function() {
			if (xmlhttp1.readyState==4) {
				if (dbl == 1) {
        	returectBrowser(xmlhttp1.responseText, dbl);
				}
				else {
         	document.getElementById("mainBodyContent").style.display="block";
				}

			}
		}
		xmlhttp1.send(null)
	}
	return 0;
}

function receiveCart(params) {
  if (xmlhttp1) {
		xmlhttp1.open("GET", "/" + params + "&get_cart=1",true);
		xmlhttp1.onreadystatechange=function() {
			if (xmlhttp1.readyState==4) {
				if (document.getElementById('cartFrom')) {
        	document.getElementById('cartFrom').innerHTML = xmlhttp1.responseText;
				}
			}
		}
		xmlhttp1.send(null)
	}
	setTimeout("receiveSmallCartFromCart('"+params+"')", 100);
}

function receiveSmallCart(params) {
	xmlhttp1.open("GET", "/" + params + "",true);
	xmlhttp1.onreadystatechange=function() {
		if (xmlhttp1.readyState==4) {
			if (document.getElementById('basketContents')) {
        document.getElementById('basketContents').innerHTML = xmlhttp1.responseText;
			}
		}
	}
	xmlhttp1.send(null)
}
function receiveSmallCartFromCart(params) {
  if (xmlhttp1 && xmlhttp1.readyState==4) {
		xmlhttp1.open("GET", "/" + params + "&get_small_cart=1",true);
		xmlhttp1.onreadystatechange=function() {
			if (xmlhttp1.readyState==4) {
				if (document.getElementById('basketContents')) {
        	document.getElementById('basketContents').innerHTML = xmlhttp1.responseText;
				}
			}
		}
		xmlhttp1.send(null)
	}
	else {
		setTimeout("receiveSmallCartFromCart('"+params+"')", 100);
	}
}

function returectBrowser (direction, dbl) {

			  if (direction == 1) {
         	window.history.back();
				}
				else {
				  if (direction == 2) {
        		window.history.forward();
            setTimeout("document.getElementById('mainBodyContent').style.display='block'", 500);
					}
					else {
						document.getElementById("mainBodyContent").style.display="block";
					}
				}
}
