<!--
function XInput(form_index, name, msg, format_check, required){
	this.form_index = form_index || 0;
	this.name = name;
	this.msg = msg;
	this.format_check= format_check;
	this.required= required;
	this.type = eval('document.forms[this.form_index].' + this.name + '.type');
	if(this.type == 'text' || this.type == 'textarea'){
		this.value = eval('document.forms[this.form_index].' + this.name + '.value')
	}
	else if(this.type == 'select-one'){
		this.value = eval('document.forms[this.form_index].' + this.name + '.options[document.forms[this.form_index].' + this.name + '.selectedIndex].value')
	}
}
function XValidator(inputs, form_index){
	this.show_alert = false;
    this.required_string = '';
    this.format_string = '';
	this.form_index = form_index || 0;
	this.inputs = inputs;
	this.validate = XValidatorValidate;
	this.format_email = XValidatorFormat_email;
	this.format_phone = XValidatorFormat_phone;
	this.format_cost = XValidatorFormat_cost;
 	this.format_drop_down = XValidatorFormat_drop_down;
	this.process_input = XValidatorProcessInput;
	this.check_required = XValidatorCheck_required;
	this.warn = XValidatorWarn;
}
function XValidatorValidate(){
	for(count=0; count < this.inputs.length; count++){ this.process_input(count); }
	return this.warn();
}
function XValidatorProcessInput(count){
	if (this.inputs[count].format_check == 'e_mail'){ this.format_email(count); }
	else if(this.inputs[count].format_check == 'phone'){ this.format_phone(count); }
	else if(this.inputs[count].format_check == 'cost'){ this.format_cost(count); }
	else if(this.inputs[count].format_check == 'drop_down'){ this.format_drop_down(count);  }
	this.check_required(count);
}
function XValidatorCheck_required(count){
	var value;
	if(this.inputs[count].required == true){
		if(this.inputs[count].value == ''){
			this.show_alert = true;
			this.required_string += "       " + this.inputs[count].msg + "\n";
		}
	}
}
function XValidatorFormat_drop_down(count){
	if(this.inputs[count].value == 'empty'){
		this.format_string += "* The field " + this.inputs[count].msg + " must be selected.\n";
		this.show_alert = true;
	}
}
function XValidatorFormat_email(count){
	var at = this.inputs[count].value.indexOf("@");
	if(at > 0){ var dot = this.inputs[count].value.lastIndexOf("."); }
	if(this.inputs[count].value != '' && at<1 || (dot<=at+1) || (dot>=(this.inputs[count].value.length-2))){
		this.format_string += "* The field " + this.inputs[count].msg + " must be in the format (user@I-provider.com).\n";
		this.show_alert = true;
	}
}
function XValidatorFormat_phone(count){
	var good = 1;
	var strValidChars = "-0123456789";
	if(this.inputs[count].value){
		for(i = 0; i < this.inputs[count].value.length; i++){
			if (strValidChars.indexOf(this.inputs[count].value.charAt(i)) == -1){ good = 0; }
		}
	}
	if(good == 0){
		this.format_string += "* The field " + this.inputs[count].msg + " must only contain numbers [0-9] and/or dashes [-].\n";
		this.show_alert = true;
	}
}
function XValidatorFormat_cost(count){
	var good = 1;
	var strValidChars = "0123456789";
	if(this.inputs[count].value){
		for(i = 0; i < this.inputs[count].value.length; i++){
			if (strValidChars.indexOf(this.inputs[count].value.charAt(i)) == -1){ good = 0; }
		}
	}
	if(good == 0){
		this.format_string += "* The field " + this.inputs[count].msg + " must only contain numbers [0-9].\n";
		this.show_alert = true;
	}
}
function XValidatorWarn(){
	if(this.show_alert == true){
		default_msg = "______________________________________________________\n\n";
		default_msg +="The form was not submitted because of the following error(s).\n";
		default_msg +="Please correct these error(s) and re-submit.\n";
		default_msg += "______________________________________________________\n\n";
		if(this.required_string != ''){ default_msg += "* The folowing required fileds are empty:\n" + this.required_string; }
		if(this.format_string != ''){ default_msg += "\n" + this.format_string }
		alert(default_msg);
		return false;
	}
}
//-->
