// JavaScript Document

//**********************************************************************

	//Verificación de Campos que requieren ser llenados
	function IsVacio(n_form,n_campos,n_long,n_mensajes){
		theform="document."+n_form+".";
		//alert(theform);
		campos=n_campos.split(";");
		longit=n_long.split(";");
		mensaje=n_mensajes.split(";");
		for (i=0; i<campos.length; i++){
			if (eval(theform+campos[i]+".value.length < "+longit[i])){
				alert(mensaje[i]); eval(theform+campos[i]+".focus()");
				document.getElementById(campos[i]).style.backgroundColor="#FFFFCC";
				return (false);
			} else document.getElementById(campos[i]).style.backgroundColor="#FFFFFF";
		}
		return (true);
	}

	//Verificación de Campos que requieren ser numéricos
	function IsNumeric(n_form,n_campos,n_check,n_mensajes){
		theform="document."+n_form+".";	c_numericos=n_campos.split(";"); 
		checkOK=n_check.split(";");	mensaje=n_mensajes.split(";");
		for (x=0; x<c_numericos.length; x++){ 
			var checkStr = eval(theform+c_numericos[x]+".value"); 
			for (i = 0;  i < checkStr.length; i++)	{
				ch = checkStr.charAt(i);
				for (j = 0;  j < checkOK[x].length;  j++){
					if (ch == checkOK[x].charAt(j))	break;
				}
				if (j == checkOK[x].length){
					alert(mensaje[x]);
					eval(theform+c_numericos[x]+".focus()");
					document.getElementById(c_numericos[x]).style.backgroundColor="#FFFFCC";
					return (false);
				} else document.getElementById(c_numericos[x]).style.backgroundColor="#FFFFFF";
			}
		}
		return (true);
	}

	//Verificación de Campos List/Menu que requieren que no se escoja la primera opción
	
	function IsSelFirst(n_form,n_campos,n_mensajes){
		theform="document."+n_form+".";	campos=n_campos.split(";"); mensaje=n_mensajes.split(";");
		for (i=0; i<campos.length; i++){
			//if (eval(theform+campos[i]+".value.length < "+longit[i])){
			if (eval(theform+campos[i]+".selectedIndex == 0")){
				alert(mensaje[i]); eval(theform+campos[i]+".focus()"); 
				document.getElementById(campos[i]).style.backgroundColor="#FFFFCC";
				return (false);
			}
		}
		return (true);
	}

	//Verificación de Radio Button que requieren ser escojidos
	function IsCheck(n_form,n_campos,n_mensajes){
		theform="document."+n_form+".";	campos=n_campos.split(";"); mensaje=n_mensajes.split(";");
		for (var j=0; j<campos.length; j++){
			var radioSelected = false;
			for (var i=0;  i<eval(theform+campos[j]+".length"); i++){
				if (eval(theform+campos[j]+"["+i+"].checked")) radioSelected = true;
			}
			if (!radioSelected)	{
				alert(mensaje[j]);	return false;
			}
		}
		return true;
	}

	function IsEmail(n_form,emailstr,n_mensajes) {
		var theform="document."+n_form+".";	
		var email=eval(theform+emailstr+".value");
		var emailregexp = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
		if (emailregexp.test(email)==false){
			alert(n_mensajes); eval(theform+emailstr+".focus()");
			document.getElementById(emailstr).style.backgroundColor="#FFFFCC";
			return false;
		}
		return true;
	}

	function OpenWindow(url, name, w, h){
		config_line = "height="+h+",width="+w+",toolbar=0,menubar=0,scrollbars=1,resizable=0,location=0,status=0,directories=0";
		window.open(url, name, config_line);
	}
	

	function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i]){
					field.form.elements[i+1].style.backgroundColor="#E3EAF0";
					break;
				} else field.form.elements[i+1].style.backgroundColor="#FFFFFF";
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      
	
	function print_email(user, site, subject){
		document.write('<a href=\"mailto:' + user + '@' + site + '?subject=' + subject + '\">');
		document.write(user + '@' + site + '</a>');
	}
	