
//---------------------------------------------------

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 change_display(objectName) {
  var object = document.getElementById(objectName);
  if(object.style.display == '') object.style.display = 'none';
  else                           object.style.display = '';
 }


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 isTelefono(valor){
      //intento convertir a entero.
     //si era un entero no le afecta, si no lo era lo intenta convertir
	 
	//valor = parseInt(valor)

      //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
			if (valor<600000000 || valor>999999999){
				return false;
			}else{
				return true;
			}
      }
}

function isCP(valor){
      //intento convertir a entero.
     //si era un entero no le afecta, si no lo era lo intenta convertir
	 
	//valor = parseInt(valor)

      //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
			if (valor<00000 || valor>99999){
				return false;
			}else{
				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){
	//NO UTILIZAR PADDINGES EN EL ESTILO DE LAS IMÄGENES DONDE SE UTILICE ESTA FUNCIÓN
	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 = parseInt((heightactual/widthactual )*maxwidth);
				objeto.width = widthnuevo;
				objeto.height = heightnuevo;
			}else if (heightactual>maxheight){
				heightnuevo = maxheight;
				widthnuevo = (widthactual / heightactual)*maxheight;
				objeto.width = widthnuevo;
				objeto.height = heightnuevo;
			}
				
	}else if(widthactual<maxwidth && heightactual<maxheight){
		//es mas pequeña que las dimensiones
		correcto=false;
		//modifico los tamaños
			if (widthactual<maxwidth){
				widthnuevo = maxwidth;
				heightnuevo = (heightactual/widthactual )*maxwidth;
				objeto.width = widthnuevo;
				objeto.height = heightnuevo;
			}else if (heightactual<maxheight){
				heightnuevo = maxheight;
				widthnuevo = (widthactual / heightactual)*maxheight;
				objeto.width = widthnuevo;
				objeto.height = heightnuevo;
			}
	}else{
		correcto=true;
	}
	
	if (correcto===false){
		tamano_imagen(objeto, maxwidth, maxheight);
	}
}

function tamano_imagen2(objeto,maxwidth,maxheight,originalwidth,originalheight)
{
	//si el ancho original es mas grande que el ancho maximo o el alto original es mayor que el alto maximo...
	while(originalwidth > maxwidth || originalheight > maxheight)
	{
		//si el ancho original es mas pequeño que el ancho maximo...
		if(originalwidth < originalheight)
		{
			if(originalwidth > maxwidth)
			{
				originalheight = (originalheight/originalwidth )*maxwidth;
				originalwidth = maxwidth;
			//si el alto original es mas grande que el ancho maximo...
			}else{
				originalwidth = (originalwidth/originalheight )*maxheight;
				originalheight = maxheight;
			}
		//si el alto original es mas grande que el alto original...
		}else{
			//si el alto original es mas grande que el alto maximo...
			if(originalheight > maxheight)
			{
				originalwidth = (originalwidth/originalheight )*maxheight;
				originalheight = maxheight;
			//si el alto original es mas pequeño que el alto maximo...
			}else{
				originalheight = (originalheight/originalwidth )*maxwidth;
				originalwidth = maxwidth;
				
			}
		}
		
		//alert("originalwidth "+originalwidth+" originalheight "+originalheight);
	}
		 
	objeto.width = originalwidth;
	objeto.height = originalheight;
}

//alert('enlazado');

/* AJAX */
/*
function createQCObject() { 
   var req; 
   if(window.XMLHttpRequest){ // Firefox, Safari, Opera... 
      req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { // Internet Explorer 5+ 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
   } else { 
      alert('Problem creating the XMLHttpRequest object'); 
   } 
   return req; 
}*/

function objectAjax()
{
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		xmlhttp = new XMLHttpRequest();
	}catch(e){
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			// Creacion del objeto AJAX para navegadores no IE
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	return xmlhttp;
}

//----------------------------------------------------
