// Copyright de JhW (Jhons W. <jhons@nbc.com.uy>)
// <script language=Javascript1.2 src="form_validacion.js" type=text/javascript></SCRIPT>


function WCST_StripChars(theFilter,theString)
{
	var strOut,i,curChar;
	strOut = "";

	for (i=0;i < theString.length; i++)
	{		
		curChar = theString.charAt(i)
		if (theFilter.indexOf(curChar) < 0)
			strOut += curChar		
	}	
	return strOut
}

//-------------------------------------------------------------------------------//

function WCST_ValidateNonBlank(FormElement)
{
	if (FormElement.value == "")
	{
		if (leng == "es"){
	    	alert("El campo " + FormElement.name + " no puede estar vacío ");
		}
		if (leng == "en"){
	    	alert("The field " + FormElement.name + " cannot be empty ");
		}
		FormElement.focus();
	  return false
	}
	return true;
}

//-------------------------------------------------------------------------------//

function WCST_AllInRange(x,y,theString,Required)
{
	var i, curChar;
	var theLen = WCST_StripChars(" ",theString).length
	if (theLen == 0) 
	{
		if (Required) return false
		else return true;
	}
	for (i=0; i < theString.length; i++)
	{
		curChar = theString.charAt(i)
		if (curChar < x || curChar > y) return false
	}
	return true
}

//-------------------------------------------------------------------------------//

function WCST_ValidateEmail(FormElement,Required)
{
	var theString = FormElement.value;
	var elementName = FormElement.name;
   var theLen = WCST_StripChars(" ",theString).length;
   if (theLen == 0)
	{
	   if (Required)
		{
			if (leng == "es"){
		  		alert("Debe ingresar un e-mail. Ej. usuario@dominio.com");
			}
			if (leng == "en"){
		  		alert("It should enter an e-mail. E.g. user@domain.com");
			}
			FormElement.focus();
			return false
		}
		else return true;
   }
   if (theString.indexOf("@",0) < 0 || theString.indexOf(".")<0)
	{
			if (leng == "es"){
				alert("El e-mail ingresado no es válido. Ej. usuario@dominio.com");
			}
			if (leng == "en"){
				alert("The entered e-mail is not valid. E.g. user@domain.com");
			}
			FormElement.focus();
		return false
	}
	return true;
}

//-------------------------------------------------------------------------------//

function WCST_Trim(theString)
{
 var i,firstNonWhite

 if (WCST_StripChars(" \n\r\t",theString).length == 0 ) return ""

	i = -1
	while (1)
	{
		i++
		if (theString.charAt(i) != " ")
			break	
	}
	firstNonWhite = i
	//Count the spaces at the end
	i = theString.length
	while (1)
	{
		i--
		if (theString.charAt(i) != " ")
			break	
	}	

	return theString.substring(firstNonWhite,i + 1)

}

//-------------------------------------------------------------------------------//
