/* Programado por : Andres Lopez Gomez - Lima Peru 2007 */
var cargador='<center><br><img src=images/loading_animation.gif><br></center>';
var exito='<table width=250 height=50 align=center class=cuadro_post><tr><td height=23><div align=center class=det_producto>El producto se ha ingresado con exito.! </div></td></tr></table>';
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 eslide()
{
	divEslide = document.getElementById('eslide');
	divEslide.innerHTML=cargador;

ajax=nuevoAjax();
	ajax.open("GET","slide_show.php",true);

   ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divEslide.innerHTML = ajax.responseText
		}
	}
	ajax.send(null)
}

function search_simple()
{
	divContenido = document.getElementById('contenido');
	busqueda= document.getElementById('busqueda').value;
	
	/*Hace el recorrido del GroupButtons y devuelve el valor seleccionado */
	for (var i=0; i<document.form1.search_tipo.length; i++) 
		{ 
			 if (document.form1.search_tipo[i].checked) { tipo=document.form1.search_tipo[i].value; } 
		}
	
	divContenido.innerHTML=cargador;
	ajax=nuevoAjax();
	ajax.open("GET","search_simple.php?busqueda="+busqueda+"&search_tipo="+tipo,true);

   ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
		}
	}
	ajax.send(null)
}

function search_avanzada()
{
	divBusqueda = document.getElementById('contenido');
	pr_nomb= document.getElementById('pr_nomb').value;
	ct_id= document.getElementById('ct_id').value;
	pr_isbn= document.getElementById('pr_isbn').value;
	pr_edicion= document.getElementById('pr_edicion').value;

	divBusqueda.innerHTML=cargador;

	ajax=nuevoAjax();
	ajax.open("GET","search_avanzada.php?pr_nomb="+pr_nomb+"&ct_id="+ct_id+"&pr_isbn="+pr_isbn+"&pr_edicion="+pr_edicion,true);

   ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divBusqueda.innerHTML = ajax.responseText
		}
	}
	ajax.send(null)
}

function oculta()
{
var div_timer;
var div_timer=setTimeout("hide_div();",3000);
document.getElementById('mensaje').innerHTML='<table width=250 height=50 align=center class=cuadro_post><tr><td height=23><div align=center class=det_producto>El producto se ha ingresado con exito.! </div></td></tr></table>';

}
function hide_div(time_here){
	if(time_here){
        div_timer=setTimeout("hide_timer();",(time_here*1000));
    }
    else{
        document.getElementById('mensaje').style.visibility='hidden';
        document.getElementById('mensaje').style.display='none';   
    }
}

function add_cesta(pr_id,pd_id,pr_prec)
{
	divContenido = document.getElementById('cesta');
	divContenido.innerHTML=cargador;
	
	ajax=nuevoAjax();
	ajax.open("GET","i_monto.php?pr_id="+pr_id+"&pd_id="+pd_id+"&pr_prec="+pr_prec,true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
			alert('El producto se agrego con exito..!');
		}
	}
	 ajax.send(null)
}

function add_cesta_form()
{
	divContenido = document.getElementById('cesta');
	divContenido.innerHTML=cargador;
	
	pr_id= document.getElementById('pr_id').value;
	pd_id= document.getElementById('pd_id').value;
	pr_prec= document.getElementById('pr_prec').value;	
	cant= document.getElementById('cant').value;		
	ajax=nuevoAjax();
	ajax.open("GET","i_monto.php?pr_id="+pr_id+"&pd_id="+pd_id+"&pr_prec="+pr_prec+"&cant="+cant,true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
			alert('El producto se agrego con exito..!');
		}
	}
	 ajax.send(null)
}
function update_perfil()
{
	divContenido = document.getElementById('contenido');

	us_nomb= document.getElementById('us_nomb').value;
	us_apell= document.getElementById('us_apell').value;
    us_email= document.getElementById('us_email').value;
    us_direc= document.getElementById('us_direc').value;
    us_fech_nac= document.getElementById('us_fech_nac').value;
    us_pais= document.getElementById('us_pais').value;
    us_pueblo= document.getElementById('us_pueblo').value;
    us_cod_postal= document.getElementById('us_cod_postal').value;
    us_telf= document.getElementById('us_telf').value;
    us_est= document.getElementById('us_est').value;
    us_login= document.getElementById('us_login').value;
    us_clave= document.getElementById('us_clave').value;	
    us_id= document.getElementById('us_id').value;	
	divContenido.innerHTML=cargador;

	ajax=nuevoAjax();
	ajax.open("POST","mi_perfil.php",true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
			alert('Su perfil se ha actualizado con exito..!');
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("ac=grabar&us_nomb="+us_nomb+"&us_apell="+us_apell+"&us_email="+us_email+"&us_direc="+us_direc+"&us_fech_nac="+us_fech_nac+"&us_pais="+us_pais+"&us_pueblo="+us_pueblo+"&us_cod_postal="+us_cod_postal+"&us_telf="+us_telf+"&us_est="+us_est+"&us_login="+us_login+"&us_clave="+us_clave+"&us_id="+us_id)

}

function insert_perfil()
{
	divContenido = document.getElementById('contenido');
	us_nomb= document.getElementById('us_nomb').value;
	us_apell= document.getElementById('us_apell').value;
    us_email= document.getElementById('us_email').value;
    us_direc= document.getElementById('us_direc').value;
    us_fech_nac= document.getElementById('us_fech_nac').value;
    us_pais= document.getElementById('us_pais').value;
    us_pueblo= document.getElementById('us_pueblo').value;
    us_cod_postal= document.getElementById('us_cod_postal').value;
    us_telf= document.getElementById('us_telf').value;
    us_est= document.getElementById('us_est').value;
    us_login= document.getElementById('us_login').value;
    us_clave= document.getElementById('us_clave').value;	
	divContenido.innerHTML=cargador;

	ajax=nuevoAjax();
	ajax.open("POST","registro.php",true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("ac=grabar&us_nomb="+us_nomb+"&us_apell="+us_apell+"&us_email="+us_email+"&us_direc="+us_direc+"&us_fech_nac="+us_fech_nac+"&us_pais="+us_pais+"&us_pueblo="+us_pueblo+"&us_cod_postal="+us_cod_postal+"&us_telf="+us_telf+"&us_est="+us_est+"&us_login="+us_login+"&us_clave="+us_clave)

}


function contenido (url, id_contenedor)
{
var pagina_requerida = false;
if (window.XMLHttpRequest) { pagina_requerida = new XMLHttpRequest (); } else if (window.ActiveXObject)
{ try  { pagina_requerida = new ActiveXObject ("Msxml2.XMLHTTP"); }
catch (e) { try { pagina_requerida = new ActiveXObject ("Microsoft.XMLHTTP"); }
catch (e) { } } }  else return false;

pagina_requerida.onreadystatechange = function () { cargarpagina (pagina_requerida, id_contenedor); }
document.getElementById (id_contenedor).innerHTML=cargador;
pagina_requerida.open ('GET', url, true); // asignamos los métodos open y send
pagina_requerida.send (null);
}
function cargarpagina (pagina_requerida, id_contenedor)
{

if (pagina_requerida.readyState == 4 && (pagina_requerida.status == 200 || window.location.href.indexOf ("http") == - 1))
document.getElementById (id_contenedor).innerHTML = pagina_requerida.responseText;
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function verificar()
{
	if (confirm("Para poder Comprar/Cotizar, Usted debe de ser un usuario registrado , Desea Registrarse ?"))
	{
	divContenido = document.getElementById('contenido');
	divContenido.innerHTML=cargador;
	ajax=nuevoAjax();
	ajax.open("GET","registro.php",true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
		}
	}
	 ajax.send(null)
	}
}
function monto()
{
	divContenido = document.getElementById('cesta');
	divContenido.innerHTML="<div align='right' class='newest_cuopons'>Espere un momento..</div>";
	ajax=nuevoAjax();
	ajax.open("GET","i_monto.php",true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
		}
	}
	 ajax.send(null)
}
function del_cesta(dpd_id)
{
	divContenido = document.getElementById('contenido');
	divContenido.innerHTML=cargador;
	ajax=nuevoAjax();
	ajax.open("GET","carro.php?dpd_id="+dpd_id+"&op=D",true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		divContenido.innerHTML = ajax.responseText
}
	}
ajax.send(null)

}
