function jsCuenta(campo,maxvalor){
if (document.getElementById(campo).value.length<=(maxvalor-1))
	document.getElementById("char"+campo).value=document.getElementById(campo).value.length;
else{
	alert ("Maximun characters exceeded at "+document.getElementById(campo).title);
	document.getElementById(campo).value = document.getElementById(campo).value.substring(0,maxvalor) ;
	document.getElementById("char"+campo).value=document.getElementById(campo).value.length;
	return false;
	}
}
function jsCadenaOrden(){
	var cadena ="";
	var i;
	for (i=0;i<document.formulario.length;i++){
		cadena += document.formulario[i].name + "|";
	}
	document.formulario.cadena.value = cadena;
}
	
function jsValidaFormulario(){

	if (document.formulario.nombre.value==''){
		alert('Debe indicar su nombre');
		return false;
	}
	if (document.formulario.primerap.value==''){
		alert('Debe escribir su apellido');
		return false;
	}
	if (document.formulario.email.value==''){
		alert('Debe indicar una dirección de correo electrónico');
		return false;
	}
	else if (emilio(document.formulario.email.value)==false){
		alert('Debe indicar un correo electrónico válido');
		return false;
	}	
}
function emilio(contcorreo){
        //compruebo el emilio
                var correo=contcorreo;
                var fallo_correo = 0;
                var pos = correo.indexOf("@");
                
                if (pos == -1){
                        equivoc=1;
                        fallo_correo = 1;
                }
        
        //compruebo q tenga al menos 1 carácter antes y después de le arroba y el punto
                if ((pos == 0)||(pos == correo.length-1)) {
                        equivoc=1;
                        fallo_correo = 1;
                }
                
                var pos2 = correo.lastIndexOf(".");
                if((pos2 < pos+1)||(pos2 == correo.length-1)){
                        equivoc=1;
                        fallo_correo = 1;        
                }

                for (i=0; i<correo.length; i++){
                        if (correo.charAt(i)==" ") {
                        equivoc=1;
                        fallo_correo = 1;
                        }
                }
                
                if (fallo_correo==1){
                        //msje+="Se requiere una dirección de correo válida.\n";
						return false;
                }
}

function validar_fecha(field){
        //compruebo la fecha mientras la mete el usuario
        var checkstr = "0123456789";
        var DateField = field;
        var Datevalue = "";
        var DateTemp = "";
        var seperator = "/";
        var day;
        var month;
        var year;
        var leap = 0;
        var err = 0;
        var i;
   err = 0;
   DateValue = DateField.value;
   DateValue = DateField;   
	/* borra todos los caracteres excepto 0..9 */
   for (i = 0; i < DateValue.length; i++) {
          if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
             DateTemp = DateTemp + DateValue.substr(i,1);
          }
   }
   DateValue = DateTemp;
   /* Siempre cambio la fecha a 8 dígitos - cadena */
   /* si el año tiene 2 digitos/ se asume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* año incorrecto si es = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* valido mes*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* valido día*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* validación de año bisiesto */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* validacion de otros meses */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* Si se mete 00, directamente borro */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* si no hay error, lo meto en el campo */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Si el error es != 0 , mensaje */
   else {
     return false;
      DateField.select();
          DateField.focus();
   }
}


function checkeacampo(tipo,campo,form){
        /*
        validacion de campos; "tipo" nos dice si es cadena, numero, fecha, dni,... Con "campo" le paso dos
        cosas: el nombre del campo y  si es o no obligatorio. por eso lo primero que hago es esplitear cada
        valor en la matriz "obligatorio"; la cadena que llega es así: "campo_n!1". 1 es obligatorio y 0, no. 
        Y finalmente, "form" es el nombre del formulario.
        */
        var obligatorio=new Array();
        obligatorio=campo.split("!");
        switch (tipo) {
                case 1:
                //numero
                        if (isNaN(eval("document."+form+"."+obligatorio[0]+".value"))) {
                                equivoc=1;
                                msje+="· El campo '"+obligatorio[0]+"' debe ser un número.\n";
                        }
                        if ( ((eval("document."+form+"."+obligatorio[0]+".value"))=="") && (obligatorio[1]==1) ) {
                                equivoc=1;
                                msje+="· El campo '"+obligatorio[0]+"' es obligatorio.\n";
                        }
                break;
                case 21:
                //numero DNI; quito la validacion de numero
                        /*if (isNaN(eval("document."+form+"."+obligatorio[0]+".value"))) {
                                equivoc=1;
                                msje+="· El campo '"+obligatorio[0]+"' debe ser un número.\n";
                        }*/
                        if ( ((eval("document."+form+"."+obligatorio[0]+".value"))=="") && (obligatorio[1]==1) ) {
                                equivoc=1;
                                msje+="· El campo '"+obligatorio[0]+"' es obligatorio.\n";
                        }
                break;
                case 4:
                //fecha corta
                        if ( ((eval("document."+form+"."+obligatorio[0]+".value"))=="") && (obligatorio[1]==1) ) {
                                equivoc=1;
                                msje+="· El campo '"+obligatorio[0]+"' es obligatorio.\n";
                        }
                break;
                case 20:
                //correo
                if (obligatorio[1]==1) {
                        emilio("'"+(eval("document."+form+"."+obligatorio[0]+".value"))+"'","'"+obligatorio[0]+"'");
                }else if ((eval("document."+form+"."+obligatorio[0]+".value"))!=""){
                        emilio("'"+(eval("document."+form+"."+obligatorio[0]+".value"))+"'","'"+obligatorio[0]+"'");
                }
                break;
                case 12:
                //editor
                break;

                default:
                //texto
                        if ( ((eval("document."+form+"."+obligatorio[0]+".value"))=="") && (obligatorio[1]==1) ) {
                                equivoc=1;
                                msje+="· El campo '"+obligatorio[0]+"' es obligatorio.\n";
                        }
        }
}
/*ejempo de cadena:
validar('Idestado_civil!0|10#numero_hijos!0|1#f_nac!1|4#email!0|20#email2!0|20#Idlugar_nacimiento!0|10#','formulario')
*/
function validar(valor,nombreform){

        var matriz_obligatorios=new Array();
        matriz_obligatorios=valor.split("#");
        var longitud=(matriz_obligatorios.length)-1;
        var matriztipo=new Array(2);
        var matrizcampos=new Array();
        
        for (i=0;i<longitud;i++){
                matriztipo=matriz_obligatorios[i].split("|");
                matrizcampos[i]=matriztipo;
        }
        
        for (i=0;i<longitud;i++){
                eval("checkeacampo("+matrizcampos[i][1]+",'"+matrizcampos[i][0]+"','"+nombreform+"')");
        }
        
        if (equivoc==0){
                eval("document."+nombreform+".submit()");
        }else{
                alert(msje);
                equivoc=0;
                msje="Por favor, revise los errores en los siguientes campos:\n\n";
        }
}

letras = new Array("T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E");
function calculonif() {
		cad = new String(document.formulario.dni.value);
		while(cad.substring(0,1)=="0" && cad.length>1){
								  cad=cad.substring(1,cad.length);}
		indice=(document.formulario.dni.value)-(parseInt(cad/23)*23); 
		if (isNaN(document.formulario.dni.value)){
				document.formulario.nif.value="";
		}else{
				document.formulario.nif.value=letras[indice];
		}
}

function cambiarImagen(enlace,imagen){
        enlace.setAttribute('src',imagen);
        
}

function abrir(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function ConfirmarBorrado(direccion,titular){
        if (confirm(titular)){
                window.location = direccion;
        }        
}

function ConfirmarPop(titular,direccion,propiedades){
        if (confirm(titular)){
                abrir(direccion,'',propiedades);
        }        
}

function casilla(campo,id,url,formulario,idcambio,valor){
        document.location.href=url+"&id_registro="+id+"&campo="+campo+"&valor="+valor+"&idcambio="+idcambio;
}

function combo(formulario,id,nombrecampo,url,campoweb){
        aux_valorcambio=eval('document.'+formulario+'.'+nombrecampo+'.value');
        document.location.href=url+"&id_registro="+id+"&campo="+campoweb+"&valor="+aux_valorcambio;
}

anterior="";
function mostrar(id){
	//Anulado por la reunion &&(anterior!="subm_4")&&(anterior!="subm_7")
        if (((anterior!="")||(anterior==id))) {
                var queoculto=anterior+'.style.display="none"';
                eval(queoculto);
        }
        if ((id!='subm_0')&&(anterior!=id)&&(id!='subm_26')&&(id!='subm_27')){
                var quemuestro=id+'.style.display="inline"';
                eval(quemuestro);
                anterior=id;
        }else{
                anterior="";
        }
}

function busqueda(){
        /*var aux_termino=document.formul1.buscar.value;
		if (document.formul1.n_col.value=="1001"){*/
			document.formul1.submit();
		/*}else{
        	alert(aux_termino);
		}*/
}

function salto(formulario){
        eval("document."+formulario+".submit()");
}

function numero(formulario,nombrecampo){
        if (isNaN(eval("document."+formulario+"."+nombrecampo+".value"))){
                eval(("document."+formulario+"."+nombrecampo+".value=''"));
        }
}
function Google_Search(valor){
        /*
        <input type="text" name="w" size="15">
        <a href="javascript:Google_Search(document.forma)">Buscar en Google</a>
        */
  if(valor!=""){
        window.location="http://www.google.com/custom?q=" + valor + "&cof=LW:228;L:http://asp.pruebasifedes.com/EYF/imagen/logo.gif;LH:50;AH:center;AWFID:4200e643e223eac5;&safe=vss&vss=1&sa=Search&sitesearch=&domains=www.coev.com";
    //window.location="http://www.google.com/custom?q=" + inForm.w.value + "&cof=LW:228;L:http://www.coev.com/imagenes/logo.gif;LH:50;AH:center;AWFID:4200e643e223eac5;&safe=vss&vss=1&sa=Search&sitesearch=&domains=www.coev.com";
  }else{
    void(0);
  }
}
function denegar(tabla,id,idregop){
	if(confirm("Está seguro de denegar la presente solicitud?")){
		document.location.href="denegar.php?tabla="+tabla+"&id="+id+"&idregop="+idregop;
	}
	
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function mostrar2(nombreCapa){
if (document.getElementById(nombreCapa).style.display=="inline")
document.getElementById(nombreCapa).style.display="none";
else
document.getElementById(nombreCapa).style.display="inline";
}
function ocultar(nombreCapa){
document.getElementById(nombreCapa).style.display="none";
}
function mover(nombreCapa){
valor=document.getElementById(nombreCapa).style.top;
document.getElementById(nombreCapa).style.top='100';
} 
function valida_fecha(field){
        //compruebo la fecha mientras la mete el usuario
		var checkstr = "0123456789";
        var DateField = field;
        var Datevalue = "";
        var DateTemp = "";
        var seperator = "/";
        var day;
        var month;
        var year;
        var leap = 0;
        var err = 0;
        var i;
	   err = 0;
   DateValue = DateField.value;
   /* borra todos los caracteres excepto 0..9 */
   for (i = 0; i < DateValue.length; i++) {
          if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
             DateTemp = DateTemp + DateValue.substr(i,1);
          }
   }
   DateValue = DateTemp;
   /* Siempre cambio la fecha a 8 dígitos - cadena */
   /* si el año tiene 2 digitos/ se asume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* año incorrecto si es = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* valido mes*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* valido día*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* validación de año bisiesto */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* validacion de otros meses */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* Si se mete 00, directamente borro */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* si no hay error, lo meto en el campo */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Si el error es != 0 , mensaje */
   else {
	return false;
   }
}
extArray = new Array('jpg','jpeg','gif','png','bmp'); // <---- Extensiones válidas
function extension(file) {
	allowSubmit = false;
	if (!file) return;
	file = file.slice(file.lastIndexOf("\\")+1);
	// Sacamos el nombre del archivo (y solucionamos bug Opera 6)
	if (file.indexOf('"') != -1) {
		var archivo = file.substring(0,file.indexOf('"'));
		file = file.substring(0,file.indexOf('"'));
	} else {
		var archivo = file;
	}
	// Sacamos la extension del archivo y la pasamos a minusculas
	file = file.slice(file.lastIndexOf(".")+1);
	var ext = file.toLowerCase();
	// Comparamos con los elementos del array
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { 
			allowSubmit = true;
			break;
		}
	}
	// Si la extension no es válida, avisamos	
	if (!allowSubmit) {
		alert("Se permiten únicamente archivos de imagen con la extensión:\n" + (extArray.join(", ")) + "\n\nEl archivo " + archivo + " no es válido. Por favor, seleccione otro archivo e intente de nuevo.");
		allowSubmit = false;
		}
	return allowSubmit;
}
extArray2 = new Array('pdf','doc','word','rtf','xls','jpg','jpeg','gif','png', 'bmp', 'zip', 'rar', 'pps', 'ppt' ); // <---- Extensiones válidas
function extension2(file) {
	allowSubmit = false;
	if (!file) return;
	file = file.slice(file.lastIndexOf("\\")+1);
	// Sacamos el nombre del archivo (y solucionamos bug Opera 6)
	if (file.indexOf('"') != -1) {
		var archivo = file.substring(0,file.indexOf('"'));
		file = file.substring(0,file.indexOf('"'));
	} else {
		var archivo = file;
	}
	// Sacamos la extension del archivo y la pasamos a minusculas
	file = file.slice(file.lastIndexOf(".")+1);
	var ext = file.toLowerCase();
	// Comparamos con los elementos del array
	for (var i = 0; i < extArray2.length; i++) {
		if (extArray2[i] == ext) { 
			allowSubmit = true;
			break;
		}
	}
	// Si la extension no es válida, avisamos	
	if (!allowSubmit) {
		alert("Se permiten únicamente archivos de documentación con la extensión:\n" + (extArray2.join(", ")) + "\n\nEl archivo " + archivo + " no es válido. Por favor, seleccione otro archivo e intente de nuevo.");
		allowSubmit = false;
		}
	return allowSubmit;
}


