function checkFormFields(){
	this.args = new Array();
}

checkFormFields.prototype.getType = function(formObj){
	var type = formObj.type;
	// Special Check for radio button
	if (! (type) && formObj.length > 0){
		type = formObj[0].type;
	}
	return type.toLowerCase();
}

checkFormFields.prototype.runFieldCheck = function(){
	this.form = arguments[0];
	this.args = arguments;
	var errorMSG =""

	for (i = 1; this.args.length > i; i = i+2){
		var formObj = eval("this.form." + this.args[i]);
		var type = this.getType(formObj);
		
		if (type == 'text' && ! this.validateText(formObj) ){
				errorMSG += "\n" + this.args[i + 1];
		}else if (type == 'checkbox' && ! this.validateCheckBox(formObj)){
				errorMSG += "\n" + this.args[i + 1];
		}else if(type == "select-one" && ! this.validateSelect(formObj) ){
				errorMSG += "\n" + this.args[i + 1];
		}else if(type == "select-multiple" && ! this.validateSelect(formObj) ){
				errorMSG += "\n" + this.args[i + 1];
		}else if(type == 'radio' && ! this.validateRadio(formObj)){
				errorMSG += "\n" + this.args[i + 1];
		}
	}
	
	if ( errorMSG.length ){
		alert("Please fill in the following fields:\n" + errorMSG);
	}
	return errorMSG.length > 0 ? false : true;
}

checkFormFields.prototype.validateCheckBox = function(formObj){
	return formObj.checked > 0 ? true : false;
}

checkFormFields.prototype.validateRadio = function(formObj){
	var value = false;
	for (var i = 0; formObj.length > i; i++){
		if (formObj[i].checked){
			value = true;
		}
	}
	return value;
}

checkFormFields.prototype.validateSelect = function(formObj){
	return formObj.selectedIndex > 0 ? true : false;
}

checkFormFields.prototype.validateText = function(formObj){
	return formObj.value.length > 0 ? true : false;
}
//
var formCheckObj = new checkFormFields();

