/*
All diese Scripte wurden von Manuel Zager selbst geschrieben!
Es erfordert eine Genehmigung, wenn du sie selbst weiterverwenden willst!
bitte sei so fair und schreib mir mal ne Mail
Tutorial mit Ajax-Grundgerüst ist zu finden unter: ajax.frozenfox.at
*/


/* Hilfe starten */
function help(link) {
 document.getElementById("help").style.display = "block";
 GetText(link,"windowcontenthelp");
}

function resolution(width) {
  /* 800*600 (795*520) */
  if(width == 800)
    height = 600;
  /* 1024*768 (1019*688) */
  else if(width == 1024)
    height = 768;
  /* 640*480 (635*400) */
  else {
    width = 640;
    height = 480;
  }
  document.getElementById("windowmenuresolution").innerHTML = width+"*"+height+" ("+(width-5)+"*"+(height-80)+")";
  /* Korrektur, weil ein Browser auch Platz braucht */
  width-=5;
  height-=80; /* 120 fürn Browser -40 für die top und bottom */
  document.getElementById("resolution").style.height = (height+20)+"px";
  document.getElementById("resolution").style.width = width+"px";
  if(document.getElementById("windowcontentresolution").innerHTML == "")
    document.getElementById("windowcontentresolution").innerHTML = '<iframe id="resolutioniframe" src="./" frameborder="0"></iframe>';
  divboxon('resolution');
}

/* Ajax-Aufruf für Hilfe */
var divid = "";
var request = false;
function GetText(link,id) {
  divid = id;
  /* Request senden */
  document.getElementById(id).innerHTML = '<p><img src="cms/design/wait.gif" alt="loading..." /></p>';
   /* Request erzeugen */
  if (window.XMLHttpRequest) {
    request = new XMLHttpRequest(); /* Mozilla, Safari, Opera */
  }
  else if(window.ActiveXObject) {
    try {
      request = new ActiveXObject('Msxml2.XMLHTTP'); /* IE 5 */
    }
    catch (e) {
      try {
        request = new ActiveXObject('Microsoft.XMLHTTP'); /* IE 6 */
      }
      catch (e) {}
    }
  }
  /* überprüfen, ob Request erzeugt wurde */
  if (!request) {
    document.getElementById(id).innerHTML = "Can not create an XMLHTTP instance";
    return false;
  }
  else {
    var url = "./?cms=help";
    /* Request öffnen */
    request.open('post', url, true);
    /* Requestheader senden */
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1'); /* utf-8 */
    /* Request senden */
    request.send('help='+link);
    /* Request auswerten */
    request.onreadystatechange = interpretRequest;
  }
}
function interpretRequest() {
  /* Request auswerten */
  switch (request.readyState) {
    /* wenn der readyState 4 und der request.status 200 ist, dann ist alles korrekt gelaufen */
    case 4:
    if (request.status != 200) {
      if (request.status == "404")
        document.getElementById(divid).innerHTML = "<p>Failed to connect to server</p>";
      else
        document.getElementById(divid).innerHTML = "<p>Error: "+request.status+"</p>";
    }
    else {
      var content = request.responseText;
      /* den Inhalt des Requests in das <div> schreiben */
      document.getElementById(divid).innerHTML = content;
    }
    break;
    default:
    break;
  }
}


/* Boxen ein- und ausblenden */

function divboxon(id) {
  document.getElementById(id).style.display = "block";
}
function spanboxon(id) {
  document.getElementById(id).style.display = "inline";
}
function listboxon(id) {
  document.getElementById(id).style.display = "list-item";
}
function tableboxon(id) {
  document.getElementById(id).style.display = "table-row";
}
function boxoff(id) {
  document.getElementById(id).style.display = "none";
}

/* Bewegung von DIV-BOXEN */

var mousex = 0, mousey = 0; /* Mausposition */
var boxx = 0, boxy = 0; /* Boxposition */
var mousefollowelement = null;

function mousefollowstart(id) {
  mousefollowelement = document.getElementById(id);
  boxx = mousex - mousefollowelement.offsetLeft;
  boxy = mousey - mousefollowelement.offsetTop;
}
function mousefollowmove(Ereignis) {
/*
  mousex = document.all ? window.event.clientX : mousefollowelement.pageX;
  mousey = document.all ? window.event.clientY : mousefollowelement.pageY;
*/
  /* hier wird immer die Mausposition gespeichert */
  if(!Ereignis)
    Ereignis = window.event;
  mousex = Ereignis.clientX;
  mousey = Ereignis.clientY;
  if(mousefollowelement != null) {
    mousefollowelement.style.left = (mousex - boxx) + "px";
    mousefollowelement.style.top  = (mousey - boxy) + "px";
  }
}
function mousefollowstop() {
  mousefollowelement = null;
}

document.onmousemove = mousefollowmove;
document.onmouseup = mousefollowstop;
window.status = "ZagerCMS by Manuel Zager - ZagerCMS.de";

/* browserupdate.org */
var $buoop = {}; $buoop.ol = window.onload; window.onload=function() { if($buoop.ol) $buoop.ol(); var e = document.createElement("script"); e.setAttribute("type", "text/javascript"); e.setAttribute("src", "http://browser-update.org/update.js"); document.body.appendChild(e); }
