/*
 * Xore::Blog JavaScript File
 * by Christopher Starke
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
var http_request = false;
function getContent(param,postvar) {

 if(postvar==null) {
  postvar=false;
 }

 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) {}
  }
 }
 if(!http_request) {
  document.getElementById('content').innerHTML = '<div style="margin-top:10px;color:#EEEEEE;text-align:center;">Konnte keine Anfrage erstellen.<br />Bitte verwenden Sie einen neueren Browser und aktivieren Sie JavaScript vollständig.</div>';
  return false;
 }
 http_request.onreadystatechange = alertContents;
 if(postvar==false) {
  http_request.open('GET', '/ajaxContent.php?' + param, true);
  http_request.send(null);
 } else {
  http_request.open('POST', '/ajaxContent.php', true);
  http_request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  http_request.setRequestHeader('Content-length', postvar.length);
  http_request.setRequestHeader('Connection', 'close');
  http_request.send(postvar);
 }
}

function alertContents() {
 if(http_request.readyState == 4) {
  if(http_request.status == 200) {
   result = http_request.responseText;
   document.getElementById('content').innerHTML = result;            
  } else {
   document.getElementById('content').innerHTML = '<div style="margin-top:10px;color:#EEEEEE;text-align:center;">Es gab ein Problem mit der Abfrage.<br />Bitte versuchen Sie es erneut.</div>';
  }
 } else {
   document.getElementById('content').innerHTML = '<center style="color:#EEEEEE;margin-top:25px;">Seite wird geladen...</center>';
 }
}

function GetRandom(min, max) {
 if(min > max) {
  return(-1);
 }
 if(min==max) {
  return(min);
 }
 return(min + parseInt(Math.random() * (max-min+1)));
}

function newCaptcha(url) {
 document.getElementById('captcha').src=url+'?x='+GetRandom(1,99);
}

function showSmileys() {
 document.getElementById('smileyBox').style['display'] = 'block';
}

function insertSmiley(obj,str) {
 wo = obj;
 was = str;

 if(document.selection) { //IE
  wo.focus();
  sel = document.selection.createRange();
  sel.text = was;
 } else if(wo.selectionStart || wo.selectionStart == '0') { //MOZILLA/NETSCAPE
  var startPos = wo.selectionStart;
  var endPos = wo.selectionEnd;
  wo.value = wo.value.substring(0, startPos) + was + wo.value.substring(endPos, wo.value.length);
 } else {
  wo.value += was;
 }
 wo.focus();
}

function doSearch(Ereignis) {
 if(!Ereignis) {
  Ereignis = window.event;
 }

 if(navigator.appName == 'Microsoft Internet Explorer') {
  if(event.keyCode == 13) {
   getContent('search='+document.getElementById('searchboxreal').value);
  }
 } else if(navigator.appName != 'Microsoft Internet Explorer') {
  if(Ereignis.which == 13) {			
   getContent('search='+document.getElementById('searchboxreal').value);
  }
 }
}

function showOrHide(obj) {
 var object = document.getElementById(obj);
 if(object != null) {
  if(object.style['display'] == 'none') {
   object.style['display'] = 'block';
  } else {
   object.style['display'] = 'none';
  }
 }
 return false;
}

