



// JavaScript Utilities
	
	function replaceAll( str, from, to )
	{
	    var strNew = "";
		var idx = str.indexOf( from );
		while ( idx > -1 )
		{
			str = str.replace( from , to );
			strNew += str.substring(0,idx+to.length);
			str = str.substring(idx+to.length);
			idx = str.indexOf( from );
		}
		if(str != null && str != "")
			strNew += str; 
		return strNew;
	}	
	
	function SetCtrlsWidth()
	{
		for(var i = 0; i < document.forms[0].length; i++)
		{
			var e = document.forms[0].elements[i];
			if((e.type.toLowerCase()=="textarea" && e.name.indexOf("CommentsMaintenance") != -1) || 
				(e.type.toLowerCase()=="text" && e.name.indexOf("CommentsMaintenance") != -1) )
			{		
				e.style.width = document.body.scrollWidth-30;
			}
		}
	}	
	


	function getTextAreaWidth(txtBoxName)
	{
		var varId = document.getElementById(txtBoxName);
		if(varId != null)
			varId.style.width = document.body.scrollWidth-30;	
		SetCtrlsWidth();			
	}
	
	
	
	function chkgetTextAreaWidth(txtBoxName)
	{
		var txtarea = document.getElementById(txtBoxName);
		if(txtarea != null)
			 getTextAreaWidth(txtBoxName);	
	}	



	function onResizeMessage()
	{
		chkgetTextAreaWidth("taRequestDesp");	
		chkgetTextAreaWidth("taOwnerComments");	
		chkgetTextAreaWidth("taBODComments");			 		 
	}
	
	function createCookie(name,value,days)
	{
		if (days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}	

	function onPwdChange()
	{
		document.myForm.hdnPwd.value = document.myForm.txtPwd.value;
		document.myForm.hdnConfirmPsw.value = document.myForm.txtConfirmPsw.value;
	}
	function getPassword()
	{
		document.myForm.txtPwd.value = document.myForm.hdnPwd.value;
		document.myForm.txtConfirmPsw.value = document.myForm.hdnConfirmPsw.value;
	}	
	
	/*
	function isUserIDPwdLenValid(intFlag,objIDPwd)
	{	
		var tempvalue = objIDPwd.value;
		if(Trim(tempvalue) == "")
		{
			if(intFlag == 0)
				window.alert("UserID can not be empty!");
			else
				window.alert("Password can not be empty!");		
			
			objIDPwd.focus();
			objIDPwd.select();	
			return false;			
		}				
		
		
		var len = tempvalue.length;
		if(len < 4)
		{
			if(intFlag == 0)
				window.alert("Length of UserID must be greater than or eaqual to 4!");
			else
				window.alert("Length of Password must be greater than or eaqual to 4");	
			
			objIDPwd.focus();
			objIDPwd.select();	
			return false;			
		}
		
		return true;
	} 

	function onMaintainUserSubmitHandler(myForm)
	{
		var varRet;		

		varRet = isUserIDPwdLenValid(0,myForm.txtUserID);
		if(!varRet)
			return false;
			
		varRet = isUserIDPwdLenValid(1,myForm.txtPwd);
		if(!varRet)
			return false;

		varRet = isUserIDPwdLenValid(1,myForm.txtConfirmPsw);
		if(!varRet)
			return false;

		varRet = isValidEmailAddress(myForm.txtEmail.value);
		if(!varRet)
		{
			alert("Email address format is invalid! ");
			myForm.txtEmail.focus();
			myForm.txtEmail.select();
			
			return false;
		}
						
		return true;
	}*/	
	
	/*
	function isUserIDPwdLenValid(intFlag,objIDPwd)
	{	
		var varReturnMsg = "";
		var tempvalue = objIDPwd.value;
		
		var len = tempvalue.length;
		if(len < 4)
		{
			if(intFlag == 0)
				varReturnMsg = <%=m_appInfo.GetErrMsg("4003")%>; //"Length of UserID must be greater than or eaqual to 4! ";
			else
				varReturnMsg = '<%=m_appInfo.GetErrMsg("4004")%>';//"Length of Password must be greater than or eaqual to 4! ";	
		}
		
		return varReturnMsg;
	} 

	function onMaintainUserSubmitHandler(myForm)
	{
		var bRet = true;
		var bTmpRet;
		var strRet;
		var strMsg = "";
		
		
		if(myForm.txtUserID.value == "" || myForm.txtPwd.value == "" || myForm.txtConfirmPsw.value == "" || myForm.txtFName.value =="" || 
		myForm.txtLName.value =="" || myForm.txtPhoneHomeArea.value == "" || myForm.txtPhoneHome.value == "" || myForm.txtEmail.value =="" || 			
		myForm.txtHomeSuiteNo.value == "" || myForm.txtHomeAddress.value == "" || myForm.txtHomeCity.value =="" || 			
		myForm.txtHomeProvince.value == "" || myForm.txtHomeCountry.value == "" || myForm.txtHomePostCode.value =="")
		{
			strMsg += '<%=m_appInfo.GetErrMsg("30001")%>' + "\n"; //"The fields indicated with an asterisk (*) are required! ";
			bRet = false;
		}		
		
		if(myForm.txtUserID.value != "")
		{
			strRet = isUserIDPwdLenValid(0,myForm.txtUserID);
			if(strRet != "")
			{
				strMsg += strRet + "\n";
				bRet = false;
			}
		}
		
		if(myForm.txtPwd.value != "")
		{
			strRet = isUserIDPwdLenValid(1,myForm.txtPwd);
			if(strRet != "")
			{
				strMsg += strRet + "\n";
				bRet = false;
			}
		}

		if(myForm.txtConfirmPsw.value != "")
		{
			strRet = isUserIDPwdLenValid(1,myForm.txtConfirmPsw);
			if(strRet != "")
			{
				strMsg += strRet + "\n";
				bRet = false;
			}
		}
			
		if(myForm.txtPwd.value != myForm.txtConfirmPsw.value)
		{
			strMsg += '<%=m_appInfo.GetErrMsg("4005")%>' + "\n";//"Password and Confirm Password should be the same! ";
			bRet = false;
		}
		
		if((new Date()).setTime(Date.parse(myForm.txtIDSetupDate)) > (new Date()).setTime(Date.parse(myForm.txtIDSpsnDate)))
		{
			strMsg += '<%=m_appInfo.GetErrMsg("4006")%>' + "\n";//"User ID Suspension Date must be greater than User ID Setup Date. ";
			bRet = false;
		}
		
		if(myForm.txtEmail.value != "")
		{

			bTmpRet = isValidEmailAddress(myForm.txtEmail.value);
			if(!bTmpRet)
			{
				strMsg += '<%=m_appInfo.GetErrMsg("30002")%>' + "\n"; //"Email address format is invalid! ";

				bRet = false;
			}
		}

		//User group
		var bIsGroupSelected = false;
		var rowsCount = parseInt('<%=GroupList.Rows.Count%>');
		for(var i = 0; i < rowsCount; i++)
		{
			var strGroupName = "chkGroup" + i;
			var bIsChecked = document.getElementById(strGroupName).checked;
			if(bIsChecked)
			{	
				bIsGroupSelected = true;
				break;
			}			
		}

		if(!bIsGroupSelected)
		{
			bRet = false;
			strMsg += '<%=m_appInfo.GetErrMsg("4007")%>' + "\n";//"Please select at least one group!";
		}	
		if(!bRet)
			window.alert(strMsg);
		return bRet;
	}		*/
	
	
