var ready = false;


addListener(window, 'load', initPage, false);

function addListener(element, type, expression, bubbling)
  {
    bubbling = bubbling || false;
    if(window.addEventListener)      // Standard 
      {
        element.addEventListener(type, expression, bubbling);
        return true;
        }
      else if(window.attachEvent)   // IE
            {
              element.attachEvent('on' + type, expression);
              return true;
              }
            else return false;
    }


function initPage()
  {
    ready=true;
    if (document.getElementById('login_id')) document.getElementById('login_id').focus();

    if (document.getElementById('search_input')) addListener(document.getElementById('search_input'), 'focus', function(e) {erase(e);}, false);
    if ((typeof search == 'string' ) && (search != '') && (document.getElementById('cse'))) var t = setTimeout('checkGoogle()',50); 

    img_preload=new Image(); img_preload.src='/layout/10-duvodu_a.gif';
    if (document.getElementById('katalog_anch')) img_preload=new Image(); img_preload.src='/layout/katalog_a.gif';
    }


function checkGoogle()
  { 
    GoogleSearchForm = findTagInElem(document,'gsc-search-box','form')
    GoogleSearchInput = findTagInElem(document,' gsc-input','input')
    if (GoogleSearchInput.length == 0) GoogleSearchInput = findTagInElem(document,'gsc-input','input');
    GoogleSearchBtn = findTagInElem(document,'gsc-search-button','input')
    if ((GoogleSearchForm.length == 1) && (GoogleSearchInput.length == 1) && (GoogleSearchBtn.length == 1))
      {
        objGoogleSearchForm = GoogleSearchForm[0];
        objGoogleSearchInput = GoogleSearchInput[0];
        objGoogleSearchBtn = GoogleSearchBtn[0];

        objGoogleSearchInput.focus(); 
        objGoogleSearchInput.value = search; 

        if( document.createEvent ) 
          {
            var evObj = document.createEvent('MouseEvents');
            evObj.initEvent( 'click', true, false );
            objGoogleSearchBtn.dispatchEvent(evObj);
            }
          else if( document.createEventObject ) 
            {
              objGoogleSearchBtn.fireEvent('onclick');
              }
            }
    } 


function erase(e)
  {
    if (document.getElementById('search_input').value == 'hledat...') document.getElementById('search_input').value = '';
    stopWorking(e);
    }


function findTagInElem(obj,name,type)
  {
    if (document.getElementsByTagName) {
      var elem = [];
      var e = obj.getElementsByTagName(type || "*");
      for ( var j = 0; j < e.length; j++ )
        {
          var eclass = e[j].getAttribute('class');
          eclass = eclass ? eclass : e[j].getAttribute('className');
          if (eclass==name) elem.push(e[j]);
          }
      return elem;
      }
    else return false;
    }


function stopWorking(e)
  {
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false; }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation(); }
    }


