/**
 *  @Class Validator is used to validate form fields.
 * 	@param fn is the text form name that we are validating. 
 * 	@param btn is the button we are using to submit.
 **/
var Validator = new Class({
	initialize: function(fn, btn) {
		this.msg=$('err_message');
		this.frm=$(fn);
		this.btn=$(btn);
		this.cn="vldtr";
		this.errs=new Array();

		this.fieldList=$$('*').filterByClass('vldtr') ;

		this.btn.addEvent('click', this.validate.bindWithEvent(this) ) ;
	},
	validate: function(e)
	{
		e.stop();

		this.isEmpty=[];
		
		this.isEmpty=this.fieldList.filter(function(item, index){ 
									if("SELECT"!=item.tagName && !item.value) 
										return item;
									else if(item.name=="eula" && item.checked==false)
										return item;
									else if(item.tagName=="SELECT" && item.value=="Please Select")	
										return item;
									else
									{
										item.removeClass('error_border');
										item.removeClass('error_text');
										item.getNext().removeClass('error_text');
										item.getParent().getParent().getFirst().getFirst().removeClass('error_text');
									}
								});

		if(0<this.isEmpty.length)
		{
			// show the message
			this.msg.style.display="block";
			this.isEmpty.each(function(el,i) 
								{ 
									asx=el.getNext();
									lbl=el.getParent().getParent().getFirst();
									if(el.tagName!="SELECT")
										el.addClass('error_border');
									else
										el.addClass('error_text');

									lbl.getFirst().addClass('error_text');
									asx.addClass('error_text');
								} );
		}
		else
		{
			this.msg.style.display="none";;
			this.frm.submit();
		}
	}
});

