function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function listado_productos(valor){	   
	var d, div_listado_productos;	
	v = valor;
	div_listado_productos = document.getElementById('div_listado_productos');
	
	ajaxlp=nuevoAjax();	

    
	ajaxlp.open("GET", "listado_productos.php?v="+v+"&rand="+Math.random(),true);
	ajaxlp.onreadystatechange=function() {
		if (ajaxlp.readyState==4) {			
		div_listado_productos.innerHTML = ajaxlp.responseText
	 	}
	}
	ajaxlp.send(null)
}

function ValidaSus()
{        
   email = document.formsuscribete.email.value;
   if (email == "") { 
      alert("Falta especificar el email para suscripción");	  
   }else{	        	  
	   if (email.indexOf("@") == -1 || email.indexOf(".") == -1 || email.length < 6){
          alert("Introduce un email valido");
       }else{	  		  
          suscribete(document.formsuscribete.email.value);
	   }
   }
}
function suscribete(correo){	   
	var co, div_suscribete,respuesta;	
	co = correo;

	div_suscribete = document.getElementById('div_suscribete');
	
	ajaxsus=nuevoAjax();	
   
	ajaxsus.open("GET", "suscribete.php?c="+co+"&rand="+Math.random(),true);
	ajaxsus.onreadystatechange=function() {
		if (ajaxsus.readyState==4) {		
		   respuesta = ajaxsus.responseText;
		   
		   if (respuesta == 1){
			   document.formsuscribete.email.value = '';
		 	   alert('Suscripción realizada\nUn correo de confirmación ha sido enviado a tu cuenta de correo');   
		   }
		   if (respuesta == 2){
			   alert('Falta confirmar su suscripción, revisar su correo');
		   }
		   if (respuesta == 3){
			   document.formsuscribete.email.value = '';
			   alert('Ya esta suscrito');
		   }		   
		//div_suscribete.innerHTML = ajaxsus.responseText
	 	}
	}
	ajaxsus.send(null)
}

function menu_lineas(valor){
	var div_menu_lineas;	
	v = valor;
	div_menu_lineas = document.getElementById('div_menu_lineas');
	
	ajaxml=nuevoAjax();	

    
	ajaxml.open("GET", "menu_lineas.php?v="+v+"&rand="+Math.random(),true);
	ajaxml.onreadystatechange=function() {
		if (ajaxml.readyState==4) {			
		div_menu_lineas.innerHTML = ajaxml.responseText
	 	}
	}
	ajaxml.send(null)
}
function contenido_productos(idprod){	   
	var div_contenido_productos;	
	
	id = idprod;
	div_contenido_productos = document.getElementById('div_contenido_productos');
	
	ajaxcp=nuevoAjax();	

	ajaxcp.open("GET", "contenido_productos.php?id="+id+"&rand="+Math.random(),true);
	ajaxcp.onreadystatechange=function() {
		if (ajaxcp.readyState==4) {			
		div_contenido_productos.innerHTML = ajaxcp.responseText
	 	}
	}
	ajaxcp.send(null)
}

function ficha_prod(idprod){	   
	var div_ficha_prod;	
	id = idprod;
	div_ficha_prod = document.getElementById('div_ficha_prod');
	
	ajaxfp=nuevoAjax();	

    
	ajaxfp.open("GET", "ficha_prod.php?id="+id+"&rand="+Math.random(),true);
	ajaxfp.onreadystatechange=function() {
		if (ajaxfp.readyState==4) {			
		div_ficha_prod.innerHTML = ajaxfp.responseText
	 	}
	}
	ajaxfp.send(null)
}

function llamado(tipopag,idprod){	   
	var tp,li,id;	
	tp = tipopag;	
	id = idprod;
	if (tp == 0){
	   window.location="productos.php?id="+id;
	}else{
	   contenido_productos(id);
	   ficha_prod(id);  	   
	}
}
function serv_mantto(){	
	var div_servicios;	
	
	div_servicios = document.getElementById('div_servicios');
	
	ajaxsm=nuevoAjax();	

    
	ajaxsm.open("GET", "serv_mantto.php?rand="+Math.random(),true);
	ajaxsm.onreadystatechange=function() {
		if (ajaxsm.readyState==4) {			
		div_servicios.innerHTML = ajaxsm.responseText
	 	}
	}
	ajaxsm.send(null)
}
function serv_vtaref(){	
	var div_servicios;	
	
	div_servicios = document.getElementById('div_servicios');
	
	ajaxsvr=nuevoAjax();	

    
	ajaxsvr.open("GET", "serv_vtaref.php?rand="+Math.random(),true);
	ajaxsvr.onreadystatechange=function() {
		if (ajaxsvr.readyState==4) {			
		div_servicios.innerHTML = ajaxsvr.responseText
	 	}
	}
	ajaxsvr.send(null)
}
function serv_vtains(){	
	var div_servicios;	
	
	div_servicios = document.getElementById('div_servicios');
	
	ajaxsvi=nuevoAjax();	

    
	ajaxsvi.open("GET", "serv_vtains.php?rand="+Math.random(),true);
	ajaxsvi.onreadystatechange=function() {
		if (ajaxsvi.readyState==4) {			
		div_servicios.innerHTML = ajaxsvi.responseText
	 	}
	}
	ajaxsvi.send(null)
}

function saeco_mex(){	
	var div_saeco;	
	
	div_saeco = document.getElementById('div_saeco');
	
	ajaxsaeco=nuevoAjax();	

    
	ajaxsaeco.open("GET", "saeco_mex.php?rand="+Math.random(),true);
	ajaxsaeco.onreadystatechange=function() {
		if (ajaxsaeco.readyState==4) {			
		div_saeco.innerHTML = ajaxsaeco.responseText
	 	}
	}
	ajaxsaeco.send(null)
}

function saeco_inter(){	
	var div_saeco;	
	
	div_saeco = document.getElementById('div_saeco');
	
	ajaxsaecoint=nuevoAjax();	

    
	ajaxsaecoint.open("GET", "saeco_inter.php?rand="+Math.random(),true);
	ajaxsaecoint.onreadystatechange=function() {
		if (ajaxsaecoint.readyState==4) {			
		div_saeco.innerHTML = ajaxsaecoint.responseText
	 	}
	}
	ajaxsaecoint.send(null)
}


function contacto(id){	
	var div_contacto;
	var opcion;

	opcion = id;
	div_contacto = document.getElementById('div_contacto');
	
	ajaxcont=nuevoAjax();	

    if (opcion == 1){
	   ajaxcont.open("GET", "contacto_con.php?rand="+Math.random(),true);
	}else{
	   ajaxcont.open("GET", "contacto_dis.php?rand="+Math.random(),true);	
	}
	ajaxcont.onreadystatechange=function() {
		if (ajaxcont.readyState==4) {			
		div_contacto.innerHTML = ajaxcont.responseText
	 	}
	}
	ajaxcont.send(null)
}

function envia_a_productos(idprod){	   
	var id,valor,longitud,linea;		
	id = idprod;	
	valor = parseInt(id);
	//validamos si es un numero
	if (isNaN(valor)) {
            //entonces (no es numero) devuelvo el valor cadena vacia
            longitud = id.length;			
			linea = id.substring(2,1);
			if (linea == 1){
			   window.location="vending/vending.php";	
			}
			if (linea == 2){
			       window.location="profesional/profesional.php";	
				}
			if (linea == 3){	
					window.location="hotfood.html";
				}
     }else{
            window.location="productos.php?id="+id;
     } 		
}

function envia_a_productos2(idprod){	   
	var id,valor,longitud,linea;		
	id = idprod;	
	valor = parseInt(id);
	//validamos si es un numero
	if (isNaN(valor)) {
            //entonces (no es numero) devuelvo el valor cadena vacia
            longitud = id.length;			
			linea = id.substring(2,1);
			if (linea == 1){
			   window.location="../vending/vending.php";	
			}else{
		       if (linea == 2){
			      window.location="../profesional/profesional.php";	
			   }else{
				   window.location="../hotfood.html";
			   }
			}			

     }else{
            window.location="../productos.php?id="+id;
     } 		
}



function ValidaDis()
{        
   envia = "Si";
   if (document.formdistri.nombre.value == ""){
	   alert("Falta especificar el nombre")
	   envia = "No";
   }
	email = document.formdistri.correo.value;
   	if (email == "") { 
      	alert("Falta especificar el correo");	  
		envia = "No";
   	}else{	        	  
	   	if (email.indexOf("@") == -1 || email.indexOf(".") == -1 || email.length < 6){
        	alert("Introduce un correo valido");
			envia = "No";
		}
	}
	if (document.formdistri.lada.value == ""){
		alert("Falta especificar la lada")
		envia = "No";
	}		   		
	if (document.formdistri.telefono.value == ""){
		alert("Falta especificar el teléfono")
		envia = "No";
	}
	if (document.formdistri.mensaje.value == ""){
		alert("Falta especificar el mensaje")
		envia = "No";
	}
   if (envia == "Si"){
	    document.formdistri.action = 'envia_distribuidores.php'
		document.formdistri.submit()
   }
}
