/* DROP DOWN MENU */
var menuTimeOut=500;
var menuCloseTimer=0;
var menuItem=0;

function moreOpen(id){	
    moreCancelCloseTime();
    if(menuItem) menuItem.style.visibility='hidden';
    menuItem=document.getElementById(id);
    menuItem.style.visibility='visible';
}
function moreCancelCloseTime(){
    if(menuCloseTimer){
    	window.clearTimeout(menuCloseTimer);
    	menuCloseTimer=null;
    }
}
function moreCloseTime(){
    menuCloseTimer=window.setTimeout(moreClose, menuTimeOut);
}
function moreClose(){
    if(menuItem) menuItem.style.visibility='hidden';
}

document.onclick=moreClose; 

/* WEATHER NAMES CHANGER */
var weatherActive=true;

function weatherChanger()
{
    var img=document.getElementById("header_weather_img");
    var wea=document.getElementById("header_weather_w");
    var names=document.getElementById("header_weather_n");
    if(weatherActive){
      if(img){
          img.style.visibility='visible';
          img.style.position='relative';
      }
      
      wea.style.display='block';
      names.style.display='none';
    }
    else{
      if(img){
          img.style.visibility='hidden';
          img.style.position='absolute';
      }
        
      wea.style.display='none';
      names.style.display='block';
    }
    weatherActive=!weatherActive;
    time=setTimeout("weatherChanger()",6000);
}

function setCurrentTime(){
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    if (m < 10){m="0"+m;}
    document.getElementById('header_weather_time').innerHTML=h+":"+m;
}

function openNamesdayPopup(){
    window.open("http://www.apollo.lv/portal/namesday/", "namesday", "width=690,height=300,scrollbars=yes,titlebar=yes,left=200,top=300");
}

weatherChanger();
setCurrentTime();

/* SEARCH FORM */
function s_select(w){
    s_sel_el.className="";
    w.className="s_sel";
    s_sel_el=w;
    document.forms["cse-search-box"].search_where.value=w.id;

    if(w.id=="photo" || w.id=="video"){
        document.forms["cse-search-box"].setAttribute('target','_blank');
        var url = w.getAttribute('href');
        document.forms["cse-search-box"].setAttribute('action',url);
      
        var s_submit = document.getElementById('s_submit');
        if(s_submit)
            document.forms["cse-search-box"].removeChild(s_submit);
    } else{
        document.forms["cse-search-box"].setAttribute('target','_parent');
        document.forms["cse-search-box"].setAttribute('action','http://www.apollo.lv/portal/search/');
      
        if(w.id=='apollo'){
            //Apollo forms
            //cx - Internet CSE
            document.forms["cse-search-box"].cx_.setAttribute('value','013151892533508336857:hguwzbedlaa');
            //cx_ - Apollo CSE
            document.forms["cse-search-box"].cx.setAttribute('value','013151892533508336857:6qkt2wbtoam');
        }
        else{
            document.forms["cse-search-box"].cx.setAttribute('value','013151892533508336857:hguwzbedlaa');
            document.forms["cse-search-box"].cx_.setAttribute('value','013151892533508336857:6qkt2wbtoam');
        }

        var tmp=document.getElementById('s_submit');
        if(!tmp){
            var m = document.createElement('input');
            m.setAttribute('type', 'hidden');
            m.setAttribute('name', '_submit');
            m.setAttribute('value', '1');
            m.setAttribute('id', 's_submit');
            document.forms["cse-search-box"].appendChild(m);
        }      
    }
}

function submitSearchForm(){
    if (document.getElementById('s_search_where').value == 'c1188' ) {
        document.location = 'http://1188.apollo.lv/apollo/search/?what=' + document.forms["cse-search-box"].q.value;
        return false;
    }
    document.getElementById('s_keyword').value=document.forms["cse-search-box"].q.value;
    document.getElementById("cse-search-box").submit();
}
function openRssPopup(){
    window.open("http://www.apollo.lv/portal/rss_about", "RSS", "width=500,height=700,scrollbars=yes,titlebar=yes,left=200,top=300");
}
