
function createRequestAndFill(url,method,data,target) 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
  {
    alert("Error creating the XMLHttpRequest object.");
  }
  else 
  {
    xmlHttp.onreadystatechange = function() 
    {
      //fillElementByRequest(target,xmlHttp) 
      if (xmlHttp.readyState == 4) 
      {
        ///if (target=="") alert(xmlHttp.responseText);
        
        if (xmlHttp.status == 200) 
        {
          if (target=="" && xmlHttp.responseText!="")
           alert(xmlHttp.responseText);
          else
          {
            document.getElementById(target).innerHTML = xmlHttp.responseText;
          }
        }
        else 
        {
          if (target!="")
          document.getElementById(target).innerHTML = "NA";
        }
      }
    };
    
    if(method=="GET")
    {
      url+="?"+data;
      data="";
    }
    
    xmlHttp.open(method, url, true);
    if (method=="POST")
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(data);
  }
}

function setCookie(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+
  ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}  
  
function getCookie(c_name)
{
  if(document.cookie.length>0)
  {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
    { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}

function page_refresh()
{
  //createRequestAndFill("all_users_count.php","POST","","user_stats"); //botton line refresh
  //createRequestAndFill("check_realm.php","POST","","realm_status1"); //real status check
  //createRequestAndFill("check_realm.php","POST","","realm_status2"); //real status check
  createRequestAndFill("/shoutboard/shoutboard_send.php","POST","","shout-text"); //shoutboard refresh
}

function URLEncode(text)
{
  // Nahrazeni ampersandu a ostatnich znaku
  text = text.replace(/&/g,"%26");
  text = text.replace(/\+/g,"%2B");
      
  return text;
}

function VoteCount(banner_id)
{
  createRequestAndFill("/banner_vote.php","POST","banner_id="+banner_id,""); //add vote to reward system
}
  
function getTextAreaSelection(id)
{
  //IE support
  if (document.selection)
  {
    id.focus();
    sel = document.selection.createRange();
    return sel.text;
  }
  //MOZILLA/NETSCAPE support
  else if (id.selectionStart || id.selectionStart == '0')
  {
    return id.value.substring(id.selectionStart, id.selectionEnd);
  }
  return "";
}

function setTextAreaSelection(id, text)
{
  //IE support
  if (document.selection)
  {
    id.focus();
    sel = document.selection.createRange();
    sel.text = text;
  }
  //MOZILLA/NETSCAPE support
  else if (id.selectionStart || id.selectionStart == '0')
  {
    var startPos = id.selectionStart;
    var endPos = id.selectionEnd;
    id.value = id.value.substring(0, startPos)
    + text
    + id.value.substring(endPos, id.value.length);
  }
  else
  {
    id.value += text;
  }
}


function getMouseXY(e)
{
  if (!e)
  {
    var e=window.event
  }
  if (e.pageX || e.pageY)
  {
    mysX=e.pageX;
    mysY=e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    mysX=e.clientX+(document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    mysY=e.clientY+(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  }
}

document.onmousemove=getMouseXY;

function tooltip(id, show)
{
  var tooltip = null;
  tooltip = document.getElementById(id);
  tooltip.style.left = mysX+1+"px";
  tooltip.style.top = mysY+1+"px";
  if (show == 1) tooltip.style.display = 'block';
  else tooltip.style.display = 'none';
}

function getInvitation(e)
{
  document.getElementById('invitation').innerHTML = '<img src="/img/loading2.gif">';
  createRequestAndFill('invite.php','post','','invitation');
  e.preventDefault();
  return false;
}


function article_delete()
{
  return confirm("Do you really want to delete this article?");
}
