//requires:
	//jquery
	//<form id="compForm">

//debugging
var firebug = (typeof console!='undefined')?console:{debug:function(){},log:function(){}};

function ClassFormValidation(){	
	this.init = function(){
		this.attachEvents();
	}
	this.attachEvents = function(){
		var objInst = this;
		$("#compForm").bind("submit",{objInst:objInst},function(e){
			return e.data.objInst.formValidate();
		})
	}
	this.formValidate = function(){
		var strUncompleteDefault = "WAIT! YOU MUST COMPLETE THE FOLLOWING FIELDS:\n";
		var strUncomplete = "";

		//check radio buttons
		var isMandatoryRadioChecked = false;	
		var arrMandatoryRadio = [];
		var strRadioTitle = "";
		$(".mandatory .radio").each(function(intIndex){
			strRadioTitle=$(this)[0].title;				
			var isChecked = $(this).attr("checked");
			if(isChecked){
				isMandatoryRadioChecked = true;				
			}		
		});
		if(!isMandatoryRadioChecked){
			strUncomplete+="\n" + strRadioTitle;
		}

		//check all inputs and select
		$("li.mandatory input,li.mandatory select").each(function(intIndex){
			var strTitle = $(this)[0].title;
			var strValue = $(this).val();
			if(strValue=="" || strValue.indexOf(" ")==0){
				strUncomplete+="\n" + strTitle;
			}
		});
		
		//display error to user
		if(strUncomplete!=""){
			strUncomplete = strUncompleteDefault + strUncomplete;
			alert(strUncomplete);
			return false;
		}
		return true;
	}

	this.init();
}


//onload
var objFormV
$(document).ready(function(e){
	objFormV = new ClassFormValidation();
});
