
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 checkAll(field)
{
	for (i = 0; i < field.length; i++)
		field[i].checked = true;
	return false;
}

function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}

function ShowHide(div3,div4) {
    if(document.getElementById(div3).className != "oculta"){
		
        document.getElementById(div3).className = "oculta";
		document.getElementById(div4).className = "muestra";
    } else {
		
        document.getElementById(div3).className = "muestra";
		document.getElementById(div4).className = "oculta";
    }
}




function confirmDel()
{
var agree=confirm("Are you Sure?");
if (agree)
return true ;
else
return false ;
}