/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */

function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}
/* Programado por : Andres Lopez Gomez - Lima Peru 2007 */
var cargador='<table width=100% height=80 border=0 align=center><tr><td><center><br><img src=images/loader.gif><br></center></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(mg_id)
{
	divEslide = document.getElementById('eslide');
	divEslide.innerHTML=cargador;

ajax=nuevoAjax();
	ajax.open("GET","i_magnificos_citas.php?mg_id="+mg_id,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;

	divContenido.innerHTML=cargador;

	ajax=nuevoAjax();
	ajax.open("GET","search_simple.php?busqueda="+busqueda,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 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 realizar esta operacion, Usted debe de ser un usuario registrado , Desea Registrarse ?"))
	{
	location.replace('registro.php');
	}
}
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)

}
function cargarResultados(){
	divResultado = document.getElementById('resultados');
	//obtengo el codigo de la encuesta
	codenc=document.frmencuesta.cod.value;
	//obtengo el numero de opciones
	nroopc=document.frmencuesta.nroopciones.value;
	//creo un bucle para ver si alguna opcion esta checked
	//si esta checked ese valor lo envio por post
	i=1;
	while(i<=nroopc){
		opcion=document.getElementById('opcion'+i).checked;
		if (opcion==true){
			alt=i;
		}
		i++;
	}
	ajax=nuevoAjax();
	ajax.open("POST", "i_resultado_encuesta.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//envio dos valores el id de la encuesta y la opcion elegida de la encuesta
	ajax.send("idenc="+codenc+"&alternativa="+alt)
}
function votar(){
	divResultado = document.getElementById('encuesta');
	en_id=document.getElementById('cod').value;
	opcion=document.getElementById('opcion').value;
	alert(opcion);
	
	/*ajax=nuevoAjax();
	divResultado.innerHTML=cargador;
	ajax.open("POST", "i_votar.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//envio dos valores el id de la encuesta y la opcion elegida de la encuesta
	ajax.send("en_id="+en_id+"&rp_id="+opcion)
*/
}

function videos_titulo(vi_id)
{
	divContenido2 = document.getElementById('video_titulo');
	divContenido2.innerHTML=cargador;	
	ajax=nuevoAjax();
	ajax.open("GET","video_ajax_titulo.php?vi_id="+vi_id,true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		divContenido2.innerHTML = ajax.responseText		
}
	}
ajax.send(null)

}
function videos(vi_id)
{
	divContenido = document.getElementById('video');
	divContenido.innerHTML=cargador;
	ajax=nuevoAjax();
	ajax.open("GET","video_ajax.php?vi_id="+vi_id,true);
    ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		divContenido.innerHTML = ajax.responseText
		videos_titulo(vi_id);

}

	}

ajax.send(null)
}