
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 = "";
}

Validator.prototype.empty = function(q) {
	for (i = 0; i < q.length; i++) {
	   if (q.charAt(i) != " ") {
	   	return false
	   }
	}
	return true
}

Validator.prototype.required = function(control,msg) {
	if (this.empty(control.value) == true) {
		this.valid = false;
		this.text = this.text+"<li>"+msg+"</li>";
		return false;
	}
	else
		return true;
}

Validator.prototype.checked = function(control,msg) {
	if (control.checked == false) {
		this.valid = false;
		this.text = this.text+"<li>"+msg+"</li>";
		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+"<li>"+msg+"</li>";
      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+"<li>"+msg+"</li>";
      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+"<li>"+msg+"</li>";
		return false;
	}
	else
		return true;
}

Validator.prototype.equal = function(ctrl1,ctrl2,msg) {
	if (ctrl1.value != ctrl2.value) {
		this.valid = false;
		this.text = this.text+"<li>"+msg+"</li>";
		return false;
	}
	else
		return true;
}

Validator.prototype.validate = function() {
	var fs = document.getElementById("error");
	if (fs != null)
		fs.parentNode.removeChild(fs);
	if (this.valid == false) {
		fs = document.createElement('fieldset');
		fs.setAttribute('id','error');
		fs.innerHTML = "<legend>ERROR:</legend><ul>"+this.text+"</ul>";
		this.form.insertBefore(fs,this.form.elements[0]);
		location.href = "#error";
	}
	var valid = this.valid;
	this.reset();
	return valid;
}

function swap(id1, id2)
{
   document.getElementById(id1).style.display = "none";
   document.getElementById(id2).style.display = "block";
}
function paper(id1, id2)
{
   document.getElementById(id1).style.display = "none";
   document.getElementById(id2).style.display = "block";
}

function checkAll(field)
{
	for (i = 0; i < field.length; i++)
		field[i].checked = true;
	return false;
}

function ShowHide(id, boton_mostrar, boton_ocultar) {
    if(document.getElementById(id).className != "oculta"){
		// mostrar
		document.getElementById(boton_ocultar).className = "oculta";
		document.getElementById(boton_mostrar).className = "muestra";
        document.getElementById(id).className = "oculta";
    } else {
		document.getElementById(boton_ocultar).className = "muestra";
		document.getElementById(boton_mostrar).className = "oculta";
        document.getElementById(id).className = "muestra";
    }
}
function confirmDel()
{
var agree=confirm("Are you Sure?");
if (agree)
return true ;
else
return false ;
}
