/*****************************************************************************
* <summary>
*		ValidatorFunction : Called by CMS Templates 
* </summary>
* <remarks>
* </remarks>
* <history>
* 	[Infosys ]	07/06/2009	Created
* </history>
******************************************************************************/
function ValidatorFunction()
	{	
	//debugger;
		//Variable for mapping the Error Label and
		//Display Label of controls
		var genLabelControl;
				
		//Variable for mapping the control
		var genControl;
				
		//Variable for storing the control name
		var controlName;
				
		//Variable for the tab index of control
		var ctrlTabIndex = -1;
		
		//Variable to store a single validation error message
		var errMessage;
		
		//Variable to hold all the validation error messages
		var errULList;
				
		var rtnFlag = true;
		
		for(var i = 0; i < Page_Validators.length; i++ )
		{
			controlName = Page_Validators[i].controltovalidate;
			genLabelControl=GetLabelControl(controlName);
			if(genLabelControl != null)
			{
				genLabelControl.className = "blanktext"
			}
		}
				
		var errULListOldObj = document.getElementById('errULList');
        if (errULListOldObj != null)
        {
            document.getElementById('divErrMsgSec2').removeChild(errULListOldObj);
        }

				
		//Loop through all the validator controls in the page
		for(var i = 0; i < Page_Validators.length; i++ )
		{
			//Explicitly validate the validator control
			ValidatorValidate(Page_Validators[i]);
			//Check whether the validator has any validation errors
			//to be displayed
			if(!Page_Validators[i].isvalid)
			{
				controlName = Page_Validators[i].controltovalidate;
				//concatErrorMsg=concatErrorMsg + GetErrorMessage(Page_Validators[i].errormessage);
				//If the control is a radio button list then get the 
				//child nodes of the control for getting the tab index
				if(controlName.substring(0,3)=="rdb" || 
				controlName.substring(0,3)=="RDB")
				{
					genControl = document.getElementById(controlName);
					genControl = genControl.childNodes.item(0);
				}
				else
				{		
					genControl = document.getElementById(controlName);
				}
						
				//Set the Tab Index Flag to the lowest
				//Tab Index of the control
				if (ctrlTabIndex < 0)
            		ctrlTabIndex = genControl.tabIndex;
			            
				//Check whether the control id ends with "_"
				//If it ends with "_" remove the last two underscores
				//and use the rest of the string for getting the label
				//control Else use the string directly for getting 
				//the label control
				genLabelControl=GetLabelControl(controlName);
						
				//Check whether the control tab index is less than 
				//the tab index corresponding to the tab index of the 
				//control whose error message has been set in the 
				//error label before
				if(genLabelControl != null)
				{
					genLabelControl.className = "redtext"
				}
			    
			    /* MOD LOG for Web Accessibility */
			    if (typeof(errULList) == "undefined")
			    {
			        errULList = document.createElement('ul');
			        errULList.id = 'errULList';
			    }
			    		                
				//if(genControl.tabIndex <= ctrlTabIndex)
				//{
					document.all.lblErrSec2.innerHTML = "Required Information is Missing Or Incorrect";
					errMessage = GetErrorMessage(Page_Validators[i].errormessage);
					if( GetErrorMessage(Page_Validators[i].errormessage) == "")
					{
						//document.all.lblErrSec2.innerHTML = Page_Validators[i].errormessage;
						errMessage = Page_Validators[i].errormessage;
					}
					document.all.lblErrSec2.className = "redtext";
					document.all.divErrMsgSec2.style.visibility = "visible";
					document.all.divErrMsgSec2.style.display = "block";	
					if (window.document.getElementById('aErrorLabel2') != null)				
					{
					    window.document.getElementById('aErrorLabel2').focus();
					}
					ctrlTabIndex = genControl.tabIndex;
										
					//Create a anchor node for displaying error messages
					var errAnchor = document.createElement('a');
					errAnchor.className="redtext";
					errAnchor.setAttribute('name', controlName);
					errAnchor.setAttribute('innerHTML',errMessage);
                    errAnchor.setAttribute('href', 'javascript:document.getElementById(\'' + Page_Validators[i].controltovalidate + '\').focus();');                                        
                    
                    //Create a li element to hold above anchor
                    var errLi = document.createElement('li');
                    errLi.style.color = '#c00000';
                    errLi.appendChild(errAnchor);
                    
                    //Append the above li element to the UL tag
                    errULList.appendChild(errLi);
										
					rtnFlag = false;
				//}
			}						
		}
		
		//Add the anchor node as the last child of divErrMsgSec2 div
		if (typeof(errULList) != "undefined")
		{
            document.getElementById('divErrMsgSec2').appendChild(errULList);
            document.all.lblErrSec2.style.visibility = "visible";
			document.all.lblErrSec2.style.display = "block";	
            document.all.lblErrSec2.focus();
        }
            
        /* END MOD LOG for Web Accessibility */
        
		return rtnFlag;			
		//If there are no error labels set from validator controls
		//then check for invalid entries in the text box controls
	}
