<!--
var checkObjects= new Array();
var errors= "";
var RetornoValor= false;
var language= new Array();
language["header"]= "The form cannot be processed, has happened the following thing:"
language["start"]= "->";
language["field"]= " The Field ";
language["require"]= " is required";
language["min"]= " and it must consist of at least ";
language["max"]= " and it must not contain but of ";
language["minmax"]= " and not more of ";
language["chars"]= " characters";
language["num"]= " and it must contain a number";
language["email"]= " it must contain a valid direction of electronic mail";

// -----------------------------------------------------------------------------
// defino - Call this function in the beginning of the page. I.e. onLoad.
// n = name of the input field (Required)
// type= string, num, email, FechaEuro (Required)
// min = the value must have at least [min] characters (Optional)
// max = the value must have maximum [max] characters (Optional)
// d = (Optional)
// -----------------------------------------------------------------------------

function defino(n, type, HTMLname, min, max, d) {
var p;
var i;
var x;
if (!d) d = document;
if ((p=n.indexOf("?"))>0&&parent.frames.length) {
d = parent.frames[n.substring(p+1)].document;
n = n.substring(0,p);
}
if (!(x = d[n]) && d.all) x = d.all[n];
for (i = 0; !x && i < d.forms.length; i++) {
x = d.forms[i][n];
}
for (i = 0; !x && d.layers && i < d.layers.length; i++) {
x = defino(n, type, HTMLname, min, max, d.layers[i].document);
return x;
}
eval("V_"+n+" = new formResult(x, type, HTMLname, min, max);");
checkObjects[eval(checkObjects.length)] = eval("V_"+n);
}
function formResult(form, type, HTMLname, min, max) {
this.form = form;
this.type = type;
this.HTMLname = HTMLname;
this.min  = min;
this.max  = max;
}

function Validar(TheForm) {
if (checkObjects.length > 0) {
errorObject = "";
for (i = 0; i < checkObjects.length; i++) {
validateObject = new Object();
/*
validateObject.form = checkObjects[i].form;
*/
validateObject.form = TheForm;
validateObject.HTMLname = checkObjects[i].HTMLname;
validateObject.val = checkObjects[i].form.value;
validateObject.len = checkObjects[i].form.value.length;
validateObject.min = checkObjects[i].min;
validateObject.max = checkObjects[i].max;
validateObject.type = checkObjects[i].type;
if (validateObject.type == "num" || validateObject.type == "string") {
if ((validateObject.type == "num" && validateObject.len <= 0) || (validateObject.type == "num" && isNaN(validateObject.val))) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['num'] + "\n";
} else if (validateObject.min && validateObject.max && (validateObject.len < validateObject.min || validateObject.len > validateObject.max)) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['min'] + validateObject.min + language['minmax'] + validateObject.max+language['chars'] + "\n";
} else if (validateObject.min && !validateObject.max && (validateObject.len < validateObject.min)) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['min'] + validateObject.min + language['chars'] + "\n";
} else if (validateObject.max && !validateObject.min &&(validateObject.len > validateObject.max)) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['max'] + validateObject.max + language['chars'] + "\n";
} else if (!validateObject.min && !validateObject.max && validateObject.len <= 0) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + "\n";
   }
}
else if(validateObject.type == "email") {
if ((validateObject.val.indexOf("@") == -1) || (validateObject.val.charAt(0) == ".") || (validateObject.val.charAt(0) == "@") || (validateObject.len < 6) || (validateObject.val.indexOf(".") == -1) || (validateObject.val.charAt(validateObject.val.indexOf("@")+1) == ".") || (validateObject.val.charAt(validateObject.val.indexOf("@")-1) == ".")) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['email'] + "\n"; }
      }
   }
}
if (errors) {
alert(language["header"].concat("\n" + errors));
errors = "";
RetornoValor = false;
} else {
RetornoValor = true;
   }
}
function trim(theString) //Remove Trailing spaces
{
	while(""+theString.charAt(theString.length-1)==" ")
		theString = theString.substring(0, theString.length-1);
	return(theString);		  					 
}

function checkIfEmpty(theString) //Check if string is empty  
{
	var bIsOk=true;
	if( typeof(theString) == "string" )
	{
  	  	if( trim(theString).length > 0 ) //Remove extra spaces and check the length 
	 	bIsOk = false;
	}
	return bIsOk;
}

function ltrim( theString ) //Remove leading spaces
{
	while(""+theString.charAt(0)==" ")
		theString = theString.substring(1, theString.length);
	return(theString);
}

function checkIfValidNumber(numberStr, decimals)
{
	// checks if the number is valid
	if( checkIfEmpty(numberStr) ) return true;

	if( decimals > 0 )
		var numberPat = "(^[\\-0-9]([0-9]*)\\.[0-9]{0,"+decimals+"}$)|(^[\\-0-9][0-9]*$)";
	else
		var numberPat = "(^[\\-0-9]([0-9]*)\\.[0-9]*$)|(^[\\-0-9][0-9]*$)";
	var toMatchstr=ltrim(trim(numberStr))
	var matchArray = toMatchstr.match(numberPat);
	if (matchArray == null)	return false;
	return true;
}
function checkIfValidPhone(numberStr, decimals)
{
	// checks if the number is valid
	if( checkIfEmpty(numberStr) ) return true;
	var numberPat = /^\+?[0-9 ()-]+[0-9]$/	
	//var numberPat = "(^[\\-0-9]([0-9]*)\\.[0-9]*$)|(^[\\-0-9][0-9]*$)";
	
	var toMatchstr=ltrim(trim(numberStr))
	var matchArray = toMatchstr.match(numberPat);
	if (matchArray == null)	return false;
	return true;
}
			
function checkIfValidEmail(emailStr)
{
	// checks if the e-mail address is valid
	if( checkIfEmpty(emailStr) ) return true;


	var emailPat = /^([a-zA-Z0-9\-_\.]*)@([a-zA-Z0-9\-_]*)(\.[a-zA-Z0-9\-_]*)+$/;
	var toMatchstr=ltrim(trim(emailStr))

	var matchArray = toMatchstr.match(emailPat);
	if (matchArray == null) return false;

	return true;
}


function CheckIfValidDate(dateStr, pattern, fieldname) 
{
	//Pattern can be MDY for month, date, year or DMY for date, month, year
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables

	if( checkIfEmpty(dateStr) ) return "OK";
	
	// To require a 2 digit year entry, use this line instead:
	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	// requires a 4 digit year entry:
	var errmes;
	 var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2,4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null)
	 {
		errmes = "Please enter a valid date.";
		return errmes;
	 }
	if( pattern.charAt(0).toUpperCase() == "D" )
	{
		//DMY format
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
	}
	else
	{
		//MDY format
		month = matchArray[1]; // parse date into variables
		day = matchArray[3];
		year = matchArray[4];	
	}
	if (month < 1 || month > 12) 
	{ 	// check month range
		errmes = "Month must be between 1 and 12.";
		return errmes;
	}
	if (day < 1 || day > 31) 
	{
		errmes = "Day must be between 1 and 31.";
		return errmes;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		errmes="Month "+month+" doesn't have 31 days!";
		return errmes;
	}
	if (month == 2) 
	{ 	// check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			errmes="February " + year + " doesn't have " + day + " days!";
			return errmes;
		}
	}
return "OK";  // date is valid
}	



function validateForm( objFrm )

//function FrontPage_Form1_Validator( objFrm)
{
	var errMessage;
	var tmpVar;
	var errCount=0;
	var allOk=true;
	var firstWrongField;
	errMessage = "";
	errCheck:	 
	do
	{
		
		if( checkIfEmpty(objFrm.name.value) ) //Check TextBox Test
		{
	 		if( typeof( firstWrongField ) != "object" ) //Identify first object with errors
			firstWrongField =objFrm.name;
			allOk=false;
			errMessage = errMessage + "\n - Please enter your name";
			if(++errCount > 10) break errCheck; //Stop if more then 10 errors detected  
		}
		if( checkIfEmpty(objFrm.email.value) ) //Check TextBox Test
		{
	 		if( typeof( firstWrongField ) != "object" ) //Identify first object with errors
			firstWrongField =objFrm.email;
			allOk=false;
			errMessage = errMessage + "\n - Please enter your email address";
			if(++errCount > 10) break errCheck; //Stop if more then 10 errors detected  
		}
		else
		{
			if( !checkIfValidEmail(objFrm.email.value) ) //Check Email validity
			{
	 			if( typeof( firstWrongField ) != "object" ) //Identify first object with errors
				firstWrongField =objFrm.email;
				allOk=false;
				errMessage = errMessage + "\n - Please enter a valid email address";
				if(++errCount > 10) break errCheck; //Stop if more then 10 errors detected  
			}
		}

	if( checkIfEmpty(objFrm.phone.value) ) //Check TextBox Test
		{
	 		if( typeof( firstWrongField ) != "object" ) //Identify first object with errors
			firstWrongField =objFrm.phone;
			allOk=false;
			errMessage = errMessage + "\n - Please enter a phone number";
			if(++errCount > 10) break errCheck; //Stop if more then 10 errors detected  
		}

		break errCheck;
	}
	while(true);
	
	if( !allOk )
	{
		if( errCount > 10 )
			errMessage = "Too many errors found!\n"+errMessage; 
		else
			errMessage = "Error(s) found!\n"+errMessage;			
		alert( errMessage ); //Display error message
		if( typeof( firstWrongField ) == "object" )	firstWrongField.focus(); //set focus to the first field with the error
	}
			
	return allOk; 	  
}

//--