function ValidateWebForm(formObjects, webForm) {
	for(var x=0;x<formObjects.length;x++) {
		if(formObjects[x].isValid(webForm) == false) return false;
	}
	return true;
}
//---------------------------------------------------------------------------------------------------//				
function FormControl(ctrlName,ctrlLength,ctrlLabelId,ctrlMandatory,ctrlType,ctrlMinVal,ctrlMaxVal,strOptionalLabel){
	this.control = "";
	this.controlName = ctrlName;
	this.textLength = ctrlLength;
	this.captionId = ctrlLabelId;
	this.caption = "";
	this.isNumeric = false;
	this.isComp = false;
	this.isDate = false;
	this.isEmail = false;
	this.maxVal = 0;
	this.minVal = 0;
	this.strMsg = "";
	this.optionalLabel = strOptionalLabel;
	if (ctrlMandatory == "0")
		this.isMandatory = false;
	else
		this.isMandatory = true;
		
	switch(ctrlType){
		case "N":
			this.isNumeric = true;
			this.maxVal = ctrlMaxVal;
			this.minVal = ctrlMinVal;
			break;
		case "D":
			this.isDate = true;
			break;
		case "E":
			this.isEmail = true;
			break;
		case "C":
			this.isComp = true;
			break;
	}//end switch(ctrlType)
	this.isValid = function(theThis) {
		objDoc = theThis.document;
		if(objDoc == null) objDoc = document;
		this.control = objDoc.getElementById(this.controlName);
		objCaption = objDoc.getElementById(this.captionId);
		if(objCaption) {
			this.caption = objCaption.innerHTML;
		}
		else {
			this.caption = this.optionalLabel;
		}
		
		//-------------------------------------------------------------------------//
		if(this.isMandatory){
			if(isEmpty(this.control) || this.control.value == "-1") {
				this.strMsg = "Please enter some valid value into " + this.caption + ".";
				showMessage(this.strMsg, img);
				highlightControl(this.control);
				return false;
			}//end if(isEmpty(this.control))
		}//end if(this.isMandatory)
		//-------------------------------------------------------------------------//
		if(!isEmpty(this.control)) {
			//-------------------------------------------------------------------------//
			if(this.textLength > 0){
				var strText = new String(this.control.value);
				if (strText.length > this.textLength){
					this.strMsg = "Text length for " + this.caption + " should not be greater than " + this.textLength + " character(s).";
					showMessage(this.strMsg, img);
					highlightControl(this.control);
					return false;
				}// end if (strText.length > this.textLength)
			}//end if(this.textLength > 0)
			//-------------------------------------------------------------------------//
			if(this.isNumeric){
				//-------------------------------------------------------------------------//
				if(!isNumber(this.control.value)) {
					this.strMsg = "Please enter valid numeric value into " + this.caption + ".";
					showMessage(this.strMsg, img);
					highlightControl(this.control);
					return false;
				}// end if(!isNumber(this.control.value))
				//-------------------------------------------------------------------------//
				if(parseFloat(this.control.value) < parseFloat(this.minVal)) {
					this.strMsg = "Please enter valid numeric value greater than or equal to " + this.minVal + " into " + this.caption +".";
					showMessage(this.strMsg, img);
					highlightControl(this.control);
					return false;
				}// end if(this.control.value < this.minVal)
				//-------------------------------------------------------------------------//
				if(parseFloat(this.control.value) > parseFloat(this.maxVal)) {
					this.strMsg = "Please enter valid numeric value less than or equal to " + this.maxVal + " into " + this.caption +".";
					showMessage(this.strMsg, img);
					highlightControl(this.control);
					return false;
				}// end if(this.control.value > this.maxVal)
				//-------------------------------------------------------------------------//
			}//end if(this.isNumeric)
			//-------------------------------------------------------------------------//
			if(this.isDate){
				/*if(!checkdate(this.control))
					return false;*/
			}//end if(this.isDate)
			if(this.isComp){
				if(objDoc.getElementById(this.captionId).value != this.control.value){
					this.strMsg = "Password and Confirm Password does not match.";
					showMessage(this.strMsg, img);
					highlightControl(this.control);
					return false;
				}
			}
			if(this.isEmail) {
				if(!isEmail(this.control.value)) {
					this.strMsg = "Please enter a valid E-Mail address in " + this.caption +".";
					showMessage(this.strMsg, img);
					highlightControl(this.control);
					return false;
				}
			}
			//-------------------------------------------------------------------------//
		}//end if(!isEmpty(this.control))
		//-------------------------------------------------------------------------//
		//return true;
	}//end this.isValid = function()
}// end Class FormControl(id,controlName,textLength)
//---------------------------------------------------------------------------------------------------//

function isNumber(chkVal) {
	/*if(!(parseInt("" + chkVal) == "" + chkVal)) return false;
	return true;*/
	var oneDecimal = false
	var digitCount=0;
	inputStr = chkVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (i == 0 && oneChar == "-") {
			continue
		}
		if (oneChar == "." && !oneDecimal) {
			oneDecimal = true
			continue
		}
		if (oneChar < "0" || oneChar > "9") {
			return false
		} else {
			digitCount++
		}
	}
	return (digitCount > 0)
}

function isFloat(chkVal) {
	if(!((parseFloat("" + chkVal) == "" + chkVal))) return false;
	return true;
}
function isEmpty(control) {
	if(!control) return false;
	var strTmp = control.value;
	do {
		strTmp = strTmp.replace('\r\n', '');
	} while (strTmp.indexOf('\r\n') > -1);
	do {
		strTmp = strTmp.replace('  ', ' ');
	} while (strTmp.indexOf('  ') >= 0);
	
	if(strTmp.replace(' ','')  == '') {
		return true;
	}
	return false;
}
function highlightControl(control) {
	if(!control) return;
	try {
		control.focus();
		control.select();
	}catch(e) { }
}
function isSelected(control) {
	if(!control) return false;
	return control.selectedIndex > -1;
}
function validateEmails(control) {
	if(!control) return false;
	if(control.value.indexOf(';') < 0) {
		return isEmail(control.value.trim());
	}
	else {
		var arrEmails = control.value.split(';');
		for(var loopX=0;loopX < arrEmails.length;loopX++) {
			if(!isEmail(arrEmails[loopX].trim())) return false;
		}
	}
	return true;
}
//Validating email using regular expressions.
function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"").replace(/\s+/g," ");
}
function lockControl(controlId,state) {
	try {
		document.getElementById(controlId).disabled = state;
		document.getElementById(controlId).readOnly = state;
	} catch(e) { }
}
function showMessage(strMsg, strImg) {
	var msgObject;
	if(!strPrefix) 
		sPrefix = '';
	else
		sPrefix = strPrefix;

	if(!objMsg)
		msgObject = document.getElementById('lblMsg');
	else
		msgObject = objMsg;

	if(msgObject) {
		try {
			switch(strImg) {
				case 'IcoErr.gif':
					msgObject.setAttribute('class', 'error');
					break;
				case 'IcoSucc.gif':
					msgObject.setAttribute('class', 'success');
					break;
			}
			msgObject.innerHTML = strMsg;
		} catch(e) { alert(strMsg); }
	}
	else {
		alert(strMsg);
	}
}
function checkAll(curObj, desObj) {
	if(!desObj) return;
	if(!desObj.length)
		desObj.checked = curObj.checked;
	else {
		for(var x=0;x < desObj.length;x++) {
			desObj[x].checked = curObj.checked;
		}
	}
}