try { window.onbeforeunload = GEN_SaveWinPosition } catch(err) {}

function GEN_ResizeRpt() {

   try {
      nWH=800
      nWH = window.innerHeight ? window.innerHeight : document.body.offsetHeight;
      tBody = document.getElementById("tbody1")
      nH = nWH - (GEN_Position_getPageOffsetTop(tBody)+10)
      if (nH<tBody.offsetHeight) {tBody.style.height=nH+"px"}   
   }catch(err){}

}


m_imgBK = new Image();
m_imgBK.src = "images/shade.gif";

function EAGEN_Error(p_sErrStr, err) {
   try {alert(p_sErrStr)} catch(err){}
}

function FN_SetSelectValue(p_cbo, p_sVal) {

   try {
      for(var iCnt=0; iCnt < p_cbo.options.length;iCnt++) {
         if(p_cbo.options[iCnt].value==p_sVal) {
            p_cbo.options[iCnt].selected=true
            try{p_cbo.selectedIndex = iCnt}catch(err){}
            return 0;
        }
      }
   } catch(err) {}

}

function FN_SetHiddenValue(p_sFieldNm, p_Val) {

   document.getElementsByName(p_sFieldNm)[0].value=p_Val
   document.getElementsByName(p_sFieldNm)[0].setAttribute("isChanged",1)

}

function FN_Trim(str) {

   return str.replace(/^\s*|\s*$/g,"");

}

String.prototype.trim = function() {
   return this.replace(/^\s+|\s+$/g,"");
}


function FN_ShowDiv(p_sDivTag,p_bShow) {
   
   try {
      objDIV = document.getElementById(p_sDivTag).style

      if (p_bShow==1) {
         objDIV.height="0";
      } else {
         objDIV.height="1";
      }
   } catch(err) {
      try{EAGEN_Error("Error displaying information (FN_ShowDiv).",err)}catch(err){}
   }

}

function EAInFm_ShowField(p_obj, p_bShow) {

   try {
      if (p_obj.className=="ea-input-item-show" | p_obj.className=="ea-input-item") { 
         if (p_bShow==1) {
            p_obj.className="ea-input-item-show";
         } else {
            p_obj.className="ea-input-item";
         }
      } else {
         if (p_bShow==1) {
            p_obj.className="ea-input-item-sm-show";
         } else {
            p_obj.className="ea-input-item-sm";
         }
      }
   } catch(err) {
      try{EAGEN_Error("Error displaying field (EAInFm_ShowField).",err)}catch(err){}
   }
   
	
}

function FN_Submit_eai_form_preset(p_frm) {
   //Call this function before editing the innerHTML property of a form in which 
   //the user may have edits in progress (otherwise - those edits won't be saved because
   //your changes to the innerHTML property will nullify the defaultValue property settings.
   
   sElName=""
   try {
      var iElements = 0
      nCnt = p_frm.elements.length
      for (iElements=0; iElements < nCnt; iElements++) {
         fld = p_frm.elements[iElements]
         if (fld.defaultValue!=fld.value|fld.MacUpdate==1) {
	    fld.setAttribute("isChanged",1)
         }
   
      }
   } catch(err) {
      bSubmitForm = 0
      try{EAGEN_Error("Error validating information("+sElName+").",err)}catch(err){}
   }
}

function FN_Submit_eai_form(p_frm) {
   //Loops through form elements and pre-pends a ~ character to the field name
   //for all EDITED fields (NOTE that if you adjust the innerHTML property of a form you 
   //must call the FN_Submit_eai_form_preset function BEFORE setting that property or this
   //function will not work properly.

   try {

      sErrLoc = "Error in PRESET"
      FN_Submit_eai_form_preset(p_frm)

      sErrLoc = "_SAVE_SUBMIT_ is missing from this form"
      p_frm.elements['_SAVE_SUBMIT_'].value = 'SAVE'
      sErrLoc = "Can't compare DefaultValue to Value for one or more elements"
      var iElements = 0
      nCnt = p_frm.elements.length
      for (iElements=0; iElements < nCnt; iElements++) {
         fld = p_frm.elements[iElements]
         if (fld.defaultValue!=fld.value | fld.getAttribute("isChanged")==1){
	    fld.name = "~" + fld.name
         }
   
      }
      bSubmitForm = 1

   } catch(err) {
      bSubmitForm = 0
      try{EAGEN_Error("Error saving information(FN_Submit_eai_form: " + sErrLoc + " -- "+err+").",err)}catch(err){}
   }

   try {
      if (bSubmitForm==1){
         p_frm.submit()
      }
   } catch(err) {
      try{EAGEN_Error("Error in save:  submitting form (FN_Submit_eai_form).",err)}catch(err){}
   }

}

function FN_Submit_eai_form_DEL(p_frm) {

   try {
      FN_Submit_eai_form_preset(p_frm)
      p_frm._SAVE_SUBMIT_.value = "DELETE"
      var iElements = 0
      for (iElements=0; iElements < p_frm.elements.length; iElements++) {
         fld = p_frm.elements[iElements]
         if (fld.defaultValue!=fld.value | fld.getAttribute("isChanged")==1){
	    fld.name = "~" + fld.name
         }
      }
      bSubmitForm = 1

   } catch(err) {
      bSubmitForm = 0
      try{EAGEN_Error("Error deleting information(FN_Submit_eai_form_DEL).",err)}catch(err){}
   }

   try {
      if (bSubmitForm==1){p_frm.submit()}
   } catch(err) {
      try{EAGEN_Error("Error deleting information(FN_Submit_eai_form_DEL).",err)}catch(err){}
   }

}


function GEN_TextMaxLen (p_fld, p_nMaxLen, p_evt) {
window.status="Code: " + p_evt.keyCode
      if (p_fld.value.length >= p_nMaxLen & p_evt.keyCode!=8 & p_evt.keyCode<63000) {
        if (p_evt.preventDefault) { 
          p_evt.preventDefault(); 
        } 
        return false; 
      } else {
        return true;
      }

}

function GEN_VerifySave(p_frm) {

   GEN_SaveWinPosition()

   var sEl_list=""
   for(iCnt=0; iCnt<p_frm.elements.length; iCnt++) {
      if(p_frm.elements[iCnt].defaultValue!=p_frm.elements[iCnt].value & p_frm.elements[iCnt].getAttribute("_NOT_FOR_UPDATE_")==null & p_frm.elements[iCnt].name!="") {
         sEl_list+=" "+p_frm.elements[iCnt].name+"("+p_frm.elements[iCnt].defaultvalue+", "+p_frm.elements[iCnt].value+")"
      }         
   }

   if(sEl_list!="" && p_frm._SAVE_SUBMIT_.value=="") {
      sMsg = "You've made changes to the information on this page without clicking SAVE.  Those changes will be lost if you click OK!"
      window.status=sEl_list
      event.returnValue = sMsg
   }

}

function GEN_LaunchDialog(p_sURL, p_nWidth, p_nHeight) {

   try {
      sFeatures = 'status:no;dialogWidth:' + p_nWidth + 'px; dialogHeight:' + p_nHeight + 'px;scroll:no;unadorned:yes;help:no'
      aReturnValue = window.showModalDialog(p_sURL, '', sFeatures)
   } catch(err) {
      try{EAGEN_Error("Launching this dialog failed (GEN_LaunchDialog).",err)}catch(err){}
   }

}

function GEN_LaunchWindow(p_sURL, p_sWinNm) {

   try {
      cWin = window.open(p_sURL, p_sWinNm)
      cWin.focus()
   } catch(err) {}

}

function GEN_LaunchSimpleWindow(p_sURL, p_nWidth, p_nHeight) {

   try {
      sFeatures = 'copyhistory:no;dependent:yes;directories:no;status:no;menubar:no;toolbar:no;resizable:yes'
      if(p_nWidth!=0){sFeatures+=';Width:' + p_nWidth + 'px'}
      if(p_nHeight!=0){sFeatures+=';Height:' + p_nHeight + 'px'}
      aReturnValue = window.open(p_sURL, '', sFeatures)
   } catch(err) {
      try{EAGEN_Error("Could not launch a window, function failed(GEN_LaunchSimpleWindow).",err)}catch(err){}
   }

}

function GEN_ShowSection(p_sSection, p_bForceOpen) {

   try {
      oIMG = eval ("document.getElementById('imgDIV_" + p_sSection + "')")
      oDIV = eval ("document.getElementById('dv_" + p_sSection + "')")
      if (oDIV.style.display=="none"||p_bForceOpen==true) {   //DIV is HIDDEN, SO SHOW IT
         oIMG.src = 'images/div_arw_down.gif'
         oDIV.style.display="inline"
         EA_setCookie("ViewSettings",p_sSection,"1")

      } else {
         oIMG.src = 'images/div_arw_left.gif'
         oDIV.style.display = "none"
         EA_setCookie("ViewSettings",p_sSection,"0")

      }
   } catch(err) {}

}

function GEN_MarkRptRow(p_objRow, p_bSkipByListItem) {

   try {

      //First, unmark all rows
      GEN_UnMarkRptRows(p_objRow)

      elList = p_objRow.getElementsByTagName("DIV")              
      for (iCntEl=0; iCntEl<elList.length; iCntEl++) {
         try {if (elList[iCntEl].id=="dvButtons") {elList[iCntEl].style.display=""}}catch(err){}
      }

      //Finally, mark the row passed to this function
      for (iCnt=0; iCnt<p_objRow.cells.length; iCnt++){
         p_objRow.cells[iCnt].style.backgroundImage="url('images/shade.gif')"
         try {if(p_objRow.cells[iCnt].className!="list-item" && p_bSkipByListItem) { p_objRow.cells[iCnt].style.backgroundImage=""}}catch(err){}
      }

   } catch(err) { alert(err)}

}

function GEN_UnMarkRptRows(p_objRow) {
   try {

      //First, get a reference to the TABLE from the row object
      objTbl = p_objRow
      nRows=0
      do {
         objTbl = objTbl.parentNode || objTbl.parentElement
      } while(objTbl.tagName.toUpperCase()!="TABLE")

      //Then, UNMARK all rows in the table
      for (iCnt=0; iCnt<objTbl.rows.length; iCnt++){
         if(objTbl.rows[iCnt].cells.length>0) {
            if(objTbl.rows[iCnt].cells[0].style.backgroundImage!=""){
               elList = objTbl.rows[iCnt].getElementsByTagName("DIV")              
               for (iCntEl=0; iCntEl<elList.length; iCntEl++) {
                  try {if (elList[iCntEl].id=="dvButtons") {elList[iCntEl].style.display="none"}}catch(err){}
               }
               for (iCntTD=0; iCntTD<objTbl.rows[iCnt].cells.length; iCntTD++){
                  objTbl.rows[iCnt].cells[iCntTD].style.backgroundImage=""
               }
            }
         }
      }

   } catch(err) {}
}



function GEN_MarkRow(p_objRow, p_bSkipByListItem) {
//MARKS a row by setting it's background image to SHADE (a semi-transparent GIF)
//NOTE that the function also UNMARKS all other rows by default.

   try {

      //First, unmark all rows
      GEN_UnMarkRows(p_objRow)

      //Finally, mark the row passed to this function
      for (iCnt=0; iCnt<p_objRow.cells.length; iCnt++){
         p_objRow.cells[iCnt].style.backgroundImage="url('images/shade.gif')"
         try {if(p_objRow.cells[iCnt].className!="list-item" && p_bSkipByListItem) { p_objRow.cells[iCnt].style.backgroundImage=""}}catch(err){}
      }

   } catch(err) { alert(err)}
}

function GEN_UnMarkRows(p_objRow) {
//UNMARKS all rows in the table (or the row's table) passed to the function 

   try {

      //First, get a reference to the TABLE from the row object
      objTbl = p_objRow
      nRows=0
      do {
         objTbl = objTbl.parentNode || objTbl.parentElement
      } while(objTbl.tagName.toUpperCase()!="TABLE")

      //Then, UNMARK all rows in the table
      for (iCnt=0; iCnt<objTbl.rows.length; iCnt++){
         if(objTbl.rows[iCnt].cells.length>0) {
            if(objTbl.rows[iCnt].cells[0].style.backgroundImage!=""){
               for (iCntTD=0; iCntTD<objTbl.rows[iCnt].cells.length; iCntTD++){
                  objTbl.rows[iCnt].cells[iCntTD].style.backgroundImage=""
               }
            }
         }
      }

   } catch(err) {}
}

function GEN_FormKeyCapture(frm, e) {

   try {
      
      try {
         element = e.target || e.srcElement 
         sType=element.type
      } catch(err) {}

      if (e.keyCode==13 && sType!='textarea') {
         if (frm.action) {
            frm.submit()
         } else { 
           if(frm.onclick){
              //Safari broswers don't support Click() method, so we need to use this EVAL() workaround
              sOnClick = frm.getAttribute("onclick").toString()
              if(sOnClick.indexOf("{")>0) {
                 sOnClick = sOnClick.substr(sOnClick.indexOf("{")+1)
                 sOnClick = sOnClick.substr(0, sOnClick.indexOf("}")-1)
              }
              eval(sOnClick)
           }
         }
      }

   } catch(err) {}

}

function GEN_FieldKeyCapture(fld, e) {

   if (e.keyCode==13) {
      if (fld.onchange) {
         fld.blur()
      } else { 
        if(fld.onclick){
              //Safari broswers don't support Click() method, so we need to use this EVAL() workaround
              sOnClick = fld.getAttribute("onclick").toString()
              if(sOnClick.indexOf("{")>0) {
                 sOnClick = sOnClick.substr(sOnClick.indexOf("{")+1)
                 sOnClick = sOnClick.substr(0, sOnClick.indexOf("}")-1)
              }
              eval(sOnClick)
        }
      }
   }
}

function GEN_TableNextPage(p_nCurrentPg, p_nMovePgs) {

   try {
      //Need to compute new page from the Current + Move page
      sHREF = document.location.href
      sHREF = sHREF.replace(/&Page=\d*/,"")

      if (p_nMovePgs==0 && p_nCurrentPg==0) {
         sHREF = sHREF + "&TblShowAll=1"
      } else {
         nPageID = p_nCurrentPg + p_nMovePgs
         if (nPageID < 1){ nPageID=1 }
         //Now replace any EXISTING Page= parameter in the QString and return to the server
         sHREF = sHREF + "&Page=" + nPageID
      }

      window.location.replace(sHREF)

   } catch(err) {}

}

function GEN_SortBy(p_sTbl, p_nTypeSID) {

   sURL = "EADIALOGS.ASP?WCI=SortBy&TblNm=" + p_sTbl
   sURL += "&TYPESID=" + p_nTypeSID

   sFeatures = "dependent,width=435,height=275"
   nNewWin = window.open (sURL, "SORTBY", sFeatures)
   try{nNewWin.focus()}catch(err){}

}

function GEN_LaunchPDashLink(p_sURL) {

   try {
      sFeatures = "dependent,resizable,scrollbars,status,width=820,height=550"
      nNewWin = window.open (p_sURL, "EAProj", sFeatures)
      try{nNewWin.focus()}catch(err){}
   } catch(err) {}

}

function GEN_LaunchProjectDash(p_nID, p_nScreen) {

   var sURL=""

   try {

      if (isNaN(p_nScreen)){p_nScreen=0}

      switch(p_nScreen) {
         case 0:
            //Default page
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=PD_20_0.htm&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 1:
            //Default page
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=PD_20_0.htm&ObjectType=EAProject&ItemID=" + p_nID
            break
         case 2:
            //Team List
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_20_0_c.htm&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 3:
            //Milestone List
            sURL="EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_20_0_b.htm&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 4:
            //Contact List
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_20_7.htm&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 5:
            //Client Data
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=PD_20_5.htm&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 6:
            //Time+Expense History
            sURL="EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_20_1_b.htm&TableView=2&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID="+p_nID
            break;
         case 7:
            //THIS MONTH TO DATE 
            sURL="EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_20_1_a.htm&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 8:
            //TIME ENTRY/Budget History (by month)
            sURL="EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_20_1_b.htm&TableView=1&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 9:
            //Project DIARY Home Page
            sURL="EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&Page=1&HTML=PD_20_3_a.htm&ObjectType=EAProject&ItemID=" + p_nID + "&ProjectSID=" + p_nID
            break;
         case 10:
            //Contract Mgmt.
            sURL="EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=PD_Contract.htm&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 11:
            //Invoice Workflow
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=PD_20_4_InvWFlow.htm&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 12:
            //Staff (Allocation) Budgets
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_20_1_e.htm&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 13:
            //Estimate Budgets
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&Page=1&HTML=PD_20_1_f.htm&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 14:
            //Invoice History
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_20_1_g.htm&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 15:
            //Revenue Pipeline
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_RevPipe.htm&GroupBy=1&ProjectSID=" + p_nID + "&ObjectType=EAProject&ItemID=" + p_nID
            break;
         case 16:
            //TASK List
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_ToDo.htm&ShowAll=1&HideDone=1&ObjectType=EAProject&ItemID=" + p_nID + "&TableRows=250&Page=1"
            break;
         case 17:
            //ALL OVERDUE TASKS
            var dtNow = new Date();
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplTableDef&HTML=PD_ToDo.htm&ShowAll=1&HideDone=1&ObjectType=EAProject&ItemID=" + p_nID + "&TableRows=250&Page=1"
            sURL += "&StartDt=&EndDt=" + EAFormat_Date2(dtNow, 3)
            break;
         default:
            //Default page
            sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=PD_20_0.htm&ObjectType=EAProject&ItemID=" + p_nID
            break;
      }

      sFeatures = "dependent,resizable,scrollbars,status,width=820,height=550"
      nNewWin = window.open (sURL, "EAProj"+p_nID, sFeatures)
      try{nNewWin.focus()}catch(err){}

   } catch(err) {
      try{EAGEN_Error("Error: The search for a project based on your entry failed(GEN_LoadPrj -- " + err + ").",err)}catch(err){}
   }

}

function EAGEN_PopForm(p_sURL, p_nWidth, p_nHeight) {

   try {

      sFeatures = "dependent,resizable,width=" + p_nWidth + ",height=" + p_nHeight
      nNewWin = window.open (p_sURL, "EAPOPDLG", sFeatures)
      try{nNewWin.focus()}catch(err){}

   } catch(err) {alert(err)}

}


function EAGEN_AddProject() {

   try {

      sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=PD_New1.htm&ObjectType=EAClient&ItemID=0&AddNew=True"
      sFeatures = "dependent,resizable,scrollbars,status,width=790,height=400"
      nNewWin = window.open (sURL, "EAProj0", sFeatures)

      try{nNewWin.focus()}catch(err){}

   } catch(err) {}

}

function EAGEN_AddStaff() {

   try {

      sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=StaffDetail_add.htm&ObjectType=EAStaff&ItemID=0&New=True"

      sFeatures = "toolbar=0,location=0,directories=0,status=0,resizable=1,dependent=1,width=800,height=570"
      nNewWin = window.open (sURL, "AddStaff", sFeatures)
      try{nNewWin.focus()}catch(err){}

   } catch(err){}

}

function EAGEN_ShowInfoBlock(p_sType, p_sBlockid) {

   objTBL = document.getElementById("DIV_"+p_sType+"_TBL_"+p_sBlockid)
   objTAB = document.getElementById("DIV_"+p_sType+"_TAB_"+p_sBlockid)

   sItem = p_sType+"_"+p_sBlockid
   if (objTBL.style.display=="inline") {
         objTBL.style.display="none"
         objTAB.style.display="inline"
         EA_setCookie("ViewSettings",sItem,"1")
   } else {
         objTBL.style.display="inline"
         objTAB.style.display="none"
         EA_setCookie("ViewSettings",sItem,"0")
   }

}

var _IB_IS_HIDDEN=0;

function EAGEN_ToggleBlock(p_bShow, p_nBlockID) {

   if (p_bShow==1) {
      try {document.getElementById("DIV_IBLOCK").style.display = "inline"} catch(err) {}
      try {document.getElementById("DIV_HDI_TBL").style.display = "inline"} catch(err) {}
      try {document.getElementById("DIV_IBLOCK_SHOW").style.display = "none"} catch(err) {}
      EA_setCookie("ViewSettings","IB_"+p_nBlockID,"1")
      _IB_IS_HIDDEN=0;
   } else {
      try {document.getElementById("DIV_IBLOCK").style.display = "none"} catch(err) {}
      try {document.getElementById("DIV_HDI_TBL").style.display = "none"} catch(err) {}
      try {document.getElementById("DIV_IBLOCK_SHOW").style.display = "inline"} catch(err) {}
      EA_setCookie("ViewSettings","IB_"+p_nBlockID,"-1")
      _IB_IS_HIDDEN=1;
   }

}

function GEN_SaveWinPosition() {
   
   try {

   } catch(err){}

}

function GEN_LoadWinPosition() {
   
   try {


   }catch(err){}

}

function GEN_GetDivRef( divID, oDoc ) {
   if( !oDoc ) { oDoc = document; }
   if( document.layers ) {
      if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
         for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
            y = getRefToDivNest(divID,oDoc.layers[x].document); }
         return y; }
   }
   if( document.getElementById ) { return oDoc.getElementById(divID); }
   if( document.all ) { return oDoc.all[divID]; }
   return document[divID];
}

function FN_SizeWinToContent ( idOfDiv ) {
   var oH = GEN_GetDivRef( idOfDiv ); if( !oH ) { return false; }
   var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
   var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
   var x = window; x.resizeTo( oW + 200, oH + 200 );
   var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
   if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
   else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
   else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
   if( window.opera && !document.childNodes ) { myW += 16; }
   x.resizeTo( oW + ( ( oW + 200 ) - myW ), oH + ( (oH + 200 ) - myH ) );
}

function GEN_AddDays(p_dt, p_nDays) {

   var nTZone = p_dt.getTimezoneOffset();
   p_dt.setMilliseconds(86400000 * p_nDays);
   try {
      //ONLY NEED TO ADJUST FOR TIMEZONES IN MAC (NON-FIREFOX) BROWSERS
      if(navigator.platform=="MacPPC" && navigator.userAgent.indexOf("Firefox")==-1) {
         if (p_dt.getTimezoneOffset()!=nTZone) {
            p_dt.setMilliseconds(60000*(p_dt.getTimezoneOffset()-nTZone))
         }
      }
   } catch(err) {}

}


function GEN_CSSUpdate(p_sClassNm, p_sStyleSetting, p_sNewValue) {
 
   try {
      for(i = 0; document.styleSheets.length > i; i++) {
         cRuleObj = document.styleSheets[i].rules||document.styleSheets[i].cssRules
         for(j = 0; cRuleObj.length > j; j++) {
            if(cRuleObj[j].selectorText.toLowerCase() == p_sClassNm) {
               cRuleObj[j].style[p_sStyleSetting] = p_sNewValue;
            }
         } 
      }
   } catch(err) {}
 
}

function GEN_CSSQuery(p_sClassNm, p_sStyleSetting) {
 
   try {
      for(i = 0; document.styleSheets.length > i; i++) {
         cRuleObj = document.styleSheets[i].rules||document.styleSheets[i].cssRules
         for(j = 0; cRuleObj.length > j; j++) {
            if(cRuleObj[j].selectorText.toLowerCase() == p_sClassNm) {
               return cRuleObj[j].style[p_sStyleSetting];
            }
         } 
      }
   return "";
 
   } catch(err) {return "";}
 
}

function FN_EditTS(p_bIsSubmitted, p_nSID, p_bIsBillable) {

   if(p_bIsBillable=="1"){p_bIsBillable=1}else{p_bIsBillable=0}
   if(p_bIsSubmitted==0){
      alert("Cannot edit time entries that have not yet been submitted by the user.")
   } else {
      sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=Fncl_6111_EditTime_Staff.htm&ObjectType=EATime&ItemID=" + p_nSID + "&OldTS=True&IsBillable=" + p_bIsBillable
      sFeatures = "toolbar=0,location=0,directories=0,status=0,resizable=1,dependent=1,width=800,height=400"
      nNewWin = window.open (sURL, "EditTM", sFeatures)
      nNewWin.focus()
   }

}

function FN_EditEXP(p_bIsSubmitted, p_nSID, p_bIsBillable) {

   if(p_bIsBillable=="1"){p_bIsBillable=1}else{p_bIsBillable=0}
   if(p_bIsSubmitted==0){
      alert("Cannot edit expense entries that have not yet been submitted by the user.")
   } else {
      if(p_nSID>0) {
         sURL = "EAPSA_MGMT.ASP?WCI=eaMain&WCE=tplFormDiv&HTML=Fncl_6111_EditExp_pop.htm&ObjectType=EAExpense&ItemID=" + p_nSID + "&IsBillable=" + p_bIsBillable
         sFeatures = "toolbar=0,location=0,directories=0,status=0,resizable=1,dependent=1,width=800,height=400"
         nNewWin = window.open (sURL, "EditEX", sFeatures)
         nNewWin.focus()
      } else {
         alert("You've clicked on an expense that exists in QuickBooks, but it hasn't been imported into BigTime yet.\n\n To edit it, locate the expense in QuickBooks and edit it there instead.  The changes you make in QuickBooks will be picked up by BigTime automatically (the next time thye system syncs up expense data).")
      }
   }

}

function FN_EditTXN(p_bIsExpense, p_bIsSubmitted, p_nSID, p_bIsBillable) {

   if(p_bIsBillable=="1"){p_bIsBillable=1}else{p_bIsBillable=0}
   if(p_bIsExpense==1){
      FN_EditEXP(p_bIsSubmitted, p_nSID, p_bIsBillable)
   } else {
      FN_EditTS(p_bIsSubmitted, p_nSID, p_bIsBillable) 
   }

}



































/*
EA_setCookie(), EA_readCookie(), EA_killCookie()
*/



function EA_readCookie(p_sCookie, p_sItem) {

   try {

   if(document.cookie == '') { // there's no cookie, so go no further
      return ''; 
   } else { // there is a cookie
      var nSt, nEnd;
      p_sCookie=EA_EncodeCookie(p_sCookie)+"="
      if (p_sItem!="") {
         p_sItem = EA_EncodeCookie(p_sItem)+"="
      }

      var sCookieVals = document.cookie;
      nSt = sCookieVals.indexOf(p_sCookie)
      if (nSt == -1) { return '' }
      nSt = nSt + p_sCookie.length
      nEnd = sCookieVals.indexOf(';',nSt)
      if (nEnd==-1) { nEnd=sCookieVals.length }

      var sItemVals = sCookieVals.substring(nSt, nEnd)
      if (p_sItem=="") {
         nSt=1
         nEnd=sItemVals.length
      } else {
         nSt = sItemVals.indexOf(p_sItem) + p_sItem.length
         if (nSt == -1) { return '' }
         if (sItemVals.indexOf('&',nSt) != -1) {
            nEnd = sItemVals.indexOf('&',nSt)
         } else {
            nEnd = sItemVals.length
         }   
      }

      return EA_DecodeCookie(sItemVals.substring(nSt,nEnd));
    }	

   } catch(err) {return '';}

}

function EA_setCookie (p_sCookie, p_sItem, p_sValue) {

   try {
   if(document.cookie == '') { 
      //-----There is NO existing cookie-----
      sCookie_item_l = ""
      sCookie_item_r = ""
   } else { 
      var nSt, nEnd;
      p_sCookie=EA_EncodeCookie(p_sCookie)+"="
      p_sItem = EA_EncodeCookie(p_sItem)+"="

      var sCookieVals = document.cookie;
      nSt = sCookieVals.indexOf(p_sCookie)
      if (nSt == -1) { 
         //-----There is NO existing value within the cookie name specified-----
         sCookie_item_l = ""
         sCookie_item_r = ""
      } else {
         nSt = nSt + p_sCookie.length

         nEnd = sCookieVals.indexOf(';',nSt)
         if (nEnd==-1) { nEnd=sCookieVals.length }


         var sItemVals = sCookieVals.substring(nSt, nEnd)
         nSt = sItemVals.indexOf(p_sItem)
         if (nSt == -1) { 
             //-----There is NO existing item within the cookie name specified-----
            sCookie_item_l = sItemVals + "&"
            sCookie_item_r = ""
         } else {
            //-----Both the cookie and the item names exist, so replace it-----
            sCookie_item_l = sItemVals.substring(0,nSt)            
            if (sItemVals.indexOf('&',nSt) != -1) {
               nEnd = sItemVals.indexOf('&',nSt)
            } else {
               nEnd = sItemVals.length
            }   
            sCookie_item_r = sItemVals.substr(nEnd)
         } 
      }	
   }   

   sCookie_item = EA_EncodeCookie(p_sItem)+EA_EncodeCookie(p_sValue)
   sCookieVals = sCookie_item_l + sCookie_item + sCookie_item_r


   document.cookie = p_sCookie + sCookieVals + '; expires=Tue, 31-Dec-2030 00:00:00 GMT'

   } catch(err) {}


} 

function EA_killCookie(p_sCookie) {

   // set an already-expired cookie
   document.cookie = EA_EncodeCookie(p_sCookie)+"=' '; expires=Fri, 13-Apr-1970 00:00:00 GMT"

} 

function EA_EncodeCookie(p_sVal) {

   var sVal = p_sVal
   do {sVal = sVal.replace('@','%40')}while (sVal.indexOf('@') > -1)
   do {sVal = sVal.replace(' ','%20')}while (sVal.indexOf(' ') > -1)
   do {sVal = sVal.replace('.','%2E')}while (sVal.indexOf('.') > -1)
   do {sVal = sVal.replace('_','%5F')}while (sVal.indexOf('_') > -1)

   return sVal;

}

function EA_DecodeCookie(p_sVal) {

   var sVal = p_sVal
   do {sVal = sVal.replace('%40','@')}while (sVal.indexOf('%40') > -1)
   do {sVal = sVal.replace('%20',' ')}while (sVal.indexOf('%20') > -1)
   do {sVal = sVal.replace('%2E','.')}while (sVal.indexOf('%2E') > -1)
   do {sVal = sVal.replace('%5F','_')}while (sVal.indexOf('%5F') > -1)

   return sVal;

}






/*=======Hashtable definition/methods========*/

function Hashtable(){
    this.clear = hashtable_clear;
    this.containsKey = hashtable_containsKey;
    this.containsValue = hashtable_containsValue;
    this.get = hashtable_get;
    this.isEmpty = hashtable_isEmpty;
    this.keys = hashtable_keys;
    this.put = hashtable_put;
    this.remove = hashtable_remove;
    this.size = hashtable_size;
    this.toString = hashtable_toString;
    this.values = hashtable_values;
    this.hashtable = new Array();
}

/*=======Private methods for internal use only========*/

function hashtable_clear(){
    this.hashtable = new Array();
}

function hashtable_containsKey(key){
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}

function hashtable_containsValue(value){
    var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

function hashtable_get(key){
    return this.hashtable[key];
}

function hashtable_isEmpty(){
    return (parseInt(this.size()) == 0) ? true : false;
}

function hashtable_keys(){
    var keys = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            keys.push(i);
    }
    return keys;
}

function hashtable_put(key, value){
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}

function hashtable_remove(key){
    var rtn = this.hashtable[key];
    this.hashtable[key] = null;
    return rtn;
}

function hashtable_size(){
    var size = 0;
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            size ++;
    }
    return size;
}

function hashtable_toString(){
    var result = "";
    for (var i in this.hashtable)
    {     
        if (this.hashtable[i] != null)
            result += "{" + i + "},{" + this.hashtable[i] + "}\n";  
    }
    return result;
}

function hashtable_values(){
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            values.push(this.hashtable[i]);
    }
    return values;
}




//XML NextSibling function (eliminates FireFox error with NextSibling)
function GEN_NextSib(startBrother){
  endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}


function GEN_trim(stringToTrim) {return stringToTrim.replace(/^\s+|\s+$/g,"");}
function GEN_ltrim(stringToTrim) {return stringToTrim.replace(/^\s+/,"");}
function GEN_rtrim(stringToTrim) {return stringToTrim.replace(/\s+$/,"");}





// Functions for IE to get position of an object (was AnchorPosition_getPageOffsetLeft)
function GEN_Position_getPageOffsetLeft (el) {
   var ol=el.offsetLeft;
   while ((el=el.offsetParent) != null) { 
      ol += el.offsetLeft; 
      try{if(el.style.left!=""){return ol}}catch(er1){}
      try{if(el.id=="divBODY" && el.style.position=="absolute"){ol -= el.offsetLeft}} catch(er2){} }
   return ol;
}

function GEN_Position_getPageOffsetTop (el) {
   var ot=el.offsetTop;
   while((el=el.offsetParent) != null) { 
	ot += el.offsetTop; 
        try{if(el.style.top!=""){return ot}}catch(er1){}
	try{if(el.id=="divBODY" && el.style.position=="absolute"){ot -= el.offsetTop}} catch(er2){}
	try{if(el.parentNode.tagName!="BODY" && el.parentNode.scrollTop>0){ot -= el.parentNode.scrollTop}}catch(er3){}
   }
   return ot;
}

function GEN_Position_getWindowOffsetLeft (el) {
   return GEN_Position_getPageOffsetLeft(el)-document.body.scrollLeft;
}	

function GEN_Position_getWindowOffsetTop (el) {
   return GEN_Position_getPageOffsetTop(el)-document.body.scrollTop;
}


