
//---------------------------------------------------

function escribeLetra(dni_numero){
  var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
  var numero = dni_numero%23;
    return letras.substring(numero, numero+1);
}

function isEmail(string) {
  if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
   return true;
  } else {
   return false;
  }
}

function isEntero(valor){
      //intento convertir a entero.
     //si era un entero no le afecta, si no lo era lo intenta convertir
	 
	//valor = parseInt(valor)
		valor=valor.replace(".","");
		valor=valor.replace(".","");
		valor=valor.replace(".","");
		
      //Compruebo si es un valor numérico
      if (isNaN(valor)) {
            //entonces (no es numero) devuelvo el valor cadena vacia
            return false;
      }else{
            //En caso contrario (Si era un número) devuelvo el valor
            return true;
      }
}


function abrirImagen(nombre,ancho,alto) {
	dat = 'width=' + ancho + ',height=' + alto + ',left=100,top=100,scrollbars=no,resize=no';
	window.open(nombre,'',dat);
}

// Esta función permitirá validar la fecha
// En el objeto text hacemos lo Siguiente
/*
   <input type=\'text\' name=cajaFecha onChange=\'fechas(this.value); this.value=borrar\'>
*/
function fechas(caja)
{ 
   if (caja)
   {  
      borrar = caja;
      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 = '';
               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 = '';
		    else
		    {
		       if((a%4 != 0) && (m == 2) && (d > 28))	   
		          borrar = ''; // 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 = '';	      				  	 
			   }  // else
		    } // fin else
         } // if (error)
      } // if ((caja.substr(2,1) == "/") && (caja.substr(5,1) == "/"))			    			
	  else
	     borrar = '';
	  if (borrar == '')
	     alert('Fecha erronea');
   } // if (caja)   
} // FUNCION


function tamano_imagen(objeto, maxwidth, maxheight){
	var widthactual;
	var heightactual;
	var widthnuevo;
	var heightnuevo;
	
	widthactual = objeto.width;
	heightactual = objeto.height;
	
	if (widthactual>maxwidth || heightactual>maxheight){
		correcto=false;
		//modifico los tamaños
			if (widthactual>maxwidth){
				widthnuevo = maxwidth;
				heightnuevo = (heightactual/widthactual )*maxwidth;
				//alert(heightnuevo);
				objeto.width = widthnuevo;
				objeto.height = heightnuevo;
			}else if (heightactual>maxheight){
				heightnuevo = maxheight;
				widthnuevo = (widthactual / heightactual)*maxheight;
				//alert(widthnuevo);
				objeto.width = widthnuevo;
				objeto.height = heightnuevo;
			}
				
	}else{
		correcto=true;
	}
	
	if (correcto===false){
		tamano_imagen(objeto, maxwidth, maxheight);
	}	/*else { 
		alert(widthactual + 'x' + heightactual);
	}*/
}
//----------------------------------------------------