//Valida que el input contenga sólo números enteros
function noEntero(x, msg){ if(isNaN(x.value) || x.value.indexOf(".")!=-1 || x.value.indexOf("-")!=-1){Action(x, msg); return true}}

//Valida que el input contenga menos de i caracteres
function ValLen(x, i, msg) { if(x.value.length > i){Action(x, msg); return true} }

//Valida que el input contenga exactamente i caracteres
function ValLenExact(x, i, msg) { if(x.value.length != i){Action(x, msg); return true} }

//Quita los espacios sobrantes a izquierda y derecha en un input
function trim(x)
{
	while(x.value.substring(0,1)==" "){x.value = x.value.substring(1, x.value.length);}
	while(x.value.substring(x.value.length-1,x.value.length)==" "){x.value = x.value.substring(0, x.value.length-1);}
}

//Envia un mensaje y enfoca al elemento x
function Action(x, msg){alert(msg); x.focus();}

//Valida que no se deje un input vacio
function vacio(x, msg)
{
	trim(x);
	if(x.value == ""){Action(x, msg); return true}
}

//Valida que se capture un Email con @ y .
function wrongEmail(x, msg)
{
	if(x.value.indexOf("@") == -1){Action(x, msg); return true}
	if(x.value.indexOf(".") == -1){Action(x, msg); return true}
}

//Valida que se seleccione una opción en una lista o combo
function noSel(x, msg){ if(x.selectedIndex==0){Action(x, msg); return true}}

//Valida que se cheque un checkbox y optionbox
function noCheck(x, msg)
{
	var i;
	if (x.length > 1)
	{
		for(i=0; i<x.length; i++)
		{
			if(x[i].checked)
			{
				return false;
			}
		}
		Action(x[0], msg);
		return true;
	}
	else
	{
		if(x.checked)
			return false;
		else {
			Action(x, msg);
			return true;
		}
	}
}

//Valida que no se capturen acentos en los inputs
function noAccents(x, msg)
{
	if( x.value.indexOf("á")!=-1 || x.value.indexOf("é")!=-1 || x.value.indexOf("í")!=-1 || x.value.indexOf("ó")!=-1 || x.value.indexOf("ú")!=-1 ){Action(x, msg); return true}
	if( x.value.indexOf("Á")!=-1 || x.value.indexOf("É")!=-1 || x.value.indexOf("Í")!=-1 || x.value.indexOf("Ó")!=-1 || x.value.indexOf("Ú")!=-1 ){Action(x, msg); return true}
}

//Valida que no se capturen espacios en los inputs
function noSpaces(x, msg)
{
	if( x.value.indexOf(" ")!= -1 ){Action(x, msg); return true}
}

//Valida que no se capturen caracteres especiales que
//corrompan las consultas SQL
function noSpecial(x, msg)
{
	if( x.value.indexOf('"')!=-1 || x.value.indexOf("'")!=-1 || x.value.indexOf("%")!=-1 || x.value.indexOf("#")!=-1  || x.value.indexOf("*")!=-1 ){Action(x, msg); return true}
}

//Utilizada para abrir las descripciones de los productos para los trivianautas
function NewWin(filename,winname, w, h)
{
	winOptions = eval("'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + w + ",height=" + h + "'");
	window.open(filename,winname, winOptions);
	return; 
}

//Esta función enfoca el primer campo de la primera forma encontrada en la página
function enfoca() {
	var form1, element1;

	//extrae la primera forma de la página
	form1 = document.forms[0];
	if(form1 && document.getElementById)
	{
	  //cicla todos los elementos de la forma
	  for (i=0; i < form1.length; i++) 
	  {
	  	//extrae el elemento
	    element1 = form1.elements[i];		
		if(element1 && document.getElementById)
		{
			//verifica que sea tipo texto
			if (element1.type == "text")
			{
			  //enfoca el elemento
			  element1.focus();
			  return true;
			}
		}
	  }
	}
}