function focusNewsletter(tipo){
    if (tipo==1) document.getElementById('newsletterText').value='';
    else
        if (document.getElementById('newsletterText').value=='') document.getElementById('newsletterText').value='c@correo.com';
}
function suscribirNewsletter(){
    var email=trim(document.getElementById('newsletterText').value);
    if (mailValido(email)){
        var poststr='email='+email;
        AJAX('./images/','includes/ajax_files/suscribirNewsletter.php','post',poststr,NewsOk,nada,'','');
    }else{
        alert ('Por favor, introduzca un email valido.');
    }
}

function NewsOk(oXML){
    alert ('Suscripcion realizada, muchas gracias.');
}
function nada(){}

function mailValido(texto){

    var mailres = true;
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";

    var arroba = texto.indexOf("@",0);
    if ((texto.lastIndexOf("@")) != arroba){
    	 arroba = -1;
    	 return false;
    	}

    var punto = texto.lastIndexOf(".");

    for (var contador = 0 ; contador < texto.length ; contador++){
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     }
    }

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;

    return mailres;
}


function trim(cad){
   var res;
   var i;
   var IndiceInferior;
   var IndiceSuperior;

   res="";
   IndiceInferior=0;
   IndiceSuperior=0;

   if (cad.length==0) // cadena vacía
       return res;

   i=0;
   while (i<cad.length && cad.charAt(i)==" ")
      i++;

   IndiceInferior=i;

   if (i==cad.length) // cadena con solo espacios
       return res;

   i=cad.length-1;
   while (i>IndiceInferior && cad.charAt(i)==" ")
       i--;

   IndiceSuperior=i+1;

   return cad.substring(IndiceInferior, IndiceSuperior);
}

function ver_telefono(tipo,id){
    var poststr='id='+id+'&tipo='+tipo;
    AJAX('./images/','includes/ajax_files/mostrarTelefono.php','post',poststr,telefonoOk,telefonoKo,'','');
    return false;
}

function telefonoOk(oXML){
    document.getElementById('telefono').innerHTML=oXML;
}

function telefonoKo(){
    document.getElementById('telefono').innerHTML='Tel&eacute;fono no encontrado';
}

function showLoader(container){
    $(container).innerHTML='';
    var cl = new CanvasLoader(container);
    cl.setDiameter(22); //default is 40
    cl.setDensity(40); //default is 40
    cl.setRange(1.86); //default is 1.3
    cl.setSpeed(2); //default is 2
    cl.setFPS(40); //default is 24
    cl.setScaling(true); //default is false
    cl.setColor('#ff0181'); //default is '#000000'
}
