

function strReverse(strString)
	{
		var strRev =new String();
		var intLen=strString.length;
		var intIndex;
		for (intIndex=intLen;intIndex>0;intIndex--)
		{
			strRev+= strString.charAt(intIndex-1);
		}
		return strRev;
	}
function lTrim(strString)
	{
		var intIndex,intLen;
		
		intLen=strString.length;
		intIndex=0;
		while(strString.charAt(intIndex)==' ' && intIndex<intLen )
		{
			intIndex++;
		}
		return strString.substring(intIndex,intLen);		
	}
	
	function checkInValidCharacters(strString)
		{
			
		//at present checking only Apstrophe ... 
		var intIndex,intLen;
		intLen=strString.length;
			intIndex=0;
		  while(intIndex<intLen )
			{
				if (strString.charAt(intIndex)=="'" )
				{
				return false;
				}
					intIndex++;
			}
			return true;
			
		}
	
	function rTrim(strString)
	{
		
		var intIndex,intLen;		
		intLen=strString.length;
		strString=strReverse(strString);
		strString=lTrim(strString)
		strString=strReverse(strString);				
		return strString;		
	}
	function trim(strString)
	{
		return rTrim(lTrim(strString));
	}
	
	function removeIntraSpaces(strStringToRemove)
	{
		var intIndex,intLen;
		var strResult;
		var chAtPos;
		
		intLen=strStringToRemove.length;
		intIndex=0;
		for(intIndex =0; intIndex < intLen ; intIndex ++)
		{
			chAtPos = strStringToRemove.charAt(intIndex);
			if(chAtPos==' ')
			{
			}else
			{
				strResult = strResult + chAtPos;
			}
		}	
		return strResult;	
	}



		function SplitWithComma(strEntireString,strFindingString)
		{ 
		        var intLength; 
		        var arrEntireString;
		        intLength = (new String(strEntireString)).split(",").length;
		       arrEntireString = (new String(strEntireString)).split(",");
		         for(i = 0; i< intLength; i++) 
		        {
		             if(strFindingString == arrEntireString[i]) return true;
		         } 
		        return false;
		}
 
 
 		function getMiscType(objCombo)
		{
		
			if(SplitWithPipe((new String(strMiscType)),trim(objCombo.options[objCombo.selectedIndex].value)+"#D"))
				return "D";
			else if(SplitWithPipe((new String(strMiscType)),trim(objCombo.options[objCombo.selectedIndex].value)+"#H"))
				return "H";	
			else
				return "O";	
		}
		
		function checkProperMisc(objCombo,objTextDollar,objTextHour,objTextMin)
		{
			if(getMiscType(objCombo) =="D") 
				return validateDollars(objTextDollar);
			else
				return validateHours(objTextHour,objTextMin);	
			return true;	
		}
		
		function validateDollars(objCombo)
		{
			var strDollarvalue = objCombo.value;
			if(isNaN(strDollarvalue))
			{
				alert("Please enter the proper Misc Dollar value ");
				objCombo.focus();
				return false;
			}
			if(strDollarvalue <= 0 )
			{
				alert("Please enter the proper Misc Dollar value ");
				objCombo.focus();
				return false;
			}
			return true;
		}
		
		function validateHours(objTextHour,objTextMin)
		{
			var strHourvalue = trim(objTextHour.value);
			var strMinValue = trim(objTextMin.value);
			
			if(strHourvalue == "")
			{
					alert("Please enter the Hour value  ");
					objTextHour.focus();
					return false;
			}
			if(strMinValue == "")
			{
					alert("Please enter the Minute value  ");
					objTextMin.focus();
					return false;
			}
			
			if (isNaN(strHourvalue)) 
			{
					alert("Please enter the proper Hour value  ");
					objTextHour.focus();
					return false;
			}
			if (isNaN(strMinValue)) 
			{
					alert("Please enter the proper Minute value  ");
					objTextMin.focus();
					return false;
			}
			if(strHourvalue > 23 || strHourvalue < 0 )
			{
					//alert("Please enter the proper Hour value  ");
					//objTextHour.focus();
					//return false;
			}
			if(strMinValue > 59 || strMinValue < 0 )
			{
					alert("Please enter the proper Minute value  ");
					objTextMin.focus();
					return false;
			}
			/*if((new String(strHourvalue)).split(":").length== 2)
			{
				if(isNaN((new String(strHourvalue)).split(":")[0]) || isNaN((new String(strHourvalue)).split(":")[0]) )
				{
					alert("Please enter the Hour value in HH:MM format ");
					objCombo.focus();
					return false;
				}
				if((new String(strHourvalue)).split(":")[0].split(".").length > 1 || (new String(strHourvalue)).split(":")[1].split(".").length > 1 || (new String(strHourvalue)).split(":")[0] < 0 || (new String(strHourvalue)).split(":")[1] < 0)
				{
					alert("Please enter the Hour value in HH:MM format ss");
					objCombo.focus();
					return false;
				}
				if((new String(strHourvalue)).split(":")[0]< 0 || (new String(strHourvalue)).split(":")[0] > 23 )
				{
					alert("Please enter the valid hour");
					objCombo.focus();
					return false;
				} 
				if((new String(strHourvalue)).split(":")[1]< 0 || (new String(strHourvalue)).split(":")[1] > 59 )
				{
					alert("Please enter the valid hour");
					objCombo.focus();
					return false;
				} 
			}
			else
			{
				alert("Please enter the Hour value in HH:MM format ");
				objCombo.focus();
				return false;
			}
			
			if(isNaN(strHourvalue))
			{
				alert("Please enter the proper Misc Hour value ");
				objCombo.focus();
				return false;
			}
			if(strHourvalue <= 0 )
			{
				alert("Please enter the proper Misc Hour value ");
				objCombo.focus();
				return false;
			}*/
			
			return true;
		}
		
		
		function SplitWithPipe(strEntireString,strFindingString)
		{ 
		    var intLength; 
		    var arrEntireString;
		    intLength = (new String(strEntireString)).split("|").length;
			arrEntireString = (new String(strEntireString)).split("|");
		    for(i = 0; i< intLength; i++) 
		    {
		         if(strFindingString == arrEntireString[i]) return true;
		     } 
		    return false;
		}	


		function padZerosBeforeTime(intTime)
		{
			if((new String(trim(intTime))).length == 1)
				return "0"+trim(intTime);
			else
				return trim(intTime);	
					
		}
		
		function padZerosAfterTime(intTime)
		{
			if((new String(trim(intTime))).length == 1)
				return trim(intTime)+"0";
			else
				return trim(intTime);	
		}
		
		function makeMinFromDecimal(intTime)
		{
			if(trim(intTime) =="")
				return "00";
			if(intTime == 0 )
				return "00";
		
			
			if( (new String(intTime)).length == 1)
			{
				intTime = intTime + "0"
			}
			if(intTime >0)
			{
				var dblTime = ((intTime*3)/5 )


				if(dblTime < 10 )
				{				
					if((new String(dblTime)).length== 1)
					{
						return "0"+dblTime
					}
					if( (new String(dblTime)).split(".").length == 2)
					{
					
						if((new String(dblTime)).split(".")[0] == 0)
						{
							return (new String(dblTime)).split(".")[0] + "" + (new String(dblTime)).split(".")[1].substring(0,1)
						}
						if( (new String(dblTime)).split(".")[0].length ==0)
						{
							return "0"+(new String(dblTime)).split(".")[1].substring(0,1)
						}
						else if( (new String(dblTime)).split(".")[0].length ==1)
						{
							return "0"+ (new String(dblTime)).split(".")[0]
						}
					}
				}	
				return padZerosAfterTime((new String(dblTime)).substring(0,2))
			}
				
		}
		
		function makeMiscHoursAndDollars(intCount)
		{
			var objForm = document.forms[1];
			if (getMiscType(objForm["Misc_Code"+intCount]) == 'H')
			{
				if(trim(objForm["txtMisc"+intCount].value) != "")
				{
					var dblHour = objForm["txtMisc"+intCount].value
					if(	(new String(dblHour)).split(".").length == 2)
					{
						objForm["txtMiscHour"+intCount].value = padZerosBeforeTime((new String(dblHour)).split(".")[0]) //+":" + makeMinFromDecimal((new String(dblHour)).split(".")[1])
						objForm["txtMiscMin"+intCount].value =  makeMinFromDecimal((new String(dblHour)).split(".")[1])
					}
					else
					{
						objForm["txtMiscHour"+intCount].value = padZerosBeforeTime((new String(dblHour)).split(".")[0]) //+":" + makeMinFromDecimal("0")
						objForm["txtMiscMin"+intCount].value =  makeMinFromDecimal("0")

					}
						
				}
				objForm["txtMisc"+intCount].value =""
				objForm["txtMisc"+intCount].disabled = true;
				objForm["txtMisc"+intCount].className = "formcellodd";
				
			}
			else if(getMiscType(objForm["Misc_Code"+intCount]) == 'D')
			{
				if(trim(objForm["txtMisc"+intCount].value) != "")
				{
					var dblHour = objForm["txtMisc"+intCount].value
					if(	(new String(dblHour)).split(".").length == 2)
					{
						objForm["txtMisc"+intCount].value = ((new String(dblHour)).split(".")[0]) +"." + padZerosAfterTime((new String(dblHour)).split(".")[1])
					}
					else
					{
						objForm["txtMisc"+intCount].value = ((new String(dblHour)).split(".")[0]) +"." + makeMinFromDecimal("00")

					}
						
				}
				objForm["txtMiscHour"+intCount].disabled= true;
				objForm["txtMiscHour"+intCount].className = "formcellodd";
				objForm["txtMiscMin"+intCount].disabled=true;
				objForm["txtMiscMin"+intCount].className = "formcellodd";
			}
		}
		
		
		function makeEnabled(intCount)
		{
			var objForm = document.timesheetFrm
			if(getMiscType(objForm["Misc_Code"+intCount]) == "D")
			{
				objForm["txtMiscHour"+intCount].value =""
				objForm["txtMiscHour"+intCount].disabled = true;
				objForm["txtMiscHour"+intCount].className = "formcellodd";
				objForm["txtMiscMin"+intCount].value =""
				objForm["txtMiscMin"+intCount].disabled = true;
				objForm["txtMiscMin"+intCount].className = "formcellodd";
				objForm["txtMisc"+intCount].disabled=false;
				objForm["txtMisc"+intCount].className = "";
			}
			if(getMiscType(objForm["Misc_Code"+intCount]) == "H")
			{
				objForm["txtMiscHour"+intCount].disabled = false;
				objForm["txtMiscHour"+intCount].className = "txthrright";
				objForm["txtMiscMin"+intCount].disabled = false;
				objForm["txtMiscMin"+intCount].className = "txtleft";
				objForm["txtMisc"+intCount].disabled=true;
				objForm["txtMisc"+intCount].className = "formcellodd";
				objForm["txtMisc"+intCount].value =""
			}
		}
		
		/* **************************************
		   Function to validate Canadian SIN number  
		   Rani Shivadas
		   Feb 25th 2002
		   **************************************/
		function checkSINValidity(strSIN)
			{
				var CheckNum;
				var intDiff;
				CheckNum = parseInt(strSIN.charAt(8), 10);
							
				strTemp = "";
				for (intCnt = 0; intCnt < strSIN.length-1; intCnt++)
				{
					c = parseInt(strSIN.charAt(intCnt), 10);
					//To Add the number to itself.
					if (intCnt % 2 != 0)
					c *= 2;
					strTemp = strTemp + c;
				}
							 
				// Finally, add up all the single digits in this string.
				newNum = 0;
				for (intCnt = 0; intCnt < strTemp.length; intCnt++) {
					c = parseInt(strTemp.charAt(intCnt), 10);
					newNum = newNum + c;
				}
							
				// if the total is a multiple of 10, the check digit should be 0.
				if (parseInt(newNum) % 10 == 0)
				{
					intDiff= 0;
					intNextNum = newNum;
				}			
				else
				{
					//subtract the total calculated from the next highest number ending in zero.
					intNextNum = Math.ceil(parseInt(newNum) / 10 ) * 10 ;
					intDiff = intNextNum - parseInt(newNum);
				}	
				
					
				
				if (intDiff == CheckNum )
				{
					return true;
				}
				else
				{
					return false;
										  
				}
		
			}
			
			/*
			Function : To validate phone numbers
			Author	 : Manikandan
			Date	 : 2nd April 2002
			Bug ID	 : AUD0173MR
			Description: 
				Allows only set of 0-9, space, (, ), + and - chars.
			*/
			function isValidPhone(strPhone){
			
				var rePhone = /^[\s0-9()+-]*$/;
				
				return rePhone.test(strPhone);
			}