// JavaScript Document

function js_Ventana(www,ancho,alto,titulo,target)
{
	var destino=www+'#'+target;
	var ventana=window.open(destino,titulo,'status=no,scrollbars=no, resizable=yes,width='+ancho+',height='+alto);
	ventana.opener.top.name="opener";
	ventana.focus();
}

function js_calendario(texto)
	{
	//alert(texto);
	document.all.eventos.innerHTML=texto;
	//document.all.hoy.innerText=fecha;
 	document.all.calenda.style.visibility = "visible";
	}

function js_calendario_off()
	{
	document.all.eventos.innerText="";
	//document.all.hoy.innerText="";
	document.all.calenda.style.visibility = "hidden";
	}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function sumaClick(id){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'cuentaclicks/sumaClick.php?id_banner='; //This is the path to the file we just finished making
    xmlhttp.open('GET', file + id , true); //Open the file through GET, and add the id we want to retrieve as a GET variable
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}
function contador(id){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'contador.php?id='; //This is the path to the file we just finished making
    xmlhttp.open('GET', file + id, true); //Open the file through GET, and add the id we want to retrieve as a GET variable
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
            var content = xmlhttp.responseText; //The content data which has been retrieved
            if ( content == 'n' ){
            }
            else{
            	array_partes = content.split('#|#');
            	document.getElementById('ventanaTitulo').innerHTML = array_partes[1]+'<br><b>'+array_partes[0]+'</b>';
            	document.getElementById('ventanaVideo').innerHTML = array_partes[2];
            }
        }
      }
    xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function cargarvideo(lafuente, donde){
		relacionaspecto=(200/280);
		anchuras = 280;
			var objectoc2 = document.createElement('embed');
			objectoc2.setAttribute("type", "application/x-shockwave-flash");
			objectoc2.setAttribute("width", (anchuras));
			objectoc2.setAttribute("height", parseInt((anchuras)*relacionaspecto));
			objectoc2.setAttribute("wmode", "opaque");
			objectoc2.setAttribute("src", lafuente);
			document.getElementById(donde).innerHTML="";
			document.getElementById(donde).appendChild(objectoc2);
}

function enviologin(logi,passw,laurl){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'complogin.php?op=1&login='; //This is the path to the file we just finished making
        var puntua = '&pass='; //This is the path to the file we just finished making
        var desde = '&url='; //This is the path to the file we just finished making
    xmlhttp.open('GET', file + logi + puntua + passw + desde + laurl, true); //Open the file through GET, and add the id we want to retrieve as a GET variable
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved
                if ( content == 'n' ){
                      alert("No esta registrado");
                }
                else if( content == 'i'){
                      alert("La clave no es correcta");
                }
                else if( content == 'f'){
                      alert("Su suscripción ha caducado");
                }
                else{ //If the response was not "n" (meaning it worked)
                      document.location = content ; //Set the inner HTML of the div with the old value in it to the new value **
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function cierrasession(laurl){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = '/complogin.php?op=6'; //This is the path to the file we just finished making
        var desde = '&url='; //This is the path to the file we just finished making
    xmlhttp.open('GET', file + desde + laurl, true); //Open the file through GET, and add the id we want to retrieve as a GET variable
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved
                if ( content != 'n' ){
                       document.location = content ;
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}
function closeIframe()
{
    $('#externalSite').dialog('close');
    return false;
}
function vote(id,puntos){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'votar.php?id='; //This is the path to the file we just finished making
        var puntua = '&puntuacion='; //This is the path to the file we just finished making
    xmlhttp.open('GET', file + id + puntua + puntos, true); //Open the file through GET, and add the id we want to retrieve as a GET variable
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved
                if ( content == 'x' ){
                      document.getElementById('graciasvotos').innerHTML = "&nbsp;&nbsp;Su voto fue recogido con anterioridad"; //Set the inner HTML of the div with the old value in it to the new value **                	
                }
                else if( content != 'n' ){ //If the response was not "n" (meaning it worked)
                      arrcontent = content.split('#', 3); //Get rid of the y infront of our result *
                      document.getElementById('resultvotos').innerHTML = arrcontent[0]; //Set the inner HTML of the div with the old value in it to the new value **
                      document.getElementById('cuantosvotos').innerHTML = arrcontent[1]; //Set the inner HTML of the div with the old value in it to the new value **
                      document.getElementById('graciasvotos').innerHTML = arrcontent[2]; //Set the inner HTML of the div with the old value in it to the new value **
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function cambiar_tamano(tamano){
	if (document.getElementById("cuerpo_texto")){
		document.getElementById("cuerpo_texto").style.fontSize=tamano;
		document.getElementById("cuerpo_texto").style.lineHeight="1.5";
	}
	if (document.getElementById("cuerpo_descripcion")){
		document.getElementById("cuerpo_descripcion").style.fontSize=tamano;
		document.getElementById("cuerpo_descripcion").style.lineHeight="1.5";
	}
	var elemento=document.getElementsByTagName('font');
	var n=0;
	while(elemento[n]){
		if(elemento[n].className=="estilo_texto" ) {elemento[n].style.fontSize=tamano;elemento[n].style.lineHeight="1.5";}
		n++;
	}
	var elemento=document.getElementsByTagName('span');
	var n=0;
	while(elemento[n]){
		if(elemento[n].className=="estilo_texto" ) {elemento[n].style.fontSize=tamano;elemento[n].style.lineHeight="1.5";}
		n++;
	}
}
function reset_tamano(){
	if (document.getElementById("cuerpo_texto")){
		document.getElementById("cuerpo_texto").style.fontSize=tamano_original;
		document.getElementById("cuerpo_texto").style.lineHeight=espaciado_original;
	}
	if (document.getElementById("cuerpo_descripcion")){
		document.getElementById("cuerpo_descripcion").style.fontSize=tamano_original_desc;
		document.getElementById("cuerpo_descripcion").style.lineHeight=espaciado_original_desc;
	}
	var elemento=document.getElementsByTagName('font');
	var n=0;
	while(elemento[n]){
		if(elemento[n].className=="estilo_texto" ) {elemento[n].style.fontSize=tamano_original;elemento[n].style.lineHeight=espaciado_original;}
		n++;
	}
	var elemento=document.getElementsByTagName('span');
	var n=0;
	while(elemento[n]){
		if(elemento[n].className=="estilo_texto" ) {elemento[n].style.fontSize=tamano_original;elemento[n].style.lineHeight=espaciado_original;}
		n++;
	}
}

function comp_enter(e){
	if(window.event) // IE
	  {
	  keycode = e.keyCode;
	  }
	else if(e.which) // Netscape/Firefox/Opera
	  {
	  keycode = e.which;
	  }	
	//alert(keycode);
	// pulsamos el enter
	if(keycode == 13)
	{
	  document.getElementById('enviar_pregunt').focus();
	}
}

function validar_formu(){
	seguir=1;
	if(document.getElementById('preguntax').value == ''){
		seguir=0;
		alert('Debe escribir una pregunta');
	}
	else if(document.getElementById('nombrex').value == ''){
		seguir=0;
		alert('Debe escribir un nombre o alias');
	}
	else if(document.getElementById('emailx').value == ''){
		seguir=0;
		alert('Debe escribir un email');
	}
	if(seguir == 1){	
		return(true);
	}
	else{
		return(false);
	}
}

function enviocomentario(id,pregunta,alias,email,capt){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'noticias/comentar.php?id_p='; //This is the path to the file we just finished making
        var puntua = '&pregunta_p='; //This is the path to the file we just finished making
        var sujeto = '&nombre_p='; //This is the path to the file we just finished making
        var direcc = '&direcc_p='; //This is the path to the file we just finished making
        var captch = '&capt_p='; //This is the path to the file we just finished making
    xmlhttp.open('GET', file + id + puntua + escape(pregunta) + sujeto + escape(alias) + direcc + email + captch + capt, true); //Open the file through GET, and add the id we want to retrieve as a GET variable
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved
                if ( content == 'x' ){
                      document.getElementById('formulario_div').innerHTML = "Sólo se permite un comentario cada hora."; //Set the inner HTML of the div with the old value in it to the new value **                	
                }
                else if ( content == 'y' ){
                      document.getElementById('formulario_div').innerHTML = "No se permiten comentarios anónimos."; //Set the inner HTML of the div with the old value in it to the new value **                	
                }
                else if ( content == 'z' ){
                      document.getElementById('formulario_div').innerHTML = "Código de confirmación incorrecto.<br><a class='btn_navega' href='javascript:document.location.reload();'>Volver a intentar</a>"; //Set the inner HTML of the div with the old value in it to the new value **                	
                }
                else if( content != 'n' ){ //If the response was not "n" (meaning it worked)
                			document.location = "#comentarios";
                      document.location.reload(); //Set the inner HTML of the div with the old value in it to the new value **
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}
function mercado(cat){
	if (document.getElementById('historico'))	
		anuncios(0,1,cat)
		
	var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
         xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
               document.getElementById('categorias').innerHTML  = xmlhttp.responseText; //The content data which has been retrieved
            }
        	}        
       xmlhttp.open('GET', "includes/mercado.php?seccion="+seccion+"&categoria="+cat+"&tipo=categorias" , true); //Open the file through GET, and add the id we want to retrieve as a GET variable
   		 xmlhttp.send(null) //Nullify the XMLHttpRequest
		return;
}

function anuncios(pagina,scrol,cat){
	var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
         xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
              var content = xmlhttp.responseText; //The content data which has been retrieved
              arrcontent = content.split('###', 2); //Get rid of the y infront of our result *
              if (arrcontent[1]==0){
              	location.assign('mercado.php');
              }
              else{
              	document.getElementById('historico').innerHTML= arrcontent[0]; //The content data which has been retrieved
              	if (scrol){window.scrollTo(0,0);}
              }
            }
        	}        
       xmlhttp.open('GET', "includes/mercado.php?seccion="+seccion+"&pagina="+pagina+"&categoria="+cat+"&tipo=historial" , true); //Open the file through GET, and add the id we want to retrieve as a GET variable
   		 xmlhttp.send(null) //Nullify the XMLHttpRequest
		return;
}

function imagen_anuncio(num){
	
	document.getElementById('slide1').style.display="none";
	if (document.getElementById('slide2'))
		document.getElementById('slide2').style.display="none";
	if (document.getElementById('slide3'))
		document.getElementById('slide3').style.display="none";
	
	document.getElementById('slide'+num).style.display="block";
}

function solicitud_informacion()
{
	var enviar=1;
	if (document.inform.mi_nombre.value=="" && enviar){
		alert("Escriba su nombre");
		enviar=0;
	}
	if (document.inform.mi_email.value=="" && enviar){
		alert("Escriba su email");
		enviar=0;
	}
	if (enviar)
		document.inform.submit();
}

function change_height(){
		document.getElementById('slider1').style.height=alto+"px";
		document.getElementById('paginate-slider1').style.marginTop=(alto-25)+"px";
}

function tecla(e){
	if(window.event) // IE
	  {
	  keycode = e.keyCode;
	  }
	else if(e.which) // Netscape/Firefox/Opera
	  {
	  keycode = e.which;
	  }	
        //alert(keycode);
        // pulsamos el enter
        if(keycode == 13)
        {
                document.formu_accesoinn.submit();
        }

}
function mostrarEvento(fechainicio,fechafin,inicio,tipoeve,texto,ciudad){
$.ajax({
   type: "POST",
   url: "cargaeventos.php",
   data: "fechainicio="+fechainicio+"&fechafin="+fechafin+"&inicio="+inicio+"&tipoeve="+tipoeve+"&texto="+texto+"&ciudad="+ciudad,
   success: function(msg){
	   //$('#agendab').slideUp(0);
     $("#agendab").html(msg) ;
	   $('#agendab').slideDown(1000);
   }
 });
}

