// JavaScript Document
var time_events = new Object();
var homeIconCounter = 0;
var homeIconBlick = 0;
//function e(name){return document.getElementById(name);}

            function parsingAjatin(sign,s,r){
               if (s.indexOf(sign)==0) return s.replace(sign,'');else return r;
            };
            
            function loadResult(){
              if (http_request.readyState == 4)
                {
                if (http_request.status == 200)
                {
                  var re = http_request.responseText;

                  var adat=re.split("\n");
                  var home_icon = '';
                  for (var i=0;i<adat.length;i++){
                    home_icon=parsingAjatin('home_icon=',adat[i],home_icon);
                  }
                  if(home_icon!='') blinkHomeIcon(home_icon);
                } else {
                
                }
                }else  return false; //statusbar.innerHTML = wait_server;
            }; 


function makePOSTRequest(url, parameters, func){
             http_request = false;
             
             if (window.XMLHttpRequest)
             {
               http_request = new XMLHttpRequest();
               if (http_request.overrideMimeType) { http_request.overrideMimeType('text/html'); }
             } else if (window.ActiveXObject) {
                try { http_request = new ActiveXObject("Msxml2.XMLHTTP");}
                catch (e) { 
                  try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); }
                  catch (e) { return false; }
                } 
             }
             
             if (!http_request) {  return false; }       //alert('Cannot create XMLHTTP instance');
             http_request.onreadystatechange = func;
             http_request.open('POST', url, true);
             http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
             http_request.setRequestHeader("Content-length", parameters.length);
             http_request.setRequestHeader("Connection", "close");
             http_request.send(parameters);
             return false;
           }

function setHomepage(x){var a=x.parentNode;makePOSTRequest('/customer/ajaxis.php','xSetHomePage='+encodeURIComponent(a.href)+'&home_icon='+x.id,loadResult);return false;}

function blinkHomeIcon(theHomeIcon){
  var o=document.getElementById(theHomeIcon);
  o.parentNode.onmouseover=null;;
  o.parentNode.onmouseout=null;;
  homeIconBlick++;
  if(Math.floor((homeIconBlick/2))==(homeIconBlick/2)){
    o.style.display='block';
  }else{
    o.style.display='none';
  }
  if(homeIconBlick>10){
    homeIconBlick=0;
    o.style.display='none';
    o.parentNode.onmouseover=function(){showHomeIcon(this);};
    o.parentNode.onmouseout=function(){hideHomeIcon(this);};
    return false;
  }
  s='blinkHomeIcon(\''+theHomeIcon+'\')';
  if(time_events['blinkHomeIcon'])clearTimeout(time_events['blinkHomeIcon']);
  time_events['blinkHomeIcon']=setTimeout(s,200);
}

function loadHomeIcon(o){
  homeIconCounter++;var alt='';
  var img_id='set_homepage_'+String(homeIconCounter);
  if(NASTAV_AKO_DOMOVSKU_STRANKU_V_ETARGET)alt = ' alt="'+NASTAV_AKO_DOMOVSKU_STRANKU_V_ETARGET+'" title="'+NASTAV_AKO_DOMOVSKU_STRANKU_V_ETARGET+'" ';
  o.innerHTML = '<img id="'+img_id+'" src="/img/homepage.png" class="miniicon" '+alt+' style="position:absolute;z-index:2;float:left;margin-top:-10px;margin-left:-10px;display:none;" onclick="return setHomepage(this);">'+o.innerHTML;
  o.onmouseover=function(){showHomeIcon(this);};
  o.onmouseout=function(){hideHomeIcon(this);};
  showHomeIcon(o);
}

function hideHomeIcon(o){
  var i=o.getElementsByTagName('IMG');
  var img_id=i[0].id;
  var s="e('"+img_id+"').style.display='none';";
  if(time_events[img_id])clearTimeout(time_events[img_id]);
  time_events[img_id]=setTimeout(s,300);
}

function showHomeIcon(o){
  var i=o.getElementsByTagName('IMG');
  var img_id=i[0].id;
  var s="e('"+img_id+"').style.display='block';";
  if(time_events[img_id])clearTimeout(time_events[img_id]);
  time_events[img_id]=setTimeout(s,1200);
}