//Validations for QForms

function getBoolean(s){
return (typeof s == "string" && s.length == 0);
}

function _Field_isPositiveNumber(){
	if (isNaN(this.value)){
		this.error = "The " + this.description + " field must contain a number.";
	} else {
		if (this.value < 0){
			this.error = "The " + this.description + " field must contain a number greater than or equal to zero.";
		}
	}
}
			
_addValidator("isPositiveNumber", _Field_isPositiveNumber);

function _Field_isRange2(low, high){
	var low = _param(arguments[0], 0, "number");
	var high = _param(arguments[1], 9999999, "number");
	if( isNaN(this.value) ){
		this.error = "The " + this.description + "field must contain a number.";
	} else {
		if( ( low > this.value ) || ( high < this.value ) ){
		this.error = "The " + this.description + " must be between " + low + " and " + high + ".";
		}
	}
}
_addValidator("isRange2", _Field_isRange2);

function _Field_isEndDateOK(StartField){
	
	if (getBoolean(eval(arguments[0] + ".isDate('yyyy-mm-dd')")) && getBoolean(this.isDate("yyyy-mm-dd"))) {
		var theStart = new Date();
		var theEnd = new Date();
		theStart = eval(arguments[0] + ".getValue()");
		theEnd = this.value;
		if (theEnd < theStart) {
			this.error = "The " + this.description + " must be later than the start date.";
		}
	}
}
_addValidator("isEndDateOK", _Field_isEndDateOK);

function _Field_isFutureDate(){
	
	if (getBoolean(this.isDate("yyyy-mm-dd"))) {
		var today = new Date();
		var theDate = new Date(this.value.substr(0,4), this.value.substr(5,2)-1, this.value.substr(8,2));
		if (theDate <= today) {
			this.error = "The " + this.description + " must be in the future.";
		}
	} else {
			this.error = "The " + this.description + " must be a valid date.";
	}
}
_addValidator("isFutureDate", _Field_isFutureDate);

