

var http = crearAjax();
var http2 = crearAjax();
var http3 = crearAjax();
var http4 = crearAjax();

function crearAjax(){
	var xmlhttp=false;
 	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e){
		try {
	   		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  	}catch (E){
	   		xmlhttp = false;
	  	}
 	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined'){
  		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}	

	
function ajaxProductos(id,tipo,txt){
	
	//ajaxMigasdepan(id,tipo,txt);
	
	//alert(id,tipo,txt);
    http.open("GET", "ajaxProductos.php?id="+id+"&tipo="+tipo, true);
	http.onreadystatechange=function() 
	{
		if (http.readyState == 4){
			results1 = unescape(http.responseText);
			results = results1.replace(/\+/gi," ");
			document.getElementById('contCentro').innerHTML = results;
		}
		if (http.readyState == 1){
			document.getElementById('contCentro').innerHTML = "<span class='bodegaProducto'> Cargando datos...</span>";
		}		
	}
    http.send(null);	
}	

function ajaxProductosPag(id,tipo,txt,ir){
	
	//ajaxMigasdepan(id,tipo,txt);
	
	//alert(id,tipo,txt);
    http.open("GET", "ajaxProductos.php?id="+id+"&tipo="+tipo+"&IR="+ir, true);
	http.onreadystatechange=function() 
	{
		if (http.readyState == 4){
			results1 = unescape(http.responseText);
			results = results1.replace(/\+/gi," ");
			document.getElementById('contCentro').innerHTML = results;
		}
		if (http.readyState == 1){
			document.getElementById('contCentro').innerHTML = "<span class='bodegaProducto'> Cargando datos...</span>";
		}		
	}
    http.send(null);	
}	

//temporalmente no usamos esta funcion
function ajaxMigasdepan(id,tipo,txt){
	//alert("migas");
    http2.open("GET", "ajaxMigasdepan.php?id="+id+"&tipo="+tipo+"&txt="+txt, true);
	http2.onreadystatechange=function() 
	{
		if (http2.readyState == 4){
			results1b = unescape(http2.responseText);
			resultsb = results1b.replace(/\+/gi," ");
			document.getElementById('barraCabecera').innerHTML = resultsb;
		}
/*
		if (http.readyState == 1){
			document.getElementById('barraCabecera').innerHTML = "<span class='bodegaProducto'> Cargando datos...</span>";
		}
*/		
	}
    http2.send(null);
}	

function ajaxCesta(id,accion){

	//alert(id);
	//si la accion es Borrar, no pasamos la cantidad (solo para agregar al carrito)
	if(accion=='borrar'){
    	http3.open("GET", "ajaxCesta.php?id="+id+"&accion="+accion, true);
	}else{
		total =  document.getElementById('txtCantidad'+id).value;
		http3.open("GET", "ajaxCesta.php?id="+id+"&accion="+accion+"&catidad="+total, true);
	}
	http3.onreadystatechange=function() 
	{
		if (http3.readyState == 4){
			results1 = unescape(http3.responseText);
			results = results1.replace(/\+/gi," ");
			document.getElementById('contCesta').innerHTML = results;
			
			//ajaxRealizarpedido();	
		}
		if (http3.readyState == 1){
			document.getElementById('contCesta').innerHTML = "<span class='compraCesta'> Cargando...</span>";
		}		
	}
    http3.send(null);
	
	
}	

function ajaxBuscadorBodegas(id){

	//alert(id);
    http2.open("GET", "ajaxBuscadorBodegas.php?id="+id, true);
	http2.onreadystatechange=function() 
	{
		if (http2.readyState == 4){
			results1 = unescape(http2.responseText);
			results = results1.replace(/\+/gi," ");
			document.getElementById('bodegasBuscador').innerHTML = results;
		}
		if (http2.readyState == 1){
			document.getElementById('bodegasBuscador').innerHTML = "<span class='compraCesta'>   Cargando...</span>";
		}		
	}
    http2.send(null);	
}	
function ajaxResultados(denominacion,bodega,color,precio,variedad,anada,ir){

	//alert(denominacion+" "+bodega+" "+color+" "+precio+" "+variedad+" "+anada+" "+ir);
    http.open("GET", "ajaxResultados.php?denominacion="+denominacion+"&bodega="+bodega+"&color="+color+"&precio="+precio+"&variedad="+variedad+"&anada"+"&IR="+ir, true);
	http.onreadystatechange=function() 
	{
		if (http.readyState == 4){
			results1 = unescape(http.responseText);
			results = results1.replace(/\+/gi," ");
			document.getElementById('contCentro').innerHTML = results;
		}
		if (http.readyState == 1){
			document.getElementById('contCentro').innerHTML = "<span class='compraCesta'> Cargando...</span>";
		}		
	}
    http.send(null);	
}

function ajaxBuscadorEnologia(id){
	//alert(id);
    http4.open("GET", "ajaxBuscadorEnologia.php?id="+id+"&tipo=2", true);
	http4.onreadystatechange=function() 
	{
		if (http4.readyState == 4){
			results1 = unescape(http4.responseText);
			results = results1.replace(/\+/gi," ");
			document.getElementById('cuerpoEnologia').innerHTML = results;
		}
		if (http4.readyState == 1){
			document.getElementById('cuerpoEnologia').innerHTML = "<span class='compraCesta'>   Cargando...</span>";
		}		
	}
    http4.send(null);	
}	