// 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 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;
}

//variable con el texto a mostrar
//var texto = "Bienvenidos a mi pagina web!!!"
//variable con la posicion en el texto. Inicializar siempre a 0
//var pos = 0


function dame_texto(){
		if (posTxT==0) 
		{ 
			document.getElementById('textomovimiento').innerHTML='' 
			posTxT = posTxT + 1
			return(textoTxT.charAt(0))
		}
    //incremento la posicion en 1 y extraigo el texto a mostrar en este momento.
    if (posTxT == textoTxT.length){
       //si hemos llegado al final, volvemos la posición al principio
      posTxT = 0
      document.getElementById('textomovimiento').innerHTML=''
      return (textoTxT.charAt(posTxT));
   }else{ posTxT = posTxT + 1 
   return (textoTxT.charAt(posTxT-1));
  }
}

var pos = 0 
function dame_texto2(){	
	pos = pos + 1
   if (pos == textoTxT.length+1){
       //si hemos llegado al final, volvemos la posición al principio
      pos = 0
      return textoTxT
   }else{
   return textoTxT.substring(0,pos)
  } 
}

function anima_texto(){
	if (navigator.appName=="Netscape")
	{
		document.getElementById('textomovimiento').innerHTML=dame_texto2();
	}
	else
	{
	 document.getElementById('textomovimiento').insertAdjacentText("beforeEnd",dame_texto());
	}
   setTimeout("anima_texto()",100)
}


//---------------------------------------------------------------------||
// FUNCTION:    SetCookie                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}
//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}
//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}

function isInElArray(myArray, elemento){
	for (x = 0; x <= myArray.length; x++) {  
	  if(myArray[x]==elemento){ 
	      return(true); 
	  }
	} 
}
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');
	}
	if(seguir == 1){	
		return(true);
	}
	else{
		return(false);
	}
}

function enviopregunta(id,pregunta,alias,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 = '/fnoticias/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 captch = '&capt_p='; //This is the path to the file we just finished making
    xmlhttp.open('GET', file + id + puntua + pregunta + sujeto + alias + 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 enviologin(logi,passw,recor,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 sujeto = '&record='; //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 + sujeto + recor + 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;
}
