function validate(){
	this.formName = 'formname';
	this.alertType = 0;						//  0-> Show all and focus 1st 	1-> Show only 1 & focus
	this.errorType = 0;						//  0-> alert				1-> Display
	this.mandCaptions = new Array();
	this.mandFields = new Array();
	this.mandFunc = new Array();
	this.mandEQ = new Array();
	this.mandReg = new Array();
	this.mandOR = new Array();
	this.mandNUM = new Array();
	this.mandMAXLIMIT = new Array();
	this.mandMAXLEN = new Array();
	this.mandLT = new Array();
	this.mandDATE = new Array();
	this.mandEXT = new Array();
	this.mandMULTIEXT = new Array();
	this.mandClassName = new Array();
	this.errStr = '';
	this.ownMsg = 1;
	this.fontSize = '9px';
	this.firstFieldObj = "";
	
	
	this.errArr = new Array(' cannot be left blank',
							' is invalid',
							' is not selected',
							' mismatch',
							' form incomplete',
							' should be numeric',
							' should be less than initial end date',
							' cannot be more than ',
							' select is invalid',
							' supports only a-z,0-9,_ and -',
							' cannot have charaters more than ');
							
	this.errorCode = -1;
	this.validateForm = function(){
		var frmObj = document.forms[this.formName];
		for(var i=0; i<this.mandFields.length; i++){
			var fldObj = frmObj.elements[this.mandFields[i]];
			if(fldObj){
				switch(fldObj.type){
					case 'password':
					case 'textarea':
					case 'text':
						if(this.mandOR[i]){
							if(!(fldObj.value) && !(document.forms[this.formName].elements[this.mandOR[i]].value)){
								this.errorCode = 4;
							}
						}else if(!fldObj.value || fldObj.value == ' '){
							this.errorCode = 0;
						}else if(this.mandEQ[i]){
							if(fldObj.value != document.forms[this.formName].elements[this.mandEQ[i]].value){
								this.errorCode = 3;
							}
						}else if(this.mandNUM[i]){
							if(isNaN(fldObj.value)){
								this.errorCode = 5;
							}
						}else if(this.mandMAXLIMIT[i]){
							if((fldObj.value) && parseInt(fldObj.value) > parseInt(this.mandMAXLIMIT[i],10)){
								this.errorCode = 7;
								this.errArr[7] += parseInt(this.mandMAXLIMIT[i],10);
							}
						}else if(this.mandMAXLEN[i]){
							if((fldObj.value) && fldObj.value.length > parseInt(this.mandMAXLEN[i],10)){
								this.errorCode = 10;
								this.errArr[10] += parseInt(this.mandMAXLEN[i],10);
							}
						}else if(this.mandDATE[i]){
							if(this.compareDate(frmObj, 'LT', fldObj.value, document.forms[this.formName].elements[this.mandLT[i]].value) == false){
								this.errorCode = 6;
							}
						}else if(this.mandReg[i]){
							var pattern = eval(this.mandReg[i]); 
							var patternMatch = pattern.test(fldObj.value);	
							if(patternMatch == false){
								this.errorCode = 9;
							}
						}
					break;
					case 'select-one':
					case 'select':
						if(!fldObj.value || fldObj.value == 0 || fldObj.value == "SELECT"){
							this.errorCode = 2;
						}
					break;
					case 'file':
						if(!fldObj.value){
							this.errorCode = 0;
						}else if(this.mandEXT[i]){
							var contStr = fldObj.value;
							var comStr = contStr.substring(contStr.length - 4);
							if(comStr != this.mandEXT[i]){
								this.errorCode = 8;
							}
						}else if(this.mandMULTIEXT[i]){
							var contStr = fldObj.value;
							var comStr = contStr.substring(contStr.length - 4);
							comStr = comStr.toLowerCase();
							var passStr = this.mandMULTIEXT[i];
							var passStrArr = passStr.split(' ');
							for(var m=0; m<passStrArr.length;m++){
								if(comStr != passStrArr[m]){
									this.errorCode = 8;
									break;
								}
							}
						}
					break;
					case 'checkbox':
						if(!fldObj.checked){
							this.errorCode = 2;
						}
					break;
					default:
						alert(fldObj.type);
					break;
				}
				if(fldObj.type){
					if(this.mandFunc[i]){
						var chk = eval(this.mandFunc[i] + '()');
						this.errorCode = -1;
						if(!chk) this.errorCode = 1;
					}
				}
				
				if(this.errorCode >= 0){
					if(this.errorType == 1){
						this.firstFieldObj = (!this.firstFieldObj) ? fldObj : this.firstFieldObj;
						this.markField(i, fldObj, this.errorCode);
						this.errStr = 'xx';
					}else{
						this.errStr += this.mandCaptions[i] + " ("+this.errArr[this.errorCode]+" )\n";
					}
					if(this.alertType == 1){
						fldObj.focus();
						return false;
					}
					this.errorCode = -1;
				}
			}
		}
		if(this.errStr){
			if(this.errorType != 1){
				alert("Following fields are either blank or filled incorrectly\n\n" + this.errStr);
			}
			this.firstFieldObj.focus();
			return false;
		}else{
			return true;
		}
	};
	this.markField = function(failIndex, fldObj, errType){
		var errDisp = '';
		if(fldObj.errBox){
			if (this.ownMsg==1) errDisp = eval('this.' + fldObj.name + '[' + errType + ']');
			errDisp = (errDisp.length==0) ? this.mandCaptions[failIndex] + this.errArr[errType] : errDisp;
			fldObj.errBox.childNodes[0].innerHTML = errDisp;
			fldObj.errBox.className = 'cboth error1';
		}else{
			var errBox = document.createElement('div');
			if (this.ownMsg==1) errDisp = eval('this.' + fldObj.name + '[' + errType + ']');
			errDisp = (errDisp.length==0) ? this.mandCaptions[failIndex] + this.errArr[errType] : errDisp;
			errBox.innerHTML = '<div class="abs error1">'+ errDisp + '</div>';
			errBox.style.fontSize = this.fontSize;
			errBox.className = 'cboth error1';
			if (this.mandClassName[failIndex])  errBox.className = errBox.className + ' ' + this.mandClassName[failIndex];
			fldObj.parentNode.appendChild(errBox);
			fldObj.errBox = errBox;
			fldObj.failIndex = failIndex;
			fldObj._self = this;
			
			if(fldObj){
				switch(fldObj.type){
					case 'select-one':
					case 'select':
						fldObj.oldonchange = fldObj.onchange;
						fldObj.onchange = function(e){
							if(this.errBox && this.value){
								this.parentNode.removeChild(this.errBox);
								this.errBox = null;
							}
							if(this.oldonchange) this.oldonchange();
						};
					break;	
					case 'file':
						fldObj.onchange = function(e){
							if(this.errBox && this.value){
								this.parentNode.removeChild(this.errBox);
								this.errBox = null;
							}
						};
					break;
					case 'checkbox':
						fldObj.onclick = function(e){
							if(this.errBox && this.value){
								this.parentNode.removeChild(this.errBox);
								this.errBox = null;
							}
						};
					break;
					default:
						fldObj.onkeydown = function(e){
							if(this.errBox && this.value){
								this.parentNode.removeChild(this.errBox);
								this.errBox = null;
							}
						};
					break;	
				}
			}
		}
	}
	
	this.compareDate = function(frmname, cmpType, cmpStr, pasDate){
		var todate = formatDate(pasDate);
		var fromdate = formatDate(cmpStr);
		if(cmpType == 'LT') {
			if(todate <= fromdate) {
				return false;
			}else{
				return true;
			}
		}
	};
}

function removeErrBox(objFld) {
	if (objFld.errBox) {
		objFld.parentNode.removeChild(objFld.errBox);
		objFld.errBox = null;
	}
}

function displayStatFieldErr(formName, fldName, errTag, fontSize, className) {
	var frmObj = document.forms[formName];
	var fldObj = frmObj.elements[fldName];
	
	if(fldObj.errBox){
		fldObj.errBox.childNodes[0].innerHTML = errTag;	
		fldObj.errBox.style.fontSize = fontSize + 'px';
		fldObj.errBox.className = 'cboth';
		if (className)  {
			fldObj.errBox.className = fldObj.errBox.className + ' ' + className;
		}else{
			fldObj.errBox.className = ' error1';
		}
	}else{
	
		var errBox = document.createElement('div');
		errBox.innerHTML = '<div class="abs error1">'+ errTag + '</div>';
		errBox.style.fontSize = fontSize + 'px';
		errBox.className = 'cboth';
		if (className)  {
			errBox.className = errBox.className + ' ' + className;
		}else{
			errBox.className = 'error1';
		}
		fldObj.xformName = formName;
		fldObj.xfldName = fldName;
		fldObj.xerrTag = errTag;
		fldObj.xfontSize = fontSize;
		fldObj.xclassName = className;
		fldObj.parentNode.appendChild(errBox);
		fldObj.errBox = errBox;
		fldObj._self = this;
		
		if(fldObj){
			switch(fldObj.type){
				default:
					fldObj.onkeydown = function(e){
						if(this.errBox && this.value){
							displayStatFieldErr(this.xformName, this.xfldName, this.xerrTag, this.xfontSize, this.xclassName);
						}
					};
				break;	
			}
		}
	}
	
}

function displayFieldErr(formName, fldName, errTag, fontSize, className) {
	var frmObj = document.forms[formName];
	var fldObj = frmObj.elements[fldName];
	if(fldObj.errBox){
		fldObj.errBox.childNodes[0].innerHTML = errTag;
	}else{
		var errBox = document.createElement('div');
		errBox.innerHTML = '<div class="abs error1">'+ errTag + '</div>';
		errBox.style.fontSize = fontSize + 'px';
		errBox.className = 'cboth';
		if (className)  {
			errBox.className = errBox.className + ' ' + className;
		}else{
			errBox.className = errBox.className + ' error1';
		}
		fldObj.parentNode.appendChild(errBox);
		fldObj.errBox = errBox;
		fldObj._self = this;
		
		if(fldObj){
			switch(fldObj.type){
				case 'select-one':
				case 'select':
					fldObj.oldonchange = fldObj.onchange;
					fldObj.onchange = function(e){
						if(this.errBox && this.value){
							this.parentNode.removeChild(this.errBox);
							this.errBox = null;
						}
						if(this.oldonchange) this.oldonchange();
					};
				break;	
				case 'file':
					fldObj.onchange = function(e){
						if(this.errBox && this.value){
							this.parentNode.removeChild(this.errBox);
							this.errBox = null;
						}
					};
				break;
				case 'checkbox':
					fldObj.onclick = function(e){
						if(this.errBox && this.value){
							this.parentNode.removeChild(this.errBox);
							this.errBox = null;
						}
					};
				break;
				default:
					fldObj.onkeydown = function(e){
						if(this.errBox && this.value){
							this.parentNode.removeChild(this.errBox);
							this.errBox = null;
						}
					};
				break;	
			}
			fldObj.focus();
		}
	}
}

function validateEmail(emailAddr) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(emailAddr)) {
		return false;
	}
	return true;
}

// function to validate the password
function validatePassword (pw, options, username, confirmpass) {
	// default options (allows any password)
	var o = {
		lower:    0,
		upper:    0,
		alpha:    0, /* lower + upper */
		numeric:  0,
		special:  0,
		length:   [0, Infinity],
		custom:   [ /* regexes and/or functions */ ],
		badWords: [],
		badSequenceLength: 0,
		noQwertySequences: true,
		noSequential:      false
	};

	for (var property in options)
		o[property] = options[property];

	var	re = {
			lower:   /[a-z]/g,
			upper:   /[A-Z]/g,
			alpha:   /[A-Z]/gi,
			numeric: /[0-9]/g,
			special: /[\W_]/g
		},
		rule, i;

	// enforce min/max length
	if (pw.length < o.length[0] || pw.length > o.length[1])
		return false;

	// enforce lower/upper/alpha/numeric/special rules
	for (rule in re) {
		if ((pw.match(re[rule]) || []).length < o[rule])
			return false;
	}

	// enforce alphanumeric/qwerty sequence ban rules
	if (o.badSequenceLength) {
		var	lower   = "abcdefghijklmnopqrstuvwxyz",
			upper   = lower.toUpperCase(),
			numbers = "0123456789",
			qwerty  = "qwertyuiopasdfghjklzxcvbnm",
			start   = o.badSequenceLength - 1,
			seq     = "_" + pw.slice(0, start);
		for (i = start; i < pw.length; i++) {
			seq = seq.slice(1) + pw.charAt(i);
			if (
				lower.indexOf(seq)   > -1 ||
				upper.indexOf(seq)   > -1 ||
				numbers.indexOf(seq) > -1 ||
				(o.noQwertySequences && qwerty.indexOf(seq) > -1)
			) {
				return false;
			}
		}
	}

	// enforce custom regex/function rules
	for (i = 0; i < o.custom.length; i++) {
		rule = o.custom[i];
		if (rule instanceof RegExp) {
			if (!rule.test(pw))
				return false;
		} else if (rule instanceof Function) {
			if (!rule(pw))
				return false;
		}
	}
	
	// check if password is same as that of username
	if(username){
		if(username==pw){
			return false;	
		}	
	}
	
	// check if confirm pass is not same as that of the password
	if(confirmpass){
		if(confirmpass!=pw){
			return false;	
		}
	}

	// great success!
	return true;
}