/*
	Globale Javascripts.
	29.03.2007
*/



// onloadRegistrierer. Beispiel:  addLoadEvent(functionsName);
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

var newWin;
var xPath = "/scripts/x/x_core.js";

function imgPopUp(cont,text, winname,w,h,scroll) {
	var width1 = (w)? (w) : 700;
	var height1 = (h)? (h) : 500;
	var width = 10;
	var height = 10;
	var left = parseInt((screen.availWidth/2) - (width1/2));
	var top = parseInt((screen.availHeight/2) - (height1/2));
	var scrolling = (scroll == 1)? ',scrollbars=yes, resizable=yes, menubar=no' : ',scrollbars=no, resizable=yes, menubar=no'
	var param = "width=" + width + ", height=" + height + ", left=" + left + ", top=" + top;
	newWin = window.open("", winname, param + scrolling);
	newWin.resizeTo(10, 10);
		setTimeout("putInWindow('" + cont + "', '" + text + "')", 50);
		newWin.focus();
	return false;
}


function putInWindow(cont, text) {
	var newCont = "<html><head><title>Preview</title>";
	newCont += "<script type='text/javascript' src=" + xPath + "><\/script>\n";
	newCont += "<script>\n";
	newCont += "window.onload=function(){\n";
	newCont += "if(xGetElementById('textBox').innerHTML != ''){\n";
	newCont += "var ih = document.getElementById('img').height;\n";
	newCont += "var th = xHeight('textBox')+10;\n";
	newCont += "var bh = xHeight('body');\n";
	newCont += "var h = ih+th;\n";
	newCont += "var dh = h-bh;\n";
	newCont += "var w = document.getElementById('img').width;\n";
	newCont += "var bw = xWidth('body');\n";
	newCont += "var dw = w-bw;\n";
	//newCont += "alert(ih + ' - ' + th + ' - ' + h);\n";
	newCont += "window.resizeTo(w+8, 0);\n";
	newCont += "window.resizeBy(0, dh);\n";
	//newCont += "window.moveBy(-dw/2, -dh/2);\n";
	newCont += "xTop('textBox', ih);";
	newCont += "xShow('textBox');";
	newCont += "window.focus();";
	newCont += "}\n";
	newCont += "}\n";
	newCont += "\n<\/script>";
	newCont += "</head>";
	newCont += "<body id='body' style='margin: 0; padding: 0; height: 100%'>"
	newCont += "<div style='position: relative; z-index: 1; font: 11px Verdana, sans-serif; color:#8A8A8A; margin-top: 30%; text-align: center;'>Bild wird geladen...</div>";
	newCont += "<div id='imageBox' style='position: absolute; z-index: 100; top: 0'><img id='img' src='"+ cont + "' onclick='window.close();' style='cursor: pointer;' title='Fenster schließen'></div>";
	newCont += "<div id='textBox' style='position: absolute;visibility: hidden; z-index: 100; top: 0;padding: 5px 20px; font: 11px Arial, sans-serif; color:#8A8A8A;'>" + text + "</div>";
	newCont += "</body></html>";
	newWin.document.write(newCont);
	newWin.document.close();
}

function openScrollWin(url, winName, width, height)
{

 	if (width == null) { width = 600;}
 	if (height == null) { height = 440; }

	var Win = window.open(url, winName,'width='+ width + ',height=' + height + ',resizable=1,scrollbars=1,menubar=1,status=0');

    var z = parseFloat(navigator.appVersion);
    if (navigator.appName.substring(0,8) == "Netscape" || z >= 4) {
    	Win.focus();
	}
}

//Cookies
function getExpDate(days, hours, minutes)
{
    var expDate = new Date();
    if (typeof days == "number" && typeof hours == "number" && typeof minutes == "number")
	{
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
    }
	return expDate.toUTCString();
}
// utility function called by getCookie()
function getCookieVal(offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
	{
        endstr = document.cookie.length;
    }
    return decodeURI(document.cookie.substring(offset, endstr));
}
// primary function to retrieve cookie by name
function getCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
	{
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
		{
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return "";
}
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie = name + "=" + encodeURI(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain)
{
    if (getCookie(name))
	{
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


