function objetoAjax(){
	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 load_page(url,imprime)
{
	
document.getElementById('catalogoproductos').innerHTML='CARRITO DE COMPRAS';
	divresultado=document.getElementById('contenedor_productos');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET",url +"?rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}

/*function load_page(url,capa)
{
	
	divresultado=document.getElementById(capa);

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET",url +"?rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}*/


function mensaje()
{
alert('Servicio Normal: escoge su entrega en un horario con rango de 4 horas.\n\nServicio Personalizado: escoge una hora determinada de entrega.');
	}


function suma_servicio(servicio)
{
		divresultado=document.getElementById('contenedor_productos');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET","mete_producto.php?tipo_servicio="+servicio+"&rand="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)
}


function ver_categoria(dato)
{
	divresultado=document.getElementById('inputcodigo');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET","show_categoria.php?codigo="+dato+"&rand="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)
}





function enviar()

{


	divresultado=document.getElementById('msg_mail');
	
	
	nom=document.registrate.nombres.value;
	pat=document.registrate.paterno.value;
	mat=document.registrate.materno.value;
		
	dni=document.registrate.dni.value;
	mai=document.registrate.email.value;
	pas=document.registrate.pass.value;
	rep=document.registrate.repass.value;
	tel=document.registrate.telefono.value;
	dir=document.registrate.direccion.value;
	dis=document.registrate.distrito.value;

	pai=document.registrate.pais.value;
	celular=document.registrate.celular.value;
	oficina=document.registrate.oficina.value;
	urb=document.registrate.urbanizacion.value;
	prov=document.registrate.provincia.value;
	sex=document.registrate.sexo.value;
	dia=document.registrate.dia.value;
	mes=document.registrate.mes.value;
	ano=document.registrate.ano.value;
	
	bol=document.registrate.boletin.value;
	nacimiento=ano+'-'+mes+'-'+dia;
	

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("POST","registrate/registrate.php?rand=" + Aleatorio,true);
	document.getElementById('msg_mail').style.visibility="visible";
	ajax.onreadystatechange=useHttpResponse;
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    ajax.send("email="+mai+"&pass="+pas+"&repass="+rep+"&nombres="+nom+"&paterno="+pat+"&materno="+mat+"&direccion="+dir+"&distrito="+dis+"&telefono="+tel+"&pais="+pai+"&dni="+dni+"&nacimiento="+nacimiento+"&celular="+celular+"&oficina="+oficina+"&boletin="+bol+"&provincia="+prov+"&urbanizacion="+urb+"&sexo="+sex+"&dia="+dia+"&mes="+mes+"&ano="+ano);
	


}



function valida_session()
{


alert('Debes Iniciar tu Cuenta, si no estas registrado puedes hacerlo ahora.');

document.frmlogin.txtnick.focus();

}


function ocultar()
{
		document.getElementById('msg_mail').style.visibility="hidden";
	}
	
function limpiar ()
{
	document.registrate.reset()
/*document.registrate.nombres.value='';
document.registrate.paterno.value='';
document.registrate.materno.value='';
document.registrate.email.value='';
document.registrate.pass.value='';
document.registrate.repass.value='';
document.registrate.telefono.value='';
document.registrate.direccion.value='';
document.registrate.distrito.value='';
document.registrate.dni.value='';
document.registrate.celular.value='';
document.registrate.oficina.value='';*/
}


function validar(){ 
    //valido el nombre 
    if (document.form1.txtnick.value==''){ 
       alert("Tiene  que ingresar su E-mail") 
       document.form1.txtnick.focus() 
       return false; 
	   
    } 

    if (document.form1.txtpass.value==''){ 
       alert("Tiene que ingresar su contraseņa") 
       document.form1.txtpass.focus() 
       return false; 
	   
} 
		  
}


function entrega(distrito,peso)

{

	divresultado=document.getElementById('cap_lugar');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();
 if (distrito=='')
 {
	 alert('Debe seleccionar un lugar de entrega valido')
	
 }
 else
 {
	ajax.open("GET","entrega.php?entrega="+distrito+"&peso="+peso+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
 }
}



function entregar(distrito,lugar,peso)

{

	divresultado=document.getElementById('contenedor');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();
 if (distrito=='')
 {
	 alert('Debe seleccionar un lugar de entrega valido')
	
 }
 else
 {
	ajax.open("GET","mete_producto.php?entregar="+distrito+"&lugar="+lugar+"&pesoss="+peso+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
 }
}



function eliminar_carrito(url)

{
	
	divresultado=document.getElementById('contenedor_productos');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET",url +"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}



function editar_cantidad(linea,stock)

{

	divresultado=document.getElementById('editar'+linea+'cantidad');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","editar_cantidad.php?div="+linea+"&stock="+stock+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}






function editar_cantidad_save(cantidad,linea)

{

	divresultado=document.getElementById('contenedor_productos');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","mete_producto.php?cantidad="+cantidad+"&linea="+linea+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}




function finalizar(totales)

{
	if (document.frmservicio.tipo_servicio.value=='')
	{
	alert('Seleccione el Tipo de servicio')
	return true
	}


	document.getElementById('catalogoproductos').innerHTML='DATOS DE ENVIO:';
vari=document.frmservicio.tipo_servicio.value;



divresultado=document.getElementById('contenedor_productos');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","mete_producto.php?datos_add=true&totales="+totales+"&tipo_servicio="+vari+"&rand="+ Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}

function comprar(documento,vari,medio,totales)
{

				if (document.frmdata.mes.value=='Enero')			{ mes='01';}
				if (document.frmdata.mes.value=='Febrero')			{ mes='02';}
				if (document.frmdata.mes.value=='Marzo')			{ mes='03';}
				if (document.frmdata.mes.value=='Abril')			{ mes='04';}
				if (document.frmdata.mes.value=='Mayo')				{ mes='05';}
				if (document.frmdata.mes.value=='Junio')			{ mes='06';}
				if (document.frmdata.mes.value=='Julio')			{ mes='07';}
				if (document.frmdata.mes.value=='Agosto')			{ mes='08';}
				if (document.frmdata.mes.value=='Septiembre')		{ mes='09';}
				if (document.frmdata.mes.value=='Octubre')			{ mes='10';}
				if (document.frmdata.mes.value=='Noviembre')		{ mes='11';}
				if (document.frmdata.mes.value=='Diciembre')		{ mes='12';}
				ano=document.frmdata.ano.value.substring(2,4);
				
				
				var fecha=mes+'/'+document.frmdata.dia.value+'/'+ano;
				f1=new Date(fecha);
				f2=new Date(document.frmdata.fecha_hoy.value);
	
				if (f1<f2)
				{
				alert('La fecha seleccionada no es valida')	;
				document.frmdata.dia.focus() 
				return false
				}
	
	if (document.frmdata.dia.value==''){ 
       alert("Por favor ingrese dia") 
       document.frmdata.dia.focus() 
       return false; } 
	   
	   
	   
	   if (document.frmdata.mes.value==''){ 
       alert("Por favor ingrese mes") 
       document.frmdata.mes.focus() 
       return false; } 
	
	   
	   	   if (document.frmdata.ano.value==''){ 
       alert("Por favor ingrese ano") 
       document.frmdata.ano.focus() 
       return false; } 
	   
	   
	      	   if (document.frmdata.horario.value==''){ 
       alert("Por favor ingrese horario") 
       document.frmdata.horario.focus() 
       return false; } 
	   
	   	   if (document.frmdata.lugar_entrega.value==''){ 
       alert("Por favor ingrese lugar_entrega") 
       document.frmdata.lugar_entrega.focus() 
       return false; } 
	   
	   	   	   if (document.frmdata.otras_ubicaciones.value==''){ 
       alert("Por favor ingrese otras_ubicaciones") 
       document.frmdata.otras_ubicaciones.focus() 
       return false; } 
	   
	   
	   
	   	   if (document.frmdata.referencia.value==''){ 
       alert("Por favor ingrese referencia") 
       document.frmdata.referencia.focus() 
       return false; } 
	   
	   
	     if (document.frmdata.direccion_entrega.value==''){ 
       alert("Por favor ingrese direccion_entrega") 
       document.frmdata.direccion_entrega.focus() 
       return false; } 
	   
	     	   if (document.frmdata.telefono_entrega.value==''){ 
       alert("Por favor ingrese telefono_entrega") 
       document.frmdata.telefono_entrega.focus() 
       return false; } 
	   
	      	   if (document.frmdata.nombre.value==''){ 
       alert("Por favor ingrese nombre") 
       document.frmdata.nombre.focus() 
       return false; } 
	   
	   
	   if (document.frmdata.factura.value=='SI')
	   {
		
		  	   if (document.frmdata.razon_social.value==''){ 
       alert("Por favor ingrese razon_social") 
       document.frmdata.razon_social.focus() 
       return false; } 
	   
	   	  	   if (document.frmdata.ruc.value==''){ 
       alert("Por favor ingrese ruc") 
       document.frmdata.ruc.focus() 
       return false; } 
		
	   }
	   
	   
dia=document.frmdata.dia.value;
mes=document.frmdata.mes.value;
ano=document.frmdata.ano.value;
horario=document.frmdata.horario.value;
lugar_entrega=document.frmdata.lugar_entrega.value;
direccion_entrega=document.frmdata.direccion_entrega.value;
telefono_entrega=document.frmdata.telefono_entrega.value;
otras_ubicaciones=document.frmdata.otras_ubicaciones.value;
nombre=document.frmdata.nombre.value;
paterno=document.frmdata.paterno.value;
materno=document.frmdata.materno.value;
referencia=document.frmdata.referencia.value;
mensaje=document.frmdata.mensaje.value;
factura=document.frmdata.factura.value;
razon_social=document.frmdata.razon_social.value;

ruc=document.frmdata.ruc.value;

divresultado=document.getElementById('contenedor_productos');


document.getElementById('catalogoproductos').innerHTML='Orden de Pedido:';




	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();
	

ajax.open("GET","mete_producto.php?fin=true&dia="+dia+"&mes="+mes+"&ano="+ano+"&horario=" + horario+"&lugar_entrega="+lugar_entrega+"&direccion_entrega="+direccion_entrega+"&telefono_entrega="+telefono_entrega+"&otras_ubicaciones="+otras_ubicaciones+"&nombre="+nombre+"&paterno="+paterno+"&materno="+materno+"&referencia="+referencia+"&mensaje="+mensaje+"&factura="+factura+"&razon_social="+razon_social+"&ruc="+ruc+"&documento="+documento+"&tipo_servicio="+vari+"&medio_pago="+medio+"&totales="+totales+"&rand="+Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
	
	
	   
}






function carrito(id_tabla,codigo,cantidad)

{
	
	ocultar_btn();
	document.getElementById('catalogoproductos').innerHTML='CARRITO DE COMPRAS';
	

	divresultado=document.getElementById('contenedor_productos');


	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","mete_producto.php?id="+id_tabla+"&codigo="+codigo+"&cantidad="+cantidad+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
}





function validar(){ 
    //valido el nombre 
    if (document.form1.txtnick.value==''){ 
       alert("Tiene  que ingresar su E-mail") 
       document.form1.txtnick.focus() 
       return false; 
	   
    } 

    if (document.form1.txtpass.value==''){ 
       alert("Tiene que ingresar su contraseņa") 
       document.form1.txtpass.focus() 
       return false; 
	   
} 
		  
}
	
	
	
function validar1(){ 
    //valido el nombre 
    if (document.form5.txtnick.value==''){ 
       alert("Tiene  que ingresar su E-mail") 
       document.form5.txtnick.focus() 
       return false; 
	   
    } 

    if (document.form5.txtpass.value==''){ 
       alert("Tiene que ingresar su contraseņa") 
       document.form5.txtpass.focus() 
       return false; 
	   
} 
		  
}
	





function valida_final(){ 
    //valido el nombre 
    if (document.frmfin.nombre.value==''){ 
       alert("Tiene que ingresar el nombre del contacto") 
       document.frmfin.nombre.focus() 
       return false; 
	   
    } 

    if (document.frmfin.telefono.value==''){ 
       alert("Tiene que ingresar el telefono del contacto") 
       document.frmfin.telefono.focus() 
       return false; 
	   
    } 
	    if (document.frmfin.direccion.value==''){ 
       alert("Tiene que ingresar en lugar de entrega") 
       document.frmfin.direccion.focus() 
       return false; 
	   
    } 
	    if (document.frmfin.referencia.value==''){ 
       alert("Tiene que ingresar la referencia del lugar de entrega") 
       document.frmfin.referencia.focus() 
       return false; 
	   
    } 
		  
}



function enviar_olvido()

{
	divresultado=document.getElementById('msg_olvido');
	olv=document.frmolvido.olvido.value;

	
	
	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("POST","olvido/olvido.php?rand=" + Aleatorio,true);
	document.getElementById('msg_olvido').style.visibility="visible";
	ajax.onreadystatechange=useHttpResponse;
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    ajax.send("olvido="+olv);


}




function ocultar_olvido()
{	
	 document.getElementById('msg_olvido').style.visibility="hidden";

}

function limpiar_olvido()
{
	
	document.frmolvido.olvido.value='';
	document.frmolvido.olvido.focus() 
return false; 


}




function useHttpResponse() {

	

   if (ajax.readyState == 4) 

   {

   		 if(ajax.status == 200) 

		{

			divresultado.innerHTML=ajax.responseText;

			

		}

  } 

  else 

  {

  divresultado.innerHTML = '<center><p /><img src="images/cargando.gif" alt="cargando..."></center>';

  }


}
	