var tt = null;		//erw
var eg_width = 650;
var eg_height = 480;
var eg_bordercolor = '#585858';
var eg_bgTitle = '#339999';
var eg_htmlfile = 'http://www.hintergrundfakten.de/wb_data/si_pop.html';
var eg_movefile = 'http://www.hintergrundfakten.de/kredite-webangebote.html#kredite-webangebot-sites';
//eg_overlayurl = 'http://www.hintergrundfakten.de/hint_data/overlay.gif';
var eg_timeout = 0;
var tt_timeout = 3000;			//erw
var eg_disable_scrollbar = false;

////////////////////////////////////////////////////////////
//// DO NOT EDIT BELOW THIS LINE ///////////////////////////
////////////////////////////////////////////////////////////
var myWidth = 0;
var myHeight = 0;
var opened = false;
var is_in = true;
var egwind = null;
var eg_overlay = null;
var eg_x = 100;
var eg_y = 100;
var nrp = -1;
var nrp_show = 1;
var autoclose = null;
var once_opened = false; //erw
var once_opened2 = false; //erw
var once_moved = false; //erw
var verzout = false; //erw
var to_in = false;
var zus = 2;
var si = 2;
var jp = 1;
var iddd = 126;
var idd = 0;


function sformat()
{
	if( arguments.length == 0 ) { return null; }
	var str = arguments[0];
	for(var i=1;i<arguments.length;i++)
	{
		var re = new RegExp('\\{' + (i-1) + '\\}','gm');
		str = str.replace(re, arguments[i]);
	}
	return str;
};


function mmove(e)
{

	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	eg_x = myWidth/2 - eg_width/2;
	eg_y = myHeight/2 - eg_height/2 + document.body.scrollTop;
	if(posy < 10 + document.body.scrollTop){
		if(!is_in) {
			nrp++;
			to_in = true;
			}
		is_in = true;
		if (once_moved) return false;
//		if (!verzout) return false;
		if (jp > 0 && to_in) {
		window.location.href = eg_movefile; 
		once_moved = true;
		jp--;
		set_cookie();
//		if(opened) return true;
//		openWindow();
		return true;
		}
	}
	else {
		is_in = false;
		to_in = false;
	if (verzout && (zus > 0))	{	//erw
		if(once_opened) return true;
		if(once_opened2) return true;
		openWindow();
		once_opened2 = true;
		zus--;
		set_cookie();
		return true;
		}
	}
	return true;
};


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
};

function sstart()
{
tt = setTimeout ("sstart2()", tt_timeout);

};

function sstart2()
{
  verzout = true;
};

clearTimeout (tt);
verzout = false;
check_cookie();




addLoadEvent( eg_init );



function eg_init() {
	sstart();
	document.onmousemove = mmove;

	var y = document.createElement('div');
	y.setAttribute('id','eg_overlay');
	document.body.appendChild(y);

	var x = document.createElement('div');
	x.setAttribute('id','egwind');
	y.appendChild(x);

	x.style.position = 'absolute';
	x.style.top =  '-1000px';
	x.style.left =  '-1000px';
	x.style.background = '#ffffff';
	x.style.border = '1px solid '+eg_bordercolor;
	x.style.width = eg_width+'px';
	x.style.height = eg_height+'px';
	x.style.display = 'block';
	var xtext = "<div style='border:1px solid "+eg_bordercolor+" !important;text-align:right !important;background:"+eg_bgTitle+" !important;padding:5px !important;font-family:arial,helvetica,sans serif !important;font-weight:bold !important;font-size:18px !important;color:#ffffff !important;'>Während Sie auf Schliessen klicken,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' style='font-family:arial,helvetica,sans serif !important;font-weight:bold !important;font-size:12px !important;color:#990000 !important;' onClick='closeWindow(); return false;'>[Schliessen]</a></div>";
	xtext += "<iframe style='border:1px solid "+eg_bordercolor+";background:white;' id='eg_iframe' name='eg_iframe' border='0' src='"+eg_htmlfile+"' width='"+(eg_width-2)+"' height='"+(eg_height-30)+"'></iframe>";
	x.innerHTML = xtext;
	egwind = x;
	eg_overlay = document.getElementById('eg_overlay');
};

function openWindow()
{

	if(opened) return false;
	if(once_opened) return false; //erw
	if( nrp%nrp_show != 0 ) { opened = false; return false; }
	opened=true;
	once_opened = true; //erw
//	window.location.href = eg_htmlfile;  //erw back
	return false;    //erw back

	var x= egwind;
	x.style.top = eg_y + 'px';
	x.style.left = eg_x + 'px';
	x.style.display = 'block';

	var y = eg_overlay;
	y.style.position = 'absolute';
	y.style.top = '0px';
	y.style.left = '0px';
	y.style.width = document.body.scrollWidth+'px';
	y.style.height = document.body.scrollHeight+'px';
	y.style.zIndex = '999';
	y.style.display = 'block';
//	y.style.background = "url('"+eg_overlayurl+"')";
	document.body.style.height = '100%';
	if(eg_disable_scrollbar) document.body.style.overflow = 'hidden';
	if(eg_timeout > 0) { autoclose = setTimeout("closeWindow()", eg_timeout); }
	return false;
};

function closeWindow()
{
	opened = false;
	egwind.style.display = 'none';
	eg_overlay.style.display = 'none';
	if(eg_disable_scrollbar) document.body.style.overflow = 'auto';
	if(autoclose) clearTimeout(autoclose);
	return false;
};


function check_cookie()
{
	var real_cookie = false;
	if (navigator.cookieEnabled == false) {
			zus = 1;
			si = 1;
			jp = 0;
			return;
			}
	real_cookie = get_cookie();
	if (!real_cookie) {
		set_cookie();
		real_cookie = get_cookie();
 		if (!real_cookie) {
			zus = 1;
			si = 1;
			jp = 0;
			return;
		}
	}
	if (zus == null) zus = 1;
	if (si == null) si = 1;
	if (jp == null) jp = 0;
};

function get_cookie()
{
	idd = readCookie("idd");
	if (idd != iddd) return false;
	zus = readCookie("zus");
	si = readCookie("si");
	jp = readCookie("jp");
	return true;
};

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
			var val = c.substring(nameEQ.length,c.length);
			val = unescape(val);
			val = parseInt(val);
			return val;
		}
	}
	return null;
};

 function set_cookie()
{
    document.cookie= "idd=" + escape(iddd) + "; path=/";
    document.cookie= "zus=" + escape(zus) + "; path=/";
    document.cookie= "si=" + escape(si) + "; path=/";
    document.cookie= "jp=" + escape(jp) + "; path=/";
};


