// JavaScript Document
function FormPolice(fname,flib) {
	this.fname = fname;
	this.lib = flib
}
FormPolice.prototype.checkAll = function() {
	var rt = true;
	for (i in this.lib) {
		var o = document.forms[this.fname].elements[this.lib[i][0]]
		rt = this.check(o)
	}
	
	if (!rt)
		rt = false
	
	return rt
	
}
FormPolice.prototype.check = function(o) {
	var check = true
	
	if (o.name) {
		
		tp = this.getType(o.name);
	}
	if (tp[0] == "not_null") {
		check = IsNull(o.value);
	}
	else if (tp[0] == "date") {
		check = IsDate(o.value);
	}
	else if (tp[0] == "date_later") {
		check = this.dateLater(o.value,tp[1]);
		}	
	else if (tp[0] == "decimal") {
		check = IsDecimal(o.value);
		}
	else if (tp[0] == "int") {
		check = IsNumber(o.value);
		}
	else if(tp[0] == "email") {
		check = IsEmail(o.value);	
	}
	else {
		alert("Tipo ainda não definido"+tp[0])
	}
	if (!check) {
		o.style.backgroundColor="#FF6666";
		return false
	}
	else { 
		o.style.backgroundColor="#FFFFFF";
		return true
	}
	
}
FormPolice.prototype.getType = function(nm) {
	
	for (i in this.lib) {
		//alert(this.lib[i] + " == "+ nm)
		if (this.lib[i][0] == nm)
			return [this.lib[i][1],this.lib[i][2]]
	}
	
}
FormPolice.prototype.dateLater = function(dt,field) {
	var resp
	 if (resp=IsDate(dt)) 
	 {
		 var dt = dt.split('/');
		 var dt2 = document.forms[this.fname].elements[field].value.split('/');
		 dt = new Date(dt[2],(dt[1]-1),dt[0]);
		 dt2 = new Date(dt2[2],(dt2[1]-1),dt2[0]);
		 var dif = dt -dt2
		 if (dif>=0)
		 	return true;
	 }
	 
	
}
FormPolice.prototype.onFocus = function(nm) {
	var cal = document.getElementById('popcalendar');
	if (cal) {
		cal.style.display="none";
	}
}