function _validateStandard(formObj){
	totalElements=formObj.length;
	for(index=0;index<totalElements;++index){
		inputType=formObj.elements[index].type;
		switch(inputType){
			case "text":
			case "password":
						if(typeof(validationRuleArray[formObj.elements[index].name])!="undefined"){
							_validateTextBox(formObj.elements[index]);
						}
						break;
			case "radio": 
						if(typeof(validationRuleArray[formObj.elements[index].name])!="undefined"){
							_validateRadioGroupBox(formObj.elements[index]);
						}
						break;
			case "checkbox":
						if(typeof(validationRuleArray[formObj.elements[index].name])!="undefined"){  
							_validateCheckBoxGroup(formObj.elements[index]);
						}
						break;								
		}
	}
 	
	for(index=0;index<totalElements;++index){
		inputTypeName=formObj.elements[index].name;
		if( typeof(validationRuleArray[inputTypeName])!="undefined" && !validationRuleArray[inputTypeName]['validStatus']){
			init();
			return false;
		}    		
	}

	return true;
}

function _validateCheckBoxGroup(checkBoxObj){
	checkBoxName=checkBoxObj.name;
	errorFlag=false;
	errorId=validationRuleArray[checkBoxName]['errorMessageId'];
	if(validationRuleArray[checkBoxName]['required']){
		if(!checkBoxObj.checked && !validationRuleArray[checkBoxName]['validStatus']){
			document.getElementById(errorId).innerHTML="<img src='images/error.gif'> " + validationRuleArray[checkBoxName]['requireErrorMessage'];
			document.getElementById(errorId).style.visibility='visible';
			errorFlag=true;				
		}else {
			validationRuleArray[checkBoxName]['validStatus']=true;
			formSubmitFlag=true;
			document.getElementById(errorId).innerHTML="";
			document.getElementById(errorId).style.visibility='hidden';
		}
	}
	if(errorFlag==false){
		document.getElementById(errorId).innerHTML="<img src='images/ok.gif'> "
		document.getElementById(errorId).style.visibility='visible';
	}
}
function _validateRadioGroupBox(radioButtonObj){ 
	radioButtonName=radioButtonObj.name;
	errorFlag=false;
	errorId=validationRuleArray[radioButtonName]['errorMessageId'];
	if(validationRuleArray[radioButtonName]['required']){
		if(!radioButtonObj.checked && !validationRuleArray[radioButtonName]['validStatus']){
			document.getElementById(errorId).innerHTML="<img src='images/error.gif'> " + validationRuleArray[radioButtonName]['requireErrorMessage'];
			document.getElementById(errorId).style.visibility='visible';
			errorFlag=true;
		}else {
			validationRuleArray[radioButtonName]['validStatus']=true;				 
			document.getElementById(errorId).innerHTML="";
			document.getElementById(errorId).style.visibility='hidden';
		}
	}
	if(errorFlag==false){
		document.getElementById(errorId).innerHTML="<img src='images/ok.gif'> "
		document.getElementById(errorId).style.visibility='visible';
	}    
}

function _validateTextBox(textBoxObj){
	textBoxName=textBoxObj.name;
	errorFlag=false;
	errorId=validationRuleArray[textBoxName]['errorMessageId'];
	if(validationRuleArray[textBoxName]['required']){    			
		if(textBoxObj.value==''){    				 
			document.getElementById(errorId).innerHTML="<img src='images/error.gif'> " + validationRuleArray[textBoxName]['requireErrorMessage'];
			document.getElementById(errorId).style.visibility='visible';
			errorFlag=true;
		}else {
			document.getElementById(errorId).innerHTML="";
			document.getElementById(errorId).style.visibility='hidden';
		}
	}
		
	if(typeof(validationRuleArray[textBoxName]['regExp'])!="undefined"  && validationRuleArray[textBoxName]['regExp']!='' && errorFlag==false){    			
		regularExpression=validationRules[validationRuleArray[textBoxName]['regExp']];
		if(!regularExpression.test(textBoxObj.value)){
			document.getElementById(errorId).innerHTML="<img src='images/error.gif'> "+ validationRuleArray[textBoxName]['validateErrorMessage'];
			document.getElementById(errorId).style.visibility='visible';
			errorFlag=true;
		}else if(document.getElementById(errorId).style.visibility!='visible'){
			document.getElementById(errorId).innerHTML="";
			document.getElementById(errorId).style.visibility='hidden';    				
		}
	}
	
		if(typeof(validationRuleArray[textBoxName]['minLength'])!="undefined"  && validationRuleArray[textBoxName]['minLength']!='' && errorFlag==false){    			
		minimumLength=validationRuleArray[textBoxName]['minLength'];
		if(textBoxObj.value.length < minimumLength){
			document.getElementById(errorId).innerHTML="<img src='images/error.gif'> "+ validationRuleArray[textBoxName]['minLengthErrorMessage'];
			document.getElementById(errorId).style.visibility='visible';
			errorFlag=true;
		}else if(document.getElementById(errorId).style.visibility!='visible'){
			document.getElementById(errorId).innerHTML="";
			document.getElementById(errorId).style.visibility='hidden';    				
		}
	}    		
	
	if(typeof(validationRuleArray[textBoxName]['maxLength'])!="undefined"  && validationRuleArray[textBoxName]['maxLength']!='' && errorFlag==false){
		maximumLength=validationRuleArray[textBoxName]['maxLength'];
		if(textBoxObj.value.length > maximumLength){
			document.getElementById(errorId).innerHTML="<img src='images/error.gif'> "+validationRuleArray[textBoxName]['maxLengthErrorMessage'];
			document.getElementById(errorId).style.visibility='visible';
			errorFlag=true;
		}else if(document.getElementById(errorId).style.visibility!='visible'){
			document.getElementById(errorId).innerHTML="";
			document.getElementById(errorId).style.visibility='hidden';    				
		}
	}
	if(errorFlag==false){
		document.getElementById(errorId).innerHTML="<img src='images/ok.gif'> "
		document.getElementById(errorId).style.visibility='visible';
		validationRuleArray[textBoxName]['validStatus']=true;
	}
}

function confirmation(msg){
	return confirm("Are you sure to delete "+msg+"?");
}

function redirectTo(address){
	//alert('I am in');
	window.location = address;
}

function Trim(s) {
   var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
   return (m == null) ? "" : m[1];
}

function disableAnchor(obj, disable){
  if(disable){
    var href = obj.getAttribute("href");
    if(href && href != "" && href != null){
       obj.setAttribute('href_bak', href);
    }
    obj.removeAttribute('href');
    obj.style.color="gray";
  }
  else{
    obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);
    }
}

function takeYear(theDate) 
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
