// Validator -- validates html forms
// (c) 2004 Born Interactive
/*
:: USAGE :: 
	
	var myValidator = new Validator("myForm");
	return myValidator.validate([
		"funcName,field1,Real Field Name,error message1",
		"funcName2,field2,Real Field Name,error message2"
	]);
	
*/

function Validator(formName)
{
	  this.formName = formName;
}

function aply(func,txt) {
	var a = this.formName ;
	if (func && (eval("document."+a+"."+txt))){
		return eval(func+"(document."+a+"."+txt+")");
	}
}	


function  validate (a) {
	var str = "";
	for(var i = 0 ; i < a.length ; i++) {
		var m = a[i].split(",") ;
		if ([m[0]] && !this.aply(m[0],m[1])) {
			str += "  "+m[2]+" :: "+(m[3] ? m[3] : "Field is not valid")+"\n" ;
		}
	}	
	if (str.length > 0) {
		str = "The information submitted is incomplete.\n please make sure all required fields are filled in order to proceed. \n-------------------------------------------------------------------------\n" + str;
		return str;
		//alert(str); 
		//return false;
	} 
	return true  ; 
}

Validator.prototype.validate = validate;
Validator.prototype.aply = aply;

/////////////////////////////////////// VALIDATION FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// add your functions below

function IsValidEmail(txt){
	if(txt.value !=""){ 
		var goodEmail = txt.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (goodEmail){
			return true;
		} else {
			return false;
		}
	}
}

function isNotEmpty(txt) {
	if (txt.value.length > 0)
	      return true ;
	 else return false ;
}

function isNumber(txt) {
	if(isNaN(parseInt(txt.value))){
		return false ;
	} else {
		//txt.value = parseInt(txt.value);
		return true;
	}
} 		
