
function fvalidaformularios(idnombrecampo, nombrecampo, tipocampo, imprescindible){
	error=""
	if (tipocampo=="email"){
		if (imprescindible=="si"){
			if (document.getElementById(idnombrecampo).value==""){
				error = "        • El campo "+nombrecampo+" es imprescindible, por favor rellenelo."+"\n";
			}else if (document.getElementById(idnombrecampo).value.indexOf ("@")==-1 || document.getElementById(idnombrecampo).value.indexOf (".")==-1 || document.getElementById(idnombrecampo).value.indexOf (" ")!=-1){
				error = "        • El campo "+nombrecampo+" no contiene un email correcto."+"\n";
			}	
		}else if (document.getElementById(idnombrecampo).value!=""){ 
			if (document.getElementById(idnombrecampo).value.indexOf ("@")==-1 || document.getElementById(idnombrecampo).value.indexOf (".")==-1 || document.getElementById(idnombrecampo).value.indexOf (" ")!=-1){
				error = "        • El campo "+nombrecampo+" no contiene un email correcto."+"\n";
			}
		}
		
	} else if (tipocampo=="texto"){
		if (imprescindible=="si"){
			if (document.getElementById(idnombrecampo).value==""){
				error = "        • El campo "+nombrecampo+" es imprescindible, por favor rellenelo."+"\n";
			}
		}
	} else if (tipocampo=="dni"){
		if (imprescindible=="si"){
			if (document.getElementById(idnombrecampo).value==""){
				error = "        • El campo "+nombrecampo+" es imprescindible, por favor rellenelo."+"\n";
			}
		}else if (document.getElementById(idnombrecampo).value!=""){
			cadena="TRWAGMYFPDXBNJZSQVHLCKET";
			numeros = "1234567890"; 
			letrasynumeros = cadena+numeros
			atexto = document.getElementById(idnombrecampo).value.toUpperCase()
			atexto = atexto.split ("");
			for (k=0;k<atexto.length;k++){
				if (letrasynumeros.indexOf (atexto[k])==-1){
					error = "        • El campo "+nombrecampo+", no contiene un DNI-NIF valido."+"\n";
					error += "        no utilice simbolos como \"-\" ó \"espacio\""+"\r";
					error += "        ejemplo: 1234567L"+"\r";
					break
				}
			}
			if (error==""){
				numero = document.getElementById(idnombrecampo).value.substring (0,document.getElementById(idnombrecampo).value.length-1)
				posicion = numero % 23
	
				letra1 = cadena.substring(posicion,posicion+1).toUpperCase()
				letra2 = document.getElementById(idnombrecampo).value.substring ((document.getElementById(idnombrecampo).value.length)-1).toUpperCase()
				if (letra1 != letra2){
					error = "        • El campo "+nombrecampo+", no contiene un DNI-NIF valido."+"\n";
	
				}			
			}	
		}
	} else if (tipocampo=="combo"){
		if (imprescindible=="si"){
			if (document.getElementById(idnombrecampo).value==0){
				error = "        • Seleccione una opción del campo "+nombrecampo+", es imprescindible."+"\n";
			}
		}
	}
	return error;
}
function focultofocus(){
	window.focus()
}
function fabrir(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
// DEJA ESCRIBIR NADA MAS QUE CIERTOS CARACTERES EN VARIABLE PERMITIDO, SIN COMAS EJEMPLO "12345678990", SERIAN LOS NOMUMEROS PERMITIDOS
function caracteres_campo_permitidos(permitido){
	apermitido=permitido.split("");
	x=0
	for (k=0;k<apermitido.length;k++){
		var key=window.event.keyCode;
		var chr = String.fromCharCode(key);
		if (chr==apermitido[k]){
			x=1;
			break;
		}
	}
	if (x==0){
		window.event.keyCode=0;		
	}

}
// NO DEJA ESCRIBIR NADA MAS QUE CIERTOS CARACTERES EN VARIABLE NOPERMITIDO, SIN COMAS EJEMPLO "12345678990", SERIAN LOS NOMUMEROS NO PERMITIDOS
function caracteres_campo_nopermitidos(nopermitido){

	anopermitido=nopermitido.split("");
	x=0
	for (k=0;k<anopermitido.length;k++){
		var key=window.event.keyCode;
		var chr = String.fromCharCode(key);
		if (chr==anopermitido[k]){
			x=1;
			break;
		}
	}
	if (x==1){
		window.event.keyCode=0;		
	}

}
function ftabindex(donde){
	if (donde =="alta"){
		index = new Array ('nombre', 'apellido1', 'apellido2', 'dia', 'mes', 'ano', 'direccion','cp', 'poblacion', 'ciudad', 'pais',  'sexo', 'email', 'emailalter', 'login','pass')
			for (k=0;k<index.length;k++){
				document.getElementById(index[k]).tabIndex =k+1
			}
	}
}
