// JavaScript Document

function creaAjax(){
         var objetoAjax=false;
         try {
          /*Para navegadores distintos a internet explorer*/
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*Para explorer*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}

function FAjax (url,capa,valores,metodo)
{
          var ajax=creaAjax();
          var capaContenedora = document.getElementById(capa);

/*Creamos y ejecutamos la instancia si el metodo elegido es POST*/
if(metodo.toUpperCase()=='POST'){
         ajax.open ('POST', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                          capaContenedora.innerHTML="<img src='img/cargando.gif'>";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200)
                   {
                        document.getElementById(capa).innerHTML=ajax.responseText;
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                           else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send(valores);
         return;
}
/*Creamos y ejecutamos la instancia si el metodo elegido es GET*/
if (metodo.toUpperCase()=='GET'){

         ajax.open ('GET', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                                      capaContenedora.innerHTML="Cargando.......";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200){
                                             document.getElementById(capa).innerHTML=ajax.responseText;
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                                             else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send(null);
         return
}
} 



function popup(url)
{
	//alert(url);
	nom=aleatorio(1,1000);
	window.open(url,nom,"width=650,height=550,scrollbars=NO"); 
}

function producto(cod)
{
	location.href="producto.php?cod="+cod;
}


function adminCarrito(cod)
{
	location.href="adminCarrito.php?cod="+cod;
}


function contadorCarrito(cod)
{
	medidas=document.producto.medidas.value;

	FAjax('contadorCarrito.php','carrito','codCarrito='+cod+'&medidas='+medidas,'post');
		
}
function destallecarrito()
{
	FAjax('descCarrito.php','detalleCarrito','','post');
	
}

function buscarCorreo()
{
	correo=document.formulario.correo1.value
	if(correo!="")
		FAjax('buscarCorreo.php','mail','correo='+correo,'post');
}


function validarRegistro()
{
	correo=document.formulario.correo1.value;
	nombre=document.formulario.nombre.value;
	clave=document.formulario.clave.value;
	clave2=document.formulario.clave2.value;
	pregunta=document.formulario.pregunta.value;
	respuesta=document.formulario.respuesta.value;
	telefono=document.formulario.telefono.value;
	estado=document.formulario.estado.value;
	ciudad=document.formulario.ciudad.value;
	direccion=document.formulario.direccion.value;
	error="";
	
	if(direccion=="")
	{
		error="Ingrese Direccion";
		document.formulario.direccion.focus();
	}
	if(ciudad=="")
	{
		error="Ingrese Ciudad";
		document.formulario.ciudad.focus();
	}
	if(estado=="")
	{
		error="Ingrese Estado";
		document.formulario.estado.focus();
	}
	
	if(telefono=="")
	{
		error="Ingrese Telefono";
		document.formulario.telefono.focus();
	}
	if(nombre=="")
	{
		error="Ingrese Nombre";
		document.formulario.nombre.focus();
	}
	
	if(respuesta=="")
	{
		error="Ingrese Respuesta";
		document.formulario.respuesta.focus();
	}
	if(pregunta=="")
	{
		error="Ingrese Pregunta";
		document.formulario.pregunta.focus();
	}
	if(clave2=="")
	{
		error="Ingrese Conformacion de Clave";
		document.formulario.clave2.focus();
	}
	if(clave=="")
	{
		error="Ingrese Clave";
		document.formulario.clave.focus();
	}
	
	if(correo=="")
	{
		error="Ingrese Correo";
		document.formulario.correo1.focus();
	}
	
	if(error!="")
	{
		document.formulario.error.value=error;
	}
	else
	{
		if(clave!=clave2)
			document.formulario.error.value="Las Clave no son iguales";
		else
			document.formulario.submit();
	}
}

function validarUsuario()
{
	correo=document.session.correo.value;
	clave=document.session.clave.value;
	error="";
	if(correo=="")
	{
		error="Ingrese Correo";
		document.session.correo.focus();
	}
	if(clave=="")
	{
		error="Ingrese Clave";
		document.session.clave.focus();
	}
	if(error!="")
	{
		document.session.error.value=error;
	}
	else
	{	document.session.submit();  }
	
}

function errorsession(error)
{
	document.session.error.value=""+error;	
}


function validarModoPago()
{
	if(document.compra.modoPago.value=="deposito")
	{
		document.getElementById("tarjeta").style.display="none";
		document.getElementById("deposito").style.display="block";
	}
	else
	if(document.compra.modoPago.value=="tarjeta")
	{
		document.getElementById("deposito").style.display="none";
		document.getElementById("tarjeta").style.display="block";
	}
}

function validarCompra()
{

	error="";
	
	if(document.compra.direc.value=="")
	{
		error="Ingrese direccion de envio."	
	}

	if(error!="")
			document.compra.error.value=error;
	else
	{
		document.compra.submit();
	}
}

function mostrarAnadir()
{
	
	if(document.producto.medidas.value!="")
	{
	
		document.getElementById("anadir").style.display="block";
	}
	else
	{
		document.getElementById("anadir").style.display="none";
	}
}


function ocultarTie()
{
	document.getElementById("caracas1").style.display="none";
	document.getElementById("caracas2").style.display="none";
	document.getElementById("valencia").style.display="none";
	document.getElementById("maracay").style.display="none";
	document.getElementById("barquisimeto").style.display="none";
	document.getElementById("sc").style.display="none";
	document.getElementById("aero").style.display="none";
}

function mostrarTie(a)
{
	ocultarTie();
	document.getElementById(a).style.display="block";
}

