/*
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
#                                                       #
#               FOOTERPANEL ADDON  v2.0.1               #
#                    FOR WEBSPELL 4.X                   #
#              COPYRIGHT 2010 BY HENNING K              #
#                LICENSED UNDER GNU GPL                 #
#             CONTACT: DarkGrafix@gmail.com             #
#                  SPECIAL THANKS TO:                   #
#                        PHIL                           #
#                    FAMFAMFAM.COM                      #
#                                                       #
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
*/
function TasteGedrueckt (Ereignis) {
  if (!Ereignis)
    Ereignis = window.event;
  if (Ereignis.which) {
    Tastencode = Ereignis.which;
  } else if (Ereignis.keyCode) {
    Tastencode = Ereignis.keyCode;
  }
  if(Tastencode == 113) {
  fpRefresh();
  } else {
  }

}
document.onkeydown = TasteGedrueckt;

function setFocus()	{
document.footerpanelshout.eintrag.focus()
}

curmodule = "";
curtitle = "";
fpdisplay = (fpdisplay = handleCookie('read','fp_display')) === false ? 1 : Number(fpdisplay);
curparameters = "";
   function footerpanelcal(m, y) {
      $('#fp_ajaxbox').load('../inc/footerpanel.php?modul=kalender&month=' + m + '&year=' + y);

}

     function shoutSubmit2() {
      $.post('../shout/index.php?ajax', $('#footerpanelshout').serialize(),function(req) {
        if(req) alert(req.replace(/  /g, ' '));
        $('#footershout').load('../inc/ajax.php?modul=shout');
		fpRefresh();
        if(!req) $('#footershouteintrag').attr('value', '');		
      });
      return false;
    }
	
function fpLoad(modul,parameter,name){
	if(curmodule == modul && curparameters == parameter){
		document.getElementById("fp_ajaxwrap").style.display = 'none';
		curmodule = '';
		curparameters = '';
	}
	else{
		document.getElementById("fp_ajaxwrap").style.display = 'block';
		if(name != undefined) document.getElementById("fp_ajaxtitle").innerHTML = '&raquo;&nbsp;' + name;
			else document.getElementById("fp_titlebar").style.display = 'none';
		curmodule = modul;
		curparameters = parameter;
		fetch('../inc/footerpanel.php?modul=' + modul + '&' + parameter,'fp_ajaxbox','replace','event');

	}
}

function fpRefresh(){
	fetch('../inc/footerpanel.php?modul=' + curmodule + '&' + curparameters,'fp_ajaxbox','replace','event');
}

function fpClose(){
	document.getElementById("fp_ajaxwrap").style.display = 'none';
	curmodule = '';
	curparameters = '';
}

function toggleFooterpanel(bycookie) {
	if(bycookie) {
		if(fpdisplay == 0) {
			document.getElementById('fp_wrap').style.display = 'none';
			document.getElementById('fp_maximize').style.display = 'block';
		}
	}
	else {
		if(fpdisplay) {
			document.getElementById('fp_wrap').style.display = 'none';
			document.getElementById('fp_maximize').style.display = 'block';
			fpdisplay = 0;
			handleCookie('write','fp_display','0');
		}
		else {
			document.getElementById('fp_wrap').style.display = 'block';
			document.getElementById('fp_maximize').style.display = 'none';			
			fpdisplay = 1;
			handleCookie('write','fp_display','1');
		}
	}
}

function handleCookie(mode,name,value) {
	if(mode == 'read' && name) {
			var cvalue = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
			return cvalue ? cvalue[2] : false;
	}
	else {
		if(mode == 'write' && name && value) {
			document.cookie = name + '=' + value + ';';
			return true;
		}
		else return false;
	}
}

function eventfetch(url,id,action){
  postRequest(url,id,action);
}
//fetch data for timebased events
function timefetch(url,id,action,milliseconds) {
	eventfetch(url,id,action);
  setTimeout(function () { timefetch(url,id,action,milliseconds); },milliseconds);
}
//generic fetch function, accepts 5 parameters (first 4 mandatory).
//url = script to access on the server
//id = html id (for example of a div, a form field etc.., works with all tags which accept an id)
//action = add, replace, return or formfield, add adds up content at the end of the original content in the id element, replace replaces the complete content in the id element, formfield replaces a form field value, return simply returns the fetched data
//base = time or event, time based means script will autoexecute itself every amount of milliseconds specified via the 5th parameter, event based means you are calling the funtion with something like onclick, onchange, onmouseover or directly in a script
//milliseconds = time in milliseconds till the script should autoexecute itself again (only needed when base==time)
function fetch(url,id,action,base,milliseconds){
	if(base == "event"){
		eventfetch(url,id,action);
	}
	else if(base == "time"){
		timefetch(url,id,action,milliseconds);
	}
}
function postRequest(strURL,id,action) {
  var xmlHttp;
  if (window.XMLHttpRequest) { 
    var xmlHttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) { 
    var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlHttp.open('POST', strURL, true);
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
      updatepage(xmlHttp.responseText,id,action);
    }
  }
  xmlHttp.send(strURL);
}
//update target
function updatepage(str,id,action){
	if (action == "add"){
    document.getElementById(id).innerHTML+=str;
	}
	else if (action == "replace"){
		document.getElementById(id).innerHTML=str;
	}
	else if (action == "formfield"){
		document.getElementById(id).value =trim(str);
	}
	else if (action == "return"){
		return str;
	}
	else if (action == "execute"){
		eval(str);
	}
}
