function showAuditTrail(userEntBy, dtEnt, userChgBy, dtChg) {
  var strText = "<TABLE width=100% style='font-family: verdana; font-size: xx-small' class='clsTableMain'><tr><td width=22% nowrap><DIV id='entby'>";

  if (userEntBy != "") {
    strText = strText + "entered by: " + userEntBy;
  }
  
  strText = strText + "</DIV></td>";
  strText = strText + "<TD width=28% Nowrap>";
  strText = strText + "<DIV id='dtent'>";

  if (dtEnt != "") {
    strText = strText + "on: " + dtEnt;
  }
  
  strText = strText + "</DIV></TD>";
  
  strText = strText + "<TD width=22% nowrap>";
  
  strText = strText + "<DIV id='chgby'>";
  
  if (userChgBy!= "") {
      strText = strText + "changed by: " + userChgBy;
  }
  
  strText = strText + "</DIV></TD>";
  strText = strText + "<TD width=28% nowrap>";
  strText = strText + "<DIV id='dtchg'>";
  
  if (dtChg != "") {
    strText = strText + "on: " + dtChg;
  }
  
  strText = strText + "</DIV></td></tr></TABLE>";
    
  return strText;    
}


function addNew(frm)
{
	var j=1;
	
	for(i=0;i<frm.elements.length;i++)
	{
		if ((!frm.elements[i].disabled) && (!frm.elements[i].readOnly) && (frm.elements[i].type != 'button') && (frm.elements[i].type != 'submit') && (frm.elements[i].type != 'reset') && (frm.elements[i].name != undefined) && (frm.elements[i].name.charAt(0) != '_'))
		{
			if(frm.elements[i].type == 'checkbox' || frm.elements[i].type == 'radio')
				frm.elements[i].checked = 0;
			else
			{
				if(j==1)
				{
					frm.elements[i].focus();
				}
				frm.elements[i].value = '';
				j = j+1
			}
		}	
	}

}



function confirmDelete()
{		
	return confirm("Delete the Record?");
}

function ShowError(e)
{
	var url = "../error/ShowJSError.aspx?params=" + e.number + "||" + e.name + "||" + e.message + "||" + window.location.pathname
	openWindow(url,600,300)
}

function MoveAllItems(fromObj,toObj)
{
	//function added by Jai - 04/11/03
	//moves the all listitems from one listbox to another
	
	//check if listboxes exist
	if(fromObj && toObj) 
	{
		if (fromObj.length>0)
		{
			var strOuterHTML = fromObj.outerHTML;
			//need to rewrite the replace function (Jscript issue)
			// - will not replace all... (here - 'id' and 'name' attribute values) 
			strOuterHTML = strOuterHTML.replace(fromObj.id, toObj.id); 
			strOuterHTML = strOuterHTML.replace(fromObj.id, toObj.id); 
		
			toObj.outerHTML = strOuterHTML;
			fromObj.innerHTML = '';
		}	
	}	
}

//sample for All select
function MoveBulkItem(fromObj,toObj)
{
	var TotalItem = fromObj.length ;
	
	for (i=1; i < TotalItem; i++)
	{  
         var newText = fromObj.options[1].text;
         var newValue = fromObj.options[1].value;

         var newOption = new Option(newText,newValue)

         toObj[toObj.length] = newOption;

         fromObj[1] = null;
	}
   
}

// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
function selectAllOptions(obj) {
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}


function MoveItem(fromObj,toObj)
{
	//extended the functionality to move 
	//multiple list items - Jai 04/11/03
	
	//check if listboxes exist
	var i = 0;
	var intListCount = fromObj.length;
	if(fromObj && toObj) 
	{
		var selIndex = fromObj.selectedIndex;
		if (selIndex < 0)
		{
			alert("Choose an item to move");
			fromObj.focus();
			return;
		}	
		
		for (i=1; i<intListCount; i++)
		{
			if (fromObj.item(i).selected)
			{
				var newText = fromObj.options[i].text;
				var newValue = fromObj.options[i].value;
				
				var newOption = new Option(newText,newValue)

				toObj[toObj.length] = newOption;
			}
		}	
		
		for(i=(intListCount-1); i>0; --i)
		{
			if (fromObj.item(i).selected)
			{
				fromObj[i] = null;
			}
		} 
	}	   
	else if(fromObj)
	{
		for(i=(intListCount-1); i>0; --i)
		{
			fromObj[i] = null;
		} 
	}
	
}

function MoveItemOld(fromObj,toObj)
{
   var selIndex = fromObj.selectedIndex;

   if (selIndex > 0)
   {
  
       var newText = fromObj.options[selIndex].text;
       var newValue = fromObj.options[selIndex].value;

       var newOption = new Option(newText,newValue)

       toObj[toObj.length] = newOption;

       fromObj[selIndex] = null;
   }
   else 
	   alert("Choose an item to move");
   
}

function fillDropDown(objXML,listObj,textPos,valuePos,startPos,textPosAlt)
{
	var textPosition = 1;
	var valuePosition = 0;
	var startPosition = 1;
	
	var strText = '';
	var strValue = '';
	
	
	if (textPos != null)
		textPosition = textPos;
		
	if (startPos != null)
		startPosition = startPos;	
		
	if (valuePos != null)
		valuePosition = valuePos;			
	
	var nodes = objXML.documentElement.childNodes
	var len = listObj.length;


	for(j=startPosition; j< len; j++)
		listObj[listObj.length-1] = null;
		
	for(i=0; i<nodes.length; i++)
	{
		if (nodes(i).childNodes.item(0))
		{
			strText = nodes(i).childNodes.item(textPosition).text;
			
			if(textPosAlt != null)
				strText = strText + '(' + nodes(i).childNodes.item(textPosAlt).text + ')';
				
			strValue = nodes(i).childNodes.item(valuePosition).text;
			
			listObj[i+startPosition] = new Option(strText,strValue)
		}	
	}	

	
}

function gotoPage(val)
{
 history.go(-val)
}

function gotoURL()
{
	var url = 'UpdateJobTitle.aspx' + window.location.search ;
	window.location.href = url ;
}


// ***** Begin Functions used for Grid row effects *******

function MouseOver()
{
	if(findEventElemet().flag=='false')
		findEventElemet().className = 'clsTRMOver';
}

function MouseOut()
{
	if(findEventElemet().flag=='false')
		findEventElemet().className = 'clsTRList';
}

function MouseClick(objTable, intGridRowNum, intRowNum, intPageSize)
{
	/* Jai extended the function on 05/21/03
	*	extended MouseClick function to select the row and page previously 
	*	selected by the user - when the user goes to child/linked
	*	page and comes back.
	*/
	
	/*	NOTE: -->
	*	get the id of the first parameter
	*	this should be 'tblHeader1' - (hard coded by the calling function,
	*	paging function which returns the string has that table name.)
	*/
	
	var objID = objTable.id;
	if (objTable && objID)
	{
		var intRowCount = objTable.rows.length; //table row size
		//reset the color to default for all rows in the 'tblHeader1'
		for (i=1; i<intRowCount; i++)
		{
			objTable.rows(i).className = 'clsTRList';
			objTable.rows(i).flag = 'false';
		}
		//finally get the tabel row to variable
		var objTR  = objTable.rows(((intRowNum % intPageSize)+ 1));
		//set the selected row color
		objTR.className = 'clsTRSelected';
		objTR.flag = 'true';
		
		//get the XML Node
		eval("node = objXMLGrid" + intGridRowNum + ".documentElement.childNodes(intRowNum).childNodes");
		fillDetails(node);
	}	
	else if (objTable)
	{// the default MouseClick event called here.
		var srcElem = window.event.srcElement;
		var srcTRElem = window.event.srcElement.parentElement;
		
		
		//added these lines to set the selected row info.
		var objRowClicked = document.all("hdnRowClicked");
		var objGridRow = document.all("hdnGridRow");
		if (objRowClicked && objGridRow )
		{
			objRowClicked.value = srcTRElem.GridNum; //srcTRElem.rownum; //
			objGridRow.value = srcTRElem.rownum; //
		} 
		// till here
		
		while (srcTRElem.tagName != 'TR')
		{
			srcTRElem = srcTRElem.parentElement
		}
	
		var styleTR = 'clsTRSelected';
		
		eval("node = objXMLGrid" + srcTRElem.GridNum + ".documentElement.childNodes(srcTRElem.rownum).childNodes");

		if (srcElem.tagName != 'INPUT')
		{
		
			for(i=1; i<srcTRElem.parentElement.rows.length; i++)
			{	
				srcTRElem.parentElement.rows(i).className = 'clsTRList';
				srcTRElem.parentElement.rows(i).flag = 'false';
			}

			srcTRElem.className = 'clsTRSelected';
			srcTRElem.flag = 'true';
			
			
			
			if(window.fillDetails)
			{
				fillDetails(node, srcTRElem.rownum);
				
			}	
		}
		else
		{
			if(window.onClickHandler)
				onClickHandler(node, srcTRElem.rownum);
		}
	}
	
}

function MouseClick_original()
{
	var srcElem = window.event.srcElement;
	
	var srcTRElem = window.event.srcElement.parentElement;
	
	var objRowClicked = document.all("hdnRowClicked");
	if (objRowClicked)
	{
		objRowClicked.value = srcTRElem.rownum;
		
	} 
	
	while (srcTRElem.tagName != 'TR')
	{
		srcTRElem = srcTRElem.parentElement
	}
	
	var styleTR = 'clsTRSelected';
	
	//if (srcElem.tagName == 'INPUT')
	//	styleTR = 'clsTRChecked'
	//debugger
	eval("node = objXMLGrid" + srcTRElem.GridNum + ".documentElement.childNodes(srcTRElem.rownum).childNodes");
	
	
	if (srcElem.tagName != 'INPUT')
	{
	
		for(i=1; i<srcTRElem.parentElement.rows.length; i++)
		{	
			srcTRElem.parentElement.rows(i).className = 'clsTRList';
			srcTRElem.parentElement.rows(i).flag = 'false';
		}

		srcTRElem.className = 'clsTRSelected';
		srcTRElem.flag = 'true';
		
		
		
		if(window.fillDetails)
		{
			fillDetails(node, srcTRElem.rownum);
			
		}	
	}
	else
	{
		if(window.onClickHandler)
			onClickHandler(node, srcTRElem.rownum);
	}

}

function findEventElemet()
{
	var srcElem;
	srcElem = window.event.srcElement;
	
	while(srcElem.tagName != 'TR')
		srcElem = srcElem.parentElement ;
	
	return srcElem;	 
}

// ***** End Functions Used for Grid row effects ******


function GetXmlObject(ProcName, Param1, Param2, Param3, Param4) 
{
	  
	var HttpUrl;
	var objXMLHttp = new ActiveXObject('Msxml2.XMLHTTP'); 
	
	if (Param1 == null)
		Param1 = '';

	if (Param2 == null)
		Param2 = '';

	if (Param3 == null)
		Param3 = '';

	if (Param4 == null)
		Param4 = '';

	//if(Param1 == null)
	//	HttpUrl = "../xmlhttp/ProcessXmlHttp.aspx?ProcName=" + ProcName ;
	//else if(Param2 == null)
	//	HttpUrl = "../xmlhttp/ProcessXmlHttp.aspx?ProcName=" + ProcName + "&Param1=" + Param1 ;
	//else
	//	HttpUrl = "../xmlhttp/ProcessXmlHttp.aspx?ProcName=" + ProcName + "&Param1=" + Param1 + "&Param2=" + Param2 ;
	
	HttpUrl = "../xmlhttp/ProcessXmlHttp.aspx?ProcName=" + ProcName + "&Param1=" + Param1 + "&Param2=" + Param2 + "&Param3=" + Param3 + "&Param4=" + Param4;
	
	//alert(HttpUrl);
	
	objXMLHttp.Open ("GET", HttpUrl, false );
	objXMLHttp.send();
		  
	//alert(objXMLHttp.responseText)
		
	var objXMLResponse = new ActiveXObject('Msxml2.FreeThreadedDOMDocument.3.0');
	objXMLResponse.loadXML(objXMLHttp.responseText);
		
	return objXMLResponse ;

}
//This function is used when we get the value from the database remotely(through javascript)
// single value to a text box.
//Author Venkat Pushpala
function fillTextBox(objXML,textObj,textPos,valuePos,startPos,textPosAlt)
{
	var textPosition = 1;
	var valuePosition = 0;
	var startPosition = 1;
	
	var strText = '';
	var strValue = '';
	
	
	if (textPos != null)
		textPosition = textPos;
		
	if (startPos != null)
		startPosition = startPos;	
		
	if (valuePos != null)
		valuePosition = valuePos;			
	
	var nodes = objXML.documentElement.childNodes
	//var len = listObj.length;


	//for(j=startPosition; j< len; j++)
		//textObj[textObj.length-1] = null;
		
	for(i=0; i<nodes.length; i++)
	{
		if (nodes(i).childNodes.item(0))
		{
			strText = nodes(i).childNodes.item(textPosition).text;
			
			if(textPosAlt != null)
				strText = strText + '(' + nodes(i).childNodes.item(textPosAlt).text + ')';
				
			strValue = nodes(i).childNodes.item(valuePosition).text;
			
			textObj.value = strValue
			//listObj[i+startPosition] = new Option(strText,strValue)
		}	
	}	

	
}

//This function is called in the above function, which serves the same job
//Author Venkat Pushpala
function GetXmlString(ProcName, Param1, Param2, Param3, Param4) 
{
	  
	var HttpUrl;
	var objXMLHttp = new ActiveXObject('Msxml2.XMLHTTP'); 
	
	if (Param1 == null)
		Param1 = '';

	if (Param2 == null)
		Param2 = '';

	if (Param3 == null)
		Param3 = '';

	if (Param4 == null)
		Param4 = '';

	//if(Param1 == null)
	//	HttpUrl = "../xmlhttp/ProcessXmlHttp.aspx?ProcName=" + ProcName ;
	//else if(Param2 == null)
	//	HttpUrl = "../xmlhttp/ProcessXmlHttp.aspx?ProcName=" + ProcName + "&Param1=" + Param1 ;
	//else
	//	HttpUrl = "../xmlhttp/ProcessXmlHttp.aspx?ProcName=" + ProcName + "&Param1=" + Param1 + "&Param2=" + Param2 ;
	
	HttpUrl = "../xmlhttp/ProcessXmlHttp.aspx?ProcName=" + ProcName + "&Param1=" + Param1 + "&Param2=" + Param2 + "&Param3=" + Param3 + "&Param4=" + Param4;
	
	//alert(HttpUrl);
	
	objXMLHttp.Open ("GET", HttpUrl, false );
	objXMLHttp.send();
		  
	//alert(objXMLHttp.responseText)
		
	var objXMLResponse = new ActiveXObject('Msxml2.FreeThreadedDOMDocument.3.0');
	objXMLResponse.loadXML(objXMLHttp.responseText);
		
	return objXMLResponse ;

}

function convertXml(objXML, objXSLId, nameParam1, valueParam1, nameParam2, valueParam2)
{
 	var objXSL, objTemplate, objProcessor

	objXSL = createXmlObject(objXSLId)
				
	objTemplate = new ActiveXObject("MSXML2.XSLTemplate.3.0")
	objTemplate.stylesheet = objXSL
				
	objProcessor = objTemplate.createProcessor()
	objProcessor.input = objXML
	
	if(nameParam1 != null && valueParam1 != null)
		objProcessor.addParameter(nameParam1, valueParam1)
	
	if(nameParam2 != null && valueParam2 != null)
		objProcessor.addParameter(nameParam2, valueParam2)
				
	objProcessor.transform()
	//alert(objProcessor.output)
	objXML.loadXML(objProcessor.output)

	return 	objXML
}


function createXmlObject(objXMLId)
{
	var objXmlCreated ;
	
	objXmlCreated = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0") ;
	objXmlCreated.async = false ;
	objXmlCreated.load(objXMLId) ;
	return objXmlCreated ;
}
function makeUpper(fldObj)
{
	fldObj.value = fldObj.value.toUpperCase();
}


function getSelectedText(objListBox)
{
	if (objListBox.value != '')
		return objListBox.options(objListBox.selectedIndex).text
	else
		return '';	
}

function getCheckBoxValue(objCheckBox)
{
	if (objCheckBox.checked)
		return 'Y';
	else
		return 'N';	
}

function setCheckBoxValue(objCheckBox, value)
{
	if (value == 'Y')
		objCheckBox.checked = 1;
	else
		objCheckBox.checked = 0;
}

function setRadioValue(objRadio, value)
{
	for (i=0; i< objRadio.length; i++)
	{	
		if(objRadio[i].value == value)
		{	
			objRadio[i].checked = 1;
			break;
		}	
		else	
			objRadio[i].checked = 0;
	}
}


function setCheckBoxList(objCheckBox, strValue)
{
	for (i=0; i< objCheckBox.length; i++)
	{	
		if(strValue.indexOf(objCheckBox[i].param) >= 0)
			objCheckBox[i].checked = 1;
		else	
			objCheckBox[i].checked = 0;
	}
}


function getCheckBoxList(objCheckBox, hdnCheckBox)
{
	hdnCheckBox.value = '';
			
	for(i=0; i<objCheckBox.length; i++)
	{
		if(objCheckBox[i].checked)
		{
			if (hdnCheckBox.value == '')
				hdnCheckBox.value = objCheckBox[i].param;
			else
				hdnCheckBox.value += ',' + objCheckBox[i].param;	
		}	

	}	
}


function openWindow(url, width, height)
{
	var Args = '';
	//alert(url);
	var Features = "dialogWidth:" + width + "px;dialogHeight:" + height +"px;center:1;status:0;scroll:1;help:0;resizable:1" ;
	return window.showModalDialog(url,Args,Features)
}

function openWindow1(url, width, height)
{
	//var Args = '';
	//alert(url);
	//var Features = "dialogWidth:" + width + "px;dialogHeight:" + height +"px;center:1;status:0;scroll:1;help:0;resizable:1" ;
	window.open(url, '', 'width=' + (screen.availWidth-20) + ', height=' + (screen.availHeight - 20) + ', scrollbars=1, resizable=1, top=0, left=0')
}


function formatDate(_control, Event)
		{
			var key = Event.keyCode;
			var str = new String(_control.value);
            if(key < 96 || key > 105)
            {
				if(key == 8 || key == 9 || key == 13 || key == 16 || key == 17 || key == 18 || key == 20 || key == 27 || key == 35 || key == 36 || key == 37 || key == 38 || key == 39 || key == 40 || key == 45 || key == 46 || key == 144)
				{
				}
				else
				{
					_control.value = str.substring(0, str.length - 1);
				}
            }
            if(str.length == 2 || str.length == 5)
            {
				_control.value = str + "/";
			}
		}
		
		function autotab(object1, object2, objectsize)
		{
			if (object1.value.length == objectsize)
				object2.focus()
		}


function PreserveValue(obj,id)
{
	if(obj.checked)
	{
		//if (chkBoxString" + id + " == ''")
		//{
			//eval("chkBoxString" + id + " = ',' + obj.id + ','");
			//chkBoxString = ',' + obj.id + ',';
			obj.form.hdnChkBoxId.value = ',' + obj.value + ',';
		//}	
		//else	
		//{
			//eval("chkBoxString" + id + " = chkBoxString" + id + " + obj.id + ','");
			//chkBoxString = chkBoxString + obj.id + ',';
			//obj.form.hdnChkBoxId.value += obj.value + ',';
		//}	
	}
	else
	{
		//eval("chkBoxString" + id + " = chkBoxString" + id + ".replace(obj.id + ',', '')");
		//chkBoxString = chkBoxString.replace(obj.id + ',', '')
		obj.form.hdnChkBoxId.value = obj.form.hdnChkBoxId.value.replace(obj.value + ',', '')
	}
}
function GotoPage(val)
		{
		
		var url;
		url=val + "?hdnHistoryCount=" + document.frmpage.hdnHistoryCount.value;
		
		window.location.href=url;
		}
function gotosearch()
		{
		
		history.go(-document.frmpage.hdnHistoryCount.value)
		
		}
		

function formatTime(fld, e ) {
var key = '';
var len = 0;
var strCheck = '0123456789';
var whichCode = (window.Event) ? e.which : e.keyCode;
key = String.fromCharCode(whichCode);
if (whichCode == 13) return true;  // Enter

if (strCheck.indexOf(key) == -1) return false; 

len = fld.value.length
if (len > 4) return false;
if (len == 2 ) fld.value += ":" ;

}

function clearTime(fld)
{		
if (fld.value == 'HH:MM')
fld.value = '';
}
function formatSysDate()
{
	var aceDate=new Date();
   			var aceYear=aceDate.getYear();
			if (aceYear < 1000)
			aceYear+=1900;
			var aceDay=aceDate.getDay();
			var aceMonth=aceDate.getMonth()+1;
			if (aceMonth<10)
			aceMonth="0"+aceMonth;
			var aceDayMonth=aceDate.getDate();
			if (aceDayMonth<10)
			aceDayMonth="0"+aceDayMonth;
			var sysDate=aceMonth + "/" + aceDayMonth + "/" + aceYear;
		return sysdate;
}


// function returns file name of a 'browse' input filed
/*eg: 
		for this filename 'c:\test\somefolder\filename.ext' or
		'c:/test/somefolder/filename.ext'
		extract function will return 'filename.ext'
*/	
function extract(fileName) 
{
    if (fileName.indexOf('/') > -1)
        answer = fileName.substring(fileName.lastIndexOf('/')+1,fileName.length);
    else
        answer = fileName.substring(fileName.lastIndexOf('\\')+1,fileName.length);
    alert(answer);
}// end function extract(fileName)

function SetSelected(objCriteria, objTarget)
{
	if(objCriteria && objTarget)
	{
		var sCriteria = objCriteria.value;
		var sCriteriaName = objCriteria.name;
		var sTargetName = objTarget.name;
		sCriteria = sCriteria.toUpperCase();
		if (sCriteria == "")
		{
			objTarget.options.selectedIndex = 0;
			return
		}	
	
			
		for(var i=0; i < objTarget.options.length;i++)
		{
			var strTargetText = objTarget.options(i).text;
			strTargetText = strTargetText.toUpperCase();
			if (strTargetText.substr(0,sCriteria.length) == sCriteria)
			{
				objTarget.options[i].selected = true
				return
			}
		}
		
	}
}	


function checkFrame()
{
	var strTopPath = top.location.pathname;
	strTopPath = strTopPath.toLowerCase();
	if (strTopPath != "/eedb/main/aspx/index.aspx")
	{
		top.location.href = "/eedb/main/aspx/index.aspx";
	}	 
}

/* ************************************************************************
This Function is used to format the values that are entered 
in Numeric Fields
Author : Venkat Pushpala
Dated:05/02/03
****************************************************************************/

function formatDecimal(fld, milSep, decSep, e, maxLen) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
for(i = 0; i < len; i++)
	if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
			aux += key;
			len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
		if (len == 2) fld.value = '0'+ decSep + aux;
		if (len > maxLen) return false;
		if (len > 2) {
			aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
		}
			aux2 += aux.charAt(i);
		j++;
	}
	fld.value = '';
	len2 = aux2.length;
	for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
return false;
}
/* Auto Select the Dropdown List while type a word
Author : Venkat Pushpala */
function autoComplete (field, select, property, forcematch) {
		var found = false;
		for (var i = 0; i < select.options.length; i++) {
	     	if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
				found=true; break;
			}
		}
		if (found) { select.selectedIndex = i;}
		else { select.selectedIndex = -1; }
		if (field.createTextRange) {
			if (forcematch && !found) {
				field.value=field.value.substring(0,field.value.length-1); 
				return;
				}
			var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
			if (cursorKeys.indexOf(event.keyCode+";") == -1) {
				var r1 = field.createTextRange();
				var oldValue = r1.text;
				var newValue = found ? select.options[i][property] : oldValue;
				if (newValue != field.value) {
					field.value = newValue;
					var rNew = field.createTextRange();
					rNew.moveStart('character', oldValue.length) ;
					rNew.select();
					}
				}
		}
	}
	
	
function trim(inputString) {
	//function added by Jai - 05/05/03
	
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces it with one space. If something besides
	// a string is passed in (null, custom object, etc.) then return the input.
	
	if (typeof inputString != "string") 
	{ 
		return inputString; 
	}
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") 
	{ // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") 
	{ // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) 
	{ // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	
	return retValue; // Return the trimmed string back to the user

} // Ends the "trim" function



function getFieldValue(field)
{
	//function added by Jai - 05/05/03
	//debugger
	//generic function which gets the field's value
	switch(field.type)
	{
		case "text" :
		case "textarea" :
		case "password" :
		case "hidden" :
			return field.value;

		case "select-one" :
			var i = field.selectedIndex;
			if (i == -1)   return "";
			else   return field.options[i].value; //(field.options[i].value == "") ? field.options[i].text : field.options[i].value;

		case "select-multiple" :
			var allChecked = new Array();
			var intLength = field.options.length;
			//if (intLength < 2)
			for(i = 1; i < intLength; i++)
			if(field.options[i].selected)
				allChecked[allChecked.length] = field.options[i].value;//(field.options[i].value == "") ? field.options[i].text : field.options[i].value;
			return allChecked;

		case "button" :
		case "reset" :
		case "submit" :
			return "";

		case "radio" :
		case "checkbox" :
			if (field.checked) { return field.value; } else { return ""; }
		default :
			if(field[0].type == "radio")
			{
			for (i = 0; i < field.length; i++)
				if (field[i].checked)
					return field[i].value;

			return "";
			}
			else if(field[0].type == "checkbox")
			{
			var allChecked = new Array();
			for(i = 0; i < field.length; i++)
				if(field[i].checked)
					allChecked[allChecked.length] = field[i].value;

			return allChecked;
			}
			else
			var str = "";
			for (x in field) { str += x + "\n"; }
			alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);
			break;
	}

	return "";
}
		
		

function checkValidDate(dateStr) 
{
	//function added by Jai - 05/05/03
	
	// dateStr must be of format month day year with either slashes
	// or dashes separating the parts. Some minor changes would have
	// to be made to use day month year or another format.
	// This function returns True if the date is valid.
	var slash1 = dateStr.indexOf("/");
	if (slash1 == -1) 
	{ 
		slash1 = dateStr.indexOf("-"); 
	}
	// if no slashes or dashes, invalid date
	if (slash1 == -1) 
	{ 
		return false; 
	}
	var dateMonth = dateStr.substring(0, slash1)
	var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length);
	var slash2 = dateMonthAndYear.indexOf("/");
	if (slash2 == -1) 
	{ 
		slash2 = dateMonthAndYear.indexOf("-"); 
	}
	// if not a second slash or dash, invalid date
	if (slash2 == -1) 
	{ 
		return false; 
	}
	var dateDay = dateMonthAndYear.substring(0, slash2);
	var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length);
	if ( (dateMonth == "") || (dateDay == "") || (dateYear == "") ) 
	{ 
		return false; 
	}
	// if any non-digits in the month, invalid date
	for (var x=0; x < dateMonth.length; x++) 
	{
		var digit = dateMonth.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) { return false; }
	}
	// convert the text month to a number
	var numMonth = 0;
	for (var x=0; x < dateMonth.length; x++) 
	{
		digit = dateMonth.substring(x, x+1);
		numMonth *= 10;
		numMonth += parseInt(digit);
	}
	if ((numMonth <= 0) || (numMonth > 12)) 
	{ 
		return false;
	}
	// if any non-digits in the day, invalid date
	for (var x=0; x < dateDay.length; x++) 
	{
		digit = dateDay.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) 
		{ 
			return false; 
		}
	}
	// convert the text day to a number
	var numDay = 0;
	for (var x=0; x < dateDay.length; x++) 
	{
		digit = dateDay.substring(x, x+1);
		numDay *= 10;
		numDay += parseInt(digit);
	}
	if ((numDay <= 0) || (numDay > 31)) 
	{ 
		return false; 
	}
	// February can't be greater than 29 (leap year calculation comes later)
	if ((numMonth == 2) && (numDay > 29)) 
	{ 
		return false; 
	}
	// check for months with only 30 days
	if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) 
	{ 
		if (numDay > 30) 
			{ 
				return false; 
			} 
	}
	// if any non-digits in the year, invalid date
	for (var x=0; x < dateYear.length; x++) 
	{
		digit = dateYear.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) 
		{ 
			return false; 
		}
	}
	// convert the text year to a number
	var numYear = 0;
	for (var x=0; x < dateYear.length; x++) 
	{
		digit = dateYear.substring(x, x+1);
		numYear *= 10;
		numYear += parseInt(digit);
	}
	// Year must be a 2-digit year or a 4-digit year
	if ( (dateYear.length != 2) && (dateYear.length != 4) ) 
	{ 
		return false; 
	}
	// if 2-digit year, use 50 as a pivot date
	if ( (numYear < 50) && (dateYear.length == 2) ) 
	{ 
		numYear += 2000; 
	}
	if ( (numYear < 100) && (dateYear.length == 2) ) 
	{ 
		numYear += 1900; 
	}
	if ((numYear <= 0) || (numYear > 9999)) 
	{ 
		return false; 
	}
	// check for leap year if the month and day is Feb 29
	if ((numMonth == 2) && (numDay == 29)) 
	{
		var div4 = numYear % 4;
		var div100 = numYear % 100;
		var div400 = numYear % 400;
		// if not divisible by 4, then not a leap year so Feb 29 is invalid
		if (div4 != 0) { return false; }
		// at this point, year is divisible by 4. So if year is divisible by
		// 100 and not 400, then it's not a leap year so Feb 29 is invalid
		if ((div100 == 0) && (div400 != 0)) { return false; }
	}
	// date is valid
	return true;
}

/*****************STARTS KEY DOWN EVENT HANDLER*************************/ 
//event handler added by Jai - 05/09/03
// handles Keydown events on the document
/*document.onkeydown = 
	function()
	{
		//enterKeyToSubmit(event, this.form);
		var objForm = document.frmPage;
		if(objForm) 
			enterKeyToSubmit(objForm);
	}	*/
function enterKeyToSubmit(objForm) 
{
	
	//function added by Jai - 05/09/03
	//handles Enter and Backspace keys 
	//pressed on the document and 
	
	/*
		IMPORTANT NOTE: THIS FUNCTION USES HARD CODED VALUES
		 - hard coded for this specific application for
		btnSearch and btnSave control which are used 
		as a standard practice.
	*/
	//debugger
	var FORBIDDENTAGS = "|SELECT|INPUT|TEXTAREA|" //control names to ignore
    var elTag = window.event.srcElement.tagName; //get control name
    if (window.event.keyCode == 8){ // Backspace
        if (FORBIDDENTAGS.indexOf("|" + elTag + "|")>=0){
            // Disable
            event.cancelBubble = true;
            event.keyCode = 0;
            return false;
        }
    }
	else if (objForm && window.event && window.event.keyCode == 13) //enter key
	{
		var objSave = objForm.btnSave;
		if (objSave)
		{		
			var strInput = confirm("Do you want to SAVE the data now?");
			if (strInput == true)
				objForm.onsubmit();
		}
		else
		{
			var objSearch = objForm.btnSearch;
			objSearch.onclick();		
		}
	}  
	else
	{
		return true;
	}  
}

/*****************ENDS KEY DOWN EVENT HANDLER*************************/ 

function checkFromToDate(strStartDate, strEndDate, strMessage)
{
/********************
* var objStart = frm.txtStartDate;
* var objEnd = frm.txtEndDate;
*******************/
/*	if (objStart != "" && objEnd)
	{
		var strStartDate = trim(objStart.value);
		var strEndDate = trim(objEnd.value);
*/
		if (trim(strStartDate) != "" && trim(strEndDate) != "")
		{
			var numStart = Date.parse(strStartDate);
			var numEnd	= Date.parse(strEndDate) ;
			var numDiffrence = numEnd - numStart ;
			if (numDiffrence >= 0) 
				return true; 
			else
			{
				addErrorMessage(strMessage);
				return displayError();	
			}	
		}
/*	}		
*/
}

function autoTabToField(cur_field, char_max, goto_field)
{    
//added by Jai on 05/21/03
//auto table to specified field
//after max number of characters are enterd.
//does not check for numerics.
	if (cur_field.value.length > (char_max-1)){
			goto_field.focus();
	}
}
//Latest code for autoskip
//dated:05/27/2003
//Author:Venkat Pushpala
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
		return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
return true;
}

//  End -->

//Function to go back to the previous screen
//Author: Venkat Pushpala
//date:11/25/03 
function goBack()
		{
			// to go back set the hit counter to a negative value
			var intCounter = (frmPage.hdnHitCounter.value)*(-1);
			alert(frmPage.hdnHitCounter.value);
			
			//go back in history
			history.go(intCounter );    
			
			
		}
//end
		
