
var url = "/includes/add_to_cart.php?"; // The server-side script
var url2 = "/includes/ajax.php?"; // The server-side script

function handleHttpResponse() {
  if (http.readyState == 4) {	
    if(http.status == 200) {
    	//hideProgress('AjaxProgressIndicator');
    	setTimeout("hideProgress('AjaxProgressIndicator')", 2000);
		document.getElementById("mini_cart").innerHTML = http.responseText;
    }
  }	
}

function handleHttpResponse2() {
  if (http.readyState == 4) {	
    if(http.status == 200) {
    	//setTimeout("hideProgress('AjaxProgressIndicator')", 500);
    	//alert(http.responseText);
    }
  }	
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

var http = getHTTPObject();

function showProgress(name) {
	
	var a = document.getElementById(name);	
	
	if (a != null) {
		a.style.top = document.documentElement.scrollTop + 2 + "px";
		a.style.display = "";  
	} else {
	    a = document.createElement("div");
	    a.id = name;    
	    a.innerHTML = "<img style='vertical-align:bottom' src='/templates/01/images/indicator.gif'>&nbsp;please wait...";
	    document.body.appendChild(a);
	}
}

function hideProgress(name) {
   a = document.getElementById(name);
   a.style.display="none";
}

function addToCart(product_id,item_url,item_title,array_product) {
	showProgress('AjaxProgressIndicator');
	var quantite1 = document.getElementById('quantite['+product_id+']');
	if( quantite1.value == 0 ) {
		document.getElementById('quantite['+product_id+']').value = 1;
	}
	
	http.open("GET", url + 'action=shopping_cart&product_id='+product_id+'&item_url='+item_url+'&quantite='+quantite1.value+'', true);
	http.onreadystatechange = handleHttpResponse; http.send(null);
}

function updateNo(article_id, action){
	//showProgress('AjaxProgressIndicator');
	var no = document.getElementById('no['+article_id+']');
	
	http.open("GET", url2 + 'action='+action+'&article_id='+article_id+'&no='+no.value+'', true);
	http.onreadystatechange = handleHttpResponse2; http.send(null);	
}

function updateCat(cat_id, action){
	//showProgress('AjaxProgressIndicator');
	var sel = document.getElementById(action);
	val =  sel.options[sel.selectedIndex].value;
	if(val == '')
		val = 0;
	
	http.open("GET", url2 + 'action='+action+'&cat_id='+cat_id+'&value='+val+'', true);
	http.onreadystatechange = handleHttpResponse2; http.send(null);
}