function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function ajax_sup(addr,post_data, fnc) {
var h=false;
post_data=post_data.replace("+", "%2B");
post_data+='&ajax=ano';
if (window.XMLHttpRequest) { // Mozilla, Safari,...
h=new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
h=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
  h=new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
  h=false;
}
}
}
if(!h) {
alert('AJAX nekompatibilní prohlížeč :-(');
return;
} else {
h.onreadystatechange = function() {
if(h.readyState==4) {
  if(h.status == 200) {
    fnc(h);
  } else {
  }
}
};
h.open('POST', addr, true);
h.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
h.send(post_data);
}
}

function ajaxrepla(txt) {
  while(txt.indexOf('&')>-1 || txt.indexOf('+')>-1 || txt.indexOf('=')>-1) {
    txt=txt.replace('&', '%26').replace('+', '%2B').replace('=', '%3D');
  }
  return txt;
}

addLoadEvent(function() {
  ajax_sup('/maily.php','',function(h) {
    var maily=Array();
    var xmaily=h.responseXML.getElementsByTagName('mail');
    if(xmaily.length>0) {
      for(i=0;i<xmaily.length;i++) {
        maily[xmaily[i].getElementsByTagName('hash')[0].firstChild.nodeValue]=xmaily[i].getElementsByTagName('jmeno')[0].firstChild.nodeValue+'@'+xmaily[i].getElementsByTagName('domena')[0].firstChild.nodeValue;
      }
    }
    var hrefy=document.getElementsByTagName('a');
    if(hrefy.length>0) {
      for(i=0;i<hrefy.length;i++) {
        if(maily[hrefy[i].title]) {
          hrefy[i].innerHTML=maily[hrefy[i].title];
          hrefy[i].href='mailto:'+maily[hrefy[i].title];
          hrefy[i].title='Poslat email na '+maily[hrefy[i].title];
          hrefy[i].onclick=function() {};
        }
      }
    }
  });
});
