
//AE added on 2.5.2009 Open IJB WebSite in JS Window
function OpenIJBWindow(url){
var windowFeatures  = 'width=960,height=600,toolbar=no,status=yes,directories=no,menubar=no,resizable=no,scrollbars=yes,dependent=yes' ;
	window.open(url,"",windowFeatures)
}
 


//AE added to validate required fields before doing save+post on s_ord_details.asp IJ1-1399
function validateandTpost(theform,strDFParms)
{
   if (theform.elements['billing_contact_id'].value == "" || theform.elements['client_reports_to_id'].value == "" || theform.elements['client_contact_id'].value == ""  || theform.elements['billing_address_id'].value == "" || theform.elements['work_address_id'].value == "" || theform.elements['contract_type_id'].value == "" || theform.elements['hiring_process_id'].value == ""  || theform.elements['charge_rate'].value == "" || theform.elements['charge_rate_high'].value == "" || theform.elements['pay_rate'].value == "" || theform.elements['pay_rate_high'].value == "" || theform.elements['currency_id'].value == "" ) 
	  {
	 	alert ("Please enter data for all required fields before posting job to Data Frenzy !");
	 	return false;
	  }
	 else
	 	{
			if ( validNumDecimal(theform.elements['charge_rate'].value.replace(/[$€£]/,'')) &&  validNumDecimal(theform.elements['charge_rate_high'].value.replace(/[$€£]/,'')) &&  validNumDecimal(theform.elements['pay_rate'].value.replace(/[$€£]/,'')) &&  validNumDecimal(theform.elements['pay_rate_high'].value.replace(/[$€£]/,'')) )
			{

			 //window.open(strDFParms);			   
  			   setCookie('savenew','true');	
			   return true;
			}
			 else
			{
				 
			 	return false;
			}

	 	}	
}


//AE added to validate required fields before doing save+post on s_ord_details.asp IJ1-1399
function validateandPpost(theform,strDFParms)
{
   if (theform.elements['billing_contact_id'].value == "" || theform.elements['client_reports_to_id'].value == "" || theform.elements['client_contact_id'].value == ""  || theform.elements['billing_address_id'].value == "" || theform.elements['work_address_id'].value == ""  || theform.elements['pay_rate'].value == "" || theform.elements['pay_rate_high'].value == ""  ) 
	  {
	 	alert ("Please enter data for all required fields before posting job to Data Frenzy !");
	 	return false;
	  }
	 else
	 	{
			//if (validNumDecimal(theform.elements['pay_rate'].value.replace(/[$€£,]/,'')) &&  validNumDecimal(theform.elements['pay_rate_high'].value.replace(/[$€£,]/,'')) )
			//{
			   //window.open(strDFParms);
  
			   setCookie('savenew','true');	
			   return true;
			//}
			// else
			//{
				 
			//	return false;
			//}

	 	}	
}
//Uma added on 10.20.2008 performance enhancement
function validateArray(fieldText2, fieldID2){
        var fieldID1 = opener.fieldID.value;
        if (fieldID1.search(fieldID2) == -1)
        {
            return true;
		}
		else
		{
		    return false;
		}
}
//===================================================================
// Functions "typeIt" and "eraseIt"  
//------------------------------------------------------------------------
//  RT 10.16.2008  Function create an animated "Saving......" label   --   Block 7.5
//====================================================================
var SaveMessage = "      Saving....";
var SaveMsgByte = 1;
var SaveMsgTimer;
var SaveMsgColor = 0;
//====================================================================
function typeIt() {  
//-alert('inside typeIt function, SaveMessage = ' + SaveMessage);   
   var obj_lbl_Saving = document.getElementById("lblSaving");
   obj_lbl_Saving.innerText = SaveMessage.substring(0, SaveMsgByte);
//-alert('SaveMessage.substring(0, SaveMsgByte):' + SaveMessage.substring(0, SaveMsgByte));
   
   if (SaveMsgByte >= SaveMessage.length) {
      SaveMsgByte = 1;
      SaveMsgColor = SaveMsgColor + 1;     
      SaveMsgTimer = setTimeout("eraseIt()",1000);     // pause after typing         
   } else {
//----alert('inside typeIt condition');
      SaveMsgByte++;
//----alert('SaveMsgByte:' + SaveMsgByte);
      SaveMsgTimer = setTimeout("typeIt()",400);       // typing speed        
//----alert('SaveMsgTimer:' + SaveMsgTimer);
   } 
}
//===================================================================
function eraseIt() {
//-alert('inside eraseIt');
   var obj_lbl_Saving = document.getElementById("lblSaving");
   obj_lbl_Saving.innerText = SaveMessage.substring(SaveMsgByte, SaveMessage.length);    
   if (SaveMsgByte >= SaveMessage.length) {
      SaveMsgByte = 1;
      var remainder = SaveMsgColor % 4;
      switch (remainder) {
         case 0:  //alert('inside case 1');
                  obj_lbl_Saving.style.color = "#ffb404";  // orange
                  break;
         case 1:  obj_lbl_Saving.style.color = "RED";
                  break;
         case 2:  obj_lbl_Saving.style.color = "BLUE";
                  break;
         case 3:  obj_lbl_Saving.style.color = "#000000";   // black
                  break;
//-------default: obj_lbl_Saving.style.color = "#00FF00"; 
//----------------break;         
      }    
      SaveMsgTimer = setTimeout("typeIt()", 100);      //pause before restart
   } else {
      SaveMsgByte++;
//------------------------------------- accelerating erase speed did not erase everything
//----eraseSpeed = eraseSpeed - 5;                     
      SaveMsgTimer = setTimeout("eraseIt()", 50);      //erasing speed
   }
}    
//====================================================================================
// JK 08/15/08 T2316
// one of the primary_job checkboxes was clicked
// set the clicked checkbox to checked, uncheck all other primary_job checkboxes

function ToggleCheckBoxes(form, checkboxName)
{
var i;

	for (i=0; i<form.elements.length; i++)
	{
		if (form.elements[i].name.indexOf('primary_job') != -1 && (form.elements[i].name != checkboxName))
			form.elements[i].checked=false;
	}

}


//Uma 7.31.2008 T2315 Changes for lookups
function openLookup_aspnet(baseURL,modified,searchParam,parentCntrl,parentName,sourceCntrl,passToField) {
	if (modified == '1') baseURL = baseURL + searchParam;
	if ((parentCntrl != null) && (parentCntrl != undefined)) {
		// check if a value has been entered for the parent control		
		if (parentCntrl.value.length == 0) {
			alert ('You need to enter a value for ' + parentName);
			return;
		} else {
			baseURL += "&" + parentCntrl.name + "=" + escape(parentCntrl.value);
		}
	}
	if ((sourceCntrl != null) && (sourceCntrl != undefined)) {
		// if field can be edited, than pass up the entered value		
		if (!(sourceCntrl.readOnly) && (sourceCntrl.value.length>0)) {			
			// change parameter search=true
			baseURL = baseURL.replace(/\?search=\&/i, "?search=true&");
			baseURL += "&" + passToField + "=" + escape(sourceCntrl.value);
			// pass additional parameter in case Lookup is not Search-type
			baseURL += "&srchpass=" + escape(passToField+"|"+sourceCntrl.value);
		}
	}
	
	var lookup = 'lookup';
	if (window.name == 'lookup') {
		lookup = lookup + '_' + parentCntrl.name;
	}
	
	
	if (multiSelectLimit == 1) {
	baseURL = baseURL.replace(/multiselect=true/,'multiselect=false');
	}
	openPopup_aspnet(baseURL, lookup, 750, 450, "width=750,height=450,toolbar=no,status=no,directories=no,statusbar=no,menubar=no,resizable=no,scrollbars=1,titlebar=0,", true);
}

function openPopup_aspnet(url, name, pWidth, pHeight, features, snapToLastMousePosition) {
    closePopup();
    features +=	"left=" + ((screen.width - pWidth)/2) + ",top=" + ((screen.height - pHeight)/2);	
	curPopupWindow = window.open(url, name, features, false);
}
//Uma 7.31.2008 T2315 Changes for lookups

// either Job Tile or Other must be populated for a work experience record to be saved
// JK T2316 08/01/08
function checkForJobTitle(form)
{
	if (form.elements['job_title_id'].value != "" || form.elements['job_title'].value != "")
		return true;
	else
		{	
		alert("Either Job Title or Other must be populated to save this record");
		return false;
		}
}

// check for only 1 primary job in the Job Titles section of the Interview Wizard
// JK 7/1/08 T2316
function checkForPrimaryJob(form)
{
var i;
var count=0;

	for (i=0; i<form.elements.length; i++)
	{
		if (form.elements[i].name.indexOf('primary_job') != -1 && form.elements[i].checked)
		{

			if (form.elements[i+1].checked)
			{
				alert("You must select another Job Title as primary before deleting")
				return false;
			}
			count++;
		}
	}
	
	if(count == 0)
	{
		alert("One Job Title must be selected as the Primary Job");
		return false;
	}
	if(count > 1)
	{
		alert("Only one Job Title can be selected as the Primary Job");
		return false;
	}
	return true;
}
//============================================================================
// Function "Open Activity Ticket"
//------------------------------------------------------------------------
//  AE 6.12.2008  Function open new activity window as modal popup Block 7.5
//  RT 8.5.2008   Changed window width and minimized whitespace
//  RT 8.14.2008  Uncommented the refresh parent logic
//  RT 8.27.2008  Added a window object as a argument
//  RT 9.22.2008  Reduced Window Size
//------------------------------------------------------
//  myvar = 'GUID->' + objectid  
//  + ':: Page->' + pagename + '::ActType->' + actype
//  alert(myvar);
//------------------------------------------------------
//  alert(window.location.href);
//  alert(priorpath);
//  alert(indx);
//  alert(priorpage);  
//  alert(myDestination); 
//------------------------------------------------------
function OpenActivityTicket(objectid) {
   var priorpath = window.location.href;
   var indx = priorpath.lastIndexOf('/');
   var priorpage = priorpath.slice(indx + 1);
   var myDestination = '../Ajilon_Staffing/s_activity_ticket.aspx?' + objectid + '&jsPrior=' + priorpage;
   var winSettings = "center:yes; resizable:no; dialogHeight:560px; dialogWidth:695px; status:no; help:off; ";
   var myPopup = window.showModalDialog(myDestination, window, winSettings);
   if (myPopup == true) { 
      location.reload();
   }
}

//Begin Arun_Dhing June 09,2009 Added new function to open candidate availability popup
//This functions opens Update Candidate Availability Page
function OpenUpdateCandAvailability(objectid) {
//   var priorpath = window.location.href;
//   var indx = priorpath.lastIndexOf('/');
//   var priorpage = priorpath.slice(indx + 1);
   var myDestination = '../Ajilon_Staffing/s_assign_update_cand_availability.aspx?' + objectid;
   var winSettings = "center:yes; resizable:no; dialogHeight:650px; dialogWidth:695px; status:no; help:off; ";
   //var winSettings = "center:yes; resizable:yes; dialogHeight:650px; dialogWidth:695px; ";
   var myPopup = window.showModalDialog(myDestination, window, winSettings);
   //if any changes are made then page returns true and parent page is refreshed to reflect new values
   if (myPopup == true) { 
      location.reload();
   }
   
}
//End Arun_Dhing June 09,2009 Added new function to open candidate availability popup


//===============================================================================
//Character Counter for Text Boxes Uma 04.12.08
function charsleft(fieldtocheck, fieldtopresent, maxcharacters) 
{
	if (fieldtocheck.value.length > maxcharacters) 
		fieldtocheck.value = fieldtocheck.value.substring(0, maxcharacters);
	else 
		fieldtopresent.value = (maxcharacters- fieldtocheck.value.length) + ' characters remaining' ;
}

var lastMouseX;
var lastMouseY;
var curPopupWindow = null;
var helpWindow = null;
var undefined;
var currentForm;
var headerTxt;
var multiSelectLimit;
var creator;
//var SigleSelectLBFalg;

//  AJAX PopUpExtender Scripts   - SC/AE 03142008
var Timer;



function ShowwithDelay(comp1)
{
Timer = setTimeout(function(){showpop1(comp1);},500);
}

function showpop1(varobj)
{ 
var v1 = Sys.Application.findComponent(varobj);
 v1.showPopup();
}
function mouseoutfunction(objctl) {
    clearTimeout(Timer);
    var be = $find(objctl);
    if (be != null && be != 'undefined') {
      if (be.get_PopupVisible()) {
        be.hidePopup();
      }
    }
}


//  AJAX PopUpExtender Scripts

//AE  For Histroy Window - 3.03.2008

function HistoryWindow(url){
var windowFeatures  = 'width=300,height=400,top=105,toolbar=no,status=no,directories=no,menubar=no,resizable=no,scrollbars=no,dependent=yes' ;
	window.open(url,"",windowFeatures)
}
 

//-----------.....................................------
//Copied AE's code, 022608
//
    function ChangeCheckBoxState(id, checkState)
   {
      var cb = document.getElementById(id);
      if (cb != null)
         cb.checked = checkState;
   }

   function ChangeAllCheckBoxStates(checkState)
   {
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
      if (CheckBoxIDs != null)
      {
         for (var i = 0; i < CheckBoxIDs.length; i++)
            ChangeCheckBoxState(CheckBoxIDs[i], checkState);
      }
      
      
   }
   
   
   
      function ChangeAllCheckBoxStates1(checkState)
   {
      
            checkState.checked;
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
     // if (CheckBoxIDs != null)
    //  {
      //   for (var i = 0; i < CheckBoxIDs.length; i++)
        //    ChangeCheckBoxState(CheckBoxIDs[i], checkState);
      //}
   }
function SelectAllCheckboxes(spanChk){

// Added as ASPX uses SPAN for checkbox

var oItem = spanChk.children;

var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];

xState=theBox.checked;

elm=theBox.form.elements;

for(i=0;i<elm.length;i++)

if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)

{

//elm[i].click();

if(elm[i].checked!=xState)

elm[i].click();

//elm[i].checked=xState;
}
}
//-----------.....................................------

//---------------------------------------------------------
function returnAddressInfo2_county(fieldText, fieldID, cityText, stateID, county, country, taxCode, tax_code_rd){
// DS:02Feb08, T1875 - Added JS function for multiselect county
   returnInfoMultiSelect(county,county)
}

function returnAddressInfo2_zip_nc(fieldText, fieldID, cityText, stateID, county, country, taxCode, tax_code_rd){
// DS:02Feb08, T1875 - Added JS function for multiselect zip
   returnInfoMultiSelect(fieldText,fieldID);
}

function removeSelectElement_nc(form,field,hiddenfield){
// DS:22Jan08, T1875 - Added JS function for multiselect list box
//	remove the selected element then rebuild concatenated values in hidden field
	var i;
	var selectObj = eval("document.getElementById('"+field+"').options");
	var selectObjLength = eval("document.getElementById('"+field+"').options.length");
	var hiddenObj = eval("document.getElementById('"+hiddenfield+"')");
	var index = selectObj.selectedIndex;
	var delim = ";";

	if (index >= 0) {
	  if (selectObjLength > 0) {

		hiddenObj.value = "";
		for (i=selectObj.length-1; i>=0; i--) {
		  if (selectObj[i].selected==true) {
			selectObj[i]=null;
		  } else {
			hiddenObj.value += selectObj[i].value + delim;		
		  }
		}
	  }
	}
}

function PrintContentOnly() 
// DS:23Jan08, T1875 - Added JS function for printer icon
{ 
	var sWinOption="status=no,toolbar=yes,location=no,directories=yes,menubar=yes,resizable=yes,dependent=yes,"; 
	sWinOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; 
	
	var sWinHTML = document.getElementById('contentstart').innerHTML; 
	
	var winContent=window.open("","",sWinOption); 
	winContent.document.open(); 
	winContent.document.write('<html>');
	winContent.document.write('<link href="../Ajilon_Staffing/App_Themes/AjilityTheme/default.css" rel="stylesheet" type="text/css">'); 
	winContent.document.write('<body><div style="position:relative;left:auto">');
	winContent.document.write('<img src="../images/logo_workplace_blue.gif" alt="" border="0" class=""/>');
	winContent.document.write('&nbsp;<a href="Javascript:window.close()" target="" class="relatedlink">Close Window</a>');
	winContent.document.write('&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:window.print();">');         
	winContent.document.write('<img src="../images/icon_print.gif" alt="Print this page." style="border:0px; z-index: 101; position: relative;" class=""/></a>');         
	winContent.document.write('&nbsp;<a href="javascript:window.print();" class="relatedlink">Print this page</a>');
	winContent.document.write('<hr /></div>');
	winContent.document.write('<div style="position:relative;left:auto">');         
	winContent.document.write(sWinHTML);          
	winContent.document.write('</div></body></html>'); 
	winContent.document.close(); 
	winContent.location.reload(true);
	winContent.focus(); 
}

//Begin Nikhil June 09,2009 Added new function to open print page from ownership page
//this is customized becuase some sections has to be hidden
function PrintPlacementOwnershipContent() 
{ 
    document.getElementById('OnPrintPageOnly').style.display="Inline";

	var sWinOption="status=no,toolbar=no,location=no,directories=yes,menubar=no,resizable=yes,dependent=yes,"; 	
	sWinOption+="scrollbars=yes,width=750,height=650,left=150,top=0"; 

//Show only following DIVs
	var sWinHTML = document.getElementById('dvPlacementSummary').innerHTML;
	    sWinHTML = sWinHTML + document.getElementById('dvDetails').innerHTML;
	    sWinHTML = sWinHTML + document.getElementById('dvIndividualOwnership').innerHTML;
	    sWinHTML = sWinHTML + document.getElementById('dvPlacementOverride').innerHTML;
	    sWinHTML = sWinHTML + document.getElementById('dvBranchOwnership').innerHTML;
	    sWinHTML = sWinHTML + document.getElementById('dvOwnershipActivity').innerHTML;
	    sWinHTML = sWinHTML + document.getElementById('OnPrintPageOnly').innerHTML;
	    
	//begin Arun_dhing 05 August 2009 - 1823 Removed Javascript Refernces from printed pages so
	//so that it would not try to download them
	if(sWinHTML.indexOf('<SCRIPT ') >= 0 ){
	    var str =  sWinHTML.substring(sWinHTML.indexOf('<SCRIPT '), sWinHTML.indexOf('</SCRIPT>') + 9);
	    if(str.indexOf('AutoComplete.js') >= 0 ){	 
	                while(sWinHTML.indexOf(str) >= 0){
	                    sWinHTML = sWinHTML.replace(str, '');
	                }   	                
	            }
	}  
	//end Arun_dhing 05 August 2009 - 1823 Removed Javascript Refernces from printed pages so	   

	var winContent=window.open("","",sWinOption); 
	winContent.document.open(); 
	winContent.document.write('<html>');
	winContent.document.write('<link href="../Ajilon_Staffing/App_Themes/AjilityTheme/default.css" rel="stylesheet" type="text/css">');
	winContent.document.write('<body><div style="position:relative;left:auto">');
	winContent.document.write('<img src="../images/logo_workplace_blue.gif" alt="" border="0" class=""/>');
	winContent.document.write('&nbsp;<a href="Javascript:window.close()" target="" class="relatedlink">Close Window</a>');
	winContent.document.write('&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:window.print();">');
	winContent.document.write('<img src="../images/icon_print.gif" alt="Print this page." style="border:0px; z-index: 101; position: relative;" class=""/></a>');
	winContent.document.write('&nbsp;<a href="javascript:window.print();" class="relatedlink">Print this page</a>');
	winContent.document.write('<hr /></div>');
	winContent.document.write('<div style="position:relative;left:auto">');
	winContent.document.write(sWinHTML);
	winContent.document.write('</div></body></html>');
	winContent.document.close();
	winContent.location.reload(true);
	winContent.focus();
    document.getElementById('OnPrintPageOnly').style.display="None";
}
//End Nikhil June 09,2009 Added new function to open print page from ownership page


function openLookup_nc(baseURL,modified,searchParam,parentCntrl,parentName,sourceCntrl,passToField) {
// DS:22Jan08, T1875 - Re-used "modified" param in JS function for aspx Look up DIVISION/BUSINESS units 
	if (modified == '1') baseURL = baseURL + searchParam;
	if ((parentCntrl != null) && (parentCntrl != undefined)) {
		// check if a value has been entered for the parent control		
		if (parentCntrl.value.length == 0) {
			alert ('You need to enter a value for ' + parentName);
			return;
		} else {
			baseURL += "&" + modified + "=" + escape(parentCntrl.value);
		}
	}
	if ((sourceCntrl != null) && (sourceCntrl != undefined)) {
		// if field can be edited, than pass up the entered value		
		if (!(sourceCntrl.readOnly) && (sourceCntrl.value.length>0)) {			
			// change parameter search=true
			baseURL = baseURL.replace(/\?search=\&/i, "?search=true&");
			baseURL += "&" + passToField + "=" + escape(sourceCntrl.value);
			// pass additional parameter in case Lookup is not Search-type
			baseURL += "&srchpass=" + escape(passToField+"|"+sourceCntrl.value);
		}
	}
	
	var lookup = 'lookup';
	if (window.name == 'lookup') {
		lookup = lookup + '_' + parentCntrl.name;
	}
	openPopup(baseURL, lookup, 300, 600, "width=500,height=400,toolbar=no,status=no,directories=no,menubar=no,resizable=no,scrollbars=1", true);
}

function setInputLookup_nc(fieldtext,text,fieldval,val){
// DS:16Jan08, T1875 - Added JS function to delete item from single selection look up (x)
// JK:21Jan08 - removed 'form' parameter

	eval("aspnetForm.elements['"+fieldtext+"'].value=" + "\""+text+"\"");
	eval("aspnetForm.elements['"+fieldval+"'].value=" + "\""+text+"\"");

	//Old code for classic .asp file
	//eval("document."+form+"[\""+fieldtext+"\"].value=" + "\""+text+"\"");
	//eval("document."+form+"[\""+fieldval+"\"].value=" + "\""+val+"\"");
}

//DS:Jan08, T1875---------------------------------------------------------


// JK T1523 10/03/07
// count number of tasks to be moved to the call planner
// test if that count + current callplanner count <= 75
// current callplanner count in num_items
//
function validateMoveCount(form)
{
var i;
//var form = document.forms[formName];
var elementName;
var moveCount=0;
var plannerCount;

	plannerCount = parseInt(form.elements["num_items"][0].value);

	for (i=0; i<form.elements.length; i++)
	{
		if (form.elements[i].type == "checkbox")
		{
			elementName = form.elements[i].name
			if (elementName.indexOf("select_box_Delete_task") != 0)
			{
				if (form.elements[i].checked)
				{
					moveCount++;
					if (moveCount + plannerCount > 75)
					{
						alert("Call Planner cannot exceed 75 calls per day. At this time, you can add " + (75 - plannerCount) + " items.");
						return false;
					}
				}
			}
		}
	}
	return true;
}

//---------------------------------------------------------
// 24Aug2007, T671, Dipak Saha (DS) - Added JS function
// 02Apr08, DS - Added "../application/" to work for .aspx pages
//

	var itimeOutID; var itimeOutoffID;
	//Elapsed time (interval) for Pop-up window
	var cMainWindowInterval=35; var cPopupWindowInt=5;
	var cIdleTime=cMainWindowInterval*60*1000; var cTimer=cMainWindowInterval*60;
	//Remained open time for the Pop-up window, get closed it's own
	var cStayOpenTime=cPopupWindowInt*60*1000; 

	var cSlack=1; var icounter=cTimer+cSlack; 
	var t; var newWindow = null; var imainWindow = null; sRedir='../application/logoff.asp?redir='
	var winFinish1=null; var winFinish2=null; var winFinish3=null;
	var sLink1=sRedir; var sLink2=sRedir;
	var sLink3=sRedir; var psLink='2';

function buttonGoCont(pLink) {
	if(pLink == '2')
	{ 
		//alert("else if(pLink=2 CONTINUE part");
		window.close();
		clearTimeoutpopupWin(); //CONTINUE button - reset timer
			
	} else if(pLink == '3'){ //alert("else if(pLink=3 LOG OFF part"+sLink1);
		window.location = sLink1; //LOG OFF button - open href

	} else { 
		pLink = sRedir + pLink;
		//alert("else part" + pLink);
		window.close(); //LOG OFF button - from popup with a web link
		window.opener.location = pLink;
	}
	return true;
	} //need to clear cache first

function clearTimeoutpopupWin() {
	clearTimeout();
	MypopupWin(); 
	return true; }    // clear/reset the Timer before opening

function MypopupWin() {
	itimeOutID=window.setTimeout("windowProp()", cIdleTime);
	return true; } // delay specific period before opening the popup

function windowProp() {
	var windowFeatures  = 'width=650,height=200,lastMouseX=310,lastMouseY=,toolbar=yes,status=yes,directories=yes,menubar=yes,resizable=no,scrollbars=no,dependent=yes' ;
	newWindow = window.open("../application/g_idlecount.asp", "idlewindow", windowFeatures , false); 
	itimeOutoffID=window.setTimeout("closeWin(newWindow);", cStayOpenTime); 
	timedCount();
	return true; } //variable from db, delay time out (5 mins before) their session expires

function closeWin(newWindow) {

	if (newWindow.closed)
	    {
		itimeOutID=null;
		icounter=0;
		return true; 
	    }

	sLink3 = sLink3 + "g_idlecount_redirection.asp";
	//alert("closeWin(newWindow) part: " + sLink3);
	newWindow.close();
	newWindow = null;
	icounter=0;
	window.location = sLink3;
        //** after the session timeout expires, redirect to the LOB page similar to LOG OFF button **
	return true; }  //close small window and depart 

function timedCount() {
	if (icounter<=0) icounter=cTimer+cSlack;
	icounter--;
	//window.status="Due to inactivity, idle session is about to time out by " + icounter + " seconds.";
	t=window.setTimeout("timedCount()",1000);
	return true; } // Idle Timer

//---------------------------------------------------------
// 6/29/06 TCS - Added JS function to disable double-click

// This will count how many times any button on the page has been clicked
clickCounter = 0;
			
function checkForMultipleClick(theButton) {
			
   // This function should be able to sense and handle a "multi"-click event
   var retValue = true;
   var preventClick = false;
				
   // Increment the click counter
   clickCounter++;
				
   // If we exceeded the allowable *one* click, set the preventClick flag
   if(clickCounter > 1 ) { 
      preventClick = true; 
   }
				
   // set the return value based on whether we are allowed to click 
   retValue = (!preventClick);
   return retValue;
				
}
//---------------------------------------------------------


function submitAndClose (form, bCloseWindow) {
//  submits "form"
//  bCloseWindow: true/false to close browser window afterwards

  form.submit();
  if (bCloseWindow) {
    self.close();
  }
}

function submitCandidate(form, fieldName, fieldValue) {
	form.elements[fieldName].value = fieldValue;
	form.submit();
}

function shiftOrder(form, fieldName, elementIndex, increment) {
// this will swap the value of one form (array) element with another
//       form : document's form
//       fieldName : name of the element
//		 elemenetIndex : index of the selected element
//	     increment : value to increment, i.e. 1, -1, 2

	var currVal, newVal;
	var swapIndex = elementIndex + increment;
	
	// make sure that the element exists
	if (form.elements[fieldName][swapIndex]==null) {return}
	
	currVal = form.elements[fieldName][elementIndex].value;
	newVal = form.elements[fieldName][swapIndex].value;
	form.elements[fieldName][elementIndex].value = newVal;
	form.elements[fieldName][swapIndex].value = currVal;
	form.submit();
}
function setLastMousePosition(e) {
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
}
function submitSetField(formObj, fieldName, fieldValue) {
	document.forms[formIndex].elements[fieldName].value = fieldValue;
	document.forms[formIndex].submit();
}

function submitSetSuccessURL(formIndex, URL) {
	document.forms[formIndex].elements["alt_success_url"].value = URL;
	document.forms[formIndex].submit();
}

function submitSetSuccessURLByForm(form, URL) {
	document.forms[form].elements["alt_success_url"].value = URL;
	document.forms[form].submit();
}

function setFieldValue(formObj, fieldName, fieldName2) {
	formObj.elements[fieldName].value = formObj.elements[fieldName2].value;
}

function setButtonQueryString(formObj, baseHREF, fieldName) {
	var qString = fieldName + "=" + formObj.elements[fieldName].value;
	if (-1 == baseHREF.indexOf("?")) {
		window.location.href = baseHREF + "?" + qString;
	} else {
		window.location.href = baseHREF + "&" + qString;
	}
}

function submitToggle(form, elementIndex) {
// this is a proprietary function for resumes right now
// need to fix it at some point to be more generic
	if (form.visible_to_client.length>1) {
		var oldValue = form.visible_to_client[elementIndex].value;
		for (i=0; i<form.visible_to_client.length; i++) {
			form.visible_to_client[i].value = 0;
		}
		if (0==oldValue) {
			form.visible_to_client[elementIndex].value = 1;
		} else {
			form.visible_to_client[elementIndex].value = 0;
		}	
	} else {
		if (0==form.visible_to_client.value) {
			form.visible_to_client.value = 1;
		} else {
			form.visible_to_client.value = 0;
		}
	}		
	form.submit();
}	

function openNewWindow(url){
	window.open(url)
}

function openPopup(url, name, pWidth, pHeight, features, snapToLastMousePosition) {
   closePopup();
	if (snapToLastMousePosition) {
		if (lastMouseX - pWidth < 0) {
			lastMouseX = pWidth;
		}
		if (lastMouseY + pHeight > screen.height) {
			lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
		}
        lastMouseX -= pWidth;
        lastMouseY += 10;
		features +=	"screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
	}
	curPopupWindow = window.open(url, name, features, false);
}

function selectChangeURL(url, selObj) {
	url += "?" + selObj.name + "=" + selObj.value
	window.location = url;
}
function closePopup() {
	if (curPopupWindow != null) {
	   
		if (!curPopupWindow.closed) {
			curPopupWindow.close();
		}
		curPopupWindow = null;
	}
}
//===================================================================================================================
// Ron Trull - 2008.11.07 - added an optional window parameter to specify listbox or textbox as the receiving control
//                        - "TEXT" = textbox
//                        - "LIST" = listbox
//-----------------------------------------------------------------------------
function returnInfo(fieldText2, fieldID2){
    if (opener.fieldType) {
        //alert(opener.fieldText.options.length);
        if (opener.fieldType === 'LIST') {
	        var currLength = opener.fieldText.options.length;
	        if (currLength > 0) { opener.fieldText.options.length = 0; }
		    opener.fieldText.options.length = 1;
	        eval("opener.fieldText.options[0].text =" + "\"" + fieldText2 + "\"");
	        eval("opener.fieldText.options[0].value =" + "\"" + fieldID2 + "\"");
	        eval("opener.fieldID.value = " + "\"" + fieldID2 + "\"");			
	        eval("opener.fieldID.value += " + "\"" + ";" + "\"");        
        } else {
            opener.fieldText.value = fieldText2;
            opener.fieldID.value = fieldID2;
        }
    } else {
        opener.fieldText.value = fieldText2;
        opener.fieldID.value = fieldID2;
    }
	window.close();
}
//==========================================================================
function returnInfoMultiSelect(fieldText2, fieldID2){
		var exists = false;
		var currLength = opener.fieldText.options.length;
		var newLength = currLength + 1;
		var delim=";"
		
		// check that there was not a limit set for the multiselect
		if (opener.multiSelectLimit > 0) {
			if (currLength > opener.multiSelectLimit-1) {
				// don't add because we've reached limit of selected options
				return;
			}
		}
		
		for (i=0; i<opener.fieldText.options.length; i++) {
			if (opener.fieldText.options[i].value == fieldID2){
				exists = true;
			}
		}
		
		if (exists == false) {
			opener.fieldText.options.length = newLength;
			eval("opener.fieldText.options[" + currLength + "].text =" + "\"" + fieldText2 + "\"");
			eval("opener.fieldText.options[" + currLength + "].value =" + "\"" + fieldID2 + "\"");
			eval("opener.fieldID.value += " + "\"" + fieldID2 + "\"");			
			eval("opener.fieldID.value += " + "\"" + delim + "\"");
		}
}

function removeSelectElement(form,field){
//	remove the selected element then rebuild concatenated values in hidden field
	var i;
	var selectObj = eval("document."+form+"[\""+field+"\"].options");
	var selectObjLength = eval("document."+form+"[\""+field+"\"].options.length");
	var hiddenObj = eval("document." + form + "." + field + "_multiselect_values");
	var index = selectObj.selectedIndex;
	var delim = ";";
	
	if (index >= 0) {
	  if (selectObjLength > 0) {
		//selectObj[index]=null;

		hiddenObj.value = "";
		for (i=selectObj.length-1; i>=0; i--) {
		  if (selectObj[i].selected==true) {
			selectObj[i]=null;
		  } else {
			hiddenObj.value += selectObj[i].value + delim;		
//			if (selectObj[i].value != empty_label) {
//				hiddenObj.value += selectObj[i].value;
//			}
		  }
		}
	  }
	}
}

function clearSelect(form,field){
//	clears all items in a select control

	var i;
	var selectObj = eval("document."+form+"[\""+field+"\"].options");
	var selectObjLength = eval("document."+form+"[\""+field+"\"].options.length");
	var hiddenObj = eval("document." + form + "." + field + "_multiselect_values");

	hiddenObj.value = "";

	if (selectObjLength > 0) {
		for (i=0; i<selectObj.length; i++) {
			selectObj[i]=null;
		}

		for (i=0; i<selectObj.length; i++) {
			selectObj[i]=null;
		}

	}
}

function OpenLookupAddress(baseURL,fldHeader,sourceForm) {
	// keep track of form information
	currentForm = sourceForm;
	headerTxt = fldHeader;
	openPopup(baseURL, "AddrLookup", 300, 600, "width=500,height=400,toolbar=no,status=no,directories=no,menubar=no,resizable=no,scrollbars=1", true);
}

function returnAddressInfo(fieldText, fieldID, cityText, stateID, county, country){
	opener.fieldText.value = fieldText;
    opener.fieldID.value = fieldID;
	opener.setAddr(cityText, 'city', true, true);
	opener.setAddr(stateID, 'state', true, true);
	opener.setAddr(county, 'county', true, true);
	opener.setAddr(country, 'country', true, false);
	opener.setAddr(country, 'country', true, true);
	opener.setAddr(country, 'country_id', true, false);
    window.close();
}

function returnAddressInfo2(fieldText, fieldID, cityText, stateID, county, country, taxCode, tax_code_rd){
	opener.fieldText.value = fieldText;
    opener.fieldID.value = fieldID;
    opener.setAddr(cityText, 'city', true, true);
    opener.setAddr(stateID, 'state', true, true);
    opener.setAddr(county, 'county', true, true);
    opener.setAddr(country, 'country', true, false);
    opener.setAddr(country, 'country', true, true);
    opener.setAddr(country, 'country_id', true, false);
    opener.setAddr(taxCode, 'tax_code', true, true);
    opener.setAddr(tax_code_rd, 'tax_code_rd', true, true);    
    window.close();
}

function returnAddressInfo3(fieldText, fieldID, cityText, stateID, county, country, taxCode, tax_code_rd){
    opener.fieldText.value = fieldText;
    opener.fieldID.value = fieldID;
    opener.document.getElementById('ctl00_AJS_MPageContent_city_text').value= cityText;
    opener.document.getElementById('ctl00_AJS_MPageContent_county_text').value= county;
    opener.document.getElementById('ctl00_AJS_MPageContent_state_code_text').value= stateID;
     
    //opener.setAddr(cityText, 'city', true, true);
    //opener.setAddr(stateID, 'state', true, true);
    //opener.setAddr(county, 'county', true, true);
    opener.setAddr(country, 'country', true, false);
    opener.setAddr(country, 'country', true, true);
    opener.setAddr(country, 'country_id', true, false);
    opener.setAddr(taxCode, 'tax_code', true, true);
    opener.setAddr(tax_code_rd, 'tax_code_rd', true, true);    
    window.close();
}

function returnJobTitleWC(fieldText, fieldID, wcID, ownerDivisionID){
	opener.fieldText.value = fieldText;
    opener.fieldID.value = fieldID;
	if (wcID !=undefined ) opener.setAddr(wcID, 'wc_id', true, false);
	if (ownerDivisionID !=undefined ) opener.setAddr(ownerDivisionID, 'owner_division_id', true, false);
    window.close();
}

function setAddr(fldValue, fldName, bAlwaysUpdate, useHeader) {
	if ((currentForm==undefined) || (currentForm==null))  return;
	
	var theField
	if (useHeader==true) {
		theField = eval("document."+currentForm+"."+headerTxt+fldName);	
	} else {
		theField = eval("document."+currentForm+"."+fldName);	
	}
	// update only if there is not currently a value	
	if ((fldValue == null) || (fldValue == undefined)) {
		alert('unkonwn null');
		fldValue='';
	}
	if ((theField != null) && (theField != undefined)) {
		if (theField.type=='select-one' || theField.type=='select-multiple') {
			setSelectValue(theField, fldValue, bAlwaysUpdate);
		} else {
			// default is type TEXT or HIDDEN
			setTextValue(theField, fldValue, bAlwaysUpdate);
		}
	}		
}

function setTextValue(fld, fldValue, bAlwaysUpdate) {
	var bDoUpdate=false;	
	if (bAlwaysUpdate) {
		bDoUpdate=true;		
	} else {
		// update only if there is not currently a value
		if (fld.value.length == 0) {
			bDoUpdate=true;		
		}
	}
	if (bDoUpdate) {
		var values = fldValue.split('~');
		fld.value = values[0];
		var displayFld = eval("document."+currentForm+"."+fld.name+'_text');
		if ((displayFld != null) && (displayFld != undefined)) {
			displayFld.value = values[0];
			if (values.length>1) {
				if (values[1].length>0) {
					displayFld.value = values[1];
				} 
			}
		}
	}
}

function setSelectValue(fld, fldValue, bAlwaysUpdate) {
	var values = fldValue.split('~');
	for (var i=0; i < fld.length; i++) {
		if (fld.options[i].value==values[0]) {
			fld.selectedIndex=i;
		}
	}
}

function setAddrState(stateID, bAlwaysUpdate) {
	if ((currentForm==undefined) || (currentForm==null))  return;
	
	var stateSelect = eval("document."+currentForm+"."+headerTxt+"state");
	if ((stateSelect != null) && (stateSelect != undefined)) {
		if (stateSelect.type=='text') {
			stateSelect.value = stateID;
		} else if (stateSelect.type=='select-one' || stateSelect.type=='select-multiple') {
			for (var i=0; i < stateSelect.length; i++) {
				if (stateSelect.options[i].value==stateID) {
					stateSelect.selectedIndex=i;
				}
			}
		}
	}
}

function setAddrText(fldValue, fldName, bAlwaysUpdate) {
	if ((currentForm==undefined) || (currentForm==null))  return;
	
	var theField = eval("document."+currentForm+"."+headerTxt+fldName);	
	// update only if there is not currently a value	
	if ((theField != null) && (theField != undefined)) {
		if (bAlwaysUpdate) {
			theField.value = fldValue;		
		} else {
			// update only if there is not currently a value
			if (theField.value.length == 0) {
				theField.value = fldValue;		
			}
		}
	}		
}

function setMultiSelectLimit(limit) {
	if (limit==undefined) {
		multiSelectLimit = -1;
	} else {
		multiSelectLimit = limit;
	}
}

function setSingleSelectLIST(){
//  alert('inside ss');
    SigleSelectLBFalg='LIST';
//  alert('SigleSelectLBFalg:' + SigleSelectLBFalg);
}

function openLookup(baseURL,modified,searchParam,parentCntrl,parentName,sourceCntrl,passToField) {

	if (modified == '1') baseURL = baseURL + searchParam;
	if ((parentCntrl != null) && (parentCntrl != undefined)) {
		// check if a value has been entered for the parent control		
		if (parentCntrl.value.length == 0) {
			alert ('You need to enter a value for ' + parentName);
			return;
		} else {
			baseURL += "&" + parentCntrl.name + "=" + escape(parentCntrl.value);
		}
	}
	if ((sourceCntrl != null) && (sourceCntrl != undefined)) {
		// if field can be edited, than pass up the entered value		
		if (!(sourceCntrl.readOnly) && (sourceCntrl.value.length>0)) {			
			// change parameter search=true
			baseURL = baseURL.replace(/\?search=\&/i, "?search=true&");
			baseURL += "&" + passToField + "=" + escape(sourceCntrl.value);
			// pass additional parameter in case Lookup is not Search-type
			baseURL += "&srchpass=" + escape(passToField+"|"+sourceCntrl.value);
		}
	}
	
	var lookup = 'lookup';
	//Begin Dinesh 20-Feb-2009 T0680 -Contact Create and update change  		
	if (window.name == 'lookup') {
	    lookup = lookup + '_' + replaceChar(parentCntrl.name,'$','_') ;
	}
	if (baseURL .search(/.aspx/i)  > -1)
	{
	openPopup_aspnet(baseURL, lookup, 810, 450, "width=600,height=450,toolbar=no,status=no,directories=no,statusbar=no,menubar=no,resizable=no,scrollbars=1,titlebar=0,", true);		
	}
	//End Dinesh 20-Feb-2009 T0680 -Contact Create and update change
	else
	{
	openPopup(baseURL, lookup, 300, 600, "width=500,height=400,toolbar=no,status=no,directories=no,menubar=no,resizable=no,scrollbars=1", true);
	}
}

function removeSelectElement3(sourceSelect, sourceLabel)
{	if (sourceSelect.selectedIndex > -1)
	{	for (i=sourceSelect.length-1; i > -1; i--) 
		{	if (sourceSelect.options[i].selected) sourceSelect.options[i] = null;
		}
		if (sourceSelect.length == 0) 
		{	var placeHolder = new Option(sourceLabel, sourceLabel);
			sourceSelect.options[0] = placeHolder;
		}
	}
}

function openCalendar(url) {
	// the width height varies depending on platform
	var cwidth, cheight;
	var agt=navigator.userAgent.toLowerCase();	// convert all characters to lowercase to simplify testing
	var is_mac    = (agt.indexOf("mac")!=-1);
	if (is_mac) {
		cwidth=300;
		cheight=275;
	} else {
		cwidth=200;
		cheight=265;		
	}
	openPopup(url, "Calendar", -20, 250, "width="+cwidth+",height="+cheight+",dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no", true);
}

function getFormValue(fieldName) {
	// first make sure form field exists, else return blank string
	try {
		var cntrl1 = eval(currentForm+"."+fieldName);
		var retVal = getInputValue(cntrl1);
		return retVal;
	} catch(exception) { 
		return ''; 
	}
}
	
function getFormValueXX(fieldName) {
	var returnValue;
	if (currentForm != null) {
			returnValue = eval("document."+currentForm+"[\""+fieldName+"\"].value");
	}
	return returnValue;
}

function setFormValue(fieldName,value) {
	var fldValue=value;
	if (isNaN(value)||value=='') fldValue="'"+value+"'";
	//alert("document."+currentForm+"[\""+fieldName+"\"].value="+fldValue);
	if (currentForm != null) {		
		try {
			var elemtype = eval("document."+currentForm+"[\""+fieldName+"\"].type");
		} catch(exception) {
			return;
		}
		if (elemtype == "select-one") {
			for (var i = 0; i < eval("document."+currentForm+"[\""+fieldName+"\"].options.length"); i++) {
				if (eval("document."+currentForm+"[\""+fieldName+"\"].options[" + i + "].value")==value) {
					eval("document."+currentForm+"[\""+fieldName+"\"].selectedIndex=" + i);
					break;
				}
			}
		} else if (elemtype == "checkbox") {	
			if (value==''||value=='0') { fldValue='false' 
				} else { fldValue='true'; }
			eval("document."+currentForm+"[\""+fieldName+"\"].checked="+fldValue);
		
		} else {	
			var svalue = eval("document."+currentForm+"[\""+fieldName+"\"].value="+fldValue);			
		}
	}
}

function setInput(form,field,val,id){
	id='';
	eval("document."+form+"[\""+field+"\"].value=" + "\""+val+"\"");
	eval("document."+form+"[\""+field+"_id\"].value=" + "\""+id+"\"");
}

function setInputLookup(form,fieldtext,text,fieldval,val){
	eval("document."+form+"[\""+fieldtext+"\"].value=" + "\""+text+"\"");
	eval("document."+form+"[\""+fieldval+"\"].value=" + "\""+val+"\"");
}

function pick(form,field,val) {
	eval("document."+form+"[\""+field+"\"].value=" + "\""+val+"\"");
   closePopup();
	return false;
}

function openComboBox(url) {
	openPopup(replaceChar(url, ' ', '%'), "Select", 220, 270, "width=270,height=200,dependent=yes,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=1", true);
}

//'Begin Dinesh 20-Feb-2009 T0680 -Contact Create and update change : Modified the function 
function replaceChar(s, oldchar, newchar) {
	var retval = '';
	for (i = 0; i < s.length; i++) {
		if (s.charAt(i) == oldchar) {
			retval = retval + newchar;
		} else {
			retval = retval + s.charAt(i);
		}
	}	
	return retval;
}
//End Dinesh 20-Feb-2009 T0680 -Contact Create and update change

function openHelp(url) {
	url = url.replace("#", "%23");
	var browserName = navigator.appName;
	if (helpWindow != null && browserName != "Netscape") { helpWindow.close(); }
	var w = window.open(url, "Help", "width=500,height=400,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,screenX=" + window.screenX + ",left=" + window.screenX + "screenY=" + window.screenY + ",top=" + window.screenY, true);
    	w.focus();
	helpWindow = w;
}

function doPrint() {
	alert("This dialog will be replaced by a new browser window containing a printable version" +
		  " of the current page. The user can then select print from the browsers file menu to"+
		  " print the page. Alternatively, this could be an automatically generated Acrobat file.");
}

function doExport() {
	alert("This dialog will be replaced by a File-Save As dialog. Clicking on save in this dialog will save the contents of the current page to a file (in .csv format).");
}

function listProperties(obj) {
	var names = "";
	for (var i in obj) names += i + ", ";
	alert(names);
}

function lookupPick(formName, parentIdElementName, parentEditElementName, id, display) {
    
	var parentIdElement = "document." + formName + "[\"" + parentIdElementName + "\"]";
	var parentEditElement = "document." + formName + "[\"" + parentEditElementName + "\"]";
	var parentEditOldValueElement = "document." + formName + "[\"" + parentEditElementName + "_lkold" + "\"]";
	if (eval(parentIdElement + ".type") == "select-one") {
		var found = false;
		for (i = 0; i < eval(parentIdElement + ".options.length"); i++) {
			if (eval(parentIdElement + ".options[" + i + "].value") == id ) {
				eval(parentIdElement + ".selectedIndex=" + i);
				found = true;
				break;
			}
		}
		if (!found) {
			eval(parentIdElement + ".options[" + parentIdElement + ".options.length] = new Option('" + display + "','" + id + "')");
			eval(parentIdElement + ".selectedIndex=" + parentIdElement + ".options.length - 1");
		}
		eval(parentEditElement + ".value = " + "\"" + display +"\"");    
		eval(parentEditOldValueElement + ".value = " + "\"" + display +"\"");
	} else {
		eval(parentIdElement + ".value = " + "\"" + id +"\"");    
		eval(parentEditElement + ".value = " + "\"" + display +"\"");
		eval(parentEditOldValueElement + ".value = " + "\"" + display +"\"");
	}
	 	
		var parentSubmitParam = parentEditElementName+"_lspf";		
	    var doPost = eval("document."+formName+"[\""+ parentSubmitParam + "\"].value");
	   	if (doPost == '1') {
	   		eval("document."+formName+".submit()");	   
		}
		closePopup();
  
		return false;
}

function insertTS(field,datetime,alias) {
	field.value = "---------------------------------\n"+ alias + " " +datetime + "\n\n\n" + field.value;
}

function setFocus() {
    var sidebarSearch;
	// search for a tabIndexed field to focus on
    for(var firstIndex=1; firstIndex < 5; firstIndex ++ ){
	    var nextIndex = firstIndex;
        for (var frm = 0; frm < document.forms.length; frm++) {
            for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
                var elt = document.forms[frm].elements[fld];
			    if ( elt.tabIndex != nextIndex ) continue;
                if ((elt.type == "text" || elt.type == "textarea" || elt.type == "password")
                   && elt.name != "sbstr" &&  elt.name.indexOf("owner") != 0) {
				    elt.focus();
	                if (elt.type == "text") {
	                    elt.select();
	                }
	                return true;
			    } else {
				    nextIndex++;
				    fld = 0;
			    }
		    }
	    }
    }

	// failed to find a tabIndexed field, try to find the field based on it's natural position.
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            // skip buttons, radio, or check-boxes
            // to skip "select" types, remove from if statement
            if (elt.type == "text" || elt.type == "textarea" || elt.type == "password") {
                if (elt.name == "sbstr" && document.forms[frm].name == "sbsearch") { 
                    sidebarSearch = elt; 
                } else if (elt.name.indexOf("owner") != 0) {
                    elt.focus();
                    // select text in text field or textarea
                    if (elt.type == "text") {
                        elt.select();
                    }
                    return true;
                }
            }
        }
    }

    return true;
}

function setNamedFocus(element_name) {
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            if (elt.name == element_name) {
                elt.focus();
                if (elt.type == "text") {
                    elt.select();
                }
                return true;
            }
        }
    }
    return true;
}

// removes the leading and trailing spaces from a string, 
// similar to the java.lang.String.trim() function
// added by lturetsky, taken from http://www.voy.com/1888/58.html
function trim(st) {
	var len = st.length
	var begin = 0, end = len - 1;
	while (st.charAt(begin) == " " && begin < len) {
		begin++;
	}
	while (st.charAt(end) == " " && begin < end) {
		end--;
	}
	return st.substring(begin, end+1);	
}


function formatPhone (field) {
	field.value = trim(field.value);

    var ov = field.value;
    var v = "";
    var x = -1;

	// is this phone number 'escaped' by a leading plus?
	if (0 < ov.length && '+' != ov.charAt(0)) {	// format it
	    // count number of digits
	    var n = 0;
		if ('1' == ov.charAt(0)) {	// skip it
			ov = ov.substring(1, ov.length);
		}

	    for (i = 0; i < ov.length; i++) {
	        var ch = ov.charAt(i);

	        // build up formatted number
	        if (ch >= '0' && ch <= '9') {
	            if (n == 0) v += "(";
	            else if (n == 3) v += ") ";
	            else if (n == 6) v += "-";
	            v += ch;
	            n++;
	        }
	        // check for extension type section; 
	        // are spaces, dots, dashes and parentheses the only valid non-digits in a phone number?
	        if (! (ch >= '0' && ch <= '9') && ch != ' ' && ch != '-' && ch != '.' && ch != '(' && ch != ')') {
	            x = i;
	            break;
	        }
	    }
	    // add the extension
	    if (x >= 0) v += " " + ov.substring(x, ov.length);

	    // if we recognize the number, then format it
	    if (n == 10 && v.length <= 40) field.value = v;
	}
    return true;
}

function dc () {
    return window.confirm('Are you sure?');
}

function clearcols () {
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            if (elt.name == "c" || elt.name.substring(0,2) == "c_") {
                elt.checked = false;
            }
        }
    }
}

function setcols () {
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            if (elt.name == "c" || elt.name.substring(0,2) == "c_") {
                elt.checked = true;
            }
        }
    }
}

function setUsername(uname, fname, lname, suffix) {
	if (uname.value.length == 0) {
		uname.value = 
					fname.value.substring(0,1).toLowerCase() 
					+ lname.value.toLowerCase()
					+ "@"
					+ suffix.value;
	}
}
function setAlias(alias, fname, lname) {
	if (alias.value.length == 0) {
		alias.value = fname.value.substring(0,1).toLowerCase() +
					  lname.value.substring(0,4).toLowerCase();
	}
}

// POPUP WINDOW NUMBER 1 
function popWin(url) {
  	closePopup();
  	curPopupWindow = window.open(url,"win","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=550,height=300",false);
}
function popWin2(url) {
   win = window.open(url,"win","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=720,height=500",false);
   //self.name = "tutWindow";
}
function adminWin(url) {
   win = window.open(url,"win","toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=600",false);
}
function privacyWin(url) {
  	closePopup();
  	curPopupWindow = window.open(url,"win","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=550,height=350",false);
}

// Changed name of window for printWin so that Printable views do not disappear
// Newname is popWin, Oldname(changed) was curPopupWindow
function printWin(url) {
  popWin = window.open(url,"win","dependent=no,toolbar=1,directories=0,location=0,status=1,menubar=1,scrollbars=1,resizable=1,width=705,height=400",false);
  popWin.focus();
}

function moveSelectElement2(sourceSelect, targetSelect, sourceLabel, targetLabel) {
	moveSelectElement3(sourceSelect, targetSelect, sourceLabel, targetLabel, false);
}


function moveSelectElement3(sourceSelect, targetSelect, sourceLabel, targetLabel, keepTarget) {
	if (sourceSelect.selectedIndex > -1) {
		for (i=0; i < sourceSelect.length; ++i) {  
			var selectedOption = sourceSelect.options[i];
			if (selectedOption.selected) {
				if (selectedOption.text != sourceLabel) {
					var newOption = new Option(selectedOption.text, selectedOption.value);
					if (targetSelect.options.length > 0 && targetSelect.options[0].text == targetLabel) {
						targetSelect.options[0] = newOption;
					} else {
						targetSelect.options[targetSelect.options.length] = newOption;
					}
				} else {
					sourceSelect.selectedIndex = -1;
				}
			}
		}
		if(!keepTarget)
		{	removeSelectElement3(sourceSelect, sourceLabel);
		}
	}
}

function moveUp(sourceSelect)
{	var sel_id;
	sel_id = sourceSelect.selectedIndex;
	if (sourceSelect.length > 1 && sel_id > 0) //got to have at least 2 items and not the first one is selected
	{	var prevOption = sourceSelect.options[sel_id-1];
		var newOption = new Option(prevOption.text, prevOption.value);
		var selectedOption = sourceSelect.options[sel_id];
		sourceSelect.options[sel_id-1] = new Option(selectedOption.text, selectedOption.value);
		sourceSelect.options[sel_id] = newOption;
		sourceSelect.focus();
		sourceSelect.selectedIndex = sel_id -1;
	}
}


function moveDown(sourceSelect)
{	var sel_id;
	sel_id = sourceSelect.selectedIndex;
	if (sourceSelect.length > 1 && sel_id < sourceSelect.length -1) //got to have at least 2 items and not the last one is selected
	{	var nextOption = sourceSelect.options[sel_id+1];
		var newOption = new Option(nextOption.text, nextOption.value);
		var selectedOption = sourceSelect.options[sel_id];
		sourceSelect.options[sel_id+1] = new Option(selectedOption.text, selectedOption.value);
		sourceSelect.options[sel_id] = newOption;
		sourceSelect.focus();
		sourceSelect.selectedIndex = sel_id + 1;
	}
}

function openwizard(url, name, resizable) {
  var win = window.open('', name, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable='+resizable+',width=675,height=550,screenx=50,screeny=10,left=50,top=10',false)
  if ((win.document.URL == '') || (win.document.URL == 'about:blank')) win.location = url; 
  win.focus ();
}

function escapeUTF(src) {
	var ret = "";
	for (i = 0; i < src.length; i++) {
		var ch = src.charCodeAt(i);
		if (ch <= 0x7F) {
			ret += escape(src.charAt(i));
		} else if (ch <= 0x07FF) {
			ret += '%' + ((ch >> 6) | 0xC0).toString(16) + '%' + ((ch & 0x3F) | 0x80).toString(16);
		} else if (ch >= 0x0800) {
			ret += '%' + ((ch >> 12) | 0xE0).toString(16) +
				   '%' + (((ch >> 6) & 0x3F) | 0x80).toString(16) + '%' + ((ch & 0x3F) | 0x80).toString(16);
		}
	}
	return ret;
}

function openRefer(url) {
	window.open(url, 'referv2', 'resizable=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=420,height=500', false); 
}

function changeOpenerWindowLocation (url) {
    if ((window.top.opener == null) || window.top.opener.closed) {
        window.top.open (url);
    } else {
        window.top.opener.location.href = url;
        window.top.opener.focus ();
    }	
}

function verifyChecked(form, element_name, errorMessage) {
    for (i = 0; i < form.elements.length; i++) {
        if ((form.elements[i].name == element_name) && form.elements[i].checked) {
            return true;
        }
    }

	// if we haven't returned yet, it's not checked
    alert(errorMessage);
    return false;
}

function submitFormActionURL (form, url) {
	form.action = url;
	form.submit();
}

function submitForm (form) {
	form.submit();
}

function submitFormQueryString (form, name, value, url) {
	form.action += (form.action.indexOf("?") > -1 ? "&" : "?") + name + "=" + value;
	if (url) form.elements["alt_success_url"].value = url; 
	form.submit();
}

function submitFormNameValues(form) {
	var name, value, tempstr, argstr, re, x, y;
	
	argstr = "";
	for (var i = 1; i < arguments.length; i += 2) { 
		name = arguments[i]; 
		value = arguments[i+1];
		
		re = new RegExp("[&\\?]?" + name + "=\\w+&?");
		
		if ((x = form.action.search(re)) > -1) {			
			tempstr = re.exec(form.action);
			
			y = x + (tempstr[0].charAt(tempstr[0].length - 1) == "&" ? tempstr[0].length - 1 : tempstr[0].length);
			
			if (tempstr[0].charAt(0) == "&" || tempstr[0].charAt(0) == "?") x++;

			form.action = form.action.substring(0, x) + name + "=" + value + form.action.substring(y);
		} else {
			argstr += (argstr.length > 0 ? "&" : "") + name + "=" + value;
		}
	} 
	
	if (argstr.length > 0) {
		form.action += (form.action.indexOf("?") > -1 ? "&" : "?") + argstr;
	}

	if (form.basket) {
		for (i=0; i<form.basket.length;i++) {
			form.basket[i].value = 1;
		}
	}
	form.submit();
}

function SelectChecked(form, element_name, value)
{
    var i = 0;
    for (i = 0; i < form.elements.length; i++) {
    	if (form.elements[i].name == element_name) {
    		form.elements[i].checked = value;
    	}
    }
}
function openClickout(url) {
		// Taken out due to inconsistent escape results between java and javascript
        //window.open('/sales/linkout.jsp?url='+escape(url), "_blank", 'width=640,height=480,dependent=no,resizable=yes,toolbar=yes,status=yes,directories=yes,menubar=yes,scrollbars=1', false);
	window.open(url, "_blank", 'width=640,height=480,dependent=no,resizable=yes,toolbar=yes,status=yes,directories=yes,menubar=yes,scrollbars=1', false);
}
function beginDownload(newlocation) {
  // newlocation = "http://workplace.net/file.csv";  		
  // Bizarre logic because JavaScript won't behave
  idl = 1;
  if (location.search) { // for NN2
    idl = -location.search.indexOf("idl=n");
  }
  if (idl > 0) {
    window.location.replace(newlocation);	
  }
  return 1;
}

function getMonthIndex(monthName) {
	var theMonths = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'];
	
    // match to find the correct month index
	var sMonth = monthName.toLowerCase();
    for (var inMonth=0; inMonth < theMonths.length; inMonth++) {
	if (sMonth == theMonths[inMonth])
		break;
    }
	return inMonth;
}

function returnDate(inDate)
{
	var theMonths = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    var day   = inDate.getDate();
    var month = theMonths[inDate.getMonth()];
    var year  = inDate.getYear();

    if (day < 10)
	{
		day = "0" + parseInt(day);
	}
    return (day + "-" + month + "-" + year);
}

function convertToDate(inDate,diffType,diffAmt) {	
	var day, month, year;
	
    // Determine Browser Type (Netscape or MSIE)
    if(navigator.appName == "Netscape") 
      year += 1900;

    // IF A DATE WAS PASSED IN THEN PARSE THAT DATE
    // The date is in the format dd-MMM-yy
	if (inDate.indexOf("-")>0) {
		var inDay = inDate.substring(0,inDate.indexOf("-"));
		var sMonth = inDate.substring(inDate.indexOf("-") + 1, inDate.lastIndexOf("-"));
		var sYear = inDate.substring(inDate.lastIndexOf("-") + 1, inDate.length);

		// correctly convert the date	
        if (inDay.substring(0,1) == "0" && inDay.length > 1)
           inDay = inDay.substring(1,inDay.length);
        inDay = parseInt(inDay);
        
		// correctly convert month 
		// method varies depending on type of value given
		if (isNaN(sMonth)) {
			inMonth = getMonthIndex(sMonth);
		} else {
			// if number given, subtract one, eg Jan = 0
			inMonth = parseInt(sMonth) - 1;
		}
		
        // check if using two-digit year and interpret correctly
        inYear = parseInt(sYear);
        if (sYear.length<3) {			
			if (inYear<50) {
				inYear += 2000;
			} else {
				inYear += 1900;
			}
        }			

        if (inDay) {
            day = inDay;
        }

		month = inMonth;

        if (inYear) {
            year = inYear;
        }		
	}
	// older code to support mm/dd/yy    
    else if (inDate.indexOf("/")>0) { 
        var inMonth = inDate.substring(0,inDate.indexOf("/"));
        if (inMonth.substring(0,1) == "0" && inMonth.length > 1)
           inMonth = inMonth.substring(1,inMonth.length);
		if (isNaN(inMonth)) {
			inMonth = getMonthIndex(sMonth);
		} else {
			// if number given, subtract one, eg Jan = 0
			inMonth = parseInt(sMonth) - 1;
		}
		
        var inDay   = inDate.substring(inDate.indexOf("/") + 1, inDate.lastIndexOf("/"));
        if (inDay.substring(0,1) == "0" && inDay.length > 1)
           inDay = inDay.substring(1,inDay.length);
        inDay = parseInt(inDay);

        var inYear  = parseInt(inDate.substring(inDate.lastIndexOf("/") + 1, inDate.length));

        if (inDay) {
            day = inDay;
        }

        if (inMonth) {
            month = inMonth-1;
        }

        if (inYear) {
            year = inYear;
        }
	} else {
		// not valid date or format supplied
		return;
    }

	// apply date adjustment
	var calcDate = new Date(year,month,day);
	var newSeconds = calcDate.getTime();
	switch (diffType) {
	case 'y':
		newSeconds += 31536000000 * diffAmt;
	case 'm':
		// using 30 days as measure for month
		newSeconds +=  2592000000 * diffAmt;
	case 'd':
		newSeconds += 86400000 * diffAmt;
	case 'h':
		newSeconds += 3600000 * diffAmt;
	case 'n':
		newSeconds += 60000 * diffAmt;
	default:
		// no adjustment applied
	}		
	// adjust date depending on adjustment type
	return new Date(newSeconds);
}

function setSameValue(cntrl1, cntrl2Name) {
// sets form element of cntrl2Name to same value as cntrl1
	var cntrl2 = cntrl1.form.elements[cntrl2Name];
	if ((cntrl1.value != null) && (cntrl1.value != undefined)) {
		cntrl2.value = cntrl1.value;
	}
}

function check() {
  var a = document.exf1.t1.value.split("");
  var b = "";
  for (var i in a)
    if (a[i].match(/\d/))
    b += a[i];
  while (b.length>1 && b.charAt(0) == "0") b=b.substr(1,b.length);
  document.exf1.t1.value = b;
}

function onlyCharDigits(cntrl1) {
	  var a = cntrl1.value.split("");
	  var b = ' ';
	  for (var i in a)
    	if (a[i].match(/\w/))
	    b += a[i];
	  while (b.length>1 && b.charAt(0) == "0") b=b.substr(1,b.length);
	  cntrl1.value = b.substr(1,b.length);	
}

function alignDate(cntrl1, cntrl2Name, forceChange, diffType, diffAmt) {	
// forceChange = true/false (false by default)
// diffTypes = 'y','m','d','h','n'
//
	var sourceDate = convertToDate(cntrl1.value,diffType,diffAmt);	
	if ((sourceDate != null) && (sourceDate != undefined)) {
		var cntrl2 = cntrl1.form.elements[cntrl2Name];
		var destDate = convertToDate(cntrl2.value);
		
		if ((forceChange) && (forceChange != null)) {							
			// always change cntrl2 has to new date value
			cntrl2.value = returnDate(sourceDate);

		} else if ((destDate != null) && (destDate != undefined)) {
			if (sourceDate > destDate) {
				cntrl2.value = returnDate(sourceDate);	
			}
					
		} else {
			// if cntrl2 has no value, then set to same as cntrl 1
			cntrl2.value = returnDate(sourceDate);
			
		}
	}
}

function validNumDecimal(myvalue) {
	var re= new RegExp();
	re = /^\d*\.?\d*$/;
	if(re.exec(myvalue))
	{
		return true;
	} else {
		alert("Please only use numeric values.")
		return false;
	}
}

function getInputValue(cntrl1) {
	if (cntrl1.type=='select-one') {
		var selectval = cntrl1.options[cntrl1.selectedIndex].value;
		if (selectval==null || selectval==undefined) {
			return '';
		} else {
			return cntrl1.options[cntrl1.selectedIndex].value;
		}
	} else if (cntrl1.value==null || cntrl1.value==undefined) {
		return '';
	} else {
		return cntrl1.value;
	}
}

function getCashSign(currencyID) {
	var curID = parseInt(currencyID)
	if (curID==1033||curID==4105) {
		return '$';
	} else {
		return '';
	}
}

function Cash(money) {
	money=Math.round(money*100).toString();
	if (money<10) return '0.0'+money;
	return (money<100)?'0.'+money:money.substring(0,money.length-2)+'.'+money.substring(money.length-2,money.length);
}

function calculateSalary(cntrl1, cntrl2, cntrl3) {
	var myvalue = cntrl1.value.replace(/[$€£]/,'');
	var mysign = getCashSign(getInputValue(cntrl3));
	if (validNumDecimal(myvalue)) {
		cntrl2.value = mysign+Cash(myvalue*2000);
		cntrl1.value = mysign+myvalue;
	}
}

function calculateHourly(cntrl1, cntrl2, cntrl3) {
	var myvalue = cntrl1.value.replace(/[$€£]/,'');
	var mysign = getCashSign(getInputValue(cntrl3));
	if (validNumDecimal(myvalue)) {
		cntrl2.value = mysign+Cash(myvalue/2000);
		cntrl1.value = mysign+myvalue;		
	}
}

/*function submitDivision(form) {
	for (var i=0; i<form.elements.length; i++) {			// Loops through all the form's element 
		var strType = form.elements[i].type;
		var strName = form.elements[i].name;
		if ((strType == "checkbox") && (strName.indexOf("billing_work_same") != -1) && (form.elements[i].checked == true)) {
			copyAddr(form);
		}
	}
	return true;
}*/

function copyAddr(form) {
	for (var i=0; i<form.elements.length; i++) {			// Loops through all the form's element 
		var strType = form.elements[i].type;
		var strShippingName = form.elements[i].name;
		var strBillingName;
		if (strShippingName.indexOf("shipping") != -1)  {
			strBillingName = strShippingName.replace(/shipping/i, "billing");
			//alert(strShippingName + ' - ' + form[strShippingName].value);
			if (typeof form[strBillingName] != "undefined") {
				if ((strType == "text") || (strType == "textarea") || (strType == "hidden")) {
					if (!isEmpty(form[strShippingName])) form[strBillingName].value = form[strShippingName].value;
				}
				if (strType == "select-one") {
					if (!isSelectEmpty(form[strShippingName])) form[strBillingName].value = form[strShippingName].value;
				}
			}
		}
	}
}

function copyAddrBuilding(form) {
	for (var i=0; i<form.elements.length; i++) {			// Loops through all the form's element 
		var strType = form.elements[i].type;
		var strShippingName = form.elements[i].name;
		var strBillingName;
		if (strShippingName.indexOf("building") != -1)  {
			strBillingName = strShippingName.replace(/building/i, "billing");
			//alert(strShippingName + ' - ' + form[strShippingName].value);
			if (typeof form[strBillingName] != "undefined") {
				if ((strType == "text") || (strType == "textarea") || (strType == "hidden")) {
					if (!isEmpty(form[strShippingName])) form[strBillingName].value = form[strShippingName].value;
				}
				if (strType == "select-one") {
					if (!isSelectEmpty(form[strShippingName])) form[strBillingName].value = form[strShippingName].value;
				}
			}
		}
	}
}

// a utility fucntion that returns true if a string contains only whitespace characters
function isBlank(str) {
	for (var i=0; i<str.length; i++) {
		var c = str.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '')) return false;
	}
	return true;
}

function isEmpty(str) {
	if ((str.value == null) || (str.value == "") || isBlank(str.value)) {
		return true;
	} else {
		return false;
	}

}

function isSelectEmpty(box) {
    if (box.selectedIndex == -1 || box.options[box.selectedIndex].value == "") {
	    return true;
    } else {
        return false;
    }
}

function valid_required(theform) {

	 var reqElements="";
	 var elemName="";
     	 var input = theform[0].txt;
	 var owner_division_id_Selected = false;
	 var cluster_id = false;
	 for( var i = 0; i < theform.elements.length; i++)
	 {
	 	var thisElem = theform.elements[i];		
		//DS, T1794 - 10/16/07	------------------------------
		if (thisElem.name == 'owner_division_id') {
			if (thisElem.selectedIndex > 0) {
				owner_division_id_Selected = true;}
			}
		
		if (thisElem.name == 'cluster_id') {
			if (thisElem.length > 0) {
				cluster_id_Selected = true;
				if (owner_division_id_Selected == true) { 
					bReqFailed = true;
					if (eval(thisElem.name+'_dispx.length')>0) {
						elemName = eval(thisElem.name+'_dispx[0].innerText');
					} else {
						elemName = eval(thisElem.name+'_dispx.innerText');
					}
					elemName = elemName.replace(/[\n\f\r]/g,' ');
					reqElements+="\n- " + "User must select either branch or cluster, not both.";
					}
				}
			}
		//---------T1794 for all quick & advance search screens---
	 	if (thisElem.required==1) {			
			var bReqFailed = false;
			if((! thisElem.disabled) && (! thisElem.readonly)) 
			{												
				if (thisElem.type == 'text' || thisElem.type == 'hidden' || thisElem.type == 'textarea' || thisElem.type == 'password' || thisElem.type == 'file') {
					var thevalue = trim(thisElem.value);
					if (thevalue.length==0) { 
						// check to make sure that there is not a _text input field for entering value
						var relatedElem = eval('theform.'+thisElem.name+'_text');
						if (relatedElem == undefined || relatedElem == null) {
							bReqFailed = true;
						} else {
							if ((relatedElem.value.length>0) && (!relatedElem.readOnly)) {
								bReqFailed = false;
							} else { bReqFailed = true; }
						}		
					}									
				} else if (thisElem.type == 'select-one' || thisElem.type == 'select-multiple') {
					var multiElem = eval('theform.'+thisElem.name+'_multiselect_values');
					if (multiElem == undefined || multiElem == null) {
						if (thisElem.selectedIndex == -1) { bReqFailed = true; }
						else if (thisElem.options[thisElem.selectedIndex].value == "") { bReqFailed = true; }
					} else {
						// this is select lookup, which validation works differently
						// the multi-select element for this control needs to have value
						if (multiElem.value.length==0) { bReqFailed = true; }
					}
				} else if (thisElem.type == 'radio' || thisElem.type == 'checkbox') {
					if (! thisElem.checked) { bReqFailed = true; }
				}
			}
			if (bReqFailed) {
				// required validation failed because of no value
				// append to list of element(s) that have failed validation
				if (eval(thisElem.name+'_dispx.length')>0) {
					elemName = eval(thisElem.name+'_dispx[0].innerText');
				} else {
					elemName = eval(thisElem.name+'_dispx.innerText');
				}
				elemName = elemName.replace(/[\n\f\r]/g,' ');
				reqElements+="\n- "+elemName+" is Required.";
			}
		}
	 }
	 if (reqElements=="") {
		if (theform.name == 'form_s_tmsht_approved_internally')
		{
			return checkDateRange();
		}
		else
		// JK 08/01/08 issue 075-83
		// work history not saved when neither Job Title nor Other populated
		{
			if (theform.name == 'form_e_people_work_exp_edit' || theform.name == 'form_s_people_work_exp_edit')
				return checkForJobTitle(theform);
			else
				return true;
		}
	 } else {
	 	 alert ("The following error(s) occurred:\n"+reqElements);

		 // reset the clickCounter so the poor user can re-submit
                 clickCounter = 0;
		 return false;
	 }
}

function addToBucketBulk (form, baseURL) {
	
	if (-1 == baseURL.indexOf("?")) {
		baseURL += "?b_item_id=&b_form_id=" + form.name;
	} else {
		baseURL += "&b_item_id=&b_form_id=" + form.name;
	}

	openLookup(baseURL,'','',null,'');
	
}

function addToBucketFromLookup (form, bucketID) {
	
	var parentForm = opener.document.forms[form];
	var itemIDs = "";
	var j;
	
	var thisForm = document.getElementsByTagName("form").item(0);
	var input;
	
	for( var i = 0; i < parentForm.elements.length; i++)
	{

		j = parentForm.elements[i].name.indexOf("select_box");
  		if ((j >= 0) && (parentForm.elements[i].checked)) {
  			itemIDs += parentForm.elements[i].name.substring(j+10, parentForm.elements[i].name.length) + ";";
  		}
  	}

  	input = document.createElement("input");
	input.setAttribute("type", "hidden");
	input.setAttribute("name", "b_item_id");
  	input.setAttribute("value", itemIDs);
	thisForm.appendChild(input);
	
	thisForm.action += "&b_action=add";
	
	j = thisForm.action.indexOf("bucket_id=");
	if (j == -1) {
		thisForm.action += "&bucket_id=" + bucketID;
	}
	
	
	thisForm.submit();
	window.close();
}

// CALCULATOR RELATED FUNCTIONS----------------------------------------
function returnCalcValues(theForm) {	
	currentForm = theForm;
	opener.setFormValue('pay_rate',getFormValue('pay_rate'));
	opener.setFormValue('markup',getFormValue('markup'));
	opener.setFormValue('charge_rate',getFormValue('charge_rate'));
	opener.setFormValue('bill_rate',getFormValue('bill_rate'));
	opener.setFormValue('ot_pay_rate',getFormValue('ot_pay_rate'));
	opener.setFormValue('ot_charge_rate',getFormValue('ot_charge_rate'));
	opener.setFormValue('ot_bill_rate',getFormValue('ot_bill_rate'));
	opener.setFormValue('dt_pay_rate',getFormValue('dt_pay_rate'));
	opener.setFormValue('dt_charge_rate',getFormValue('dt_charge_rate'));
	opener.setFormValue('dt_bill_rate',getFormValue('dt_bill_rate'));
	window.close();
}

function openCalculator(url, sourceFormName, cwidth, cheight, params) {
	currentForm = sourceFormName;  // sets currentForm	
	if (cwidth=='')  cwidth==300;
	if (cheight=='') cheight==500;
	if (params=='')  params='toolbar=no,resizable=yes,status=no,directories=no,menubar=no,scrollbars=1';
	params = 'width='+cwidth+',height='+cheight+',dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no';
	openPopup(url, 'Calculator', cwidth, cheight, params, false);
}

function openCalculatorWC(url,sourceForm,bSkipCheck,height,disable) {
	currentForm = sourceForm;	
	var thisform = eval("document."+sourceForm);
	// height is an optional parameter
	if ((height == null) || (height == undefined)) { height=550; }
	// check if there are values for wc_id and owner_division_id	
	if (!bSkipCheck) {
		if (thisform.wc_id.value == '' || thisform.owner_division_id.value == '') {	
			alert("Values for both Worker's Comp and Owner Branch are required");
			return;
		}
	}
		url=url+'?wc_id='+getFormValue('wc_id');
		url=url+'&owner_division_id='+getFormValue('owner_division_id');
		url=url+'&company_id='+getFormValue('company_id');
		url=url+'&division_id='+getFormValue('division_id');
		url=url+'&rate_type_id='+getFormValue('rate_type_id');
		url=url+'&people_id='+getFormValue('people_id');
		url=url+'&assignment_id='+getFormValue('assignment_id');
		url=url+'&start_date='+escape(getFormValue('start_date'));
		url=url+'&end_date='+escape(getFormValue('end_date'));
		url=url+'&start_time='+escape(getFormValue('start_time'));
		url=url+'&end_time='+escape(getFormValue('end_time'));	
		url=url+'&shift_id='+escape(getFormValue('shift_id'));
		url=url+'&order_id='+escape(getFormValue('order_id'));		
		if (disable==1) { url=url+'&disable=1'; }		
		openPopup(url, "Calculator", -20, 250, "width=300,height="+height+",dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no", true);
}

function clearCalculator(theform) {
  	var thisform = eval("document."+theform);
	for(var i=0; i<thisform.length; i++) {
	   		var e = thisform.elements[i];
			if ((e.type=="text")||(e.type=="textarea")) {
				e.value="";
			}
	}
}
//Uma modified on 10.15.2008 performance enhancement
function returnInfoMultiSelectaspnet(fieldText2, fieldID2){
		var currLength = opener.fieldText.options.length;
		var newLength = currLength + 1;
		var delim=";"

		// check that there was not a limit set for the multiselect
		if (opener.multiSelectLimit > 0) {
			if (currLength > opener.multiSelectLimit-1) {
				// don't add because we've reached limit of selected options
				return;
			}
		}
		opener.fieldText.options.length = newLength;
		eval("opener.fieldText.options[" + currLength + "].text =" + "\"" + fieldText2 + "\"");
		eval("opener.fieldText.options[" + currLength + "].value =" + "\"" + fieldID2 + "\"");
		eval("opener.fieldID.value += " + "\"" + fieldID2 + "\"");			
		eval("opener.fieldID.value += " + "\"" + delim + "\"");
}
// -----------------------------------------------------------------------
