/**
* JS pro vyber polozek select listu podle vice pocatecnich pismen
*/

function __getDdlKey(e)
{
  var code;
  if (!e)
    var e = window.event;
  if (e.keyCode)
    code = e.keyCode;
  else
   if (e.which)
     code = e.which;
  return code;
}

var lastValue = '';
var listChooserTimer = null;
var chooserInputSecondClick = false;
var oldListChooserInputName = "";

function __searchDdlReset(formName,actionInputName,scr)
{
    if (scr == undefined)
        scr = "scr";    
  if (lastValue != '') 
  {
    if (actionInputName != undefined)
      eval("document." + formName + "."+ actionInputName + ".value='" + scr + "'");
    if (formName != undefined)  
      eval("document." + formName + ".submit()");   
  }
  lastValue = '';
}

/*
*   odesle formular po druhem kliku na stejny select list
*/
function __searchSubmitSecondClick(eventObj,formName,actionInputName,scr)
{
    if (scr == undefined)
        scr = "scr";
  if (chooserInputSecondClick && oldListChooserInputName == eventObj.name) 
  {
    if (actionInputName != undefined)
      eval("document." + formName + "."+ actionInputName + ".value='" + scr + "'");
    if (formName != undefined)  
      eval("document." + formName + ".submit()"); 
      
    return;    
  }    
  oldListChooserInputName = eventObj.name;
  chooserInputSecondClick = !chooserInputSecondClick; 
}

/*
*   odesle formular po druhem kliku na stejny select list (Pro pouziti ve filtrech)
*/
function __searchSubmitSecondClickFilter(eventObj)
{    
  if (chooserInputSecondClick && oldListChooserInputName == eventObj.name) 
  {
    document.form_filter.filter_action.value='search';
    document.form_filter.show_list.value='';
    submit_filter();
    document.form_filter.submit();      
    return;    
  }    
  
  oldListChooserInputName = eventObj.name;
  chooserInputSecondClick = !chooserInputSecondClick; 
}


function __searchDdlList(eventObj,slcObj,formName,actionInputName,scr)
{
  if (scr == undefined)
        scr = "scr";   
    
  if (navigator.userAgent.indexOf('MSIE') > -1 || navigator.userAgent.indexOf('Opera') > -1)
  {
    if (listChooserTimer) clearTimeout(listChooserTimer);
    listChooserTimer = setTimeout("lastValue = ''", 2000);
    var lastKey = __getDdlKey(eventObj);
    
    if (lastKey == 13)
    {
      __searchDdlReset(formName,actionInputName,scr);
    }
    if (lastKey == 8 && lastValue.length > 1)
      lastValue = lastValue.substring(0,lastValue.length-1);
    else
      lastValue += String.fromCharCode(lastKey); 

    used = false
    for (i=0; i<slcObj.length; i++)
    {
      if ((slcObj.options[i].text.toLowerCase().indexOf(lastValue.toLowerCase()) == 0) && (lastValue.value != '') && !used)
      {
        slcObj.options[i].selected = true;
        used = true;        
      }
      else
      {
        slcObj.options[i].selected = false;
      }
    }
  
    return false;
  }
  else
    return true;
}

