/* ******************************************
	Primary object prototype--pass it a text
	or textarea and it creates a validation 
	object with various properties
*********************************************/ 
function Validator(obj, usrName, dataType, regExpObj, regScope){ 		
	this.elem = obj
	this.usrName = usrName
	this.dType = (dataType) ? dataType: null
	this.regExpObj = (regExpObj) ? regExpObj: ""
	this.regScope = regScope
}

/* *****************************
	Declare mValid function
*******************************/
function mValid()	{
	var strMsg = "";
	var objValue;
	var bolCustomVal;
	//custom1 is a selelct field
	if(this.dType == "Custom1")	{
	  objValue = this.elem[3].checked;
	  bolNormalMode = false;

	}
	else	{
	 objValue = this.elem.value 	
	 bolNormalMode = true;
	}	
		
	if ((objValue==null || objValue=="") && bolNormalMode) { 		
		strMsg = strMsg + this.usrName + " is required\n"
	}
		
	if (!(objValue==null || objValue=="") || !(bolNormalMode)) { 
		
		if (this.dType!=null)
			{
			switch (this.dType)
				{
				case "Alpha":
					if(!isNaN(objValue))	{
						strMsg = strMsg + this.usrName + " cannot contain numbers.\n"
					}	
					break
				case "Num":
					if(isNaN(objValue))	{
						strMsg = strMsg + this.usrName + " cannot contain letters.\n"
					}	
					break
				case "Custom1":
					if(objValue && document.customerservice.frmCategoryOtherText.value.length == 0)	{
						strMsg = strMsg + "You chose 'Other' for the category that best represents your questions/commnets. Please provide a description in the field next to your selection.\n"
					}	
					break	
				// case "Date": Date type validation
				//		goes here
				} 
			}
		if (this.regExpObj) {
			var valReg = new RegExp(this.regExpObj,	this.regScope) 		
			blnValid = valReg.test(objValue) 			
		}
	}
	return strMsg;
} 
//link the method to the object definition
Validator.prototype.validate = mValid

function mValid2(f)	{
	//this is called from the form onsubmit or onclick event handler and in turn calls the validate method of the 
	//validator object
	var strErrorMsg = ""
	var lenf = f.length - 1;
	//loop through the object array (f) and call the validate method of each Validator object (which is what is in
	//the array)
	for(i=0;i<=lenf;i++)	{
		strErrorMsg = strErrorMsg + f[i].validate();
	}
	if (strErrorMsg.length > 0)	{
		strErrorMsg = "The following errors have occured:\n\n" + strErrorMsg;
		alert(strErrorMsg);
		return false;	
	}	
	else	{
		return true;
	}
	
}
