/* AJAX functions */

function GetXmlHttpObject() {
  var xmlHttp;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  } catch(e) {
    // Internet Explorer
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {      
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");      
    }    
  } 
  return xmlHttp;
}

function anketa_hlasovat(anketa) {
  xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null) {
    alert ("Your browser does not support AJAX!");
    return false;
  } 
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {      
      document.getElementById('answers').innerHTML = xmlHttp.responseText;
    }
  }
  var host = location.hostname;
  var elm = document.getElementById('poll').getElementsByTagName('input');
  for(i = 0; i < elm.length; i++) {
    if(elm[i].className == 'radio-btn' && elm[i].checked == true) {
      var odpoved = elm[i].value;      
    }
  }  
  if(odpoved != undefined) {       
    xmlHttp.open("GET", "http://"+host+"/anketa-rpc?anketa="+anketa+"&odpoved="+odpoved, true);
    xmlHttp.send(null);
  }  
  return true;  
}

function video_spustit(id) {
  xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null) {
    alert ("Your browser does not support AJAX!");
    return false;
  } 
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {      
      document.getElementById('video').innerHTML = xmlHttp.responseText;
    }
  }
  var host = location.hostname;      
  xmlHttp.open("GET", "http://"+host+"/video-ajax?id="+id, true);
  xmlHttp.send(null);    
  return true;  
}

/* diskuze */
document.observe('dom:loaded', function() {   
  if($('message') && $('message').empty()) {  
    $('forum-form').hide();
    Event.observe('add-post', 'click', function(event) {
      $('forum-form').show();
      Event.stop(event);
    });  
  }  
  if($('ep_pageMetaTags')) {
    $('ep_pageMetaTags').addClassName('not4bbtext');   
  }    
});

function reply(id) {
  $('forum-form').show();
  $('input-id').writeAttribute('value', id);
  $('forum-form').scrollTo();
  return false;
}