/// PCR 5205	02/24/06	Li	Do not allow users to enter more than 24 hours in a day
///								change CheckSave(). If user click cancel first time and click button/link to other page, 
///								It didn't display the message.
///				02/27/06	Li	Don't count 'PO' class when checking for 24 hours. also don't count it in daily total and tc total.
/// PCR 5247	03/28/06	Li	Call RoundNumber() for totals.
/// PCR 5682, 5683 09/24/07  BS  Default pay code when a linked work order is entered manually.

var dialogWin = new Object();
var txtBoxNum;
var txtBoxName;
var txtBoxValue;
var txtBoxFrom;

var timecardChanged = false;
var approvalChanged = false;
var firstTime = true;
var runOnce = true;

var previousJob;
var ddlJobCodeDescription;
var resetJob;

var previousPayCode;
var	savedDdlPayCode;
var	resetPayCode;

var commentBtn;

//Run Comments 
function RunComments(btn)
{
	
	var ddlJobDesc = document.getElementById(btn.name.replace("ibtnComment", "ddlJobDescription").split(":").join("_"));
	var ddlJobCode = document.getElementById(btn.name.replace("ibtnComment", "ddlJobCode").split(":").join("_"));
	var line = document.getElementById(btn.name.replace("ibtnComment", "txtTimeCardLine").split(":").join("_"));
	var commentPage;
	var blankCheck = ddlJobDesc.options[ddlJobDesc.selectedIndex].text;
	if (blankCheck == '' || blankCheck == 'BLANK' || blankCheck == 'SEARCH' || blankCheck == 'ADDMULTI' || blankCheck == 'MANUAL')
	
	{
		alert("You need to enter a valid job before adding comments");	
	}
	else
	{
		commentBtn = btn;
		dialogWin.name = "Comments";		
//		if (navigator.appName == 'Netscape') 
        if(IsIEBrowser)
        {
			w = 700; 
			h = 735;
			commentPage = "Comments.aspx" + "?LineNumber=" + line.value +
//							"&JobCode=" + ddlJobCode.options[ddlJobCode.selectedIndex].text +
							"&JobDesc=" + ddlJobDesc.options[ddlJobDesc.selectedIndex].text;
		}
		else
		{
			w = 700; 
			h = 735;
			commentPage = "Comments.aspx" + "?LineNumber=" + line.value +
//							"&JobCode=" + ddlJobCode.options[ddlJobCode.selectedIndex].text +
							"&JobDesc=" + ddlJobDesc.options[ddlJobDesc.selectedIndex].text;
			
		} 
//		else 
//		{
//			w = 690; 
//			h = 735;
//			commentPage = "CommentsDialog.aspx" + "?LineNumber=" + line.value +
//							"&JobCode=" + ddlJobCode.options[ddlJobCode.selectedIndex].text +
//							"&JobDesc=" + ddlJobDesc.options[ddlJobDesc.selectedIndex].text;
//		}
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h - 40) / 2;
		
//		if (navigator.appName == 'Netscape')
        if(IsIEBrowser)
        {
		    ClearTimer();
            window.status = "";
        
			retValue = window.showModalDialog(AddDynamicSessionParameter(commentPage), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
			SetCommentImage(retValue);
		}
		else
		{
			ResetTimer();
			
			if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter(commentPage),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
		}
	}
	return false;
}

function ViewComments(btn)
{
	if (btn.src.indexOf("commentoff") <= 0)
	{
		var line = document.getElementById(btn.name.replace("ibtnComment", "txtTimeCardLine").split(":").join("_"));
		var rows = document.getElementById("tblTimeCardView").getElementsByTagName("tr");
		var	cols = rows[window.document.forms["frmTimeCardView"]["txtLineNumber"].value].getElementsByTagName("td");
		var ddlJobDesc = cols[2].innerHTML.substring(6);
//		var ddlJobDesc = cols[3].innerHTML + " (" + cols[4].innerHTML + ")";
		var commentPage;

		dialogWin.name = "Comments";		
//		if (navigator.appName == 'Netscape') 
        if(IsIEBrowser)
        {
			w = 690; 
			h = 710;
			commentPage = "Comments.aspx" + "?LineNumber=" + line.value +
							"&JobDesc=" + ddlJobDesc;
		}
		else
		{
			w = 690; 
			h = 710;
			commentPage = "Comments.aspx" + "?LineNumber=" + line.value +
						"&JobDesc=" + ddlJobDesc;
		} 
//		else 
//		{
//			w = 690; 
//			h = 710;
//			commentPage = "CommentsDialog.aspx" + "?LineNumber=" + line.value +
//							"&JobDesc=" + ddlJobDesc;
//		}
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h - 40) / 2;
		
//		if (navigator.appName == 'Netscape')
        if(IsIEBrowser)
        {
		    ClearTimer();
            window.status = "";
            
			window.showModalDialog(AddDynamicSessionParameter(commentPage), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		}
		else
		{
			ResetTimer();
			
			if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter(commentPage),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
		}
	}
	
	return false;
}

function SetCommentImage(hasComment)
{
	if (hasComment[0])
		commentBtn.src = "images/commenton.gif";
	else
		commentBtn.src = "images/commentoff.gif";

	if (hasComment[1])
		document.frmTimeCardEdit.imgTCComment.src = "images/commenton.gif";
	else
		document.frmTimeCardEdit.imgTCComment.src = "images/commentoff.gif";
}

//Backup and Set extra information
function SetRow(fname, force)
{	
	var rptInfo = GetRepeaterInfo(fname)
	//rptInfo[0] is current line number. [1] is repeater prefix.
	
	//get the line number from the line number box
	var preLineNumber = window.document.frmTimeCardEdit['txtLineNumber'].value;
	//check the current line number against the number in the line number box
	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
	{
		if ((preLineNumber != rptInfo[0]) && (preLineNumber > 0))
				SaveExtraInfoToLine(rptInfo[1], preLineNumber);

		if (force || (preLineNumber != rptInfo[0]))
		{
			GetExtraInfoFromLine(rptInfo[1], rptInfo[0], "frmTimeCardEdit");
			//change the number in the line number box
			window.document.forms["frmTimeCardEdit"]["txtLineNumber"].value = rptInfo[0];
			if (preLineNumber > 0)
			{
				window.document.frmTimeCardEdit["imgLineFocus" + preLineNumber].src = "images/linearrowoff.gif";
			}
			window.document.frmTimeCardEdit["imgLineFocus" + rptInfo[0]].src = "images/linearrowon.gif";
		}
	}
}
function SelectRow(fname)
{	
	var rptInfo = GetRepeaterInfo(fname)
	//rptInfo[0] is current line number. [1] is repeater prefix.
	
	//check the current line number against the number in the line number box
	//get the line number from the line number box
	var preLineNumber = window.document.frmTimeCardView['txtLineNumber'].value;
	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
	{
		if (preLineNumber != rptInfo[0])
		{
			GetExtraInfoFromLine(rptInfo[1], rptInfo[0], "frmTimeCardView");
			//change the number in the line number box
			window.document.forms["frmTimeCardView"]["txtLineNumber"].value = rptInfo[0];
			if (preLineNumber > 0)
			{
				window.document.frmTimeCardView["imgLineFocus" + preLineNumber].src = "images/linearrowoff.gif";
			}
			window.document.frmTimeCardView["imgLineFocus" + rptInfo[0]].src = "images/linearrowon.gif";
		}
	}
}

function SaveExtraInfoToLine(prefix, lineNumber)
{
	var tempID;
	var tempDesc;
	//this splits the extra info list in to an array
	var valInfo = document.frmTimeCardEdit.txtExtraInfoList.value.split('|');
	
	for (var i = 1; i <= 7 ; i++)
	{	
		var extraID = "txtExtraInfo" + i;
		var extraDesc = "txtExtraInfoDesc" + i;

		//this will be put and get code for the form
		switch (valInfo[i-1])
		{
			case "WorkOrder":
			    if (document.frmTimeCardEdit.txtWorkOrderOnEveryLine.value != "true")
			    {
				    tempID = prefix + lineNumber + ":" + "txtWorkOrder";
				    tempDesc = prefix + lineNumber + ":" + "txtWorkOrderDesc";
				    document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;
				    document.frmTimeCardEdit[tempDesc].value = document.frmTimeCardEdit[extraDesc].value;
				}
				break;
			case "Organization":
				tempID = prefix + lineNumber + ":" + "txtDepartment";
				tempDesc = prefix + lineNumber + ":" + "txtDepartmentDesc";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;
				document.frmTimeCardEdit[tempDesc].value = document.frmTimeCardEdit[extraDesc].value;
				break;
			case "CostElement":
				tempID = prefix + lineNumber + ":" + "txtCostElement";
				tempDesc = prefix + lineNumber + ":" + "txtCostElementDesc";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;
				document.frmTimeCardEdit[tempDesc].value = document.frmTimeCardEdit[extraDesc].value;
				break;
			case "Location":
				tempID = prefix + lineNumber + ":" + "txtLocation";
				tempDesc = prefix + lineNumber + ":" + "txtLocationDesc";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;
				document.frmTimeCardEdit[tempDesc].value = document.frmTimeCardEdit[extraDesc].value;					
				break;
			case "Text":
				tempID = prefix + lineNumber + ":" + "txtText";
				tempDesc = prefix + lineNumber + ":" + "txtTextDesc";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;
				document.frmTimeCardEdit[tempDesc].value = document.frmTimeCardEdit[extraDesc].value;					
				break;
			case "EstimatedHours":
				tempID = prefix + lineNumber + ":" + "txtEstimatedHours";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;					
				break;
			case "LaborCategory":
				tempID = prefix + lineNumber + ":" + "txtLaborCategory";
				tempDesc = prefix + lineNumber + ":" + "txtLaborCategoyDesc";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;
				document.frmTimeCardEdit[tempDesc].value = document.frmTimeCardEdit[extraDesc].value;						
				break;
			case "SpecialPayCode":
				tempID = prefix + lineNumber + ":" + "txtSpecialPayCode";
				tempDesc = prefix + lineNumber + ":" + "txtSpecialPayCodeDesc";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;
				document.frmTimeCardEdit[tempDesc].value = document.frmTimeCardEdit[extraDesc].value;
				break;
			case "SpecialAmount":
				tempID = prefix + lineNumber + ":" + "txtSpecialPayAmount";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;					
				break;
			case "BudgetHours":
				tempID = prefix + lineNumber + ":" + "txtBudgetHoursRemain";
				document.frmTimeCardEdit[tempID].value = document.frmTimeCardEdit[extraID].value;					
				break;
		}	
	}
}

function GetExtraInfoFromLine(prefix, lineNumber, frmName)
{
	var tempID;
	var tempDesc;
	
	//this splits the extra info list in to an array
	var valInfo = document.forms[frmName].txtExtraInfoList.value.split('|');
	for (var i = 1; i <= 7 ; i++)
	{	
		var extraID = "txtExtraInfo" + i;
		var extraDesc = "txtExtraInfoDesc" + i;
		//this will be put and get code for the form
		switch (valInfo[i-1])
		{
			case "WorkOrder":
			    if (document[window.name].txtWorkOrderOnEveryLine.value != "true")
			    {
				    tempID = prefix + lineNumber + ":" + "txtWorkOrder";
				    tempDesc = prefix + lineNumber + ":" + "txtWorkOrderDesc";
				    document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				    document.forms[frmName][extraDesc].value = document.forms[frmName][tempDesc].value;
				}
				break;
			case "Organization":
				tempID = prefix + lineNumber + ":" + "txtDepartment";
				tempDesc = prefix + lineNumber + ":" + "txtDepartmentDesc";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				document.forms[frmName][extraDesc].value = document.forms[frmName][tempDesc].value;					
				break;
			case "CostElement":
				tempID = prefix + lineNumber + ":" + "txtCostElement";
				tempDesc = prefix + lineNumber + ":" + "txtCostElementDesc";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				document.forms[frmName][extraDesc].value = document.forms[frmName][tempDesc].value;
				break;
			case "Location":
				tempID = prefix + lineNumber + ":" + "txtLocation";
				tempDesc = prefix + lineNumber + ":" + "txtLocationDesc";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				document.forms[frmName][extraDesc].value = document.forms[frmName][tempDesc].value;
				break;
			case "Text":
				tempID = prefix + lineNumber + ":" + "txtText";
				tempDesc = prefix + lineNumber + ":" + "txtTextDesc";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				document.forms[frmName][extraDesc].value = document.forms[frmName][tempDesc].value;
				break;
			case "EstimatedHours":
				tempID = prefix + lineNumber + ":" + "txtEstimatedHours";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				break;
			case "LaborCategory":
				tempID = prefix + lineNumber + ":" + "txtLaborCategory";
				tempDesc = prefix + lineNumber + ":" + "txtLaborCategoyDesc";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				document.forms[frmName][extraDesc].value = document.forms[frmName][tempDesc].value;
				break;
			case "SpecialPayCode":
				tempID = prefix + lineNumber + ":" + "txtSpecialPayCode";
				tempDesc = prefix + lineNumber + ":" + "txtSpecialPayCodeDesc";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				document.forms[frmName][extraDesc].value = document.forms[frmName][tempDesc].value;
				break;
			case "SpecialAmount":
				tempID = prefix + lineNumber + ":" + "txtSpecialPayAmount";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				break;
			case "BudgetHours":
				tempID = prefix + lineNumber + ":" + "txtBudgetHoursRemain";
				document.forms[frmName][extraID].value = document.forms[frmName][tempID].value;
				break;
		}	
	}
	//5390
	switch (document.forms[frmName].txtDisplay1.value)
	{
		case "LongJob":
			tempDesc = prefix + lineNumber + ":" + "txtJobLongDesc";
			document.forms[frmName].txtDescription1.value = document.forms[frmName][tempDesc].value;
			break;
		case "WorkBreakDown":
			tempDesc = prefix + lineNumber + ":" + "txtWBSLabel";
			tempID = prefix + lineNumber + ":" + "txtWBSText";
			if (document.forms[frmName][tempID].value == "")
			{
				document.forms[frmName].lblDescription1.value == "Work Breakdown ID:";
			}
			else
			{
				document.forms[frmName].lblDescription1.value = document.forms[frmName][tempDesc].value + ":";
			}
			document.forms[frmName].txtDescription1.value = document.forms[frmName][tempID].value;
			break;
	}
	if (document.forms[frmName].txtDisplay2.value == "WorkBreakDown")
	{
		tempDesc = prefix + lineNumber + ":" + "txtWBSLabel";
		tempID = prefix + lineNumber + ":" + "txtWBSText";
		//alert(document.forms[frmName][tempID].value);
		if (document.forms[frmName][tempID].value.length > 0)
		{
			document.forms[frmName].lblDescription2.value = document.forms[frmName][tempDesc].value + ":";
		}
		else
		{
			document.forms[frmName].lblDescription2.value = "Work Breakdown ID:";
		}
		document.forms[frmName].txtDescription2.value = document.forms[frmName][tempID].value;
	}
}

function LookUpExpenseLocation(src)
{
   
    tempName = src;
    w = 540; 
	h = 590;
//  if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
	    window.status = "";
	    
	    retValue = window.showModalDialog(AddDynamicSessionParameter("LookUpExpenseLocation.aspx"), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		
		if (retValue != null) 
		{
			SendExpenseLocationValue(retValue, src );			
		}
    }
    else
    {
        var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
        ResetTimer();
        if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpExpenseLocation.aspx"),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
		    fSrc = src;
			dialogWin.win.focus();
		}	
    }
}
function SendCostElementValue(rVal, src, id)
{
    //need differ for purchase req or time entry
    if (id == 'PRDetail')
    {
        src = src.replace("ibtnLookUp", "tbx");
        document.getElementById(src).value = rVal[0];
        src = src.replace("CELM", "CELMDesc");//tbx
        document.getElementById(src).value = rVal[1];
    }
    else
    {
        src = src.replace("ibtnLookUp", "txt");
	    src = src.replace("txtLocation", "txtLocationDescription");
        document.getElementById(src).value = rVal[0];
    }
}
function SendExpenseLocationValue(rVal, src)
{
    src = src.replace("ibtnLookUp", "txt");
    //used for PreAuth with Desc and ExpenseEdit w/o Desc
    document.getElementById(src).focus();
	document.getElementById(src).value = rVal[0];
	//checks if last digit is a number for ExpenseEdit w/o Desc
	var checkChar = src.charAt(src.length-1);
	if(isNaN(parseInt(checkChar)))
	{
	    src = src.replace("txtLocation", "txtLocationDescription");
	    document.getElementById(src).value = rVal[1];
	}
}

function LookUp(fnum)//WO 
{	
//	calls timer function in Global.js
	//ResetTimer();
	BlockEvents();
	var lNum = window.document.frmTimeCardEdit['txtLineNumber'].value;	
	var rptVal = "rptTimeCardEdit__ctl" + lNum + "_ddlJobDescription";
	var strVal = window.document.frmTimeCardEdit[rptVal].value;
	var valInfo = document.frmTimeCardEdit.txtExtraInfoList.value.split('|');
    
	if ((strVal == 'BLANK') && ((valInfo[fnum] != "WorkOrder") || (document.frmTimeCardEdit.txtLinkedWorkOrder.value != "True")))
	{
	
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				alert("You need to enter a valid Job before looking up");	
			}
			else
			{
				dialogWin.win.focus();
			}		
	}
	else
	{
		dialogWin.name = valInfo[fnum]
//		if (navigator.appName == 'Netscape') 
        if(IsIEBrowser)
        {
			switch (valInfo[fnum])
			{
				case "WorkOrder":
					w = 800; 
					h = 600;
					break;
				case "Organization":
					w = 625; 
					h = 520;
					break;
				case "CostElement":
					w = 635; 
					h = 525;
					break;
				case "Location":
					w = 550; 
					h = 500;
					break;
				case "LaborCategory":
					w = 550; 
					h = 490;
					break;
				case "SpecialPayCode":
					w = 550; 
					h = 525;
					break;
				case "Text":
					w = 550; 
					h = 500;
					break;
			}	
		}
		else
		{
			switch (valInfo[fnum])
			{
				case "WorkOrder":
					w = 530; 
					h = 600;
					break;
				case "Organization":
					w = 625; 
					h = 520;
					break;
				case "CostElement":
					w = 635; 
					h = 525;
					break;
				case "Location":
					w = 550; 
					h = 500;
					break;
				case "LaborCategory":
					w = 550; 
					h = 490;
					break;
				case "SpecialPayCode":
					w = 550; 
					h = 525;
					break;
				case "Text":
					w = 550; 
					h = 500;
					break;
			}
			var winl = (screen.width - w) / 2;
			var wint = (screen.height - h) / 2;
		} 

        if (valInfo[fnum] == "CostElement")
        {
            strVal = "JobID=" + strVal + "&frmTimeCardEdit";
        } 
        if(IsIEBrowser)
        {
		    ClearTimer();
		    window.status = "";
			if (valInfo[fnum] == "SpecialPayCode")
				retValue = window.showModalDialog(AddDynamicSessionParameter('LookUpPayCode.aspx?PayRank=L'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
			else if (valInfo[fnum] == "CostElement" || valInfo[fnum] == "LaborCategory" || valInfo[fnum] == "WorkOrder")
				retValue = window.showModalDialog(AddDynamicSessionParameter('LookUp' + valInfo[fnum] + '.aspx?' + strVal), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 				
			else//Location and Organization
				retValue = window.showModalDialog(AddDynamicSessionParameter('LookUp' + valInfo[fnum] + '.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
            
			
			if (retValue != null) 
			{
				if ((valInfo[fnum] == "WorkOrder") && (document.frmTimeCardEdit.txtLinkedWorkOrder.value == "True"))
					SetWorkOrderSearch(retValue[0], retValue[1], retValue[2], retValue[3])
				else
					SetValue(retValue, fnum);
			}
		}
		else
		{
		    ResetTimer();
			if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				tempName = fnum;
				
				if (valInfo[fnum] == "SpecialPayCode")
					dialogWin.win = window.open(AddDynamicSessionParameter('LookUpPayCode.aspx?PayRank=L'), '','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
				else if (valInfo[fnum] == "CostElement" || valInfo[fnum] == "LaborCategory" || valInfo[fnum] == "WorkOrder")
					dialogWin.win = window.open(AddDynamicSessionParameter('LookUp' + valInfo[fnum] + '.aspx?' + strVal), '','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
				else
					dialogWin.win = window.open(AddDynamicSessionParameter('LookUp' + valInfo[fnum] + '.aspx'), '','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
		}
		
	}
}

function LookUpUnallowCostElement(fName)
{
    try
    {
        if(document.getElementById('_ctl0_JamisContentPlaceHolder_ddlUnallowJob').value)
        {
            var strVal = document.getElementById('_ctl0_JamisContentPlaceHolder_ddlUnallowJob').value;
        }
        else
        {
    	    var strVal = '0';
        }
    }
    catch(e)
    {
        var strVal = '0';
    }
    
    tempName = fName;
    if(IsIEBrowser)
    {
        w = 615; 
		h = 545;
		ClearTimer();
		window.status = "";
		
		retValue = window.showModalDialog(AddDynamicSessionParameter('LookUpCostElement.aspx?' + strVal), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
        if (retValue != null) 
		{
			SendUnallowCostElementValue(retValue, tempName);		
		}
	}
	else
	{
	    w = 615; 
		h = 545;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		
	    ResetTimer();
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpCostElement.aspx?" + strVal),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}	
	}
}
function SendUnallowCostElementValue(rVal, src)
{
    src = src.replace("ibtnLookUp", "txt");
    var txtBefore = document.getElementById(src).value;
    if (txtBefore != rVal[0])
    {
        document.getElementById(src).value = rVal[0] ;
        src = src.replace("txtUnallowCostElement", "txtUnallowCostElementDesc");
        document.getElementById(src).value = rVal[1];
        var txtChange = '_ctl0_JamisContentPlaceHolder_txtExpenseReportChanged';
        window.document.getElementById(txtChange).value = 'true';
    }
}
var butName;
function LookUpEmpl(fName, sig)
{
    butName = sig;
    lookUpEmployeeCaller = fName;
	var tmpName = "empl";
	var queryString;
	// change condition to match mass entry or expense approvee
	if(fName != 'undefined')
	{
	    switch (fName)
	    {
	        case "frmViewEmployeePreviousReport":
	            queryString = "?LookupFor=ExpenseApprovee";
		        break;
		    case "frmViewEmployeeReportReceipt":
	            queryString = "?LookupFor=ExpenseApprovee";
		        break;
		    case "frmExpenseMassEntry":
		        queryString = "?LookupFor=ExpenseUser";
		        break;
		    case "frmAdditionalApproverInfo":
		        queryString = "?LookupFor=ExpenseApprover";
		        break;
		    default:
		        queryString = "?LookupFor=Mass";
		        break;
	    }
	 }
	 else
	 {
	    queryString = "?LookupFor=Mass";
	 }
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";
        w = 505; 
		h = 550;
		retValue = window.showModalDialog(AddDynamicSessionParameter("LookUpEmployee.aspx" + queryString), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		
		if (retValue != null) 
		{
			SendValue(retValue, tmpName, fName, sig);			
		}
	}
	else
	{
	    ResetTimer();
	    w = 505; 
		h = 550;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpEmployee.aspx" + queryString),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}	
	}
}
function LookUpDepartment(fName, sig)
{
    var tmpName = "dept"; 
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";
        w = 615; 
		h = 525;
		retValue = window.showModalDialog(AddDynamicSessionParameter('LookUpOrganization.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		if (retValue != null) 
		{
			SendValue(retValue, tmpName, fName, sig);
		}
	}
	else
	{
	    ResetTimer();
	    w = 615; 
		h = 525;
	    var winl = (screen.width - w) / 2;
	    var wint = (screen.height - h) / 2;
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('LookUpOrganization.aspx'), '','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}
function SendValue(rVal, src, fName, sig)
{
    if(IsIEBrowser)
	{
        switch (fName)
	    { 
            case "frmAdditionalApproverInfo": 
	            idField = "txtApproverID";
		        nameField = "";
		        window.document[fName][idField].value = rVal[0];
		        return; 
            case "frmViewEmployeePreviousReport": 
                switch (sig)
	            {
	                case 'from1':
                        idField = "_ctl0_JamisContentPlaceHolder_txtOrg9From";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtOrg9Desc1";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
		            case 'thru1':
                        idField = "_ctl0_JamisContentPlaceHolder_txtOrg9Thru";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtOrg9Desc2";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
		            case 'from2':
                        idField = "_ctl0_JamisContentPlaceHolder_txtEmplFrom";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName1";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
		            case 'thru2':
                        idField = "_ctl0_JamisContentPlaceHolder_txtEmplThru";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName2";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
		        } 
		    case "frmViewEmployeeReportReceipt":  
		        switch (sig)
	            {
		            case 'from1':
                        idField = "_ctl0_JamisContentPlaceHolder_txtOrg9From";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtOrg9Desc1";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
		            case 'thru1':
                        idField = "_ctl0_JamisContentPlaceHolder_txtOrg9Thru";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtOrg9Desc2";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
		            case 'from2':
                        idField = "_ctl0_JamisContentPlaceHolder_txtEmplFrom";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName1";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
		            case 'thru2':
                        idField = "_ctl0_JamisContentPlaceHolder_txtEmplThru";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName2";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
		        }
            case "frmExpenseMassEntry": 
                switch (src)
                {
                    case "dept":
                        idField = "_ctl0_JamisContentPlaceHolder_txtOrg9";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtOrg9Desc";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
                    case "empl": 
                        idField = "_ctl0_JamisContentPlaceHolder_txtEmployee";
		                nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName";
		                document.forms.aspnetForm[idField].value = rVal[0];
		                document.forms.aspnetForm[nameField].value = rVal[1];
		                return;
                }
            case "frmPurchaseRequisitionDetail":
                idField = "tbxOrg";  
                document.getElementById(idField).value = rVal[0];
                idField = "tbxOrgDesc";  
                document.getElementById(idField).value = rVal[1];
                return;
	    }
	}
	//two cases, dept or empl
	switch (src)
	{
	    case "dept": 
	        idField = "txtOrg9ID";
		    nameField = "txtOrg9Desc";
	        break;
	    default:
	        idField = "txtEmployeeID";
		    nameField = "txtEmployeeName";
		    break;     
	}
	    if ((fName == "dept") && (sig == "frmExpenseDistribution"))
	    {
	        fName = "frmExpenseDistribution"
	    }
		window.document[fName][idField].value = rVal[0];
		window.document[fName][nameField].value = rVal[1];
}		
//////////////////////////////////////////////////////////		        
//	    case "AAI": //103 Additional Approver Information
//	        idField = "txtApproverID";
//		    nameField = "";
//		    window.document[fName][idField].value = rVal[0];
//		    return;    
//	    case "EE": //104 Expense Edit
//	        idField = "txtUnallowCostElement";
//		    nameField = "txtUnallowCostElementDesc";
//	        break;
//		case "EPR1": //105 View Employee Previous Report
//	        idField = "_ctl0_JamisContentPlaceHolder_txtOrg9From";
//		    nameField = "_ctl0_JamisContentPlaceHolder_txtOrg9Desc1";
//		    document.forms.aspnetForm[idField].value = rVal[0];
//		    document.forms.aspnetForm[nameField].value = rVal[1];
//		    return;
//		case "EPR2": //106 View Employee Report Receipt
//	        idField = "_ctl0_JamisContentPlaceHolder_txtOrg9Thru";
//		    nameField = "_ctl0_JamisContentPlaceHolder_txtOrg9Desc2";
//		    document.forms.aspnetForm[idField].value = rVal[0];
//		    document.forms.aspnetForm[nameField].value = rVal[1];
//		    return;
//		case "EPR3": //107 View Employee Previous Report
//	        idField = "_ctl0_JamisContentPlaceHolder_txtEmplFrom";
//		    nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName1";
//		    document.forms.aspnetForm[idField].value = rVal[0];
//		    document.forms.aspnetForm[nameField].value = rVal[1];
//		    return;
//		case "EPR4": //108 View Employee Previous Report
//	        idField = "_ctl0_JamisContentPlaceHolder_txtEmplThru";
//		    nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName2";
//		    document.forms.aspnetForm[idField].value = rVal[0];
//		    document.forms.aspnetForm[nameField].value = rVal[1];
//		    return;
//		case "EMEO": //109 Expense Mass Entry
//	        idField = "_ctl0_JamisContentPlaceHolder_txtOrg9";
//		    nameField = "_ctl0_JamisContentPlaceHolder_txtOrg9Desc";
//		    document.forms.aspnetForm[idField].value = rVal[0];
//		    document.forms.aspnetForm[nameField].value = rVal[1];
//		    return;
//		case "EMEE"://110 Expense Mass Entry
//	        idField = "_ctl0_JamisContentPlaceHolder_txtEmployee";
//		    nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName";
//		    document.forms.aspnetForm[idField].value = rVal[0];
//		    document.forms.aspnetForm[nameField].value = rVal[1];
//		    return;
//	    default:
//	        idField = "txtEmployeeID";
//		    nameField = "txtEmployeeName";
//		    break;
//	}
//		window.document[fName][idField].value = rVal[0];
//		window.document[fName][nameField].value = rVal[1];
////////////////////////////////////////////////////////////////////////
//}

//***********************************
function StartStopTime()
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 980; 
		h = 695;
	}
	else
	{
		w = 980; 
		h = 695;
	} 
//	else 
//	{
//		w = 980; 
//		h = 695;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
	    window.status = "";
	    
		window.showModalDialog(AddDynamicSessionParameter('StartStopTime.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no');
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('StartStopTime.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}

var valTextName;
var valTextVal;
var valCallFrom
///===============================
function TextChange(txtName, txtVal, callFrom)
{
	if (callFrom == "LookUp")
	{
		valTextName = txtName;
		valTextVal = txtVal;
	}
	
	if (valTextName == txtName)
	{
		if (valTextVal != txtVal)
		{
			TcChanged();
		}
	}
}

// return focus to dialog window if it's open.
function CheckModal()
{	
//	if  (txtBoxName == "")
//	{
//		txtBoxValue = window.document.frmTimeCardEdit[txtBoxName].value
//		TextChange(txtBoxName, txtBoxValue, "CheckModal");
//	}
	
	
	setTimeout("FinishChecking()", 1);
	//FinishChecking();
	return true;
} 

function FinishChecking() 
{
//	if (navigator.appName == 'Netscape')
	if(!IsIEBrowser)
	{
		try
		{
			if (dialogWin.win && !dialogWin.win.closed) 
			{			
				dialogWin.win.focus();
				BlockEvents();
				return true; 
			}
			else
			{	
				UnblockEvents();
				return false;
			}
		}
		catch(e)
		{
			
		}
	}
}
// Grab all Navigator events//####

var tempObj = new Object();
var winName = window.opener;
var ctlVal = new Array();

function BlockEvents() 
{
return;
/*	if (navigator.appName == 'Netscape')
	{
		if (document.frmTimeCardEdit.all || document.frmTimeCardEdit.getElementsByTagName)
		{
			var j = 0;
			for (var i = 0; i < document.frmTimeCardEdit.length; i ++)
			{	
				
				tempObj = document.frmTimeCardEdit.elements[i];
				if(tempObj.disabled)
				{
					ctlVal[j] = document.frmTimeCardEdit.elements[i].name;
					j++
				}
				else
				{
					tempObj.disabled = true;
				}
			}
		}
		
	window.captureEvents(Event.CLICK || Event.MOUSEDOWN || Event.MOUSEUP || Event.FOCUS);
	window.onclick = DeadEnd();
	//window.onfocus = CheckModal();	
	}*/
}

// As dialog closes, restore the main window's original event mechanisms.
function UnblockEvents(winName) 
{
return;
/*	if (navigator.appName == 'Netscape')
	{	
		if (document.frmTimeCardEdit.all || document.frmTimeCardEdit.getElementsByTagName)
		{	var j = 0;
			for (var i = 0; i < document.frmTimeCardEdit.length; i ++)
			{
				tempObj = document.frmTimeCardEdit.elements[i];
				{
					if(ctlVal.length > 0)//this prevents the first time load from enabling everything
					{
						if (ctlVal[j] == tempObj.name)
						{
							//tempObj.disabled = true;
							j++
						}
						else
						{
							tempObj.disabled = false;
						}
					}
				}	
			}
		}
	}	
	window.releaseEvents(Event.CLICK || Event.MOUSEDOWN || Event.MOUSEUP || Event.FOCUS);
	window.onclick = DeadEnd();
	//window.onfocus = CheckModal();	
	*/
}
// Event handler to inhibit Navigator form element
function DeadEnd() 
{	
	if (dialogWin.win && !dialogWin.win.closed) 
	{
		dialogWin.win.focus();
		return false;
	}
}
////////////////////////////////////////////////
function SetDeptValue(rVal, sVal, sName)
{

    if(sName == "frmViewEmployeePreviousReport5")
    {
        document.forms.aspnetForm['_ctl0_JamisContentPlaceHolder_' + 'txtOrg9From'].value = rVal;
        document.forms.aspnetForm['_ctl0_JamisContentPlaceHolder_' + 'txtOrg9Desc1'].value = sVal;
    }
    else if(sName == "frmViewEmployeePreviousReport6")
    {
        document.forms.aspnetForm['_ctl0_JamisContentPlaceHolder_' + 'txtOrg9Thru'].value = rVal;
        document.forms.aspnetForm['_ctl0_JamisContentPlaceHolder_' + 'txtOrg9Desc2'].value = sVal;
    }
    else if(sName == "frmExpenseMassEntry")
    {
        document.forms.aspnetForm['_ctl0_JamisContentPlaceHolder_' + 'txtOrg9'].value = rVal;
        document.forms.aspnetForm['_ctl0_JamisContentPlaceHolder_' + 'txtOrg9Desc'].value = sVal;
    }
    else
    {
	    window.document[sName].txtOrg9ID.value = rVal;
	    window.document[sName].txtOrg9Desc.value = sVal;

	}
	if(sName == "frmExpenseDistribution")
	{

	   __doPostBack('btnSearchOrg', '');
	}
}

function SetValue(rVal, sName)
{	
    var extraID;
    var extraDesc;
    var extraIDValue;

	var valInfo = document.frmTimeCardEdit.txtExtraInfoList.value.split('|');
    if ((valInfo[sName] == "WorkOrder") && (document.frmTimeCardEdit.txtWorkOrderOnEveryLine.value == "true"))
    {
    	var lNum = window.document.frmTimeCardEdit['txtLineNumber'].value;	
	    extraID = "rptTimeCardEdit__ctl" + lNum + "_txtWorkOrder1";
	    extraDesc = "rptTimeCardEdit__ctl" + lNum + "_txtWorkOrderDesc1";
	    extraIDValue = window.document.frmTimeCardEdit[extraID].value;
	}
	else
	{
    	var sNum = sName + 1
	    extraID = "txtExtraInfo" + sNum;
	    extraDesc = "txtExtraInfoDesc" + sNum;
	    extraIDValue = window.document.frmTimeCardEdit[extraID].value;
	}

	if (extraIDValue != rVal[0])
	{
		window.document.frmTimeCardEdit[extraID].value = rVal[0];
		window.document.frmTimeCardEdit[extraDesc].value = rVal[1];
		TcChanged();
	}	
}

function SetJobID(ddlJob)
{
	if ((ddlJob.value != "MANUAL") && (ddlJob.value != "SEARCH") && (ddlJob.value != "ADDMULTI"))
	{
		previousJob = ddlJob.value;
		SetRow(ddlJob.name, false);
	}
}

function SetPayCodeID(ddlPay)
{
	if ((ddlPay.value != "Search") && (ddlPay.value != "Create"))
	{
		previousPayCode = ddlPay.value;
		SetRow(ddlPay.name, false);
	}
}


var defaultJobFromPay;
var defaultCelmFromPay;
var payCodeWithJob;
var payCodeList;
var PayClassList;
var hourIncrement;
var decimals;
var defaultJobDescFromPay;

function TimeCardEditInit()
{
	defaultJobFromPay = document.frmTimeCardEdit.txtDefaultJobFromPay.value.split("|^|");
	defaultCelmFromPay = document.frmTimeCardEdit.txtDefaultCelmFromPay.value.split("|^|");
	payCodeWithJob = document.frmTimeCardEdit.txtPayCodeWithJob.value.split("|^|");
	payCodeList = document.frmTimeCardEdit.txtPayCodeList.value.split("|^|");
	payClassList = document.frmTimeCardEdit.txtPayClassList.value.split("|^|");
	defaultJobDescFromPay = document.frmTimeCardEdit.txtDefaultJobDescFromPay.value.split("|^|");

	hourIncrement = parseFloat(document.frmTimeCardEdit.txtHourInterval.value);
	temp = hourIncrement * 10;
	if (temp == Math.floor(temp))
		decimals = 1;
	else
		decimals = 2;

//	if (document.frmTimeCardEdit.txtTimecardChanged.value == "true")
//		timecardChanged = true;
	
	ResetTimer();
	
}
function ApprovalViewInit()
{
	ResetTimer();
}

function TimeCardViewInit()
{
	SelectRow("rptTimeCardView:_ctl1:ibtnComment");

	ResetTimer();
}
function TimeCardReportInit()
{
	ResetTimer();
}


function SelectJobChanged(changedElement, caller)
{
	if (changedElement.value == "SEPARATER")
	{
		ResetJob(changedElement);
		return;
	}
	if (changedElement.value == "MANUAL")
	{
		RunJobManualEntry(changedElement, caller);
		return;
	}
	if (changedElement.value == "SEARCH")
	{
		LookUpJob(changedElement, caller);
		return;
	}
	if (changedElement.value == "ADDMULTI")
	{
		if (previousJob == "BLANK")
			AddMultipleJob(changedElement);
		else
		{
			alert("You can add multiple jobs only on a blank line.");
			ResetJob(changedElement);
		}	
			
		return;
	}
	
/*	if (fname.substring(fname.length - 4) == "Code")
	{
		ddlPayName = fname.replace("JobCode", "PayCode");
		fname = fname.substring(0, (fname.length - 4)) + "Description";
	}
	else
	{
		fname = fname.substring(0, (fname.length - 11)) + "Code";
	}

	var jobID = changedElement.value;
	var elementToChange = document.getElementById(fname);
	for (var i = 0; i < elementToChange.options.length; i++)
	{
		if (elementToChange.options[i].value == jobID)
		{
			elementToChange.options[i].selected = true;
			break;
		}
	}
*/	
	var fname = changedElement.name.split(":").join("_");
	var ddlPayName = fname.replace("JobDescription", "PayCode");
	var ddlPayCode = document.getElementById(ddlPayName);
	var payCelm = GetPayCelmFromJob(changedElement.options[changedElement.selectedIndex].text);
	if (payCelm == null)
	{
		if (ddlPayCode.value == "")
			SetDropDownValue(ddlPayCode, document.frmTimeCardEdit.txtDefaultPayCode.value);
	    else
	    {
		    var oldJobCelm = GetJobCelmFromPay(ddlPayCode.value);
		    if (oldJobCelm != null)
		    {
    			SetDropDownValue(ddlPayCode, document.frmTimeCardEdit.txtDefaultPayCode.value);
            }	    
	    }
 	}
	else
	{
		SetDropDownValue(ddlPayCode, payCelm[0]);
		var celmName = ddlPayName.replace("ddlPayCode", "txtCostElement");
		document.frmTimeCardEdit[celmName].value = payCelm[1];
		SetRow(changedElement.name, true);
	}
	TcChanged();
}

function SelectPayCodeChanged(ddlPayCode)
{
	if (ddlPayCode.value == "")
	{
	//cc5907
		var oldPayCode;
		idx = previousPayCode.indexOf(",");
		if (idx < 0)
			oldPayCode = ddlPayCode.value;
		else
			oldPayCode = ddlPayCode.value.substring(0, idx);
		var oldJobCelm = GetJobCelmFromPay(previousPayCode);

		if (oldJobCelm != null)
		{
	        var ddlJobDesc;
	        var celmName = ddlPayCode.name.replace("ddlPayCode", "txtCostElement");
	        var fname = ddlPayCode.name.split(":").join("_");
	        fname = fname.replace("PayCode", "JobDescription");
	        ddlJobDesc = document.getElementById(fname);
			SetDropDownValue(ddlJobDesc, "BLANK");
//			ddlJobDesc.options[0].selected = true;
			document.frmTimeCardEdit[celmName].value = "";
			SetRow(ddlPayCode.name, true);
		}
		return;
	}
	if (ddlPayCode.value == "______")
	{
		ResetPayCode(ddlPayCode);
		return;
	}
	if (ddlPayCode.value == "Search")
	{
		LookUpPayCode(ddlPayCode);
		return;
	}
	if (ddlPayCode.value == "Create")
	{
		CreatePayCode(ddlPayCode);
		return;
	}

	var rptInfo = GetRepeaterInfo(ddlPayCode.name)
	//rptInfo[0] is current line number. [1] is repeater prefix.
	var lineTotal = rptInfo[1] + rptInfo[0] + ":txtJobTotals";

	var preClass = ResetTotal(lineTotal);

	var primaryPayCode;
	idx = ddlPayCode.value.indexOf(",");
	if (idx < 0)
		primaryPayCode = ddlPayCode.value;
	else
		primaryPayCode = ddlPayCode.value.substring(0, idx);
		
	var ddlJobDesc;
	var jobCelm = GetJobCelmFromPay(primaryPayCode);
	var celmName = ddlPayCode.name.replace("ddlPayCode", "txtCostElement");
	var fname = ddlPayCode.name.split(":").join("_");
	fname = fname.replace("PayCode", "JobDescription");
	ddlJobDesc = document.getElementById(fname);

	if (jobCelm != null)
	{
//		SetDropDownValue(ddlJobDesc, jobCelm[0]);
		ddlJobDesc.options[jobCelm[2] + 1].selected = true;
		document.frmTimeCardEdit[celmName].value = jobCelm[1];
		SetRow(ddlPayCode.name, true);
	}
	else
	{
		var oldPayCode;
		idx = previousPayCode.indexOf(",");
		if (idx < 0)
			oldPayCode = ddlPayCode.value;
		else
			oldPayCode = ddlPayCode.value.substring(0, idx);
		var oldJobCelm = GetJobCelmFromPay(previousPayCode);

		if (oldJobCelm != null)
		{
			SetDropDownValue(ddlJobDesc, "BLANK");
//			ddlJobDesc.options[0].selected = true;
			document.frmTimeCardEdit[celmName].value = "";
			SetRow(ddlPayCode.name, true);
		}
	}

	var pClass = GetPayClass(primaryPayCode);
	if (pClass == "P")
	{
		document.frmTimeCardEdit["txtPremiumHours"].value = SetDecimals(parseFloat(document.frmTimeCardEdit["txtPremiumHours"].value) + 
			parseFloat(document.frmTimeCardEdit[lineTotal].value));
	}
	if (pClass == "R")
	{
		document.frmTimeCardEdit["txtRegularHours"].value = SetDecimals(parseFloat(document.frmTimeCardEdit["txtRegularHours"].value) +
			parseFloat(document.frmTimeCardEdit[lineTotal].value));
	}

	var adjTotal = 0;
	if (preClass == "O" && pClass != "O")
		adjTotal = 1;
	if (preClass != "O" && pClass == "O")
		adjTotal = -1;


	var dailyHours;
	var dailyTotal;
		
	if (adjTotal != 0)
	{
		for (var j = 1; j<= 8; j++)
		{
			dailyHours = rptInfo[1] + rptInfo[0] + ":txtDay" + j;
			dailyTotal = "txtDailyTotals" + j;
			if (document.frmTimeCardEdit[dailyHours] != undefined)
			{
				if (document.frmTimeCardEdit[dailyHours].value != "")
				{
					document.frmTimeCardEdit[dailyTotal].value = SetDecimals(parseFloat(document.frmTimeCardEdit[dailyTotal].value) +
						parseFloat(document.frmTimeCardEdit[dailyHours].value) * adjTotal);
				}
			}
		}
		document.frmTimeCardEdit.txtDailyTotals.value = SetDecimals(parseFloat(document.frmTimeCardEdit.txtDailyTotals.value) +
			parseFloat(document.frmTimeCardEdit[lineTotal].value) * adjTotal);
	}
	previousPayCode = ddlPayCode.value;
	TcChanged();
}

function ResetTotal(lt)
{
	var prePayCode;
	var idx = previousPayCode.indexOf(",");
	if (idx < 0)
		prePayCode = previousPayCode;
	else
		prePayCode = previousPayCode.substring(0, idx);
		
	var pClass = GetPayClass(prePayCode);
	if (pClass == "P")
	{
		document.frmTimeCardEdit["txtPremiumHours"].value = SetDecimals(parseFloat(document.frmTimeCardEdit["txtPremiumHours"].value) - 
			parseFloat(document.frmTimeCardEdit[lt].value));
	}
	if (pClass == "R")
	{
		document.frmTimeCardEdit["txtRegularHours"].value = SetDecimals(parseFloat(document.frmTimeCardEdit["txtRegularHours"].value) -
			parseFloat(document.frmTimeCardEdit[lt].value));
	}
	
	return pClass;
}

function GetPayCelmFromJob(jobDesc)
{
	var retVal = new Array();
	for (var i = 0; i < defaultJobDescFromPay.length; i++)
	{
		if (defaultJobDescFromPay[i] == jobDesc)
		{
			retVal[0] = payCodeWithJob[i];
			retVal[1] = defaultCelmFromPay[i];
			return retVal;
		}
	}
	return null;
}

function GetJobCelmFromPay(pid)
{
	var retVal = new Array();
	for (var i = 0; i < payCodeWithJob.length; i++)
	{
		if (payCodeWithJob[i] == pid)
		{
			retVal[0] = defaultJobFromPay[i];
			retVal[1] = defaultCelmFromPay[i];
			retVal[2] = i;
			return retVal;
		}
	}
	return null;
}

function SetDropDownValue(ddl, id)
{
	for (var i = 0; i < ddl.options.length; i++)
	{
		if (ddl.options[i].value == id)
		{
			ddl.options[i].selected = true;
			break;
		}
	}
}

function AddMultipleJob(ddlJob)
{
	ddlJobCodeDescription = ddlJob; //save this for Netscape reset.
	resetJob = true;
//	calls timer function in Global.js
//	ResetTimer();
//	BlockEvents();
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 820; 
		h = 850;
	}
	else
	{
		w = 820; 
		h = 850;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 800; 
//		h = 860;
//	}
//add code here to deal with modal form in netscape
//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter('LookupPersonalJob.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		
		if (retValue != null) 
		{
			SetPersonalJobSearch(retValue[0]);
		}
		else
		{
			ResetJob(ddlJob);
		}
	}
	else
	{
	    ResetTimer();
	    BlockEvents();
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter('LookupPersonalJob.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
	}
}

var lookUpJobCaller;
function LookUpJob(ddlJob, caller)
{
//	calls timer function in Global.js
	ResetTimer();
	BlockEvents();
	ddlJobCodeDescription = ddlJob; //save this for Netscape reset.
	lookUpJobCaller = caller;
	resetJob = true;
	var multiJob;
	
	if (previousJob == "BLANK")
		multiJob = "?MultiJob=true&" + caller;
	else
		multiJob = "?MultiJob=false&" + caller;
	RunLookUpJob(ddlJob, multiJob);
}

function LookUpJob2(caller)
{
//	calls timer function in Global.js
	ResetTimer();
	BlockEvents();
	lookUpJobCaller = caller;
	resetJob = false;
	RunLookUpJob("", "?MultiJob=true&" + caller);
}

function RunLookUpJob(ddlJob, queryString)
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 760; 
		h = 580;
	}
	else
	{
		w = 760; 
		h = 580;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 525; 
//		h = 620;
//	}
//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter('LookUpJobCode.aspx' + queryString), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'resizable:yes' + 'help:no'); 
		
		if (retValue != null) 
		{
			SetJobSearch(retValue[0], retValue[1], retValue[2]);
		}
		else
		{
			if (resetJob)
				ResetJob(ddlJob);
		}
	}
	else
	{
	    ResetTimer();
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter('LookUpJobCode.aspx' + queryString),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
	}
}

function SetPersonalJobSearch(jobID)
{		 
	resetJob = false;

	var idList = jobID[0];
	for (var i = 1; i < jobID.length; i++)
	{
		idList = idList + "|^|" + jobID[i];
	}
	document.frmTimeCardEdit.txtJobIDList.value = idList;
	document.frmTimeCardEdit.txtAddToEmployeeJob.value = "false";
	AllowExit();
	__doPostBack('btnAddMultipleJob', '');
}

function SetJobSearch(jobID, jobDesc, AddToEmployeeJob)
{
//	document.frmTimeCardEdit.txtJobIDList.value = jobID.join("|^|");
//	document.frmTimeCardEdit.txtJobDescList.value = jobDesc.join("|^|");
//don't know why join doesn't work. have to do it by self.

	resetJob = false;

	var idList = jobID[0];
	var descList = jobDesc[0];
	var idListField;
	var descListField;
	var addToField;
	var postBackTarget;
	
	for (var i = 1; i < jobID.length; i++)
	{
		idList = idList + "|^|" + jobID[i];
		descList = descList + "|^|" + jobDesc[i];
	}
	switch (lookUpJobCaller)
	{
		case "frmTimeCardEdit":
			idListField = "txtJobIDList";
			descListField = "txtJobDescList";
			addToField = "txtAddToEmployeeJob";
			postBackTarget = "btnJobSearch";
			break;
		case "frmPersonalJobList":
			idListField = "txtJobIDList";
			descListField = "";
			addToField = "";
			postBackTarget = "ibtnAddJob";
			break;
		case "frmTimeCardMassEntry":
			idField = "txtEmployeeID";
			nameField = "txtEmployeeName";
			break;
		case "frmTimeCardMassAmend":
			idField = "txtEmployeeID";
			nameField = "txtEmployeeName";
			break;
		case "frmPreAuthorizationEdit":
		case "frmExpenseEdit":
			idListField = "_ctl0_JamisContentPlaceHolder_hidJobID";
			descListField = "_ctl0_JamisContentPlaceHolder_hidJobDescription";
			addToField = "_ctl0_JamisContentPlaceHolder_hidAddToEmployeeJob";
			postBackTarget = "_ctl0$JamisContentPlaceHolder$btnJobSearch";
			break;
		case "frmExpenseDistribution":
			idListField = "txtJobIDList";
			descListField = "txtJobDescList";
			addToField = "txtAddToEmployeeJob";
			postBackTarget = "btnSearchJob";
			break;
		case "frmPurchaseRequisitionEdit":
		    var txtFieldName =  ddlJobCodeDescription.replace('ibtnLookUp', 'tbx');
			idListField = txtFieldName;
			descListField = "";
			addToField = "";
			postBackTarget = "";
			lookUpJobCaller = "aspnetForm";
			break;
		case "frmPurchaseRequisitionDetail":
		    var txtFieldName =  ddlJobCodeDescription.replace('ibtnLookUp', 'tbx');
			idListField = txtFieldName;
			var txtDescName = ddlJobCodeDescription.replace('ibtnLookUpJob', 'tbxJobDesc');
			descListField = txtDescName;
			addToField = "";
			postBackTarget = "";
			break;
		default:
			alert("You need to define return value fields to use LookUpJob");
			break;

	}
	if (lookUpJobCaller == "frmPreAuthorizationEdit" ||
	    lookUpJobCaller == "frmExpenseEdit")
	    lookUpJobCaller = "aspnetForm";
	    
	document.forms[lookUpJobCaller][idListField].value = idList;
	if (descListField != "")
		document.forms[lookUpJobCaller][descListField].value = descList;
	if (addToField != "")
		document.forms[lookUpJobCaller][addToField].value = AddToEmployeeJob;
//	alert(idList);
//	alert(descList);
//	alert(AddToEmployeeJob);

	AllowExit();
    if (postBackTarget != "")
    {
        __doPostBack(postBackTarget, '');
    }
}

function RunJobManualEntry(ddlJob, caller)
{
    lookUpJobCaller = caller;

//	ResetTimer();
//	BlockEvents();
	ddlJobCodeDescription = ddlJob; //save this for Netscape reset.
	resetJob = true;
//	calls timer function in Global.js
//	ResetTimer();
//	if (navigator.appName == 'Netscape') 
	if(IsIEBrowser)
	{
		w = 525; 
		h = 275;
	}
	else
	{
		w = 525; 
		h = 275;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 520; 
//		h = 310;
//	}

//	if (navigator.appName == 'Netscape')
	if(IsIEBrowser)
	{
	    ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter('ManualEntry.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		
		if (retValue != null) 
		{
			SetJobManualEntry();
		}
		else
		{
			ResetJob(ddlJob)
		}
	}
	else
	{
	    ResetTimer();
	    BlockEvents();
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('ManualEntry.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}

//^^^
function SetJobManualEntry()
{	
//	if (navigator.appName == 'Netscape')
    if(!IsIEBrowser)
	{
		UnblockEvents(window.name);
	}
	resetJob = false;	
	AllowExit();
	if (lookUpJobCaller == "frmPreAuthorizationEdit" || lookUpJobCaller == "frmExpenseEdit" )
		__doPostBack('_ctl0$JamisContentPlaceHolder$btnJobManual', '');
	else if (lookUpJobCaller == "frmExpenseDistribution")
	    __doPostBack('btnJobManual', '');

	else
    	__doPostBack('btnJobManualEntry', '');
}

function ResetJobNS()
{
	if (resetJob)
		ResetJob(ddlJobCodeDescription);
}

function ResetJob(ddlJob)
{
	for (var i = 0; i < ddlJob.options.length; i++)
	{
		if (ddlJob.options[i].value == previousJob)
		{
			ddlJob.options[i].selected = true;
			break;
		}
	}
}

function LookUpPayCode(ddlPay)
{
	savedDdlPayCode = ddlPay; //save this for Netscape reset.
	resetPayCode = true;
//	calls timer function in Global.js
	ResetTimer();
	
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 510; 
		h = 510;
	}
	else
	{
		w = 510; 
		h = 510;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 510; 
//		h = 510;
//	}

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter('LookUpPayCode.aspx?PayRank=P'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		
		if (retValue != null) 
		{
			SetPayCodeSearch(retValue[0]);
		}
		else
		{
			ResetPayCode(ddlPay);
		}
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('LookUpPayCode.aspx?PayRank=P'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}	
			
	}
}

function CreatePayCode(ddlPay)
{
	savedDdlPayCode = ddlPay; //save this for Netscape reset.
	resetPayCode = true;
//	calls timer function in Global.js
//	ResetTimer();
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 515; 
		h = 600;
	}
	else
	{
		w = 515; 
		h = 600;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 515; 
//		h = 600;
//	}

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter('CreateCombinationPayCode.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		
		if (retValue != null) 
		{
			SetPayCodeCreate(retValue);
		}
		else
		{
			ResetPayCode(ddlPay);
		}
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('CreateCombinationPayCode.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}

function SetPayCodeCreate(payCodes)
{
	document.frmTimeCardEdit.txtPayCodeID.value = ProcessSelectedPayCode(payCodes);
	AllowExit();
	__doPostBack('btnPayCodeCreate', '');
}

function SetPayCodeSearch(payCodeID)
{
	document.frmTimeCardEdit.txtPayCodeID.value = ProcessSelectedPayCode(payCodeID);
	AllowExit();
	__doPostBack('btnPayCodeSearch', '');
}

function ProcessSelectedPayCode(pid)
{
	resetPayCode = false;

	var rptInfo = GetRepeaterInfo(savedDdlPayCode.name)
	
	var lineTotal = rptInfo[1] + rptInfo[0] + ":txtJobTotals";
	var preClass = ResetTotal(lineTotal);
	var len = pid.length - 1;
	var pClass = pid.substr(len, 1);
	if (pClass == "P")
	{
		document.frmTimeCardEdit["txtPremiumHours"].value = SetDecimals(parseFloat(document.frmTimeCardEdit["txtPremiumHours"].value) + 
			parseFloat(document.frmTimeCardEdit[lineTotal].value));
	}
	if (pClass == "R")
	{
		document.frmTimeCardEdit["txtRegularHours"].value = SetDecimals(parseFloat(document.frmTimeCardEdit["txtRegularHours"].value) +
			parseFloat(document.frmTimeCardEdit[lineTotal].value));
	}
    return pid.substr(0, len);
}

function ResetPayCodeNS()
{
	if (resetPayCode)
		ResetPayCode(savedDdlPayCode);
}

function ResetPayCode(ddlPay)
{
	for (var i = 0; i < ddlPay.options.length; i++)
	{
		if (ddlPay.options[i].value == previousPayCode)
		{
			ddlPay.options[i].selected = true;
			break;
		}
	}
}



///////////////////////////////////////////

//#Approval Changed
function AppChanged(sName)
{	
	SetAppChanged();
	switch (sName)
	{
		case "DA":
			window.document.frmDelegateApproval.txtApprovalChanged.value = "Changed";
			break;
		case "AA":
			//dateFrom = document.frmApprovalArchived.txtStartDate.value;
			//dateTo = document.frmApprovalArchived.txtEndDate.value;
			break;
		case "ANC":
			//dateFrom = document.frmApprovalNotCreated.txtStartDate.value;
			//dateTo = document.frmApprovalNotCreated.txtEndDate.value;
			break;
			
	}
	//window.document.frmDelegateApproval.txtApprovalChanged.value = "Changed";
}

function SetAppChanged() 
{	
	if(firstTime) 
	{
		firstTime = false;
		//catch in check save issue warning
		approvalChanged = true;
	}
}

function AppSaved()
{
	
	//catch in check save pass
	approvalChanged = false;
	window.document.frmDelegateApproval.txtApprovalChanged.value = "Saved";
}

function TcSaved()
{	
//	timecardChanged = false;
    document.frmTimeCardEdit.txtTimecardChanged.value = "false"
	firstTime = true;
}
//Time Card Changed
function TcChanged() 
{
//	if(firstTime) 
//	{
//		firstTime = false;
		SetTcChanged();
//	}
}
function SetTcChanged() 
{		
//	timecardChanged = true;
    document.frmTimeCardEdit.txtTimecardChanged.value = "true"
}

var badExit = true;
function AllowExit(pName)
{
	badExit = false;
	//run check save
	CheckSave(pName);
}
function CheckSave(pass, extra)
{	
        //alert(window.name);
	if((pass != 'Login') && (pass != 'undefined'))
	{
		if(badExit == true)
		{
			if(pass == "frmTimeCardEdit")
			{
				if (document.frmTimeCardEdit.txtTimecardChanged.value == "true")
				{
				    return "You have attempted to leave this page without saving your changes. Your changes will be lost. Are you sure that you want to do this?";
				}
			}
			//if approvalChanged is true we should get this warning
			if(window.name == "frmDelegateApproval")
			{
				if((approvalChanged) || (window.document.frmDelegateApproval.txtApprovalChanged.value == "Changed") || (window.document.frmDelegateApproval.txtApprovalChanged.value == "true"))
				{
					return "You have attempted to leave this page without saving your changes. Your changes will be lost. Are you sure that you want to do this? " + window.name;			
				}
			}
			if(window.name == "frmPreAuthorizationEdit")
			{                
			    var nuName = "_ctl0_JamisContentPlaceHolder_txtPreAuthorizationChanged";
			    if(document.forms.aspnetForm[nuName].value == "true")
			    {
				    return "You have attempted to leave this page without saving your changes. Your changes will be lost. Are you sure that you want to do this? " + pass;			
			    }
			}
			if(window.name == "frmExpenseEdit")
			{                
			    var nuName = "_ctl0_JamisContentPlaceHolder_txtExpenseReportChanged";
			    if(document.forms.aspnetForm[nuName].value == "true")
			    {
				    return "You have attempted to leave this page without saving your changes. Your changes will be lost. Are you sure that you want to do this? " + pass;			
                }
			}	
		}	
	}
}

//called on tab
function CheckChanged()
{
    var changed = false;

	if(window.name == "frmTimeCardEdit")
	{
		if (document.frmTimeCardEdit.txtTimecardChanged.value == "true")
		    changed = true;
	}
	
	//if approvalChanged is true we should get this warning
	if(window.name == "frmDelegateApproval")
	{
		if((approvalChanged) || (window.document.frmDelegateApproval.txtApprovalChanged.value == "Changed"))
		    changed = true;
	}
	if(window.name == "frmPreAuthorizationEdit")
	{                
	    var nuName = "_ctl0_JamisContentPlaceHolder_txtPreAuthorizationChanged";
	    if(document.forms.aspnetForm[nuName].value == "true")
		    changed = true;
	}
	if(window.name == "frmExpenseEdit")
	{                
	    var nuName = "_ctl0_JamisContentPlaceHolder_txtExpenseReportChanged";
	    if(document.forms.aspnetForm[nuName].value == "true")
		    changed = true;
	}
	if (changed)
    {
	    if (confirm("You have attempted to leave this page without saving your changes. Your changes will be lost. Are you sure that you want to do this? "))
	    {
	        AllowExit();
	        return true;
	    }
	    else
	        return false;
    }

	return true;
}
/////////////////////////////////////////
var rsField = "";
var hoursBefore = 0;
function HoursOnFocus(hrsField)
{
	rsField = hrsField;
	if (isNaN(hrsField.value) || (hrsField.value == ""))
		hoursBefore = 0;
	else
		hoursBefore = parseFloat(hrsField.value);

	SetRow(hrsField.name, false);
}
function CheckEnter(hField)
{
	if (tabKey == 13)
	{
        HoursOnBlur(rsField);
	}
}
function HoursOnBlur(hrsField)
{
	var fname = hrsField.name;
	var rptInfo = GetRepeaterInfo(fname)
	//rptInfo[0] is current line number. [1] is repeater prefix.
	var jobTotal = rptInfo[1] + rptInfo[0] + ":txtJobTotals";
	var dayNumber = fname.substring(fname.lastIndexOf('y') + 1);
	var dailyTotal = "txtDailyTotals" + dayNumber;
	var tcTotal = "txtDailyTotals";
	var diff;
	var ddlPayCode = rptInfo[1] + rptInfo[0] + ":ddlPayCode";
	var hrs;
	var payCode;
	
	var idx = document.frmTimeCardEdit[ddlPayCode].value.indexOf(",");
	if (idx < 0)
		payCode = document.frmTimeCardEdit[ddlPayCode].value;
	else
		payCode = document.frmTimeCardEdit[ddlPayCode].value.substring(0, idx);

	var payClass = GetPayClass(payCode);
	
	hrsField.value = Trim(hrsField.value);
	if ((isNaN(hrsField.value)) || (hrsField.value == ""))
	{
		hrs = 0;
		hrsField.value = "";
	}
	else
	{
		hrs = parseFloat(hrsField.value);
        //hrs = RoundNumber(hrs);
		if (hrs > 0) 
		{
		    hrs = RoundNumber(hrs);
		}
	    else
	    {
	        hrs = (-1 * RoundNumber(hrs  * -1));
	    }
	}
    //diff =(hrs - hoursBefore);
	diff = RoundNumber(hrs - hoursBefore);
	if (document.frmTimeCardEdit.txtByTotal.value != "true" && payClass != "O")
	{
		var newTotal = RoundNumber(parseFloat(document.frmTimeCardEdit[dailyTotal].value) + diff);
		if (newTotal < -24 || newTotal > 24)
		{
			if (hoursBefore == 0)
				hrsField.value = "";
			else
				hrsField.value = SetDecimals(hoursBefore);

			alert("You cannot enter more than 24 hours in one day.");
			hrsField.focus();
			return false;
		}
	}

	if (hrs != hoursBefore)
	{	
		TcChanged();
	}

	if (hrsField.value != "")
		hrsField.value = SetDecimals(hrs);

	document.frmTimeCardEdit[jobTotal].value = SetDecimals(RoundNumber(parseFloat(document.frmTimeCardEdit[jobTotal].value) + diff));
	if (payClass != "O")
	{
		document.frmTimeCardEdit[dailyTotal].value = SetDecimals(RoundNumber(parseFloat(document.frmTimeCardEdit[dailyTotal].value) + diff));
		document.frmTimeCardEdit[tcTotal].value = SetDecimals(RoundNumber(parseFloat(document.frmTimeCardEdit[tcTotal].value) + diff));
	}
	
	if (payClass == "P")
	{
		document.frmTimeCardEdit["txtPremiumHours"].value = SetDecimals(RoundNumber(parseFloat(document.frmTimeCardEdit["txtPremiumHours"].value) + diff));
	}
	if (payClass == "R")
	{
		document.frmTimeCardEdit["txtRegularHours"].value = SetDecimals(RoundNumber(parseFloat(document.frmTimeCardEdit["txtRegularHours"].value) + diff));
	}
	
}

function GetPayClass(pCode)
{
	var pc = "R";
	for (var i = 0; i < payCodeList.length; i++)
	{
		if (payCodeList[i] == pCode)
		{
			pc = payClassList[i];
		}
	}
	return pc;
}

function RecognitionPayOnBlur()
{
	if (isNaN(document.frmTimeCardEdit.txtRecognitionPay.value) || document.frmTimeCardEdit.txtRecognitionPay.value == "")
		document.frmTimeCardEdit.txtRecognitionPay.value = "";
	else
		document.frmTimeCardEdit.txtRecognitionPay.value = SetDecimals(parseFloat(document.frmTimeCardEdit.txtRecognitionPay.value));
}

function RoundNumber(number) 
{
	if (hourIncrement == 0)
		return Math.round(number);

	intVal = Math.floor(number);

	if (intVal != number)
	{
		decVal = (number - intVal) + 0.000001;
		if (decVal < hourIncrement)
		{
			if ((decVal / hourIncrement) >= 0.5)
				val = intVal + hourIncrement;
			else val = intVal;
		}
		else val = intVal + Math.round(decVal / hourIncrement) / (1 / hourIncrement);
		
		number = val;
	}
	else
		if (number != 0)
			number = intVal;
	return number;
}


function SetDecimals(x)
{
//	if (x == 0)
//		return "";
		
	s = x.toString();
	
	switch (decimals)
	{
		case 1:
			if (x == Math.floor(x))
			{
				s = s + ".0";
			}
			break;
		case 2:
			if (x == Math.floor(x))
			{
				s = s + ".00";
			}
			else
			{
				if (x * 10 == Math.floor(x * 10))
				{
					s = s + "0";
				}
			}
			break;
	}
    return s;
}

function CheckErrorAndChange()
{
	if (document.frmTimeCardEdit.txtConfirmError.value == "true")
	{
		DisplayError();
	}
	else
	{
		if (document.frmTimeCardEdit.txtConfirmChange.value == "true")
		{
			DisplayChange();
		}
		else
		{
			if (document.frmTimeCardEdit.txtConfirmLate.value == "true")
			{
				DisplayLate();
			}
		}
	}
	
}

function DisplayError()
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 690; 
		h = 660;
	}
	else
	{
		w = 690; 
		h = 660;
	} 
//	else 
//	{
//		w = 690; 
//		h = 660;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		ConfirmErrors(window.showModalDialog(AddDynamicSessionParameter('ConfirmErrors.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'));
	}
	else
	{
	    ResetTimer();
	    
		dialogWin.win = window.open(AddDynamicSessionParameter('ConfirmErrors.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
	}
}

function ConfirmErrors(confirm)
{
	if (confirm)
	{
		if (document.frmTimeCardEdit.txtConfirmChange.value == "true")
		{
			DisplayChange();
		}
		else
		{
			if (document.frmTimeCardEdit.txtConfirmLate.value == "true")
			{
				DisplayLate();
			}
			else
			{
				document.frmTimeCardEdit.txtConfirmError.value = "CONFIRMED";
				PostBackTimeCard();
			}
		}
	}
	else
	{
		document.frmTimeCardEdit.txtConfirmError.value = "";
		document.frmTimeCardEdit.txtConfirmChange.value = "";
		document.frmTimeCardEdit.txtConfirmLate.value = "";
	}
	
}

function ViewTimeCardErrors()
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 690; 
		h = 660;
	}
	else
	{
		w = 690; 
		h = 660;
	} 
//	else 
//	{
//		w = 690; 
//		h = 660;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
	    window.status = "";
	    
		window.showModalDialog(AddDynamicSessionParameter('TimeCardErrors.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no');
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('TimeCardErrors.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}

function DisplayChange()
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 940; 
		h = 720;
	}
	else
	{
		w = 940; 
		h = 720;
	} 
//	else 
//	{
//		w = 940; 
//		h = 720;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
        ClearTimer();
        window.status = "";

		ConfirmChanges(window.showModalDialog(AddDynamicSessionParameter('Explanations.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'));
	}
	else
	{
	    ResetTimer();
			dialogWin.win = window.open(AddDynamicSessionParameter('Explanations.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
	}
}

function ConfirmChanges(confirm)
{
	if (confirm[0])
	{
		document.frmTimeCardEdit.txtReasonCode.value = confirm[1];
		document.frmTimeCardEdit.txtReasonText.value = confirm[2];
		if (document.frmTimeCardEdit.txtConfirmLate.value == "true")
		{
			DisplayLate();
		}
		else
		{
			document.frmTimeCardEdit.txtConfirmError.value = "CONFIRMED";
			PostBackTimeCard();
		}
	}
	else
	{
		document.frmTimeCardEdit.txtReasonCode.value = "";
		document.frmTimeCardEdit.txtReasonText.value = "";
		document.frmTimeCardEdit.txtConfirmChange.value = "";
		document.frmTimeCardEdit.txtConfirmLate.value = "";
	}
}

function ViewTimeCardHistory()
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 820; 
		h = 650;
	}
	else
	{
		w = 820; 
		h = 650;
	} 
//	else 
//	{
//		w = 820; 
//		h = 650;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		window.showModalDialog(AddDynamicSessionParameter('ChangeHistory.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no');
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('ChangeHistory.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}

function DisplayLate()
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 915; 
		h = 720;
	}
	else
	{
		w = 915; 
		h = 720;
	} 
//	else 
//	{
//		w = 915; 
//		h = 720;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		ConfirmLate(window.showModalDialog(AddDynamicSessionParameter('LateEntry.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'));
	}
	else
	{
	    ResetTimer();
	    
			dialogWin.win = window.open(AddDynamicSessionParameter('LateEntry.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
	}
}

function ConfirmLate(confirm)
{
	if (confirm[0])
	{
		document.frmTimeCardEdit.txtConfirmError.value = "CONFIRMED";
		document.frmTimeCardEdit.txtLateReasonCode.value = confirm[1];
		document.frmTimeCardEdit.txtLateReasonText.value = confirm[2];
		PostBackTimeCard();
	}
	else
	{
		document.frmTimeCardEdit.txtLateReasonCode.value = "";
		document.frmTimeCardEdit.txtLateReasonText.value = "";
		document.frmTimeCardEdit.txtConfirmLate.value = "";
	}
}

function PostBackTimeCard()
{
    AllowExit();
    document.frmTimeCardEdit.txtPasswordRequired.value = "false"
//    document.frmTimeCardEdit.txtTimecardChanged.value == "false"
//	timecardChanged = false;
	if (document.frmTimeCardEdit.txtSubmitTimeCard.value == "Submit")
		__doPostBack('ibtnSubmit','');
		
	if (document.frmTimeCardEdit.txtSubmitTimeCard.value == "Save")
		__doPostBack('ibtnSave','');

	if (document.frmTimeCardEdit.txtSubmitTimeCard.value == "Approve")
		__doPostBack('ibtnApprove','');

	if (document.frmTimeCardEdit.txtSubmitTimeCard.value == "Reject")
		__doPostBack('ibtnReject','');

	if (document.frmTimeCardEdit.txtSubmitTimeCard.value == "Finish")
		__doPostBack('ibtnDone','');
}
//*********EDIT
function ViewApproverInfo()
{    
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 640; 
		h = 365;
	}
	else
	{
		w = 640; 
		h = 365;
	} 
//	else 
//	{
//		w = 640; 
//		h = 385;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";
        //window.showModalDialog('ApproverInformationDialog.aspx', self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no');
	    window.showModalDialog(AddDynamicSessionParameter('ApproverInformation.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no');
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('ApproverInformation.aspx'), self,'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}
//**** END EDIT

function ViewLateEntry()
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 830; 
		h = 650;
	}
	else
	{
		w = 830; 
		h = 650;
	} 
//	else 
//	{
//		w = 830; 
//		h = 650;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		window.showModalDialog(AddDynamicSessionParameter('LateEntryView.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no');
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('LateEntryView.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}
function ViewLateSubmit()
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 850; 
		h = 535;
	}
	else
	{
		w = 850; 
		h = 535;
	} 
//	else 
//	{
//		w = 840; 
//		h = 525;
//	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h - 40) / 2;

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		window.showModalDialog(AddDynamicSessionParameter('LateSubmitView.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no');
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter('LateSubmitView.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
		}
	}
}

var previousStartDate;
var savedDdlDate;
var resetStartDate;

function TimeCardDateSelected(ddlDate)
{
    if (window.name == "frmTimeCardEdit")
    {
        if (document.frmTimeCardEdit.txtTimecardChanged.value == "true")
        {
            var pDate = prevDate;
            if (confirm("You have attempted to leave this page without saving your changes. Your changes will be lost. Are you sure that you want to do this?"))
            {
                AllowExit();
            }
            else
            {
                prevDate = pDate;
                ResetStartDate(ddlDate)
                return;
            }
        }
    }
    
    if (ddlDate.value == "12/31/9999 11:59:59 PM")
    {
	    LookUpDate(ddlDate);
    }
    else
    {
	    __doPostBack('ctlTimeCardSelector$ddlDate','');
    }
    return;
}

function SetStartDate(ddlDate)
{
	previousStartDate = ddlDate.value;
	SetDate(ddlDate);
	return;
}
var prevDate;
function SetDate(ddlDate)
{
	if (ddlDate.value != "12/31/9999 11:59:59 PM")
	{
		prevDate = ddlDate.value;
	}
}
function LookUpDate(ddlDate)
{
//	calls timer function in Global.js
//	ResetTimer();
	BlockEvents();
	savedDdlDate = ddlDate;
	resetStartDate = true;
	
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 525; 
		h = 475;
	}
	else
	{
		w = 525; 
		h = 475;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 525; 
//		h = 495;
//	}

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
        ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter('LookUpDates.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		
		if (retValue != null) 
		{
			SetStartDateSearch(retValue[0], retValue[1]);
		}
		else
		{
			ResetStartDate(ddlDate);
		}
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter('LookUpDates.aspx'), '','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
	}
}
//222
function ResetDateNS()
{
	if (resetStartDate)
		ResetStartDate(savedDdlDate);
}

function ResetStartDate(ddlDate)
{
	for (var i = 0; i < ddlDate.options.length; i++)
	{
		if (ddlDate.options[i].value == prevDate)
		{
			ddlDate.options[i].selected = true;
			break;
		}
	}
}

function SetDateValue(rVal)
{
	var startDate = rVal[0];
	var amended = rVal[1];
	var ctlTC = "ctlTimeCardSelector_ddlDate";
	
	resetStartDate = false;
	document.frmTimeCardEdit.txtStartDate.value = startDate;
	document.frmTimeCardEdit.txtAmended.value = amended;

	for (var i = 0; i < document.frmTimeCardEdit[ctlTC].options.length; i++)
	{
		var idx = document.frmTimeCardEdit[ctlTC].options[i].value.indexOf(" ");
		var ddlDate = document.frmTimeCardEdit[ctlTC].options[i].value.substring(0, idx);
		if (ddlDate == startDate)
		{
			document.frmTimeCardEdit[ctlTC].options[i].selected = true;
			break;
		}
	}

	AllowExit();
	__doPostBack('ctlTimeCardSelector$ddlDate', '');
	
}
function SetStartDateSearch(startDate, amended)
{
//	document.frmTimeCardEdit.txtStartDate.value = startDate;
//	document.frmTimeCardEdit.txtAmended.value = amended;

	resetStartDate = false;
	document[window.name].txtStartDate.value = startDate;
	document[window.name].txtAmended.value = amended;
	AllowExit();
	__doPostBack('ctlTimeCardSelector$ddlDate', '');
}

var rptName = "rptTimeCardEdit:_ctl";
var rptFieldName = ":ddlJobDescription";

function DisplayJobInstruction(lineNo)
{
	var ddlJobName = rptName + lineNo + rptFieldName;
	if (rptName == "rptTimeCardEdit:_ctl")
	{
		if (document.frmTimeCardEdit[ddlJobName].value == "BLANK")
		return;
		OpenJobInstruction(document.frmTimeCardEdit[ddlJobName].value, "true", "UserSession", "");
	}
}

function OpenJobInstruction(jobID, noEdit, jobSource, lineNo)
{
	var queryString;	
	queryString = "?JobID=" + jobID + "&DisplayOnly=" + noEdit + "&JobSource=" + jobSource + "&LineNo=" + lineNo;
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 580; 
		h = 390;
	}
	else
	{
		w = 580; 
		h = 390;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 590; 
//		h = 430;
//	}

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";
        
		retValue = window.showModalDialog(AddDynamicSessionParameter("JobInstructions.aspx" + queryString), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter("JobInstructions.aspx" + queryString), '','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
	}
}

var savedDdlEmployee
var resetEmployee = false;
var previousEmployee;
var lookUpEmployeeCaller;
var postBackTarget;

function LookUpEmployee(ddlEmployee, caller)
{
    
	if (ddlEmployee.value != "SEARCH")
	{
		previousEmployee = ddlEmployee.value;
		if (caller == "frmPersonalJobList" && postBackTarget == "ddlEmployee")
		{
		    __doPostBack(postBackTarget,"");
		}
		if (caller == "frmDelegateApproval" && postBackTarget == "ddlDelegatee")
		{
		    __doPostBack(postBackTarget,"");
		}
		return;
	}
	
	var urlPage;
	var queryString;
	lookUpEmployeeCaller = caller;
	savedDdlEmployee = ddlEmployee; //save this for Netscape reset.
	resetEmployee = true;
//	calls timer function in Global.js
	ResetTimer();
	
	switch (caller)
	{
		case "frmSubmit":
			queryString = "?LookupFor=Approver";
			break;
		case "frmDelegateApproval":
			queryString = "?LookupFor=TimeCardAndExpenseApprover";
			break;
		case "frmApprovalArchived":
		case "frmPersonalJobList":
			queryString = "?LookupFor=Approvee";
			break;
		default:
			alert("You must define a queryString for LookUpEmployee");
	}
	
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 505; 
		h = 580;
	}
	else
	{
		w = 505; 
		h = 580;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 505; 
//		h = 580;
//	}

//	if (navigator.appName == 'Netscape')
    
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter("LookUpEmployee.aspx" + queryString), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		
		if (retValue != null) 
		{
			SetEmployeeSearch(retValue[0], retValue[1]);
		}
		else
		{
			ResetEmployee(ddlEmployee);
		}
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpEmployee.aspx" + queryString),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
			dialogWin.win.focus();
	
		}	
			
	}
}

function SetEmployeeSearch(id, name)
{    
	resetEmployee = false;
	switch (lookUpEmployeeCaller)
	{
		case "frmSubmit":
		case "frmDelegateApproval":
			idField = "txtApproverID";
			nameField = "txtApproverName";
			break;
        case "frmExpenseMassEntry":
	        queryString = "?LookupFor=ExpenseUser";
	        idField = "_ctl0_JamisContentPlaceHolder_txtEmployee";
			nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName";
			document.forms.aspnetForm[idField].value = id;
			document.forms.aspnetForm[nameField].value = name;
			return;
		case "frmApprovalArchived":
		case "frmPersonalJobList":
			idField = "txtEmployeeID";
			nameField = "txtEmployeeName";
			break;
		case "frmViewEmployeePreviousReport":
		    //from
		    if(butName == "from2")
		    {
		        idField = "_ctl0_JamisContentPlaceHolder_txtEmplFrom";
		        nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName1";
		    }
		    else//through
		    {
		        idField = "_ctl0_JamisContentPlaceHolder_txtEmplThru";
		        nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName2";
		    }
		    document.forms.aspnetForm[idField].value = id;
			document.forms.aspnetForm[nameField].value = name;
			return;
		case "frmAdditionalApproverInfo":
		    idField = "txtApproverID";
		    document.forms[lookUpEmployeeCaller][idField].value = id;
			return;
		default:
			alert("You need to define return value fields to call LookUpEmployee");
	}
	
	document.forms[lookUpEmployeeCaller][idField].value = id;
	document.forms[lookUpEmployeeCaller][nameField].value = name;
	__doPostBack(postBackTarget, '');
}
function SetEmplSearch(id, name, fName)
{
    
    switch (fName)
    {
        case "frmViewEmployeePreviousReport7":
            idField = "_ctl0_JamisContentPlaceHolder_txtEmplFrom";
			nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName1";
			document.forms.aspnetForm[idField].value = id;
			document.forms.aspnetForm[nameField].value = name; 
            return;
        case "frmViewEmployeePreviousReport8":
            idField = "_ctl0_JamisContentPlaceHolder_txtEmplThru";
			nameField = "_ctl0_JamisContentPlaceHolder_txtEmployeeName2";
			document.forms.aspnetForm[idField].value = id;
			document.forms.aspnetForm[nameField].value = name; 
            return;
        case "frmAdditionalApproverInfo":
            idField = "txtApproverID";
            document.forms[fName][idField].value = id;
            return;
        default:
            idField = "txtEmployeeID";
	        nameField = "txtEmployeeName";
            break;
    }
    	
	document.forms[fName][idField].value = id;
	document.forms[fName][nameField].value = name;
	
}
function ResetEmployeeNS()
{
	if (resetEmployee)
		ResetEmployee(savedDdlEmployee);
}

function ResetEmployee(ddlEmployee)
{
	for (var i = 0; i < ddlEmployee.options.length; i++)
	{
		if (ddlEmployee.options[i].value == previousEmployee)
		{
			ddlEmployee.options[i].selected = true;
			break;
		}
	}
}

function SetEmployeeID(ddlEmployee)
{
	if (ddlEmployee.value != "Search")
	{
		previousEmployee = ddlEmployee.value;
	}
}
function SetPostBackTarget(controlID)
{
	postBackTarget = controlID;
}

function SetWorkOrderSearch(woID, woDesc, jobID, addToPersonal)
{
	var idList = woID[0];
	var descList = woDesc[0];
	var jobIDList = jobID[0];
	for (var i = 1; i < woID.length; i++)
	{
		idList = idList + "|^|" + woID[i];
		descList = descList + "|^|" + woDesc[i];
		jobIDList = jobIDList + "|^|" + jobID[i];
	}
	document.frmTimeCardEdit.txtWorkOrderList.value = idList;
	document.frmTimeCardEdit.txtWorkOrderDescList.value = descList;
	document.frmTimeCardEdit.txtJobIDList.value = jobIDList;
	document.frmTimeCardEdit.txtAddToEmployeeJob.value = addToPersonal;
	AllowExit();
	__doPostBack('btnWorkOrderSearch', '');
}

var lNum;
var rptVal;



function TTLHoursOnFocus(fName)
{	
	//mousedown-a mouse click event so leave here at once!
	if(tabKey == 0 || tabKey == 1 )
	{
		return;
	}
	//var rptInfo = GetRepeaterInfo(fName);
	lNum = document.frmTimeCardEdit["txtLineNumber"].value;
	//backwards tab
	if((shiftKey) && (tabKey == 9))
	{
		if(fName.match(/txtExtraInfo1/))
		{	
			try
			{	
				rptVal = "rptTimeCardEdit__ctl" + lNum + "_txtDay8";
				return document.frmTimeCardEdit[rptVal].focus();
			}
			catch(e)
			{
				rptVal = "rptTimeCardEdit__ctl" + lNum + "_txtDay7";
				return document.frmTimeCardEdit[rptVal].focus();
			}
		}
		if(fName.match(/ibtnComment/))
		{
			lNum--
			if(lNum == 0){lNum++}
			try
			{	
				rptVal = "rptTimeCardEdit__ctl" + lNum + "_txtDay8";
				document.frmTimeCardEdit[rptVal].focus();
			}
			catch(e)
			{
				rptVal = "rptTimeCardEdit__ctl" + lNum + "_txtDay7";
				document.frmTimeCardEdit[rptVal].focus();				
			}
			finally
			{
				for(var i = 7; i > 0; i--)
				{
					if(!document.frmTimeCardEdit["txtExtraInfo" + i].disabled)
					{
						return document.frmTimeCardEdit["txtExtraInfo" + i].focus();
					}		
				}
			}
		}
	}
	//forward tab
	if((tabKey == 9) && (!shiftKey))
	{
		lNum++;
		rptVal = "rptTimeCardEdit__ctl" + lNum + "_ddlJobDescription";
		if(fName.match(/txtJobTotals/))
		{
			document.frmTimeCardEdit.txtExtraInfo1.focus();
		}
		if(fName.match(/txtExtraInfoDesc1/))
		{	
			try
			{	
				return document.frmTimeCardEdit[rptVal].focus();
			}
			catch(e)
			{
				return document.getElementById("ibtnPreviousPage").focus();
			}
		}
		if(fName.match(/txtPremiumHours/))
		{
			return document.getElementById("ibtnSubmit").focus();
		}
		if(fName.match(/txtDailyTotals/))
		{
			try
			{
				document.frmTimeCardEdit.txtRecognitionPay.focus();
			}
			catch(e)
			{
				document.frmTimeCardEdit.txtPremiumHours.focus();
			}
		}
	}
}

function ArrowKey(e, fName)
{
	var rptInfo = GetRepeaterInfo(fName);
	lNum = rptInfo[0];
	var dayNum = fName.substring(fName.length - 1);
	var keyEvent;
//	if(navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		keyEvent = window.event.keyCode;
	}
	else
	{
		keyEvent = e.which
	}
//	else
//	{
//		keyEvent = window.event.keyCode;
//	}
	switch (keyEvent)
	{
	    case 37:
	        dayNum--;
	        break;
		case 38:
			lNum--;
			break;
		case 39:
		    dayNum++;
		    break;
		case 40:
			lNum++;
			break;
		default:
			break;
	}
	var rptVal = "rptTimeCardEdit__ctl" + lNum + "_txtDay" + dayNum;
	try
	{
		  document.frmTimeCardEdit[rptVal].focus();
		 
	}
	catch(e)
	{
		//doesn't do anything
	}
}
var rptName;
var fldName;
var frmName;
function SetCheckBoxName(frName, rName, fName)
{
	
	frmName = frName;
	rptName = rName;
	fldName = fName;
	
}

function SelectAllTimeCardClick(cbxValue)
{
    //alert(fldName);
	var cbxName;
	var tableOf;
	var rows;
	var totalLine;
	try	
	{
		tableOf = document.getElementById("tblApproval");
		rows = tableOf.getElementsByTagName("tr");
		totalLine = rows.length;
		//alert(totalLine);
		if (totalLine == 0)
		{
		    return;
		}
		if(fldName == '_cbxSelectExpenseReport')
		{
		    for (var i = 1; i <= totalLine; i++)
		    {
			    var strVal = '_ctl0_JamisContentPlaceHolder_rptExpenseApprovalView__ctl' + i + '_cbxSelectExpenseReport';
			    window.document.getElementById(strVal).checked = cbxValue;
		    }
		}
        else
        {
		    for (var i = 1; i <= totalLine; i++)
		    {
			    cbxName = rptName + i + fldName;
			    //document.forms[frmName][cbxName].checked = cbxValue;
			    window.document.getElementById(cbxName).checked = cbxValue;
		    }
		}
	}
	catch(e)
	{
		
	}	
}

function SelectAllDelegate(cbxValue)
{
	var cbxName;
	var tableOf;
	var rows;
	var totalLine;
	try	
	{
		tableOf = document.getElementById("tblDelegate");
		rows = tableOf.getElementsByTagName("tr");
		totalLine = rows.length;
		if (totalLine == 0)
			return;
		for (var i = 1; i <= totalLine; i++)
		{
			cbxName = rptName + i + fldName;
			document.forms[frmName][cbxName].checked = cbxValue;
		}
	}
	catch(e)
	{
	}
}
function ViewProfile(profile)
{
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 900; 
		h = 615;
	}
	else
	{
		w = 900; 
		h = 615;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 900; 
//		h = 615;
//	}
   var queryString;
   queryString = "?Profile=" + profile;
//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		window.showModalDialog(AddDynamicSessionParameter('ViewProfile.aspx' + queryString), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'resizable:yes' + 'help:no'); 
		
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter('ViewProfile.aspx' + queryString),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
	}
}
//delegateApprover
var apply = false;
function OnOKAction()
{
	apply = true;
}
function CheckForComplete(fName)
{	
	var dat1 = document.frmDelegateApproval.txtDate0.value
	var dat2 = document.frmDelegateApproval.txtDate1.value
	doDateCheck(dat1, dat2);
	//warn flag is set in calendar date formating
	if(warnFlag == true)
	{
		warnFlag = false;
		return false;
	}
	var ddlDelegator2 = document[frmName]['ddlDelegatee'].options[document[frmName]['ddlDelegatee'].selectedIndex].text;
	var ddlReason2 = document[frmName]['ddlReasonCode'].options[document[frmName]['ddlReasonCode'].selectedIndex].text;

	if(ddlDelegator2.match(/Select/))
	{
		alert("A delegate approver is required!");
		document.frmDelegateApproval.ddlDelegatee.focus();
		return false;
	}
	if(document.frmDelegateApproval.txtDate0.value == "")
	{
		alert("A from date is required!");
		document.frmDelegateApproval.txtDate0.focus();
		return false;
	}
	if(document.frmDelegateApproval.txtDate1.value == 0)
	{
		alert("An thru date is required!");
		document.frmDelegateApproval.txtDate1.focus();
		return false;
	}
	if(ddlReason2.match(/Select/))
	{
		alert("A reason code is required!");
		document.frmDelegateApproval.ddlReasonCode.focus();
		return false;
	}
	return true;
}


//Reject time card
function RejectOnClick(rejFunction)
{
    var pageName = "ExplainReject.aspx?" + rejFunction;
    
//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 765; 
		h = 335;
	}
	else
	{
		w = 765; 
		h = 335;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 765; 
//		h = 335;
//	}

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter(pageName), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'resizable:yes' + 'help:no'); 

		if (retValue != null) 
		{
			RejectFunction(retValue[0], retValue[1], retValue[2], retValue[3]);
		}
	}
	else
	{
	    ResetTimer();
	    	
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter(pageName),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
	}
}

function RejectFunction(rejectReason, rejectText, password, rf)
{
    if (rf == "TIMECARD")
        RejectTimeCard(rejectReason, rejectText, password);
    if (rf == "REQUEST" || rf == "REPORT")
        RejectRequest(rejectReason, rejectText, password);
}
			
function RejectTimeCard(rejectReason, rejectText, password)
{
	document.forms[window.name].txtRejectReasonCode.value = rejectReason;
	document.forms[window.name].txtRejectReasonText.value = rejectText;
	document.forms[window.name].txtRejectPassword.value = password;
	__doPostBack('ibtnReject', '');
}

function RejectRequest(rejectReason, rejectText, password)
{
	document.aspnetForm._ctl0_JamisContentPlaceHolder_txtRejectReasonCode.value = rejectReason;
	document.aspnetForm._ctl0_JamisContentPlaceHolder_txtRejectReasonText.value = rejectText;
	document.aspnetForm._ctl0_JamisContentPlaceHolder_txtRejectPassword.value = password;
	__doPostBack('_ctl0$JamisContentPlaceHolder$ibtnReject', '');
}

//GTK create time card and ask for reason code
function GTKCreateTimeCard(func)
{
	document.frmTimeCardEdit.txtSubmitTimeCard.value = func;

//	if (navigator.appName == 'Netscape') 
    if(IsIEBrowser)
    {
		w = 740; 
		h = 310;
	}
	else
	{
		w = 740; 
		h = 310;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} 
//	else 
//	{
//		w = 740; 
//		h = 310;
//	}

//	if (navigator.appName == 'Netscape')
    if(IsIEBrowser)
    {
	    ClearTimer();
        window.status = "";

		retValue = window.showModalDialog(AddDynamicSessionParameter('ExplainCreate.aspx'), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'resizable:yes' + 'help:no'); 

		if (retValue != null) 
		{
			CreateTimeCardReason(retValue[0], retValue[1]);
		}
	}
	else
	{
	    ResetTimer();
	    
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
			{
				dialogWin.win = window.open(AddDynamicSessionParameter('ExplainCreate.aspx'),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
			}
			else
			{
				dialogWin.win.focus();
			}
	}
}
			
function CreateTimeCardReason(createReason, createText)
{
	document.forms[window.name].txtRejectReasonCode.value = createReason;
	document.forms[window.name].txtRejectReasonText.value = createText;
	PostBackTimeCard();
}

function SelectAllStatus(isSelected)
{
	document.forms.frmApprovalView.cbxSelectSubmitted.checked = isSelected;
	document.forms.frmApprovalView.cbxOpen.checked = isSelected;
	document.forms.frmApprovalView.cbxSelectApproved.checked = isSelected;
	document.forms.frmApprovalView.cbxRejected.checked = isSelected;

	if (document.forms.frmApprovalView.cbxPartiallyApproved != undefined)
		document.forms.frmApprovalView.cbxPartiallyApproved.checked = isSelected;
	if (document.forms.frmApprovalView.cbxMyPartiallyApproved != undefined)
		document.forms.frmApprovalView.cbxMyPartiallyApproved.checked = isSelected;
}
function DefaultPayCodeFromWO(fname)
{
   var extraNum;
   var isWO = "false";

   if (document.frmTimeCardEdit.txtLinkedWorkOrder.value != "True")
      return;

   if (fname.substring(0, 12) != "txtExtraInfo")
   {
       if (document.frmTimeCardEdit.txtWorkOrderOnEveryLine.value == "true") 
       {
           isWO = "true";
       }
   }
   else
   {
       extraNum = fname.substring(12);
       var valInfo = document.frmTimeCardEdit.txtExtraInfoList.value.split('|'); 
       if (valInfo[extraNum - 1] == "WorkOrder")
       {
           isWO = "true";
       }
   }

   if (isWO != "true")
        return;

   var lNum = window.document.frmTimeCardEdit['txtLineNumber'].value;
   if (Trim(document.frmTimeCardEdit[fname].value) != "")
   {
      var rptName = "rptTimeCardEdit:_ctl";
      var rptFieldName = ":ddlPayCode";
      
      var ddlPayCodeName = rptName + lNum + rptFieldName;
      if (rptName == "rptTimeCardEdit:_ctl")
      {
      	  if (document.frmTimeCardEdit[ddlPayCodeName].value == "")
              document.frmTimeCardEdit[ddlPayCodeName].value = document.frmTimeCardEdit["txtDefaultPayCode"].value;
      }

   }
}
//used for purchase requestion lookups ****
function LookUpGLAcct(src, id)
{
    tempName = src;//?    
    w = 540; 
	h = 590;
    if(IsIEBrowser)
    {
	    ClearTimer();
	    window.status = "";
	    retValue = window.showModalDialog(AddDynamicSessionParameter("LookUpGLAccount.aspx"), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		if (retValue != null) 
		{
			SendGLAccountValue(retValue, src, id );			
		}
    }
    else
    {
        var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
        ResetTimer();
        if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpGLAccount.aspx"),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
		    fSrc = src;//?
			dialogWin.win.focus();
		}	
    } 
}
function SendGLAccountValue(rVal, src, id)
{
    src = src.replace("ibtnLookUp", "tbx");
    document.getElementById(src).focus();
	document.getElementById(src).value = rVal[0];
    src = src.replace("tbxGLAcct", "tbxGLAcctDesc");
    document.getElementById(src).value = rVal[1];
}

function LookUpShipTo(src)
{
    tempName = src;//?
    w = 540; 
	h = 590;
    if(IsIEBrowser)
    {
	    ClearTimer();
	    window.status = "";
	    retValue = window.showModalDialog(AddDynamicSessionParameter("LookUpShipTo.aspx"), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		if (retValue != null) 
		{
			SendShipToValue(retValue, src );			
		}
    }
    else
    {
        var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
        ResetTimer();
        if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpShipTo.aspx"),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
		    fSrc = src;//?
			dialogWin.win.focus();
		}	
    } 
}
function SendShipToValue(rVal, src)
{
    src = src.replace("ibtnLookUp", "tbx");
    document.getElementById(src).focus();
	document.getElementById(src).value = rVal[0];
    src = src.replace("tbxShipTo", "tbxShipToName");
    document.getElementById(src).value = rVal[1];
    src = src.replace("tbxShipToName", "tbxShipToAddress1");
    document.getElementById(src).value = rVal[2];

}
function LookUpVendor(src)
{
    tempName = src;//?
    w = 540; 
	h = 590;
    if(IsIEBrowser)
    {
	    ClearTimer();
	    window.status = "";
	    retValue = window.showModalDialog(AddDynamicSessionParameter("LookUpVendor.aspx"), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		if (retValue != null) 
		{
			SendVendorValue(retValue, src );			
		}
    }
    else
    {
        var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
        ResetTimer();
        if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpVendor.aspx"),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
		    fSrc = src;//?
			dialogWin.win.focus();
		}	
    } 
}
function SendVendorValue(rVal, src)
{
    src = src.replace("ibtnLookUp", "tbx");
    document.getElementById(src).focus();
	document.getElementById(src).value = rVal[0];
	src = src.replace("tbxVendor", "tbxVendorName");
	document.getElementById(src).focus();
	document.getElementById(src).value = rVal[1];
	src = src.replace("tbxVendorName", "tbxVendorAddress1");
	document.getElementById(src).focus();
	document.getElementById(src).value = rVal[2];
	src = src.replace("tbxVendorAddress1", "tbxVendorAddress2");
	document.getElementById(src).focus();
	document.getElementById(src).value = rVal[3];
	src = src.replace("tbxVendorAddress2", "tbxVendorAddress3");
	document.getElementById(src).focus();
	document.getElementById(src).value = rVal[4];
}
var txtChange = false;
function LookUpItem(src, id)
{
    //tempName = src;
    src = src.replace('ibtnLookUp', 'tbx');
    var startName = document.getElementById(src).value;
    w = 540; 
	h = 590;
    if(IsIEBrowser)
    {
	    ClearTimer();
	    window.status = "";
	    retValue = window.showModalDialog(AddDynamicSessionParameter("LookUpItem.aspx"), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		if (retValue != null) 
		{
			if (startName != retValue[0])
		    {
		        txtChange = true;
		    }
		    SendItemValue(retValue, src, id, txtChange);			
		}
    }
    else
    {
        var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
        ResetTimer();
        if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpItem.aspx"),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
		    fSrc = src;//?
			dialogWin.win.focus();
		}	
    } 
}
function SendItemValue(rVal, src, id, txtChange)
{
    src = src.replace("ibtnLookUp", "tbx");
    if (id == 'PRDetail')
    {
        document.getElementById(src).focus();
	    document.getElementById(src).value = rVal[0];
	    src = src.replace("ItemNo", "Descr1");
        document.getElementById(src).focus();
        document.getElementById(src).value = rVal[1];
        src = src.replace("Descr1", "Descr2");
        document.getElementById(src).focus();
        document.getElementById(src).value = rVal[2];
        if (txtChange == true)
        {  
            document.getElementById('txtItemChanged').value = 'true';
        }
    }
    else
    {
        document.aspnetForm[src].focus();
	    document.aspnetForm[src].value = rVal[0];
	    if (rVal[1] != "")
	    {
	        src = src.replace("ItemNo", "ItemDescription1");
	        document.aspnetForm[src].focus();
	        document.aspnetForm[src].value = rVal[1];
	    }
	}
}

function LookUpCostElement(src, caller)
{
    var jobSrc = src.replace("ibtnLookUpCELM", "tbxJob");
    var jobVal = document.getElementById(jobSrc).value;
    if (jobVal == "")
    {
	    alert("You need a valid Job Number before looking up Cost Element  ");	
	    return;
	}	
    queryString ="?jobID=" + jobVal + "&" + caller;
    tempName = src;//?
    w = 540; 
	h = 590;
    if(IsIEBrowser)
    {
        w = 615; 
		h = 545;
	    ClearTimer();
	    window.status = "";
	    retValue = window.showModalDialog(AddDynamicSessionParameter('LookUpCostElement.aspx' + queryString), self, 'dialogWidth:' + w + 'px;' + 'dialogHeight:' + h + 'px;' + 'help:no'); 
		if (retValue != null) 
		{
			SendCostElementValue(retValue,src, caller);			
		}
    }
    else
    {
        var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
        ResetTimer();
        if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.win = window.open(AddDynamicSessionParameter("LookUpCostElement.aspx"),'','directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,modal=yes,top='+wint+',left='+winl+',width=' + w + ',height=' + h);
		}
		else
		{
		    fSrc = src;//?
			dialogWin.win.focus();
		}	
    } 
}

