

function Validator(form) {
    this.form = form;
    this.valid = true;
    this.text = "";

}



Validator.prototype.form;

Validator.prototype.valid;

Validator.prototype.text;



Validator.prototype.getForm = function() {

    return this.form;

}



Validator.prototype.reset = function() {

	this.valid = true;

	this.text = "";

	$(this).removeClass("fielderror");

	

}



Validator.prototype.empty = function(q) {

	for (i = 0; i < q.length; i++) {

	   if (q.charAt(i) != " ") {

		   $(q).addClass("fielderror");

	   	return false

	   }

	}

	$(q).removeClass("fielderror");

	return true

}



Validator.prototype.required = function(control,msg) {

	if (this.empty(control.value) == true) {

		this.valid = false;

		this.text = this.text+""+msg+"\n";

		$(control).addClass("fielderror");

		return false;

	}

	else{

		$(control).removeClass("fielderror");

		return true;

	}

}



Validator.prototype.checked = function(control,msg) {

	if (control.checked == false) {

		this.valid = false;

		this.text = this.text+""+msg+"\n";

		return false;

	}

	else

		return true;

}



Validator.prototype.date = function(control,msg) {

   var expr = /^(\d{4})[/-](0[1-9]|1[012])[/-]([012][1-9]|3[01])$/;

   if (expr.test(control.value) == false) {

      this.valid = false;

      this.text = this.text+""+msg+"\n";

      return false;

   }

   else

      return true;

}



Validator.prototype.datetime = function(control,msg) {

   var expr = /^(\d{4})[/-](0[1-9]|1[012])[/-]([012][1-9]|3[01])\s*(\s(0\d|1\d|2[0-3]):([0-5]\d)(:([0-5]\d))?)?$/;

   if (expr.test(control.value) == false) {

      this.valid = false;

      this.text = this.text+""+msg+"\n";

      return false;

   }

   else

      return true;

}



Validator.prototype.email = function(control,msg) {

	if ((control.value.indexOf("@") == -1) || (control.value.indexOf(".") == -1)) {

		this.valid = false;

		this.text = this.text+""+msg+"\n";

		$(control).addClass("fielderror");

		return false;

	}

	else{

		$(control).removeClass("fielderror");

		return true;

	}

}



Validator.prototype.equal = function(ctrl1,ctrl2,msg) {

	if (ctrl1.value != ctrl2.value) {

		this.valid = false;

		this.text = this.text+""+msg+"\n";

		$(ctrl1).addClass("fielderror");

		$(ctrl2).addClass("fielderror");

		return false;

	}

	else{

		$(ctrl1).removeClass("fielderror");

		$(ctrl2).removeClass("fielderror");

		return true;

	}

}



Validator.prototype.validate = function() {

	if (this.valid == false) {

		alert("Error/s :\r\n\r\n"+this.text+"\r\n");

	}

	var valid = this.valid;

	this.reset();

	return valid;

}















Validator.prototype.validate = function() {

	if (this.valid == false) {

		alert("Error/s found:\r\n\r\n"+this.text+"\r\n");



	}

	var valid = this.valid;

	this.reset();

	return valid;

}

