﻿// JScript File

function binSearch(list,text) 
{ 
    var Lo = 0, Hi = list.options.length-1;
    //CT.2006.07.21 skip eventuele ... waarden    
    if (list.options[Hi].value == "..." && Hi > 0)
        --Hi;
        
    var pivot = Lo;
    text.toLowerCase();

    if(text < list.options[Lo].value.toLowerCase())
    {            
        return -1; //the word is on a previous page return -1
        
    }
    if(text > list.options[Hi].value.toLowerCase())
    {
        return -2; //the word is on a next page return -2
    }

    while(Lo < Hi)
    {
        pivot = Math.floor((Lo+Hi)/2);
        if(text > list.options[pivot].value.toLowerCase())
        {
            Lo = pivot + 1;
            if(text <= list.options[Lo].value.toLowerCase()) 
            {                
              return Lo;
            }
        }
        else if(text < list.options[pivot].value.toLowerCase())
        {
            Hi = pivot - 1;
            if(text > list.options[Hi].value.toLowerCase())
            { 
                return pivot;                
            }
            else if(text == list.options[Hi].value.toLowerCase())
            {
                return Hi;
            }
        }
        else
        {
            return pivot;
        }
    }        
    return pivot;
}
      
function removeDelimiters(input, delimiter)
/*cc:removes delimiter from the beginning of the string*/
{
  var ind = 0;
  while (input.charAt(ind) == delimiter)
    ind++;
  if (ind > 0)
    input = input.substr(ind, input.length - ind);
  return input;
}      
      
      function interrogate(what) 
      {
        var output = '';
        for (var i in what)
            output += i + ' ';
        alert(output);
      }

function LoginIfEnterPressed(e, oDocument)
{
  
  if (document.all)
  {
    wdw = e;
    s = '';
    k = wdw.event.keyCode;
  }
  else
  {
    k = window.which;
  }
  if (k==13)
  {
    var oBtnLogin=oDocument.getElementById("CtrlLeftmenu$btnLogin");
    if (!oBtnLogin)                       
      oBtnLogin=oDocument.getElementById("ControlLeftmenu$btnLogin");
    
    var oForm=oDocument.getElementById("frmMain");
    if (!oForm)
      oForm=oDocument.getElementById("frmBestel");
    if (oForm)
    {
      oForm.onkeypress = "";
    }
    if (oBtnLogin)
      oBtnLogin.click();
  }
  return false;
}
