
////////////////////////////////////////////////
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 pago_deposito(codigo)

{
		divresultado=document.getElementById('categoria');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();


    ajax.open("GET","mete_producto.php?codigo="+codigo+"&pagodeposito=true&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}

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 save_comprobante(nombre,telefono,codigo,direccion,ciudad,postal,ruc,razon,direccionn,envio2)
{

	divresultado=document.getElementById('categoria');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","mete_producto.php?save_comprobante=true&nombrecom="+nombre+"&telefonocom="+telefono+"&codigocom="+codigo+"&direccion="+direccion+"&ciudad="+ciudad+"&postal="+postal+"&rucc="+ruc+"&razon="+razon+"&direccionn="+direccionn+"&envio2="+envio2+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}

function finalizar(costo_envio,ubicacion,total)

{
	
	   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 la direccion del lugar de entrega") 
       document.frmfin.direccion.focus() 
       return false; 
	   
    } 
	
		    if (document.frmfin.ciudad.value==''){ 
       alert("Tiene que ingresar la  ciudad de entrega") 
       document.frmfin.ciudad.focus() 
       return false; 
	   
    } 

	 
	

	
		    if (document.frmfin.postal.value==''){ 
       alert("Tiene que ingresar el Codigo Postal") 
       document.frmfin.postal.focus() 
       return false; 
	   
    } 
	
	 
	 
/*	 if (document.frmfin.comprobante.value==''){ 
       alert("Tiene que seleccionar el tipo de comprobante") 
       document.frmfin.comprobante.focus() 
       return false; 
	   
    }*/
		  
		  
		  if (document.factura.chek.value!='')
		  {
			 
			 
	if (document.factura.ruc.value==''){ 
       alert("Tiene ingresar su ruc") 
       document.factura.ruc.focus() 
       return false; 
	   
    }  
	if (document.factura.razonsocial.value==''){ 
       alert("Tiene ingresar la razonsocial") 
       document.factura.comprobante.focus() 
       return false; 
	   
    }  
	if (document.factura.direccion.value==''){ 
       alert("Tiene que ingresar la direccion") 
       document.factura.direccion.focus() 
       return false; 
	   
    }   
	
	
			  
		}
	nom=document.frmfin.nombre.value;
	tel=document.frmfin.telefono.value;
	ent=document.destino.entrega.value;
	entt=document.destino.entregar.value;
	
	dire=document.frmfin.direccion.value;
	ciu=document.frmfin.ciudad.value;
	pos= document.frmfin.postal.value;
	
	
	//datos de factura
	
	
	
	
	ruc=document.factura.ruc.value;
	razon=document.factura.razonsocial.value;
	direccion=document.factura.direccion.value;
	
	
	
	/////////////////////////////
	

 if (document.factura.chek.value!='')
		  
		  {		
		tipo='factura';	  
		  }
		  else
		  {
			tipo='boleta';	   
			}

	divresultado=document.getElementById('categoria');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","mete_producto.php?entrega="+ent+"&entregar="+entt+"&nombre="+nom+"&telefono="+tel+"&referencia=&costoenvio="+costo_envio+"&ubicacion="+ubicacion+"&total="+total+"&direccion="+dire+"&ciudad="+ciu+"&postal="+pos+"&rucc="+ruc+"&razon="+razon+"&direccionn="+direccion+"&tipo="+tipo+"&fin=fin&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}




//////////////////////////////////////////
function tipo_comprobante(tipo)

{

if (tipo=='factura')
{
document.getElementById('factura').style.visibility='visible'
document.getElementById('factura').style.display ='';
document.factura.chek.value='lll';
	
}
else
{
document.getElementById('factura').style.visibility='hidden'
document.getElementById('factura').style.display ='none';
document.factura.chek.value='';
	
}


}


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,comprobante)

{

	divresultado=document.getElementById('categoria');

	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+"&comprobante="+comprobante+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
 }
}








function ocultar1()
{	

	 document.getElementById('zoom_empresa').style.visibility="hidden";

	document.getElementById('tablita').style.MozOpacity = 1;
document.getElementById('tablita').style.filter = "alpha(opacity=100)";




}


function editar_cantidad(linea,id_prod)

{

	divresultado=document.getElementById('editar'+linea+'cantidad');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","editar_cantidad.php?div="+linea+"&codigo="+id_prod+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}

function editar_cantidad_save(cantidad,linea)

{

	divresultado=document.getElementById('categoria');

	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 validar(){ 
    //valido el nombre 
    if (document.frmlogin.txtnick.value==''){ 
       alert("Tiene  que ingresar su E-mail") 
       document.frmlogin.txtnick.focus() 
       return false; 
	   
    } 

    if (document.frmlogin.txtpass.value==''){ 
       alert("Tiene que ingresar su contraseņa") 
       document.frmlogin.txtpass.focus() 
       return false; 
	   
} 
		  
}
	



////////////////////////////////////////////////////
function load_page(url)
{
	divresultado=document.getElementById('home_flash');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}

function load_pageSub(url)
{
	divresultado=document.getElementById('categoria');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}






function load_SubCategorias(url)
{
	divresultado=document.getElementById('categoria');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}
function load_prod_acor(url)
{
	divresultado=document.getElementById('categoria');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}


function load_prod_des(url)
{
	divresultado=document.getElementById('categoria');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}




function load_depas(url)
{
	divresultado=document.getElementById('departamentos1');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}

function cargar_flash(url)
{
	divresultado=document.getElementById('categoria');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}


function load_empresas(url)
{
	divresultado=document.getElementById('empresas');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"&ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}



function eliminar_carrito(url)

{
	divresultado=document.getElementById('categoria');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET",url +"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}







function carrito(can,codigo,foto,nombre,precio,preciox,fotomax,peso)

{

	
	divresultado=document.getElementById('categoria');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","mete_producto.php?cantidad="+can+"&id="+codigo+"&foto="+foto+"&nombre="+nombre+"&precio="+precio+"&preciox="+preciox+"&fotomax="+fotomax+"&peso="+peso+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
}



function load_empresazoom(url,posicion)
{
	divresultado=document.getElementById('zoom_empresa');
	document.getElementById('zoom_empresa').style.visibility="visible";
	
document.getElementById('zoom_empresa').style.top=posicion+"px";


	document.getElementById('tablita').style.MozOpacity = .5;
    document.getElementById('tablita').style.filter = "alpha(opacity=50)";
	                             
	
	
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"&ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}




function load_page3(url)
{
	divresultado=document.getElementById('pdfs');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"&ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
}


function load_page_mapas(url)
{
	divresultado=document.getElementById('pais_ciudad');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET",url+"ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)

}


function mostrar_ubic(distrito)
{
	

divresultado=document.getElementById('locales');
		
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("POST","distri_ubic.php?rand="+ Aleatorio+"&distrito="+distrito,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null);


}

function show_subcategoria(codigo)
{
	divresultado=document.getElementById('subcategoria');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET","subcategoria.php?codigo="+ codigo +"&ramd="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)	
	
}
/////////////////////////////////////////////////////



function ocultar()
{	
/*divresultado=document.getElementById('imagen_code');*/
	 document.getElementById('msg_mail').style.visibility="hidden";
//	 document.getElementById('base_form_registro').style.visibility="visible";
	 
	 
 document.getElementById('base_form_registro').style.MozOpacity = 1;
   document.getElementById('base_form_registro').style.filter = "alpha(opacity=100)";
/*	 var Aleatorio=parseInt(Math.random()*99999999);
	 ajax=new objetoAjax();
	 ajax.open("GET","registrate/validar.php?rand=" + Aleatorio,true);
	 ajax.onreadystatechange=useHttpResponse;
	 	ajax.send(null)*/
}

function limpiar()
{
	
	document.registrate.correo.value='';
	document.registrate.pass.value='';
	document.registrate.repass.value='';
	document.registrate.nombres.value='';
	document.registrate.apellidos.value='';
	document.registrate.direccion.value='';
	document.registrate.distrito.value='';
	document.registrate.telefono.value='';
		
document.registrate.correo.focus() 
return false; 


}



function enviar()

{

	divresultado=document.getElementById('msg_mail');

	nom=document.registrate.nombres.value;
	ape=document.registrate.apellidos.value;
	mai=document.registrate.correo.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;
	
	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

 document.getElementById('base_form_registro').style.MozOpacity = .3;
   document.getElementById('base_form_registro').style.filter = "alpha(opacity=30)";

	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+"&apellidos="+ape+"&direccion="+dir+"&distrito="+dis+"&telefono="+tel);


}



//////////////////////////











////////////

function ver_subcategorias(cat)
{
	divresultado=document.getElementById('subcategoria');
	var Aleatorio=parseInt(Math.random()*99999999);
	ajax=new objetoAjax();
	ajax.open("GET","clientes/clientes1.php?categoria="+cat+"&rand="+Aleatorio,true);
	ajax.onreadystatechange=useHttpResponse;
	ajax.send(null)
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//////////////////////////////////////////////////////////////

function prodmodificar(codigo)
	{

	divresultado=document.getElementById('contenedor');
	

	cat=document.form_productos.categoria.value;

	subcat=document.form_productos.subcategoria.value;

    cod=document.form_productos.codigo.value;

	nom=document.form_productos.nombre.value;

	

code=document.form_productos.code.value;



	ajax=objetoAjax();
	var Aleatorio=parseInt(Math.random()*99999999);

	ajax.open("POST", "productos/editar.php?codigo="+codigo+"&editar=true&random="+ Aleatorio ,true);
	ajax.onreadystatechange=useHttpResponse;
	//muy importante este encabezado ya que hacemos uso de un formulario
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores

    ajax.send("categoria="+cat+"&subcategoria="+subcat+ "&codigo="+cod+"&nombre="+nom+"&id="+code);
}

//////////////////////////////////////////////////////




//////////////////////////////////////////////////////	
function useHttpResponse() {
	
   if (ajax.readyState == 4) 
   {
   		 if(ajax.status == 200) 
		{
			divresultado.innerHTML=ajax.responseText;

		}
  } 
  else 
  {
  divresultado.innerHTML = '<center><br/><br/><br/><br/><br/><img  src="images/loader1.gif" ></center>';
  }
 
  
}

////////////////////////////////////////////////////////////////////////////////////////////
function useHttpResponse_login() {
	
   if (ajax.readyState == 4) {
    if(ajax.status == 200) {
		
	
       divresultado.innerHTML=ajax.responseText;
	   	if (ajax.responseText=='<img src="images/loader.gif" boder="1">')
	  		{ 
	   		window.location=('intranet.php');
	   		}
	   
    }
  } else {
  document.getElementById('respuesta').innerHTML = '<img src="images/loader.gif" boder="1">';
  }
  
}