    ///////////////////////////////////////////////////////////////////////////////
    // Copyright  2005-06 Roberto Flores Morfn. All Rights Reserved.           //
    //                                                                           //
    // This class is for private use. 													 //	
	// It is illegal to use use this code without the consent of Roberto Flores. //  
	// Please respect this intellectual property.                       		 //
    ///////////////////////////////////////////////////////////////////////////////

function Validate(){

	//Member variables
	this.error="";
	this.i=0;
	this.focus_var=new Array();

	//Regular expressions with their respective error alerts
	this.reg=new Array();
	this.mess=new Array();

		//Name
			this.reg['name']= new RegExp("(^[.A-Za-z ]+$)");
			this.mess['name']="-FIRST NAME-\n Please input your Name.";
			this.mess['lname']="-LAST NAME-\n Please input your Last Name.";


		//City
		this.reg['city']= new RegExp("(^[.A-Za-z ]{3,}$)");
			this.mess['city']="-CITY- \nPlease enter a valid city. Use only letters.";
			this.mess['country']="-COUNTRY- \nPlease enter your country. Use only letters and dots.";
		//ZIP Number
		this.reg['zip']= new RegExp("(^[0-9]{5}$)");
			this.mess['zip']="-ZIP- \nPlease enter a valid zip number, 5 digits.";
			
		//Phone Number
		this.reg['tel']= new RegExp("(^[-\(\)0-9]{5,15}$)");
		this.reg['area']= new RegExp("(^[0-9]{3}$)");
			this.mess['tel']="-TEL- \nPlease enter a valid phone number, max 15 digits.";
			this.mess['area']="-AREA CODE- \nPlease enter a valid area code number.";			


		//Address
		this.reg['address']= new RegExp("^([0-9]+[ ][ 0-9A-Za-z .#-]{5,})$");
		this.reg['address2']= new RegExp("^[-.0-9A-Za-z ]{5,}$");
			this.mess['address']="-ADDRESS- \nPlease correct your address, eg. 420 W San Ysidro Blvd. ste. L-200"; 
			
		//General drop menu
		this.reg['listmenu']= new RegExp("^([A-Za-z0-9]{2,})$");
			this.mess['state']="-STATE- \nPlease select your state"; 
			this.mess['cardType']="-CARD TYPE- \nPlease select a card type"; 
			this.mess['expMonth']="-CARD EXP. MONTH - \nPlease select a month"; 
			this.mess['expYear']="-CARD EXP. YEAR - \nPlease select a year"; 

		//E-mail
		this.reg['email']= new RegExp("^[a-zA-Z0-9_.\-]+@[A-Za-z0-9\-]+\\.[A-Za-z0-9\.]+$");
			this.mess['email']="-E-MAIL- \nPlease enter a valid E-mail.";

		//Social Security number
		this.reg['ssn']= new RegExp("^[0-9]{3}-[0-9]{2}-[0-9]{4}$");
			this.mess['ssn']="-SSN- \nPlease enter a valid social security number. eg. 053-27-0293.";

		//Credit card 16 numbers
		this.reg['card16']= new RegExp("^[0-9]{16}$");
			this.mess['card16']="-CARD NUMBER- \nKindly enter a correct card number, 16 digits, no dashes or spaces.";
			
		//Credit card CVS
		this.reg['cvs']= new RegExp("^[0-9]{3,4}$");
			this.mess['cvs']="-CARD CVS- \nKindly enter a correct CVS number, usually 3 digits.";

			
		//Common characters
		this.reg['common']= new RegExp("^[#-.()0-9A-Za-z ]{10,}$");
			this.mess['etiqueta']="-ETIQUETA- \nKindly enter a correct card number, 16 digits, no dashes or spaces.\n\n";



//Validation method 
    this.fieldRegMess=function(field,regExp,mess){

		var y=document.form1.elements[field];

		if(!y.value.match(this.reg[regExp])){
	
			this.error+=this.mess[mess]+"\n\n";
			y.className="error_field";			
			this.focus_var[this.i]=field;
			this.i=this.i+1;

		} 
		else {y.className="field"; }
	
		}

	// Message method
	this.Mensajes=function(){
		
		if(this.error){
		
			//Index Focus() 
			var tope=this.focus_var.length-1;
			this.focus_var.reverse();
			
			for (number=0; number<=tope; number=number+1) { 
				document.form1.elements[this.focus_var[number]].focus();					
			}

			//Create alert
			var temp=this.error;
			this.error=":::::::::: PLEASE CORRECT THE FOLLOWING INPUT FIELDS ::::::::::\n\n_____________________________________________________\n\n";
			this.error+=temp;
			
	
			// Send alert
			alert(this.error);
			
			//Reset variables
			this.error='';
			this.i=0;
			return false;
		}
	}
}