function nuevoAjax(){
	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 Mostrarpagina2(pagina,variable,datos){
	mivariable=variable;
	divResultado1 = document.getElementById('resultado');
	ajax=nuevoAjax();
	ajax.open("POST", datos,true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado1.innerHTML = ajax.responseText
			}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("contenido="+mivariable+"&pagina="+pagina)
}

function mostrarDetalleFamilia(familia){
       ajax=nuevoAjax();
       Y.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "detalle_familia.php?id_familia=" +familia,true);
	   //Y.innerHTML ='';
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   Y.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send(null)
}




function cambia(id){
       ajax=nuevoAjax();
       P.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "cambia.php?id="+id,true);
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   P.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send(null)
}


/*function carro(){
       ajax=nuevoAjax();
       X.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "carro.php",true);
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   X.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send(null)
}*/

function carro(){
	divResultado = document.getElementById('todo');
	ajax=nuevoAjax();
	ajax.open("POST", "carro.php",true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado.innerHTML = ajax.responseText
			}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send(null)
}

function carro2(pagina,variable){
	divResultado = document.getElementById('todo');
	ajax=nuevoAjax();
	ajax.open("POST", "carro.php",true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado.innerHTML = ajax.responseText
			cambia();
			}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("variable="+variable)
}


///////////////////////////////////////////////////ANGELES CARE
function mostrarSubFamilia(familia){
       ajax=nuevoAjax();
       menu_izq.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "subfamilias.php?id_familia=" +familia,true);
	   //Y.innerHTML ='';
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   menu_izq.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send(null)
}


function mostrarProductos(subFamilia){
       ajax=nuevoAjax();
       todo.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "productos.php?id_sub_familia=" +subFamilia,true);
	   //Y.innerHTML ='';
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   todo.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send(null)
}

function contacta(){
   nombre=document.formulario.nombre.value;	   	     
   telefono=document.formulario.telefono.value;	   	     
   edad=document.formulario.edad.value;	   	     
   email=document.formulario.email.value;	   	     
   comentario=document.formulario.comentario.value;	
   captcha = document.formulario.code.value;
   bandera=validar(nombre,edad,email,comentario,4);
   if(bandera==0){
ajax=nuevoAjax();
       todo.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "procesa_contacto.php",true);
	   //Y.innerHTML ='';
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   todo.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send("nombre="+nombre+"&telefono="+telefono+"&edad="+edad+"&email="+email+"&comentario="+comentario+"&code="+captcha)   
	   }//fin del if de bandera
}




function validar(nombre,edad,email,comentario,j){
	bandera=0;
for(i=0; i<j; i++)
{
if(nombre==""){
		alert("Debe escribir su nombre. ");	
		bandera=1;	
		break;
	}
	if(edad=="@x@"){
		alert("Debe seleccionar un rango de edad. ");	
		bandera=1;
		break;		
	}
	if(email==""){
		alert("Debe escribir su e-mail. ");	
		bandera=1;
		break;		
	}
	if(comentario==""){
		alert("Debe escribir su comentario. ");	
		bandera=1;
		break;		
	}
	
	
}
return bandera;
}

function mostrarPagina(datos){
	divResultado = document.getElementById('todo');
	ajax=nuevoAjax();
	ajax.open("POST", datos,true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado.innerHTML = ajax.responseText
			}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send(null)
}

function mostrarPagina2(pagina){
	dato=document.formulario1.palabra.value;	
	divResultado1 = document.getElementById('todo');
	ajax=nuevoAjax();
	ajax.open("POST", pagina,true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado1.innerHTML = ajax.responseText
			}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("palabra="+dato)
}


function mostrarPagina3(){
	divResultado = document.getElementById('todo');
	ajax=nuevoAjax();
	ajax.open("POST", "form_datos.php",true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado.innerHTML = ajax.responseText
			}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send(null)
}


function agregarACarro(id){
	
       ajax=nuevoAjax();
       todo.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "agregar.php?id_prod=" +id,true);
	   //Y.innerHTML ='';
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   todo.innerHTML = ajax.responseText	   
	   cambia();
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send(null)
}

function cambia(){
       ajax=nuevoAjax();
       carrito.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "cambia.php",true);
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   carrito.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send(null)
}

function mostrarDetalleProducto(producto){
       ajax=nuevoAjax();
       todo.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "detalles.php?id=" +producto,true);
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   todo.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send(null)
}

function pedido(){
   nombre=document.formulario.nombre.value;	   	     
   domicilio=document.formulario.domicilio.value;	   	     
   numero=document.formulario.numero.value;	   	     
   seguridad=document.formulario.seguridad.value;
   tipo=document.formulario.tipo.options[document.formulario.tipo.selectedIndex].value;
  // var textoEscogido = document.formulario.tipo.options[indice].text; 
   email=document.formulario.email.value;	 
   
ajax=nuevoAjax();
       todo.innerHTML = '<p style="text-align:center;"><img src="imagenes/esperando.gif"/></p>'; 
       ajax.open("POST", "procesa_pedido.php",true);
       ajax.onreadystatechange=function() {
       if (ajax.readyState==4) {      
	   todo.innerHTML = ajax.responseText	   
       }       
       }
       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       ajax.send("nombre="+nombre+"&domicilio="+domicilio+"&email="+email+"&ntarjeta="+numero+"&nseguridad="+seguridad+"&tipo="+tipo)   

}

function rentas(pagina,variable){
	divoferta = document.getElementById('resultado');
	ajax=nuevoAjax();
	ajax.open("POST", pagina,true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divoferta.innerHTML = ajax.responseText
			cambia();
			}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("variable="+variable)
}
