﻿
function fnMandatory()
{	
 
	var stErrorMsg;
	var indexForFocus;
	var sTrimValue;
	indexForFocus=0; 
	stErrorMsg=""; 
	document.getElementById("uctlSCIErrorValidator_lblError").innerHTML  ="";
	
	for(var iCounter=0;iCounter < ControlArray.length;iCounter++){
	//check for textbox control				
	if (ControlArray[iCounter].substr(0,4)=="rdbl"){
			var obj;
			var iCount="0";
			var jIncrement=0;
			var bCheck=1; 
			var objFirst;
			obj=document.all.RadioButtonList1;
			obj=document.getElementById(ControlArray[iCounter]+"_"+iCount);
			while (obj != null){
				if (objFirst==null)
				objFirst=obj;
				if (obj.checked==false)
					bCheck=bCheck*1;
				else
					bCheck=bCheck*0;
		 		jIncrement=parseInt(iCount)+1;
				iCount=jIncrement;
				obj=document.getElementById(ControlArray[iCounter]+"_"+iCount);
			}	
			if (bCheck!=0){
				stErrorMsg+="<font color=red>" + ErrorMessage[iCounter] + CORP_REQUIRED_FIELD +"</font><br />";
				objFirst.style.background ="yellow" ;
				}
			else
				objFirst.style.background ="white" ;	
	}
	var objControl=document.getElementById(ControlArray[iCounter]);
	if (objControl.type=="text" || objControl.type=="textarea" ){
	
		sTrimValue=Trim(objControl.value);				  
		//return false;
		if(sTrimValue == ""){
		stErrorMsg+="<font color=red>" + ErrorMessage[iCounter]+ CORP_REQUIRED_FIELD +"</font><br />";
		objControl.style.background ="yellow" ;
		indexForFocus++;
		////set focus for the first control that violates the validation
		if (indexForFocus==1){					
			objControl.focus();
		}
		}	
		else
		objControl.style.background ="white";		
						
	}				
	//check for Combobox or Listbox
	//For ComboBox	:	Size will be 0 and SelectedIndex will be zero if None is Selected
	//For ListoBox	:	Size will be greater then 0 and SelectedIndex will be -1 if None is Selected	
	else if (objControl.type=="select-one"){	
		
		if((objControl.size==0 && objControl.selectedIndex==0)||(objControl.size>0 && objControl.selectedIndex==-1)){	
					stErrorMsg+="<font color=red>" + ErrorMessage[iCounter]+ CORP_REQUIRED_FIELD +"</font><br />";		
					objControl.style.background ="yellow";
					indexForFocus++;
					if (indexForFocus==1){					
						objControl.focus();
					}								
		}			
		else
		objControl.style.background ="white";		
		
	}	
	//check for checkbox control	
	else if (objControl.type=="checkbox")
	{		
		if(objControl.checked==false)
		{
			stErrorMsg+="<font color=red>" + ErrorMessage[iCounter]+ CORP_REQUIRED_FIELD +"</font><br />";
					objControl.style.background ="yellow" ;
					indexForFocus++;
					if (indexForFocus==1) 
					{					
						objControl.focus();
					}					
		}								
		else
		objControl.style.background ="white";		
	}	 
	else if (objControl.type=="table")
	alert("table"+objControl.id);
	
			
	}	
	
	if (stErrorMsg!="")
	{

		indexForFocus=0;
		if(document.getElementById("uctlSCIErrorValidator_lblError") != null)
		{
		document.getElementById("uctlSCIErrorValidator_lblError").innerHTML  = stErrorMsg; 
		}
		return false;
	}
	else
	return true;
	
	
}	

	function Trim(strSrc)
	{
			var exp=/^[\s]{1,}/g;
			var exp1=/[\s]{1,}$/g;
			var strTrimmedString;
			strTrimmedString=strSrc.replace(exp,"");
			strTrimmedString=strTrimmedString.replace(exp1,"");
			return strTrimmedString;
	}
