//
//	$Id: global_functions.js,v 1.8 2009/10/02 10:35:45 volker Exp $
//

function openWindow (url, params) {
	window.open (url, '', params);
}


function ws_open_centered_window (u, n, w, h, p) {
  lp = (screen.width) ? (screen.width - w) / 2 : 100;
  tp = (screen.height) ? (screen.height - h) / 2 : 100;
  return window.open (u, n, 'width='+w+',height='+h+',top='+tp+',left='+lp+','+p);
}


var tobj = 0;
var czoom = 100;
var isIE = (document.all) ? true : false;
var zoomurl = '';

function settime() {
	var d = new Date();
	var h = (String(d.getHours()).length == 1) ? "0" + d.getHours() : d.getHours();
	var i = (String(d.getMinutes()).length == 1) ? "0" + d.getMinutes() : d.getMinutes();
	var s = (String(d.getSeconds()).length == 1) ? "0" + d.getSeconds() : d.getSeconds();
	var da = (String(d.getDate()).length == 1) ? "0" + d.getDate() : d.getDate();
	var m = d.getMonth() + 1;
	m = (m < 10) ? "0" + m : m;
	tobj.childNodes[0].data = da + "." + m + "." + d.getFullYear() + " | " + h + ":" + i + ":" + s;
}


function screeninit() {
	tobj = document.getElementById('timeval');
	window.setInterval("settime()", 200);
	try {
		var a = getCookie();
		if (a) set_zoom(a);
	} catch(e) {}
}

function sendRemarks() {
	var frm = document.getElementById('remarkform');
	if (!frm) return false;
	
	var m1 = document.getElementById('remarksemail');
	if (m1.value == "") {
		alert('Bitte geben Sie Ihre EMail-Adresse an.\\nPlease provide an E-mail adress.');
		return false;
	}
	frm.F_SECIDPOST.value = frm.F_SECIDFORM.value;
	if (frm) frm.submit();
	
}

function text_zoomin() {
	if (czoom == 145) return;
	czoom = Number(czoom) + 15;
	var cnt = document.getElementById('cntContent');
	cnt.style.fontSize = czoom + "%";
	setStyle ("#cntNavigation .blackwhite li a", "font-size: " + czoom + "%");
	setCookie(czoom, 30, "/", "", "");
}

function text_zoomout() {
	if (czoom == 100) return;
	czoom = Number(czoom) - 15;
	var cnt = document.getElementById('cntContent');
	cnt.style.fontSize = czoom + "%";
	setStyle ("#cntNavigation .blackwhite li a", "font-size: " + czoom + "%");
	setCookie(czoom, 30, "/", "", "");
}

function set_zoom(newzoom) {
	newzoom = Number(newzoom);
	if (newzoom > 145) newzoom = 145;
	czoom = newzoom.toFixed();
	var cnt = document.getElementById('cntContent');
	cnt.style.fontSize = czoom + "%";
	setStyle ("#cntNavigation .blackwhite li a", "font-size: " + czoom + "%");
}



function setStyle(fRule, styleValue) {
	
	// Wenn kein Stylesheet vorhanden ist, ein neues anlegen
	if (document.styleSheets.length == 0) {
		var styleTag = document.createElement('STYLE');
		var docHead = document.getElementsByTagName('head');
		docHead[0].appendChild(styleTag);
	}
	
	var thesheet = 0;
	for (var i=0; i<document.styleSheets.length; i++) {
		if (document.styleSheets[i].title == 'maincss') {
			thesheet = i;
			break;
		}
	}

	var curRules=document.styleSheets[thesheet].cssRules? document.styleSheets[thesheet].cssRules: document.styleSheets[thesheet].rules;
	if (isIE) {
		document.styleSheets[thesheet].addRule(fRule, styleValue);
	} else {
		var len = (document.styleSheets[thesheet].cssRules.length == 0) ? 0 : document.styleSheets[thesheet].cssRules.length-1;

		try {
		
		document.styleSheets[thesheet].insertRule(fRule + "{" + styleValue + "}", len);
		} catch (e) {}
	}
}

function noaction() {
	
}

function zoomimage_popup(obj,w,h,url) {
	var docHeight = document.documentElement.scrollHeight;
	var scrolltop = (isIE) ? document.documentElement.scrollTop : window.pageYOffset;
	var bodyHeight = (isIE) ? document.documentElement.clientHeight  : window.innerHeight; 
	var bodyWidth = (isIE) ? document.documentElement.clientWidth  : window.innerWidth; 
	var imagetext = obj.attributes['imagetext'].value
	var zoomimage = document.getElementById('zoomimage');
	var cntimage = document.getElementById('imageoverlay');
	var theoverlay = document.getElementById('cntimageoverlay');
	var textcnt = document.getElementById('textoverlay');
	var holder = document.getElementById('overlayimageholder');
	var iholder = document.getElementById('cntinfooverlay');
	textcnt.childNodes[0].data = imagetext;
	holder.style.height = h + "px";
	theoverlay.style.top = '0px';
	theoverlay.style.width = bodyWidth + "px";
	theoverlay.style.height = docHeight + "px";
	theoverlay.style.display = 'block';
	var l = (bodyWidth / 2) - (zoomimage.offsetWidth /2);
	var t = ((bodyHeight - (zoomimage.offsetHeight + 100)) / 2) + scrolltop;
	cntimage.style.left = l + "px";
	cntimage.style.top = t + "px";
	cntimage.style.width = zoomimage.offsetWidth + "px";
	zoomurl = url;
	var n = window.setTimeout("loadZoomImage()",100);	
}

function loadZoomImage() {
	
	if (zoomurl != '') {
		var zoomimage = document.getElementById('zoomimage');
		if (zoomimage.src != zoomurl)	zoomimage.src = zoomurl;
		zoomurl = '';
	}
}

function zoomimage_hide() {
	var theoverlay = document.getElementById('cntimageoverlay');
	theoverlay.style.display = 'none';	
	
}


function positionEmailFrame(url) {
	var ecnt = document.getElementById('cntEMailToFriend');
	var lcnt = document.getElementById('emailtofriendlink');
	var ifr = document.getElementById('ifEMailToFriend');
	ifr.src=url;
	ecnt.style.top = (lcnt.offsetTop - 200) + "px";
	ecnt.style.left = (lcnt.offsetLeft + 190) + "px";
	ecnt.style.display = 'block';
	
}

function hideEmailFrame() {
	var ecnt = document.getElementById('cntEMailToFriend');
	if (ecnt) ecnt.style.display = 'none';	
}

function setCookie( value, expires, domain, secure ){
	var today = new Date();
	today.setTime( today.getTime() );
	
	if ( expires ) expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = "zoomfactor=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ";path=/" ;
}

function getCookie() {
	var name = "zoomfactor";
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

