function createXMLHttpRequest() {
		try{ return new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){}
		try{ return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){}
		try{ return new XMLHttpRequest(); }catch(e){}
		alert("XMLHttpRequest not supported");
		return null;
}

var timer;

function updateShoppingCart( post_data ) {
	var url = 'shopping_cart.php?action=update_product&ajax_request=true';
	
	var form = document.getElementById( 'cart_quantity' );
	var fe = form.elements;
	
	for(var i=0 ; i<fe.length ; i++) {
		if ( fe[i].type=="radio" || fe[i].type=="checkbox" ) {
			if ( fe[i].checked ) post_data += '&'+ fe[i].name +'='+ fe[i].value;
		} else {
			post_data += '&'+ fe[i].name +'='+ fe[i].value;
		}
	}
	
	var xhReq = createXMLHttpRequest();
	xhReq.open("post",url,true);
	xhReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhReq.onreadystatechange = function do_readyStateChange() {
		if (xhReq.readyState == 4) {
			document.getElementById('shoppingCart').innerHTML = xhReq.responseText;
			
			updateRightShoppingCart();
		}
	}
	xhReq.send(post_data);
}

function confirmDeleteProduct( id ) {
	if ( confirm( '¿Estás seguro de que deseas eliminar este producto?') )
	{
		updateShoppingCart( '&cart_delete[]='+ id );
	}
}

function updateRightShoppingCart() {
	var url = 'ajax_shopping_cart.php?no_subsys=true';
	
	var xhReq = createXMLHttpRequest();
	xhReq.open("get",url,true);
	xhReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhReq.onreadystatechange = function do_readyStateChange() {
		if (xhReq.readyState == 4) {
			document.getElementById('divShoppingCard').innerHTML = '<table width="100%">'+ xhReq.responseText +'</table>'
		}
	}
	xhReq.send();
}

function doAfterClick() {
	if ( timer != undefined || timer != null )
	{
		window.clearTimeout( timer );
	}
	
	timer = window.setTimeout( 'afterClickUpdate()' , 700 );
}

function afterClickUpdate() {
	updateShoppingCart();
}