function setImagen(archivo,posicion,nombredivima){
	oDivImg=document.getElementById(nombredivima);
	oImg=document.getElementById(posicion);
	oFile=document.getElementById(archivo);
	oDivImg.style.visibility='visible';
	oImg.width=100;
	oImg.src=oFile.value;
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   }
function isInteger(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   }

function isMonth(mes)
{
 if (! isNumeric(mes) || mes<1 || mes>12)
   {
   return false
   }
   return true;
 
}

function isDay(dia)
{
 if (! isNumeric(dia) || dia<1 || dia>31)
   {
   return false
   }
   return true;
 
}
//function for hidde objects
function hidde_object(id_tag,id_ima,id_hidden,nom_ima_1,nom_ima_2) {
			var mhd = document.getElementById(id_tag);
			var img = document.getElementById(id_ima);
			var hdd = document.getElementById(id_hidden);
			var ima_0 = nom_ima_1;
			var ima_1 = nom_ima_2;
			if(hdd.value=='c' || hdd.value=='') {
				mhd.style.display = 'none';
				hdd.value='e';
				img.src=ima_1;
			
			} else {
				mhd.style.display = '';
				hdd.value='c';
				img.src=ima_0;
				
			}
		}
function isBlanco(cadena)
{
	var s = new String(cadena);
	while (s.indexOf(" ") != -1)
	{
 		s=s.replace(" ","")
	}
	if ( s.length == 0)	return true; 
		else return false;
}

/// envia los formularios si campo no es blanco es paera poner en los onblur
// de los campos claves 
function tmj_enviar(campo,formulario)
{
		f = eval("document.forms"+"."+formulario)
		if(!isBlanco(campo.value)) f.submit();
}

// funcion para cuando se apreta el boton guardar 
function tmj_guardar(modulo,valor) //"usuario", "guardar"
{
	
	funcion = "validar_"+modulo+"()"; //"validar_usuario"
	if (eval(funcion))
	{
		eval("document.forms.frm_"+modulo+".operacion.value='guardar';")
		eval("document.forms.frm_"+modulo+".submit()")
	}
}
// funcion para cuando se apreta el boton eliminar
function tmj_eliminar(modulo,valor)
{

	eval("document.forms.frm_"+modulo+".operacion.value='"+valor+"';")
	eval("document.forms.frm_"+modulo+".submit()")
}
function validarEmail(valor){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
  //if (/^\w+([-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){		
    	return true
	}else{
		//alert("El formato del e-mail no es válido");
		return false;
	}
}

/*** validacion de cta de espania **/

		/**
		 * Validación de los datos introducidos
		 * 
		 * Validación general y llamada a la comprobación de cuenta corriente
		 *
		*/
		function tmj_validate_cta(entidad,oficina,dc,cta){
       
       		var str_error = "";
       		var arrCC = new Array(entidad, oficina,
       	       		              dc, cta);
       		
       	    /*
       	     * Si algún campo no ha sido completado satisfactoriamente cambiar su estilo,
       	     * darle el foco y mostrar el error
       	    */
       		for (i=3;i>=0;i--){
       			if (arrCC[i].getAttribute("maxlength") != arrCC[i].value.length) {
       				arrCC[i].setAttribute("class","incompleto");
       				str_error = "No ha completado todos los datos";
       				arrCC[i].focus();
       			};
       		};
       		
       		if ("" != str_error) {
       			//alert (str_error);
				return str_error;
       			//return false;
			};
       		
			/*
			 * Comprobar la cuenta corriente introducida
			*/
 	  		if (checkDC(arrCC[0].value+arrCC[1].value,arrCC[3].value,arrCC[2].value))
			{
				//alert ("Ok");
				//return true;
			}    
    		else
			{
    			//alert ("La cuenta corriente introducida no es correcta.\nPor favor, compruebe los datos.");
				str_error+="La cuenta corriente introducida no es correcta.\nPor favor, compruebe los datos.";
				arrCC[0].focus();
				//return false;
			}
       		return str_error;
		} // end validate()
		
		/**
		 * Filtrado de los valores introducidos en los campos de texto
		 * 
		 * Sólo permite introducir números, y cambia el estilo del campo si ha sido completado
		 * hasta el máximo de su longitud.
		 *
		 * IN: object objecto Campo sobre el que realizar el filtrado
		*/
		function filter(field){
       	    
			/*
			 * Eliminar todos los caracteres no numéricos del campo
			*/
     		field.value = field.value.replace(/\D/,"");
		
     		/*
     		 * Si el campo se ha completado hasta su maxima extensión cambiar su estilo
     		*/
        	if (field.getAttribute("maxlength") == field.value.length)
        		field.setAttribute("class","completo");
        	else
        		field.setAttribute("class","incompleto");

		} // end filter()
		
		/**
		 * Mostrar el código fuente del documento actual
		 *
		 * IN: bool onNewWindow Abrir en nueva ventana
		*/
		function viewSource(onNewWindow){
			
			if (onNewWindow == true)
				window.open("view-source:"+document.location.href,"Source");
			else
				document.location = "view-source:"+document.location.href;
				
		} // end viewSource()
			
		/**
		 * Validación de una cuenta corriente
		 * 
		 * Comprueba un número de cuenta corriente
		 *
		 * IN:  cc1	 string	 Primeros ocho dígitos de la cuenta corriente (entidad.oficina)
		 * IN:  cc2  string  Últimos diez dígitos de la cuenta corriente  (#cuenta)
		 * IN:  dc   string  Dígitos de control
		 * OUT:      bool    ¿Cuenta válida? 
		*/
		function checkDC(cc1,cc2,dc){
            
			/*
			 * Comprobar que los datos son correctos
			*/
     		if (!(cc1.match(/^\d{8}$/) && cc2.match(/^\d{10}$/) && dc.match(/^\d{2}$/) )) return false;
       	    
	   	    var arrWeights = new Array(1,2,4,8,5,10,9,7,3,6);	// vector de pesos
    		var dc1=0, dc2=0;
       	    
    		/*
    		 * Cálculo del primer dígito de cintrol
    		*/
   		    for (i=7;i>=0;i--) dc1 += arrWeights[i+2] * cc1.charAt(i);
    		dc1 = 11 - (dc1 % 11);
  		    if (11 == dc1) dc1 = 0;
   		    if (10 == dc1) dc1 = 1;
       	    
   		    /*
   		     * Cálculo del segundo dígito de control
   		    */
   		    for (i=9;i>=0;i--) dc2 += arrWeights[i] * cc2.charAt(i);
    		dc2 = 11 - (dc2 % 11);
   		    if (11 == dc2) dc2 = 0;
    		if (10 == dc2) dc2 = 1;
       	    
    		/*
    		 * Comprobar la coincidencia y delvolver el resultado
    		*/
     		return (10*dc1+dc2 == dc);	// Javascript infiere tipo entero para dc1 y dc2
  	    
		} // end checkDC()
		


