var objBroType = new BrowserTypes();
//function that allows Numeric and dot(.) only
function validNumAndDot()
	{
		if (event.keyCode < 46 || event.keyCode == 47 || event.keyCode > 57)
			event.keyCode = 0;
	}

//function that allows only Numeric
function validNumOnly()
	{
		if (event.keyCode < 48 || event.keyCode > 57)
			event.keyCode = 0;
	}

//function that allows only positive decimals
function PositiveDecimal()
	{		
			if (event.keyCode < 46 || event.keyCode == 47 || event.keyCode > 57)
				event.keyCode = 0;
	}
	
//Created By Phani on Mar-04-2004; to restrict the Reset Button to Invalid Action when the Page is Back Using the IE Back Button
//Modified By Phani on Mar-06-2004; Add the Parameter in the Func to enhance the same functionality to any form
function validReset(frmName)
{
	var hits1;	
	hits1 = eval("document."+ frmName +".hits.value") + 1;
	eval("document."+ frmName +".hits.value = hits1");
	
	if (hits1 > 1)
		{
			alert("Invalid Action\nPlease Refresh the page and Continue");
			return false;
		}
}

//Created By Phani on Feb-11-2004 ; the below Function allows Only Single dot(.) in textbox	
		function PosValnSingleDecimal(frmName,lint)
		{	
			if (event.keyCode < 46 || event.keyCode == 47 || event.keyCode > 57)
			{
			event.keyCode = 0;
			//alert("Allows Positive Int/Float Values Only");
			return false;
			}
			
			if(event.keyCode==46)
			{
				var str;
				var strLen, k;
					strLen = 0;
					k = 0;
				str=eval("document." + frmName + "." + lint + ".value");
				strLen = str.length;					
					if(strLen>0)						//MAIN IF
					{
					for (i=0; i<strLen; i++)			//For
						{
							if (str.charAt(i) == ".")	//Outer IF
							{
								k += 1;
								if (k >= 1)				//SUB IF
								{
									alert("Enter Only Single (.) Dot");
									event.keyCode=0;
								}		//End SUB IF
							}		//End Outer IF
						}		//End For
					}	//End MAIN IF
						
		    }	   //End IF event.keyCode==46
		}	//End function
		
//Created By Phani on Mar-03-2004 ; the below Function allows a Single dot(.) string value to Zero
//and the combination of Zeros with Dot to Zero. ex:- 0.000, 0., .0 etc

function OnblurForDotnZeros(frmName,ctrlName)
{
		var str;
		str=eval("document."+ frmName + "." + ctrlName +".value");		
		
		var strLen=0, k=0, count=0;
		strLen = str.length;					

		if(strLen>0)
		{
			if (str==".")
			{
				eval("document."+ frmName + "." + ctrlName +".value='0'");
			}
			var acc=0;
			acc=eval("parseFloat(document."+ frmName + "." + ctrlName +".value)");
			eval("document."+ frmName + "." + ctrlName +".value=acc");
					
		}
		else //if the textbox value is empty then by default it occupies by '0'
		{
			eval("document."+ frmName + "." + ctrlName +".value='0'");
		}
}
	
//function that allows positive and negative decimals
function Decimal()
	{
		if (event.keyCode < 45 || event.keyCode == 47 || event.keyCode > 57)
			event.keyCode = 0;
	}
//function that allows positive and negative decimals with %
function DecimalWithPercent()
	{
		if ((event.keyCode < 45 && event.keyCode != 37) || event.keyCode == 47 || event.keyCode > 57)
			event.keyCode = 0;
	}
//function that allows value >= 0 (whole numbers)
function PositiveInteger()
	{
		if (event.keyCode < 48 || event.keyCode > 57)
		{
			event.keyCode = 0;
			//alert("Allows Positive Integers Only");
			return false;
		}	
	}

//function that allows only Integers
function Integer()
	{
		if (event.keyCode < 45 || event.keyCode == 46 || event.keyCode == 47 || event.keyCode > 57)
			event.keyCode = 0;
	}

//function that Checks the length of the typing string and informs to user
// Here "Name" indicates formName.fieldName...
//Length stands for the Max length allowed in that field...
function MaxLength(Name,Length)
	{   
	
		if(event.keyCode == 34 || event.keyCode == 39)
			event.keyCode = 0;
		var str ;
		str = new String(eval("document."+Name+".value"));
		if(str.length>Length)
			alert("Maximum allowed Length : "+Length+"\nCurrent Length :"+str.length);
	}
	
	//function that restricts characters &, #, -, ', and "
function RestrictChar()
	{
	//alert("RestrictChar(2)");
		if (event.keyCode == 34 || event.keyCode == 35 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 45)
			event.keyCode = 0;
	}
	
	//Function that restricts all characters except Alphabet,Positive Num.,Space and UnderScore	
	//by vamsip on 21/10/2003
	//Modified by Phani on 04-03-04 
function RestrictAll()
	{
		if ((event.keyCode >= 33 && event.keyCode <= 47) || (event.keyCode >=58 && event.keyCode <=64) || (event.keyCode >=91 && event.keyCode <=94) || (event.keyCode ==96) || (event.keyCode >=123 && event.keyCode <=126))
		{    
		event.keyCode = 0;
		//alert("Allows Only Alphabet, 0-9, Space and UnderScore");
		return false;
		}
	}
//Created By Phani on 04-03-04;
//Function that allows Alphabet And 0-9 Numbers Only	
function CharsNnumOnly()
	{
		if ((event.keyCode <= 47) || (event.keyCode >=58 && event.keyCode <=64) || (event.keyCode >=91 && event.keyCode <=96) || (event.keyCode >=123 && event.keyCode <=126))
		{    
		event.keyCode = 0;
		//alert("Allows Only Alphabet, 0-9\nand Maximum Allowed 3 Chars");
		return false;
		}
	}
		
	/*	***		Function to restrict null string	***	*/
function validNullString(strName,name)
	{
		//alert(" in ValidNullString ");
		var lenName, strString, k;
		lenName = 0;
		k = 0;
		eval("strString="+strName+".value");
		lenName = strString.length;					
		if(lenName>0){
		for (i=0; i<lenName; i++)
			{
				if (strString.charAt(i) == " ")
					k += 1;
			}				
		if (k == lenName){
			eval(strName+".focus()");				
			alert(name+" Cannot be Blank");
			eval(strName+".value=''");
			}
		}				
	}

function openNewWin(fname)
	{
	
	    window.open(fname,"Details","height=" + (window.screen.height - 150) + ", width=" + (window.screen.width - 75) + ", top=30, left=30, dependent=yes, scrollbars=yes, resizable=yes")
	}
//	function conFirmDelEmp(strJob)
//		{
//			var conEmp;
//			conEmp = confirm(" Are you sure you want to delete the " + strJob + "?");
//			
//			if(conEmp == false)
//			{
//				return false;
//			}
//		}


/*
##############################################################################################################
				Created By : Ravindra
				Created Dt : 29-May-2004
				Purpose    : To show the dynamic time counter
##############################################################################################################
*/
				var get_ServerTime, blnFirst, eleName, fName;
				
				function fnShowTimer(fmName, txtName, hidName)
					{
						//this function eventually calls another function "fnStartTimeCounter()"
						//for every second (1000 milli seconds). I choose one b'se
						//that's how often we want our clock to change for every second
					
						fName = fmName;
						eleName = txtName;
						//	get_ServerTime = new Date(eval("document." + fName + "." + hidName + ".value"));
						get_ServerTime = new Date(document.getElementById(hidName).value);
						fnProcessTime(get_ServerTime);
						setInterval("fnStartTimeCounter()", 1000);
					}
				
				function fnStartTimeCounter()
					{
						var update_time, hours, minutes, seconds, tag;
						var curDtTime, prev_Time;
						var strTime;
						
						//get the date from server
						hours = get_ServerTime.getHours();
						minutes = get_ServerTime.getMinutes();
						seconds = (get_ServerTime.getSeconds() + 1);
						
						if (seconds > 59)
							{
								seconds = 0;
								minutes = minutes + 1;
								
								if (minutes > 59)
									{
										minutes = 0;
										hours = hours + 1;
									}
							}
							
												
						strTime = (get_ServerTime.getMonth() + 1) + "-" + get_ServerTime.getDate() + "-" + get_ServerTime.getFullYear() + " " + hours + ":" + minutes + ":" + seconds;
						curDtTime = new Date(strTime);
					
						
						//call the function to process the time and assign it to text-box
						fnProcessTime(curDtTime);
						
						get_ServerTime = curDtTime;
					}
				
				
				
			function fnProcessTime(varDt)
				{
					var curDtTime;
					var update_time, hours, minutes, seconds, tag;
					
					curDtTime = new Date(varDt);
						
					//process hours and set the value for "Tag"
					hours = curDtTime.getHours();
					if (hours >= 12)
						tag = "PM";
					else
						tag = "AM";
					
					if (hours > 12)
						{
							hours = hours - 12;
						}
					
					//process minutes
					minutes = curDtTime.getMinutes();
					if (minutes < 10)
						{
							minutes = "0" + minutes;
						}
					
					//process seconds
					seconds = curDtTime.getSeconds();
					if (seconds < 10)
						{
							seconds = "0" + seconds;
						}
					
					update_time = hours + ":" + minutes + ":" + seconds + " " + tag;
					//eval("document." + fName + "." + eleName + ".value = update_time");
					document.getElementById(eleName).value = update_time;
				}
				
				/*this function is written by pattan.
				this function is mainly used for calculating the number of characters
				in a given textarea. on 3-6-2004.*/ 
			function CharVal(frmName,txaText,maxLength,txtName,hidName)
			{
			
			
			   	var lstrTextName,lstrCharVal,lstrCharCnt;
			  	
			  lstrTextName = eval("document."+frmName+"."+txaText+".name");
				 
				if (lstrTextName==txaText)
				{
		
					lstrCharVal = eval("document."+frmName+"."+txaText+".value");
					lstrCharCnt = lstrCharVal.length;
					if(lstrCharCnt<=maxLength)
					{
			
						var temp = (maxLength - eval("document."+frmName+"." +txaText+".value.length")) + " Characters remaining";
						
						eval("document."+frmName+"."+txtName+".value=temp"); 
						
						if(lstrCharCnt==maxLength)
						{
							var temp2 = eval("document."+frmName+"."+txaText+".value");
							eval("document."+frmName+"."+hidName+".value = temp2");
									
						}
	
					}
			
					if (lstrCharCnt>maxLength)
					{
							
						alert("Exceeding the limit of max "+maxLength+" characters");
						eval("document."+frmName+"."+txaText+".value = document."+frmName+"."+hidName+".value");
						
						eval("document."+frmName+"."+txaText+".focus()");
						return false;
					}
				}
			}
			
//Modified By Surya On 11-Aug-2004;for checking all check boxes when clicking 
//on checkAll checkbox.


function fnCheckAll(str,count,frmName)
 {
 
	var str1,j;
	var arrStr1=new Array();
	var str5;
	var inc=1;

 str1=(eval("document." + frmName + ".hidTemp" + count + ".value"));
  if(str1.charAt(0)!= "#"){
		str5 =str1.charAt(0);
		str5 = str5 + str1.charAt(1);
	}
  else{str5 = str1.charAt(1);}

	for(j=2;j<str1.length;j++){
		str5=str5+str1.charAt(j);
	}
   	arrStr1=str5.split("#");

	for(j=0;j<arrStr1.length;j++){
		inc = inc + 1;
	if (eval("document."+ frmName + "." + arrStr1[j] + ".disabled== false")){
		if (eval("document."+ frmName + "." + arrStr1[j] + ".checked!=1")){
		eval("document."+ frmName + "." + arrStr1[j] + ".checked=1");
		}
		else{
		eval("document."+ frmName + "." + arrStr1[j] + ".checked=0");
		}		
		var str3="";
		if (eval("document."+ frmName + "." + arrStr1[j] + ".disabled== false")){
			for (var k=inc-2;k<inc-1;k++){
				var str2 = arrStr1[k];	
				for(var l=0; l<str2.length;l++){
					if(isNaN(str2.charAt(l))){
						str3 = str3 + str2.charAt(l);
					}		
				}
      		check(str3,count,frmName);
			str3="";
            }
        }	
        
    }
   }
}

//Created By VamsiP On 02-Jun-2004;for checking all check boxes when clicking 
//on checkAll checkbox.
	
function check(str,count,frmName)
		{	
			
	
			var hidChkStr;
			arrChkStr = new Array();
		
			arrAttStr = new Array();
			arrMSRStr = new Array();
			arrVRStr = new Array();
			arrSRStr = new Array();
			arrJobsStr = new Array();
			arrDefectsStr = new Array();
			
			hidChkStr = (eval("document." + frmName + ".hidVal" + count + ".value"));
		
			arrChkStr=hidChkStr.split("*");
			arrAttStr=arrChkStr[0].split("#");
			arrMSRStr=arrChkStr[1].split("#");
			arrVRStr=arrChkStr[2].split("#");
			arrSRStr=arrChkStr[3].split("#");
			arrJobsStr=arrChkStr[4].split("#");
			arrDefectsStr=arrChkStr[5].split("#");
			
				
			arr1 = new Array();
			if (str == "chkAllAtt")
			{
				arr1 = arrAttStr;
				
			}else if (str == "chkAllMSR")
			{
				arr1 = arrMSRStr;
			
			}else if (str == "chkAllVR")
			{
				arr1 = arrVRStr;
			}else if (str == "chkAllSR")
			{
				arr1 = arrSRStr;
			}else if (str == "chkAllJobs")				
			{
				arr1 = arrJobsStr;
			}else
			{
				arr1 = arrDefectsStr;
			}
					
				
			for (i=0;i<arr1.length;i++)
			{

				eval("document." + frmName + "." + arr1[i] + ".checked=1");
			}

			if (eval("document." + frmName + "." + str + count + ".checked!=1"))
			{
				for (i=0;i<arr1.length;i++)
				{
					eval("document." + frmName + "." + arr1[i] + ".checked=0");
				}
			}
		}
		
function disableChecklistItem(cmbId,divId){
   // alert("Hi");
	var strValue = document.getElementById(cmbId).value
	
	if (strValue =="Appraisal"){
	      document.getElementById(divId).style.display="";
	}
    else{
	 	 document.getElementById(divId).style.display="none";
	}
}
//Added by rayudu for tooltip on may-20th-2005
function BrowserTypes()
{
	var d = document;
	
	this.agt = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.dom = (d.getElementById) ? 1:0;
	
	this.ns = (d.layers);
	this.ns4up = (this.ns && this.major >= 4);
	this.ns6 = (this.dom && navigator.appName == "Netscape");
	
	this.op = window.opera ? 1:0;
	
	this.ie = (d.all);
	this.ie4 = (d.all && this.dom) ? 1:0;
	this.ie4up = (this.ie && this.major >= 4);
	this.ie5 = (d.all && this.dom);
		this.win = ( (this.agt.indexOf("win") != -1) || (this.agt.indexOf("16bit") != -1) );
	this.mat = (this.agt.indexOf("mac") != -1);
}
function fnDivMouseOver(){

                document.getElementById("hidDivMouseOver").value="true";
    }
   function fnMouseOverTip(divID)
			{
					
			    var hidMenu=document.getElementById("hidPrevMenu").value;
			   
			    if(hidMenu!=""){
			  	 document.getElementById(hidMenu).style.visibility='hidden';}
			
			    var objDIV = document.getElementById("dvStyle" + divID);
			//alert(objDIV);
				if (objDIV)
				{//alert(objDIV);
					if (document.all) objDIV.style.width = objDIV.offsetWidth;
					
					var objLink = document.getElementById("lnkStyle" + divID);
					
					var intTop = GetPageY(objLink) + objLink.offsetHeight + 10;
					
					var intLeft = GetPageX(objLink);
					objDIV.style.top = intTop;
					objDIV.style.left = intLeft;
					objDIV.style.width = 550;
								
					objDIV.style.visibility='visible';
					objDIV.style.position='absolute';
					objDIV.style.background='lightyellow';
					document.getElementById("hidPrevMenu").value="dvStyle"+ divID;
				}
				//setTimeout("setTimeToTip('dvStyle'+ divID)",3000)
				//alert("TEST");
			}
			
			function fnMouseOutTip(divID)
			{
			//alert(divID)
			var blnDivMouseOver=document.getElementById("hidDivMouseOver").value;
			
			   if(blnDivMouseOver=="false"){
				   var objDIV = document.getElementById("dvStyle" + divID);
				    if (objDIV)
				    {      
    				    
					    objDIV.style.visibility = 'hidden';
				  }
			    }	
			}  
			  
function GetPageY(obj)
{
	var y = 0;
	if (objBroType.ns)
		y = obj.pageY;
	else
	{
		while (eval(obj))
		{
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return y;
}

function GetPageX(obj)
{
	var x = 0;
	if (objBroType.ns)
		x = obj.pageX;
	else
	{
		while (eval(obj))
		{
			x += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	return x;
}