function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}


function updateSideCart(){

	var xmlHttp = GetXmlHttpObject();
	
    var params = "";
    xmlHttp.open("POST", "/browse/cart/action/updateSideCart/", true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
	  xmlHttp.onreadystatechange = function() { 
 	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var response = new String(xmlHttp.responseText);
			document.getElementById('sideCart').innerHTML = response;
		  
        }
	}
	xmlHttp.send(params);
}

function updateProducQuantytInCart(idop, idproduct){

	var xmlHttp = GetXmlHttpObject();
	quanty = document.getElementById('opQuanty_' + idproduct).value;
    var params = "idop=" + idop + "&quanty=" + quanty;
    xmlHttp.open("POST", "/browse/cart/action/updateProductQuanty/", true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
	  xmlHttp.onreadystatechange = function() { 
 	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var response = new String(xmlHttp.responseText);
			document.getElementById(idproduct).innerHTML = response;
		  
        }
	}
	xmlHttp.send(params);
}

function addToCart(idproduct, idprice){

	var xmlHttp = GetXmlHttpObject();
    var params = "idproduct=" + idproduct + "&idprice=" + idprice;
    xmlHttp.open("POST", "/browse/cart/action/add/", true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
	  xmlHttp.onreadystatechange = function() { 
 	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var response = new String(xmlHttp.responseText);
			document.getElementById(idproduct).innerHTML = response;
		  
        }
	}
	xmlHttp.send(params);
}

function jUpdate(idproduct, idprice, price, money, cntid){

	var xmlHttp = GetXmlHttpObject();
    var params = "idproduct=" + idproduct + "&idprice=" + idprice + "&split=1";
    xmlHttp.open("POST", "/browse/cart/action/add/", true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
	  xmlHttp.onreadystatechange = function() { 
 	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var response = new String(xmlHttp.responseText);
			//document.getElementById(idproduct).innerHTML = response;		  
			var containertxt = response.split("|");

			var cnt = document.getElementById(cntid).value;
			var idop = containertxt[0];
			var idorder = containertxt[1];
			var inner = document.getElementById(idproduct);
	
			if(cnt > 1){
		
				changeProductCount(idop, idorder, cnt);
		
				for(i=1; i<=cnt; i++){
					updateSidebarCart('1', price, money);
				}
		
			} else {
				updateSidebarCart('1', price, money);
			}
	
			inner.innerHTML = '<a href="/browse/cart/"><img src="/htdocs/images/default/cart_added.jpg" style="border: none;"></a>&nbsp;&nbsp;';			
        }
	}
	xmlHttp.send(params);
}

function addToCart1(idproduct, idprice, divname, cart_lang){

	var xmlHttp = GetXmlHttpObject();
    var params = "idproduct=" + idproduct + "&idprice=" + idprice;
    xmlHttp.open("POST", "/browse/cart/action/add/", true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
	  xmlHttp.onreadystatechange = function() { 
 	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var response = new String(xmlHttp.responseText);
			document.getElementById(divname+"_"+idproduct).innerHTML = "<a href='/browse/cart'>"+cart_lang+"</a>";
		  
        }
	}
	xmlHttp.send(params);
}

function changeProductCount(idop, idorder, count){ 

	var xmlHttp = GetXmlHttpObject();
    var params = "idop=" + idop + "&idorder=" + idorder +"&count=" + count;
    xmlHttp.open("POST", "/browse/cart/action/count/", true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
	  xmlHttp.onreadystatechange = function() { 
 	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var response = new String(xmlHttp.responseText);
			document.getElementById("all_price").innerHTML = response;
        }
	}
	xmlHttp.send(params);
}

function changeMark(mark){ 

	var xmlHttp = GetXmlHttpObject();
    var params = "mark=" + mark;
    xmlHttp.open("POST", "/browse/mark/name/"+mark, true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
	  xmlHttp.onreadystatechange = function() { 
 	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var response = new String(xmlHttp.responseText);
			document.getElementById("mark").innerHTML = response;
        }
	}
	xmlHttp.send(params);
}


function updateSidebarCart(addtotal, addprice, money_format){

	var total = document.getElementById('cart_total_input').value;
	var price = document.getElementById('cart_sum_input').value;
	var total_inner = document.getElementById('cart_total');
	var price_inner = document.getElementById('cart_sum');
	var newtotal;
	var newprice;
	
	newtotal = Number(total)+Number(addtotal);
	newprice = Number(price)+Number(addprice);
	newprice = Math.round(newprice*100) / 100;
	
	total_inner.innerHTML = '<input type="hidden" id="cart_total_input" name="cart_total_input" value="'+newtotal+'">'+newtotal+'';
	price_inner.innerHTML = '<input type="hidden" id="cart_sum_input" name="cart_sum_input" value="'+newprice+'">'+newprice+' '+money_format+'';
	
}

function emp(id){
	var val = document.getElementById(id).value;
	var bval = document.getElementById('b'+id).value;
	
	document.getElementById('b'+id).value = val;
	document.getElementById(id).value = '';
}

function re(id){
	
	var val = document.getElementById(id).value;
	var bval = document.getElementById('b'+id).value;
	
	if(val == '' || val == '0')
		document.getElementById(id).value = bval;
}