//----------------------------------------------
function SetFocusColor(p_obField,p_bFocus) {
//----------------------------------------------
  ele_type = p_obField.type;
  if (p_bFocus) {
    if (ele_type != "radio" && ele_type != "checkbox" && ele_type != "select-one") {
      p_obField.style.backgroundColor = l_strCOLORONFOCUS;
    }
  } else {
    if (ele_type != "radio" && ele_type != "checkbox" && ele_type != "select-one") {
      p_obField.style.backgroundColor = l_strCOLORONBLUR;
    }
  }
}

//--------------------------------------------------
function HexEncodeString(p_str) {
//--------------------------------------------------
  var g_achHex = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  var l_str = new String();
  for (i = 0; i < p_str.length; i++) {
    var l_n = p_str.charCodeAt(i);
    l_str += g_achHex[(l_n >> 4) & 0x0F] + g_achHex[l_n & 0x0F];
  }
  return l_str + "00";
}

// Suchen - Absenden Suchformular
// aufgerufen, wenn im Suchfenster Return betätigt (über SubmitHandler der Form)
// unterscheidet, welche Art der Suche gestartet wird
//--------------------------------------------------
function SearchFormByReturn(p_lAppSearch, p_bEmplSearch, p_strInputSearch, p_strClientControlPath) {
//--------------------------------------------------
  if(p_lAppSearch) {
    //Anwendungssuche
    SearchForm(1, p_strInputSearch, p_strClientControlPath);
  } else if(p_bEmplSearch) {
    //Mitarbeitersuche
    SearchForm(2, p_strInputSearch, p_strClientControlPath);
  }
  return;
}

//--------------------------------------------------
function SearchForm(p_lSearchCase, p_strInputSearch, p_strClientControlPath) {
//--------------------------------------------------
  l_strQuery=document._UpSearchForm.fr_strWord.value;
  if(l_strQuery.length == 0 && p_lSearchCase != 3) {
    alert(p_strInputSearch);
    document._UpSearchForm.fr_strWord.focus();
    return; 
  }
  //Mitarbeitersuche nur, wenn Formrights auf Benutzerseite hat
  if (p_lSearchCase == 2) {
    // Mitarbeitersuche
    l_strQuery = HexEncodeString(l_strQuery);
    l_strQuery=escape(l_strQuery);
    l_strUrl = p_strClientControlPath + 'UpApplications/UpSystem/CtsUserManager/ListUser.asp?rq_strQuery=' + l_strQuery;

    if(!self.wndShowUser) {
      wndShowUser = window.open(l_strUrl, 'UpPopup','dependent=yes,resizable=yes,width=750,height=600,screenX=100,screenY=100,scrollbars=yes');
    } else {
      if (self.wndShowUser.closed) {
          wndShowUser = window.open(l_strUrl, 'UpPopup','dependent=yes,resizable=yes,width=750,height=600,screenX=100,screenY=100,scrollbars=yes');
      } else {
          self.wndShowUser.document.location.href = l_strUrl;
          self.wndShowUser.focus();
      }
    }
  } else {
    l_strQuery=HexEncodeString(l_strQuery);
    if (p_lSearchCase == 3) {
      // Erweiterte Suche
      l_strUrl = p_strClientControlPath + 'UpApplications/UpArea/searchdetail.asp?rq_bPopUp=1&fr_strWord=' + l_strQuery;
    } else {
      // Anwendungssuche
      l_strUrl = p_strClientControlPath + 'UpApplications/UpArea/UpSearch.asp?rq_bPopUp=1&fr_strWord=' + l_strQuery;
    }
    if(! self.SearchWin) {
      SearchWin = window.open(l_strUrl,'UpPopup','width=800,height=600,screenX=100,screenY=100,dependent=yes,menubar=no,locationbar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes');
    } else {
      if (self.SearchWin.closed) {
        SearchWin = window.open(l_strUrl,'UpPopup','width=800,height=600,screenX=100,screenY=100,dependent=yes,menubar=no,locationbar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes');
      } else {
        self.SearchWin.document.location.href = l_strUrl;
        self.SearchWin.focus();
      }
    }
  }
}

//----------------------------------------------------------------------------
function showhover(event,p_strHover) {
//----------------------------------------------------------------------------
  if ( window.event ) { event = window.event; }
  if ( ! document.getElementById(p_strHover) )
    return false;
  objHover = document.getElementById(p_strHover);
  objHover.style.display = "block";
  objHover.style.top = event.clientY;
  objHover.style.left = event.clientX;
}
//----------------------------------------------------------------------------
function hidehover(p_strHover) {
//----------------------------------------------------------------------------
  if ( ! document.getElementById(p_strHover) )
    return false;
  objHover = document.getElementById(p_strHover);
  objHover.style.display = "none";
}

//----------------------------------------------------------------------------
function SwitchModeDate(p_oField) {
//----------------------------------------------------------------------------

  if ( typeof p_oField == 'undefined' ) {
    document.forms[0].xUseDateFilter.checked = false;
    //document.forms[0].xLastChanged.checked = false;
    document.forms[0].xdtFilter.value = '';
    document.forms[0].xdtFilter.disabled = 'disabled';
    document.forms[0].xstrCondition.disabled = 'disabled';
    return;
  }

  if ( p_oField.name == 'xUseDateFilter' ) {
    document.forms[0].xdtFilter.disabled = '';
    document.forms[0].xstrCondition.disabled = '';
    //document.forms[0].xLastChanged.checked = false;
  } else {
    document.forms[0].xdtFilter.disabled = 'disabled';
    document.forms[0].xUseDateFilter.checked = false;
  }
}

//----------------------------------------------------------------------------
function SwitchModeDocs(p_oField) {
//----------------------------------------------------------------------------
  if ( typeof p_oField == 'undefined' ) {
    document.forms[0].xExcludeFileWalker.checked = false;
    document.forms[0].xExcludeDocs.checked = false;
    return;
  }
  if ( p_oField.name == 'xExcludeDocs' && document.forms[0].xExcludeDocs.checked == true ) {
    document.forms[0].xExcludeFileWalker.checked = true;
    return;
  }
  if ( p_oField.name == 'xExcludeFileWalker' && document.forms[0].xExcludeDocs.checked == true ) {
    document.forms[0].xExcludeFileWalker.checked = true;
  }
}

//----------------------------------------------------------------------------
function SwitchMode(p_oField) {
//----------------------------------------------------------------------------

  if ( typeof p_oField == 'undefined' ) {
    document.forms[0].xUseTemplSearch.checked = false;
    document.forms[0].xUseAppSearch.checked = false;
    document.forms[0].xTemplSearch.selectedIndex = 0;
    document.forms[0].xAppSearch.selectedIndex = 0;
    document.forms[0].xTemplSearch.disabled = 'disabled';
    document.forms[0].xAppSearch.disabled = 'disabled';
    return;
  }

  if ( p_oField.name == 'xUseAppSearch' ) {
    document.forms[0].xUseTemplSearch.checked = false;
    document.forms[0].xTemplSearch.selectedIndex = 0;
    document.forms[0].xTemplSearch.disabled = 'disabled';
    if ( document.forms[0].xUseAppSearch.checked == true ) {
      document.forms[0].xAppSearch.disabled = '';
    } else {
      document.forms[0].xAppSearch.disabled = 'disabled';
      document.forms[0].xAppSearch.selectedIndex = 0;
    }
  } else {
    document.forms[0].xUseAppSearch.checked = false;
    document.forms[0].xAppSearch.selectedIndex = 0;
    document.forms[0].xAppSearch.disabled = 'disabled';
    if ( document.forms[0].xUseTemplSearch.checked == true ) {
      document.forms[0].xTemplSearch.disabled = '';
    } else {
      document.forms[0].xTemplSearch.disabled = 'disabled';
      document.forms[0].xTemplSearch.selectedIndex = 0;
    }
  }
}

//----------------------------------------------------------------------------
function SwapRangeImg(p_lID, p_lPackId, p_strPathSeperator) {
//----------------------------------------------------------------------------
  l_oSource = document.getElementById('range' + p_lID + '_' + p_lPackId);
  var RegEx = /range_in.gif$/gi;
  if ( RegEx.test(l_oSource.src) ) {
    l_oSource.src = p_strPathSeperator + 'images/assets/range/range_out.gif';
  } else {
    l_oSource.src = p_strPathSeperator + 'images/assets/range/range_in.gif';
  }
}

//----------------------------------------------------------------------------
function SwapDetailImg(p_lID, p_lPackId, p_strPathSeperator) {
//----------------------------------------------------------------------------
  l_oSource = document.getElementById('detail' + p_lID + '_' + p_lPackId);
  var RegEx = /minus.gif$/gi;
  if ( RegEx.test(l_oSource.src) ) {
    l_oSource.src = p_strPathSeperator + 'images/assets/plus.gif';
  } else {
    l_oSource.src = p_strPathSeperator + 'images/assets/minus.gif';
  }
}

//----------------------------------------------------------------------------
function ViewPump(p_lID, p_lPackId, p_lAppId, p_bPopUp) {
//----------------------------------------------------------------------------
  if ( p_bPopUp ) {
    opener.top.UpNavigate.location.href = '__searchPump.asp?rq_lDBId=' + p_lID + '&rq_lPackId=' + p_lPackId + '&rq_lAppId=' + p_lAppId + '&p_bApp=0';
  } else {
    self.location.href = '__searchPump.asp?rq_lDBId=' + p_lID + '&rq_lPackId=' + p_lPackId + '&rq_lAppId=' + p_lAppId;
  }
}

//----------------------------------------------------------------------------
function ViewDetail(p_lID, p_lPackId, p_lAppId, p_lFormdId, p_strPathSeperator) {
//----------------------------------------------------------------------------
  l_oSource = document.getElementById('SID_' + p_lID + '_' + p_lPackId);
  if ( l_oSource.style.display == 'none' ) {
    l_oSource.style.display = 'block';
    window.searchprocess.location.href= p_strPathSeperator + '_UpInclude/script/searchDetail.asp?rq_lId=' + p_lID + '&rq_lPackId=' + p_lPackId + '&rq_lAppId=' + p_lAppId + '&rq_lFormId=' + p_lFormdId;
  } else {
    l_oSource.style.display = 'none';
  }
}

//----------------------------------------------------------------------------
function SubmitPage(p_bDetailMode,p_lCntStart, p_bPopUp) {
//----------------------------------------------------------------------------
  if ( p_bDetailMode == true ) {
    var l_arrFieldList  = new Array('xlPageIdx','fr_strHiddenWord','fr_strWord','xdtFilter','xstrCondition','xUseDateFilter','xUseAppSearch','xAppSearch','xUseTemplSearch','xTemplSearch','xExcludeFileWalker','xExcludeDocs','xUseDetailView');
  } else {
    var l_arrFieldList  = new Array('xlPageIdx','fr_strHiddenWord','fr_strWord');
  }
  var l_strPageTarget = window.document.forms[0].action + '?rq_bPaging=true';
  window.document.forms[0].xlPageIdx.value=p_lCntStart;
  for (var i=0; i<=l_arrFieldList.length-1; i++ ) {
    var l_oTmp = eval('window.document.forms[0].'+l_arrFieldList[i]);
    if ( typeof l_oTmp != 'undefined' )
      l_strPageTarget = l_strPageTarget + '&' + l_oTmp.name + '=' + l_oTmp.value;
  }
  if ( p_bPopUp ) MaskValue();
  return l_strPageTarget;
}