function crear_xmlHttp(){
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Tu navegador no soporta AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}
function leer_categoria_ajax(num_cat,cPath)
{
	_xmlHttp = crear_xmlHttp();
	_xmlHttp.onreadystatechange=function()
	{
		if(_xmlHttp.readyState==4)
		{
			/*if (num_cat<2){
				document.getElementById('cat2').innerHTML = document.getElementById('cat3').innerHTML = "";
			} */
			document.getElementById('cat'+num_cat).innerHTML = _xmlHttp.responseText;
		}
	}
	if (document.getElementById('cat'+(num_cat))){
		document.getElementById('cat'+(num_cat)).innerHTML = '<img src="images/ajax-loader.gif">';
	}
	_xmlHttp.open("GET","ver_categoria.php?cPath="+escape(cPath)+"&num_cat="+num_cat,true);
	_xmlHttp.send(null);
}

function compra_ajax(){
	var productos = ""; //separados por comas
	var cantidades= ""; //separadas por comas
	_xmlHttp = crear_xmlHttp();
	_xmlHttp.onreadystatechange=function()
	{
		if(_xmlHttp.readyState==4)
		{
			document.getElementById('resultado_compra').innerHTML = _xmlHttp.responseText;
			document.getElementById('el_carrito').innerHTML = '<img src="images/ajax-loader.gif">';
			actualizar_carro();
		}
	}
	//Construir las opciones de la compra
	var f = document.contenidoBusqueda;
	//Respuesta:
	//foreach form.elements
	for (i=0; i<f.elements.length; i++) {  //Recorre el formulario recogiendo todas las cantidades y su identificador
		//...
		if (f[i].name.substr(0,9)=="cantidad_"){
			n = f[i].name.split("_");
			productos  += n[1]+",";
			cantidades += f[i].value+",";  //cantidad
			
			//new 15may2008
			f[i].value=0;
		}

	}
	document.getElementById('resultado_compra').innerHTML = '<img src="images/ajax-loader.gif">';
	_xmlHttp.open("GET","compra_ajax.php?productos="+escape(productos)+"&cantidades="+escape(cantidades),true);
	_xmlHttp.send(null);
}

function actualizar_carro(){
	_xmlHttp = crear_xmlHttp();
	_xmlHttp.onreadystatechange=function()
	{
		if(_xmlHttp.readyState==4)
		{
			document.getElementById('el_carrito').innerHTML = _xmlHttp.responseText;
		}
	}
	_xmlHttp.open("GET","ver_carrito.php",true);
	_xmlHttp.send(null);
}
var win = null;
function PopUp(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}