

// CONFIG
var cfg_legend		= '&nbsp;KCN Systemnachricht&nbsp;';		// complete URL
var cfg_iconpath	= '/layout/icon/48/2e2f2f/';				// complete URL
var cfg_okbutton	= '/layout/button/100/2e2f2f/OK.png';		// complete URL

var cfg_showtime = 8;											// in seconds
var cfg_overlay_duration = 0.2;									// in seconds
var cfg_overlay_opacity	= 0.8;									// in percent (float)


///////////////////////////////////////////////////////////////////////



// Timeout Variable
var closeSysmsg;


// DIVs erstellen
document.write('<style type="text/css">#sysmsg_overlay, #sysmsg {  position: absolute; left: 0px; top: 0px;}body > div#sysmsg_overlay, div#sysmsg {  position: fixed;}</style><!--[if gte IE 5.5]><![if lt IE 7]><style type="text/css">div#sysmsg_overlay, div#sysmsg {  left: expression( ( 0 + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + \'px\' );  top: expression( (  0 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + \'px\' );}</style><![endif]><![endif]-->');
document.write('<DIV ID="sysmsg_overlay" STYLE="display:none; z-index: 950;" onclick="sysmsg_hide();"></DIV>');
document.write('<DIV ID="sysmsg" STYLE="z-index: 951; display:none;" onclick="sysmsg_hide();"><CENTER><DIV STYLE="width: 700px;"><FIELDSET ID="sysmsg_fieldset" STYLE="border:1px solid #AAA; color: #999; background-color: #2e2f2f; "><LEGEND STYLE="color: #ffffff;">' + cfg_legend + '</LEGEND><DIV ID="sysmsg_text"></DIV><DIV ID="sysmsg_subtext" STYLE="line-height: 24px;"></DIV></FIELDSET></DIV></CENTER></DIV>');


function sysmsg(msg,submsg,icon,autohide)
{
	var arrayPageSize = getPageSize();
	
	clearTimeout(closeSysmsg);


	document.onkeydown = sysbox_closeByKey;


	document.getElementById('sysmsg_overlay').style.width = arrayPageSize[0] + 'px';
	document.getElementById('sysmsg_overlay').style.height = arrayPageSize[1] + 'px';

	document.getElementById('sysmsg').style.width	= arrayPageSize[0] + 'px';
	document.getElementById('sysmsg').style.margin	= arrayPageSize[3]/4 + 'px auto';

	if(typeof icon == "undefined")
		icon = 'check';

	if(typeof autohide == "undefined")
		autohide = true;


	document.getElementById('sysmsg_text').innerHTML = '<IMG SRC="' + cfg_iconpath + icon + '.png" STYLE="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop src=\'' + cfg_iconpath + icon + '.png\'); margin-right: 10px; vertical-align: middle;">' + msg;
	
	if(typeof submsg != "undefined" && submsg != "" && autohide == true)
		document.getElementById('sysmsg_subtext').innerHTML = submsg + '<BR><BR>';
	else if(typeof submsg != "undefined" && submsg != "" && autohide != true)
		document.getElementById('sysmsg_subtext').innerHTML = submsg +'<DIV STYLE="text-align: right;"><IMG STYLE="margin-top: 30px; cursor: pointer;" SRC="' + cfg_okbutton +'"></DIV>' ;
	else	
		document.getElementById('sysmsg_subtext').innerHTML = '';



	new Effect.Appear('sysmsg_overlay', { duration: cfg_overlay_duration, from: 0.0, to: cfg_overlay_opacity });
	new Effect.Appear('sysmsg', { duration: 0.5 });


	if(	autohide == true )
		closeSysmsg = setTimeout('sysmsg_hide()',cfg_showtime * 1000);
}



function sysmsg_hide()
{
	document.onkeydown = '';

	new Effect.Fade('sysmsg_overlay', { duration: cfg_overlay_duration});
	new Effect.Fade('sysmsg', { duration: cfg_overlay_duration});
}



function sysbox_closeByKey(e)
{

	if (e == null) { // ie
		keycode = event.keyCode;
		escapeKey = 27;
	} else { // mozilla
		keycode = e.keyCode;
		escapeKey = e.DOM_VK_ESCAPE;
	}

	key = String.fromCharCode(keycode).toLowerCase();
		
	//if(keycode == "27" || keycode == "13" || keycode == "32")
	//{
		sysmsg_hide();
		return false;
	//}

}











// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------


function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}

