

/********* FUNCIONES DE VALIDACION DE FORMATO *****************/

function comprueba_mail(mail) {
  var re_mail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
  if (re_mail.test(mail)) {
    return true;
  } else {
    alert(mail + " no es una dirección de correo válida.");
    return false;
  }
}

function comprueba_nif(nif){

    dni=nif.substring(0,nif.length-1)
    letra=nif.charAt(nif.length-1)
    
    if (!isNaN(letra))
     {
        alert('El NIF debe tener 8 dígitos y una letra');
        return false;
     }                     
    else
     {
        cadena="TRWAGMYFPDXBNJZSQVHLCKET";
        posicion = dni % 23;
        letra2 = cadena.substring(posicion,posicion+1);
        if (letra2!=letra.toUpperCase())
         {
            alert("Nif no válido")
            return false
         }
     }
     return true;
}

function validarCIF(texto){ 
				var pares = 0; 
        var impares = 0; 
        var suma; 
        var ultima; 
        var unumero; 
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I"); 
        var xxx; 

				texto = texto.toUpperCase(); 
        
				if (texto.length != 9){
						alert('El CIF debe tener 9 dígitos');
						return false;
				}
				
        var regular =/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g; 
        
				if (!regular.exec(texto)) {
					alert('El CIF no es correcto');
					return false; 
				}
         ultima = texto.substr(8,1); 

         for (var cont = 1 ; cont < 7 ; cont ++){ 
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0"; 
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1)); 
             pares += parseInt(texto.substr(cont,1)); 
         } 
         xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0"; 
         impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1)); 
          
         suma = (pares + impares).toString(); 
         unumero = parseInt(suma.substr(suma.length - 1, 1)); 
         unumero = (10 - unumero).toString(); 
         if(unumero == 10) unumero = 0; 
          
         if ((ultima == unumero) || (ultima == uletra[unumero])){
         	return true; 
				 }else{
					alert('El CIF no es correcto');
         	return false; 
				 }

} 

function comprueba_select(obj,nombreCampo){
	 for (i=0;i<obj.length;i++){ 
			if ( obj.options[obj.selectedIndex].value != '' ){
				return true;
			}
	 }
	 alert('El campo '+ nombreCampo +' es obligatorio');
	 return false;
	
}



/********* VALIDACION DE NUMEROS **************/
function esEntero_Rango(obj,min,max){
	valor = obj.value;
    entero = parseInt(valor);
    if (isNaN(entero)){
    	alert("El valor no es correcto. Debe de ser un número entero de " + min + " a " + max);
	    return false;
    }
    if (min<= entero && entero <= max){
    	obj.value = entero;
    	return true;
    }else{
        alert("El valor no es correcto. Debe de ser un número entero de " + min + " a " + max);
	    return false;
    }
}


function esEntero(obj){
    valor = obj.value;
    entero = parseInt(valor);
    if (isNaN(entero)){
       alert("El valor no es correcto. Debe de ser un número entero");
        return false;
    }else{
        return true;
    }
}


function esNumero(obj){
    valor = obj.value;
    entero = parseFloat(valor);
    if (isNaN(entero)){
       alert("El valor no es correcto. Debe de ser un número");
	    return false;
    }else{
    	return true;
    }
}


function comprueba_blanco(obj, nombreCampo) {
  if (obj.value == "") {
    alert('El campo '+ nombreCampo +' es obligatorio');
    return false;
  } else {
    return true;
  }
}

function comprueba_radio(obj, nombreCampo) {
	 valor = false;
	 for (i=0;i<obj.length;i++){ 
       if (obj[i].checked){
				 	valor = true;
          break; 
			 }
   }
	 if (!valor){
		 	alert('El campo '+ nombreCampo +' es obligatorio');
	 		return false;
	 }else{
		return true; 
	}

	
}

function comprueba_radio2(obj) {
	 valor = false;
	 for (i=0;i<obj.length;i++){ 
       if (obj[i].checked){
				 	valor = true;
          break; 
			 }
   }
	 if (!valor){
	 		return false;
	 }else{
		return true; 
	}

	
}


/*********** *****************/

// voy a mostrat el objeto que me pasan con display o con visibility
function mostrarCapa(nombre){
   obj = eval(document.getElementById(nombre));
   if (eval(document.getElementById(nombre))){
	   if (obj.style.display == "block"){
	        obj.style.display = "none";
	   }else{
       		if (obj.style.display == "none"){
		        obj.style.display = "block";
            }
	   }
		 if (obj.style.visibility == "hidden"){
			obj.style.visibility = "visible";
		 }else{
			if (obj.style.visibility == "visible") obj.style.visibility = "hidden";
		 }
   }
}


function muestraCapa(nombre){
   obj = eval(document.getElementById(nombre));
   if (eval(document.getElementById(nombre))){
       if (obj.style.display == "none"){
            obj.style.display = "block";
       }
       if (obj.style.visibility == "hidden") obj.style.visibility = "visible";
         
   }
}

function ocultaCapa(nombre){
   obj = eval(document.getElementById(nombre));
   if (eval(document.getElementById(nombre))){
       if (obj.style.display == "block"){
            obj.style.display = "none";
       }
       if (obj.style.visibility == "visible") obj.style.visibility = "hidden";
         
   }
}
                
/********** VARIAS ***********/

//--------- Función para abrir popup --------------------
function NuevaVentana (MyURL, MyNombre, Ancho, Alto, PosX, PosY, Botones, CampoURL, BarraEstado, MenuNavegador, Scrolls, Redimensionable) {
  if (PosX == "c") {
    var CoordenadaX = (screen.width - Ancho) / 2;
  } else {
    var CoordenadaX = PosX;
  }
  if (PosY == "c") {
    var CoordenadaY = (screen.height - Alto) / 2;
  } else {
    var CoordenadaY = PosY;
  }
  Propiedades = 'width=' + Ancho + ',height=' + Alto + ',top=' + CoordenadaY + ',left=' + CoordenadaX +
                ',toolbar=' + Botones + ',location=' + CampoURL + ',status=' + BarraEstado +
                ',menubar=' + MenuNavegador + ',scrollbars=' + Scrolls + ',resizable=' + Redimensionable;
  win = window.open(MyURL, MyNombre, Propiedades);
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//--------- Función para agregar a favoritos --------------------

function Favoritos() {
  if (document.all){
    var url = "http://www.clubgentesaludable.com";
    var titulo = "Club Gente Saludable";
    window.external.AddFavorite(url,titulo);
  } else {
    if(navigator.appName == "Netscape")
    alert ("Presione Crtl+D para agregar este sitio en sus Bookmarks");
  } 
}


	function resizeImg(cualImg,ancho) { 
		var maxwidth = ancho; 
		var imagen = document.getElementById(cualImg); 
		if (imagen.width>maxwidth) { 
			imagen.width = ancho; 
		} 
	}
    

    
function valida_fecha(caja){ 
   var borrar;
   borrar = true;

      if ((caja.substr(2,1) == "/") && (caja.substr(5,1) == "/")){      
         for (i=0; i<10; i++){    
            if (((caja.substr(i,1)<"0") || (caja.substr(i,1)>"9")) && (i != 2) && (i != 5))
            {
               borrar = false;
               break;  
            }  
         }
         if (borrar){ 
            a = caja.substr(6,4);
            m = caja.substr(3,2);
            d = caja.substr(0,2);
            if((a < 1900) || (a > 2050) || (m < 1) || (m > 12) || (d < 1) || (d > 31))
               borrar = false;
            else
            {
               if((a%4 != 0) && (m == 2) && (d > 28))       
                  borrar = false; // Año no viciesto y es febrero y el dia es mayor a 28
               else    
               {
                  if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29)))
                     borrar = false;                                 
               }  // else
            } // fin else
         } // if (error)
      } else{
      borrar= false;
      }                            
     
      if (borrar == false) alert('Fecha erronea');
      return borrar;   
}


//la voy a utilizar para saltar la seguridad de windows
function carga_flash(archivo,pelicula,ancho,alto){
    
    document.write('<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width='+ancho+' height='+alto+'>'); 
    document.write('<param name=movie value="'+archivo+'" />') ;
    document.write('<param name=quality value=high />') ;
    document.write('<param name=wmode value=transparent />') ;
    document.write('<param name=flashvars value="&Banners='+pelicula+'" />') ;
    document.write('<embed src='+archivo+' quality=high pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash flashvars=&Banners='+pelicula+' width='+ancho+' height='+alto+'></embed>'); 
    document.write('</object>')
}

//la voy a utilizar para saltar la seguridad de windows
function carga_banner_flash(archivo,pelicula,ancho,alto){
    
    document.write('<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width='+ancho+' height='+alto+'>'); 
    document.write('<param name=movie value="'+archivo+'" />') ;
    document.write('<param name=quality value=high />') ;
    document.write('<param name=wmode value=transparent />') ;
    document.write('<param name=flashvars value="&Banners='+pelicula+'" />') ;
    document.write('<embed src='+archivo+' quality=high pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash flashvars=&Banners='+pelicula+' width='+ancho+' height='+alto+'></embed>'); 
    document.write('</object>')
}

//la voy a utilizar para saltar la seguridad de windows
function carga_videoflash(archivo,video,tiempo,ancho,alto){
    
    document.write('<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width='+ancho+' height='+alto+'>'); 
    document.write('<param name=movie value='+archivo+' />') ;
    document.write('<param name=quality value=high />') ;
    document.write('<param name=wmode value=transparent />') ;
    document.write('<param name="allowFullScreen" value="true" />') ;
    document.write('<param name=flashvars value="&archivo='+video+'&tiempo='+tiempo+'" />') ;
    document.write('<embed src='+archivo+' allowFullScreen="true" quality=high pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash flashvars="&archivo='+video+'&tiempo='+tiempo+'" width='+ancho+' height='+alto+'></embed>'); 
    document.write('</object>')
}

function imprSelec(nombre)
{
  var ficha = document.getElementById(nombre);
  var ventimp = window.open(' ', 'popimpr');
  
  ventimp.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
  ventimp.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
  ventimp.document.write('<head><title>Portal del Melanoma</title>');
  ventimp.document.write('<link href="printestilo.css" rel="stylesheet" type="text/css"/>'); 
  ventimp.document.write( ficha.innerHTML );
  ventimp.document.write( '</body></html>' ); 
  ventimp.document.close();
  ventimp.print( );
  ventimp.close();
} 

// quita espacios en blanco al prinicipio y al final de una cadena
function quitablancos(obj){
    cadena = obj.value;
    for(i=0; i<cadena.length; )
    {
        if(cadena.charAt(i)==" ")
            cadena=cadena.substring(i+1, cadena.length);
        else
            break;
    }

    for(i=cadena.length-1; i>=0; i=cadena.length-1)
    {
        if(cadena.charAt(i)==" ")
            cadena=cadena.substring(0,i);
        else
            break;
    }
    
    obj.value=cadena;

}  

// quita espacios en blanco en una cadena
function quitaTodosBlancos(c){ 
    
   var oc=new String(c.value),nt=new String(""),nc; 
    for(var q=0;q<oc.length;q++) 
    { 
    (oc.charAt(q)==' ')?nc='':nc=oc.charAt(q);   
    nt+=nc; 
    } 
    c.value=nt; 
    delete oc,nt; 

}

// quita caracter en una cadena
function quitaCaracter(c,caracter){ 
    
   var oc=new String(c.value),nt=new String(""),nc; 
    for(var q=0;q<oc.length;q++) 
    { 
    (oc.charAt(q)==caracter)?nc='':nc=oc.charAt(q);   
    nt+=nc; 
    } 
    c.value=nt; 
    delete oc,nt; 

}


    // maximizamos la ventana
function maximizar_ventana(){  
    window.moveTo(0,0);
    if (document.all) {
        top.window.resizeTo(screen.availWidth,screen.availHeight);
    }
    else if (document.layers||document.getElementById) {
        if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}

//--------- Función para abrir popup --------------------
function NuevaVentana (MyURL, MyNombre, Ancho, Alto, PosX, PosY, Botones, CampoURL, BarraEstado, MenuNavegador, Scrolls, Redimensionable) {
  if (PosX == "c") {
    var CoordenadaX = (screen.width - Ancho) / 2;
  } else {
    var CoordenadaX = PosX;
  }
  if (PosY == "c") {
    var CoordenadaY = (screen.height - Alto) / 2;
  } else {
    var CoordenadaY = PosY;
  }
  Propiedades = 'width=' + Ancho + ',height=' + Alto + ',top=' + CoordenadaY + ',left=' + CoordenadaX +
                ',toolbar=' + Botones + ',location=' + CampoURL + ',status=' + BarraEstado +
                ',menubar=' + MenuNavegador + ',scrollbars=' + Scrolls + ',resizable=' + Redimensionable;
  win = window.open(MyURL, MyNombre, Propiedades);
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}