// JavaScript Document
function Validaciones(forma, campos, etq, idm) {
	
	var valores = campos.split(",");
	var nombres = etq.split(",");
	
	if (valores.length != nombres.length)
	{
		if (idm == "I") {
			alert ("Error validating current form");
		}
		else {
			alert ("Error validando el formulario actual");
		}
		return false;
	}
	else
	{
		
		var hilera = true;
		errores = "";
		for (i=0;i<valores.length;i++)
		{						
			valorcomp = "";
			switch(eval("document." + forma.name + "." + valores[i] + ".type")){
			case "select-one":
				valorcomp = -1;
				break;			
			}
			
			if (eval("document." + forma.name + "." + valores[i] + ".value") == valorcomp)
			{
				
				if (hilera)
				{
					if (idm == "I")
					{
						errores="Please verify\n -Field " + nombres[i] + " is required"					
					}
					else
					{
						errores="Por favor verifique\n -Campo " + nombres[i] + " es requerido"					
					}
					eval("document." + forma.name + "." + valores[i]).style.backgroundColor = "#FFFF99"
					hilera = false;
				}				
				else
				{					
					if (idm == "I")
					{
						errores = errores + "\n -Field " + nombres[i] + " is required";					
					}
					else
					{
						errores = errores + "\n -Campo " + nombres[i] + " es requerido";
					}					
					eval("document." + forma.name + "." + valores[i]).style.backgroundColor = "#FFFF99"
				}				
			}
		}		
		
		if (errores != "")
		{			
			alert(errores);
			return false;
		}
					
	}
	
	return true;
	//eval("document." + forma.name).submit();
}

function SeleccionaInput(forma,obj)
{
	eval("document." + forma.name + "." + obj.name).style.backgroundColor = "#FFFFFF"
}

//-------------------------------------------------------------------------------

function EMailAddressIsValid(strVal,idm) 
{
	var x = strVal;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) 
		return true;
	else
	{
		if (idm == "E")
			alert("Dirección de correo electrónico inválida. Por favor verifique");
		else
			alert("Invalid e-mail address. Please check.");
		return false;
	}

} 

//--------------------------------------------------------------------------------

	//Unicode key value info
	//-----------------------
	//Backspace = 8
	//Tab = 9
	//Enter = 13
	//Space = 32
	//Arrows (left, up, right, down) = 37, 38, 39, 40
	//Delete = 46
	//Dash (-) = 109 or 189
	//Numbers (0 to 9) = 48 to 57 (reg) and 96 to 105 (keypad)
	//-----------------------

	function solonumeros (e) {
		var unicode = e.charCode? e.charCode : e.keyCode;
		//alert(unicode);
		if (unicode != 37 && unicode != 38 && unicode != 39 && unicode != 40) { //if the key isn't one of the arrow keys (which we should allow)
			if (unicode != 8 && unicode != 9 && unicode != 13 && unicode != 46) { //if the key isn't the backspace key, delete key, tab key or enter key (which we should allow)
				if ((unicode < 48 || unicode > 57) && (unicode < 96 || unicode > 105)) { //if not a number
					return (false); //disable key press
				}
			}
		}
	}

	function solonumerosyguiones (e) {
		var unicode = e.charCode? e.charCode : e.keyCode;
		//alert(unicode);
		if (unicode != 37 && unicode != 38 && unicode != 39 && unicode != 40) { //if the key isn't one of the arrow keys (which we should allow)
			if (unicode != 8 && unicode != 9 && unicode != 13 && unicode != 46 && unicode != 109 && unicode != 189) { //if the key isn't the backspace key, delete key, tab key, enter key or the dash (-) (which we should allow)
				if ((unicode < 48 || unicode > 57) && (unicode < 96 || unicode > 105)) { //if not a number
					return (false); //disable key press
				}
			}
		}
	}
	
	function solomontos (e) {
		var unicode = e.charCode? e.charCode : e.keyCode;
		//alert(unicode);
		if (unicode != 190 && unicode != 37 && unicode != 38 && unicode != 39 && unicode != 40) { //if the key isn't one of the arrow keys (which we should allow)
			if (unicode != 8 && unicode != 9 && unicode != 13 && unicode != 46) { //if the key isn't the backspace key, delete key, tab key or enter key (which we should allow)
				if ((unicode < 48 || unicode > 57) && (unicode < 96 || unicode > 105)) { //if not a number
					return (false); //disable key press
				}
			}
		}
	}


//--------------------------------------------------------------------------------
function VPOPUP(myurl,Vwd,Vhg) 
{
	reWin = window.open(myurl,'determined','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+Vwd+',height='+Vhg+',top=100,left=100');
}

//--------------------------------------------------------------------------------
function VPOPUPscroll(myurl,Vwd,Vhg) 
{
	reWin = window.open(myurl,'determined','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+Vwd+',height='+Vhg+',top=100,left=100');
}

//--------------------------------------------------------------------------------
function VPOPUPcompleto(myurl,Vwd,Vhg) 
{
	reWin = window.open(myurl,'determined','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+Vwd+',height='+Vhg+',top=100,left=100');
}

//----------------------------------------------------------------------------------
function setfocus(campo)
{
	campo.focus();
}

//----------------------------------------------------------------------------------
var checkflag = "false";
var totalchecks = 0;
var inicio = 0;
function check(field) 
{		
	if (checkflag == "false") 
	{
		for (i = inicio; i < totalchecks; i++) 
		{						
			eval(field+i+".checked = true");
		}
		checkflag = "true";		
	}
	else 
	{
		for (i = inicio; i < totalchecks; i++) 
		{
			eval(field+i+".checked = false");
		}
		checkflag = "false";
	}
}

//--------------------------------------------------------------------------------------
//Longitud de un textarea
function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength)
}

//--------------------------------------------------------------------------------------
//Corrige un input de anos
function GenFixYearInput(YearField,CmpHD,CmpMS) {   
   var YearRE = new RegExp('\\d{' + YearField.defaultValue.length + '}');
   if (!YearRE.test(YearField.value)){ YearField.value = YearField.defaultValue };
   
   nuevoval = CmpMS.value +'/'+YearField.value
   CmpHD.value = nuevoval;
}

function GenMesInput(MesField,objYear,objHD)
{	
	objHD.value=MesField.value + '/' + objYear.value
}