var req;
var loadingImage = new Image();
loadingImage.src = "images/loadingAnimation.gif";

function showLoading() {
	  var imgLoading = document.getElementById("_loading_");
	  if(!imgLoading) {
		imgLoading = document.createElement("img");
		with(imgLoading) {
		  id = "_loading_";
		  style.position = "absolute";
		  style.visibility = "hidden";
		}
		document.body.appendChild(imgLoading);
	  }
	  with(imgLoading) {
		src = loadingImage.src;
		style.left = "380px";
		style.top = "350px";
		style.visibility = "visible";
	} 
}
function ChgCategories(cId, pId, osc) {
	if(osc){
		osId = '&osCsid='+osc;
	}else{
		osId = '';
	}
	showLoading();
	if(pId){
		var url = "categories_display.php?cPath="+cId+"&action=buy_now_product&products_id="+pId+osId;
	}else{
		var url = "categories_display.php?cPath="+cId+osId;
	}
	// Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
}

function acclog(osc) {
	if(osc){
		osId = 'osCsid='+osc;
	}else{
		osId = '';
	}
	showLoading();
	var url = "log.php?"+osId;
		// Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
}

function shop(osc) {
	if(osc){
		osId = 'osCsid='+osc;
	}else{
		osId = '';
	}
	showLoading();
	var url = "shop_cart.php?"+osId;
		// Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
}

function cart_update(r, osc, pId, qty){
	if(osc){
		osId = '&osCsid='+osc;
	}else{
		osId = '';
	}
	showLoading();
	if(r == 'remove'){
		var url = "shop_cart.php?action=remove_item&products_id="+pId+osId;
	}else{
		var url = "shop_cart.php?action=update_qty&products_id="+pId+"&cart_quantity="+qty+osId;
	}
		// Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
}

function seach(key, osc){
	if(osc){
		osId = '&osCsid='+osc;
	}else{
		osId = '';
	}
	showLoading();
    var url = "search_result.php?key="+key+osId;
	// Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
}

function processChange() {
   // The page has loaded and the HTTP status code is 200 OK
   if (req.readyState == 4 && req.status == 200) {
      // Write the contents of this URL to the searchResult layer
	    getObject("catChange").innerHTML = req.responseText;
		hide();
   }
}

function hide() {
	  var imgLoading = document.getElementById("_loading_");
	  if(!imgLoading) {
		imgLoading = document.createElement("img");
		with(imgLoading) {
		  id = "_loading_";
		  style.position = "absolute";
		  style.visibility = "hidden";
		}
	  }
	  with(imgLoading) {
		src = loadingImage.src;
		style.visibility = "hidden";
	} 
}

function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}

