/*
infobar.js v1.6
IE Detection Script simulating an IE Information Bar with Messages based on Visitor's Web Browser.
Developed by aixsoft Software- & Online-Services Mathias Schiffer (Schiffer@mvps.org) for MSDN Online Germany.
Do not copy, reproduce, (re-)distribute, change or publish without written consent.
Feedback: pingme@microsoft.com
© Copyright 2010-2011 Microsoft Corporation. Alle Rechte vorbehalten.
Scripting modified with other information text queries based on local - 07.01.2012 by ixi
*/

displayNotification();

/*@cc_on
	 @if (@_jscript_version <= 5.6 && @_jscript_version >= 3.0)
		window.onscroll = legacySetBar;
		window.onresize = legacySetBar;
	 /*@end
@*/	


function legacySetBar(bar)
{

	if (!bar)
	{
		bar = document.getElementById('ieInfoBar'); 
	}

	if (bar)
	{ 
		if (document.documentElement && document.documentElement.clientWidth)
		{
	        bar.style.width = document.documentElement.clientWidth;
	    }
		else if (document.body && document.body.clientWidth)
		{
    		bar.style.width = document.body.clientWidth;
		}


		if (document.documentElement && document.documentElement.scrollTop)
		{
	        bar.style.top = document.documentElement.scrollTop;
	    }
		else if (document.body && document.body.scrollTop)
		{
    		bar.style.top = document.body.scrollTop;
		}

	};

};


function getIeVersion()
{

	var ieVersion = null;

	/*@cc_on
		 @if   (@_jscript_version == 9.0)  ieVersion = 9;
		 @elif (@_jscript_version == 5.8)  ieVersion = 8;
		 @elif (@_jscript_version == 5.7)  ieVersion = 7;
		 @elif (@_jscript_version == 5.6)  ieVersion = 6;
		 @elif (@_jscript_version == 5.5)  ieVersion = 5.5;
		 @elif (@_jscript_version == 5.0)  ieVersion = 5;
		 @elif (@_jscript_version == 5.01) ieVersion = 5;
		 @elif (@_jscript_version == 3.0)  ieVersion = 4;
		 @elif (@_jscript_version == 1.0)  ieVersion = 3;
		 @else @*/                     //  ieVersion = null;
	   /*@end
	@*/

	if (ieVersion == 7 && !window.XMLHttpRequest)
	{
		ieVersion = 6;
	}

	return ieVersion;
	
}


function displayNotification() 
{
	
	var ieVersion = getIeVersion();
	var isXP = (navigator.userAgent.indexOf('Windows NT 5.1') > -1);

	var evalmode = false;
	if (evalmode)
	{
		switch (queryStringParameterValue('os').toLowerCase())
		{
			case 'xp':    isXP = true;  break;
			case 'notxp': isXP = false;  break;
			default:      break;
		}
		
		switch (queryStringParameterValue('test'))
		{
			case '9': ieVersion = 9; break;
			case '8': ieVersion = 8; break;
			case '7': ieVersion = 7; break;
			case '6': ieVersion = 6; break;
			case '5': ieVersion = 5; break;
			case '4': ieVersion = 4; break;
			case '3': ieVersion = 3; break;
			default:  break;
		}
	}

	var u = navigator.userAgent; 
	var isIEMobile = (    u.indexOf("IEMobile") > -1   
					   || u.indexOf("ZuneWP7") > -1
					   || u.indexOf("Windows CE") > -1
					   || u.indexOf("WM5 PIE") > -1
					 ); 
	var isIE = (ieVersion && !isIEMobile)

	if (!isIE)
	{	
		return;
	}		

	if (document.cookie.indexOf('notificationdisplayed=true') == -1 || queryStringParameterValue('shownotificationbar') == 'always')
	{
	
		if (ieVersion == 8)
		{
			if (!isXP)
			{
				var notificationBar = new ieInfoBar({message: '<font color="red"><strong>ACHTUNG: Ihr Webbrowser ist veraltert.</strong> Mit Ihrem veralterten Internet Explorer gehen Sie im Internet unn&ouml;tige Risiken ein. Auch lassen sich viele moderne Webseiten nicht mehr ordentlich darstellen. </font><br><a href="http://go.microsoft.com/?linkid=9742840" target="_blank"><strong><font color="black">Installieren Sie <strong><u> jetzt </u></strong> den kostenlosen Internet Explorer&nbsp;9</strong></font></a><font color="black">, der ein deutlich <strong>h&ouml;heres Schutzniveau</strong> hat,  standardkonform, schneller und einfacher ist.</font>', icon: 'images/alert.gif'});
				notificationBar.show(50);
				createDocumentCookie('notificationdisplayed', 'true', 3 * 24);		
			}
		}
								
		if (ieVersion <= 7 && ieVersion >= 4)
		{

			if (!isXP)
			{
				var notificationBar = new ieInfoBar({message: '<font color="red"><strong>ACHTUNG: Ihr Webbrowser ist veraltert.</strong> Mit Ihrem veralterten Internet Explorer gehen Sie im Internet unn&ouml;tige Risiken ein. Auch lassen sich viele moderne Webseiten nicht immer ordentlich darstellen.</font><br><a href="http://go.microsoft.com/?linkid=9742840" target="_blank"><font color="black">Installieren Sie <strong><u>jetzt</u></strong> den kostenlosen Internet Explorer&nbsp;9<</font>/a><font color="black">, der ein deutlich <strong>h&ouml;heres Schutzniveau</strong> hat, standardkonform, schneller und einfacher ist.</font>', icon: 'images/alert.gif'});
				notificationBar.show(50);
				createDocumentCookie('notificationdisplayed', 'true', 6);
			}
			else
			{
				var notificationBar = new ieInfoBar({message: '<font color="red"><strong>ACHTUNG: Ihr Webbrowser ist veraltert.</strong> Mit Ihrem veralterten Internet Explorer gehen Sie im Internet unn&ouml;tige Risiken ein. Auch lassen sich viele moderne Webseiten nicht immer ordentlich darstellen.</font><a href="http://go.microsoft.com/?linkid=9742839" target="_blank"><font color="black"> Installieren Sie <strong><u>jetzt</u></strong> den kostenlosen Internet Explorer&nbsp;8</font></a><font color="black">, der ein deutlich <strong>h&ouml;heres Schutzniveau</strong> hat, standardkonform, schneller und einfacher ist.</font>', icon: 'images/alert.gif'});
				notificationBar.show(50);
				createDocumentCookie('notificationdisplayed', 'true', 6);
			}
		}

	}
	
}


function createDocumentCookie(name, value, hours)
{

	if (hours)
	{
		var date = new Date();
		date.setTime(date.getTime() + hours * 60 * 60 * 1000);
		var expires = '; expires=' + date.toGMTString();
	}
	else
	{
		var expires = '';
	}
	document.cookie = name + '=' + value + expires + '; path=/';
	
}


function queryStringParameterValue(parameterName)
{

	var retVal = '';
	var hRef = window.location.href;

	if (hRef.indexOf('?') > -1)
	{
		var queryString = hRef.substr(hRef.indexOf('?')).toLowerCase();
		var queryStringArray = queryString.split('&');
		for (var i = 0; i < queryStringArray.length; i++)
		{
			if (queryStringArray[i].indexOf(parameterName + '=') > -1)
			{
				var aParam = queryStringArray[i].split('=');
				retVal = aParam[1];
				break;
			}
		}
	}

	return retVal;
	
}

		
function ieInfoBar(params)
{

	var ieVersion = getIeVersion();

	if (!document.createElement || !ieVersion)
	{
		return;
	}

	if(!params)
	{
		params = {};
	}

	var infoBarTag = document.createElement('div');
	infoBarTag.id = 'ieInfoBar';
	infoBarTag.style.cssText ='position: absolute; padding-top: 3px; padding-bottom: 3px; display: block; z-Index: 50000; left: 0; right: 0; border-bottom: 1px black groove; width:100%;';
	infoBarTag.style.backgroundColor = params.backColor || '#ffffe1';
	infoBarTag.style.fontColor = params.foreColor || '#000000';
	if (ieVersion <= 6 && ieVersion >= 4)
	{
		if (document.documentElement && document.documentElement.clientWidth)
		{
	        infoBarTag.style.width = document.documentElement.clientWidth;
	    }
		else if (document.body && document.body.clientWidth)
		{
	       	infoBarTag.style.width = document.body.clientWidth;
	   	}
	};

	var iconTag = document.createElement('img');
	iconTag.style.cssText = 'width: 14px; height: 16px; float: left; border: 0px; margin-right: 5px; margin-left: 7px;';
	iconTag.src = params.icon || 'images/alert.gif'; 

	var textTag = document.createElement('div');
	textTag.innerHTML = params.message || '';
	textTag.style.cssText ='text-align:left; padding-left: 26px; padding-right: 24px; font-family: Arial; font-size: small; cursor: default;';
	
	var closeTag = document.createElement('img');
	closeTag.style.cssText = 'width: 18px; height: 18px; float: right; border: 0px; margin-right: 7px; cursor: default;';
	closeTag.src = 'images/x.gif';
	closeTag.onclick = function()
	{
		infoBarTag.style.display = 'none';
	};
	
	infoBarTag.appendChild(closeTag);
	infoBarTag.appendChild(iconTag);
	infoBarTag.appendChild(textTag);

	this.InfoBar = infoBarTag;
	document.body.insertBefore(infoBarTag, document.body.firstChild);
	infoBarTag.style.top = document.body.scrollTop - parseInt(this.InfoBar.offsetHeight) + 'px';
	
	this.show = function(speed)
	{
		var me=this;
		if (parseInt(this.InfoBar.style.top) < 0)
		{
			infoBarTag.style.top = parseInt(infoBarTag.style.top) + 2 + 'px';
			setTimeout(function(){me.show(speed)}, speed || 50);
		}
		else
		{
			if (ieVersion <= 6 && ieVersion >= 4)
			{
				this.InfoBar.style.top = (document.compatMode == 'CSS1Compat') ? document.documentElement.scrollTop + 'px' : body.scrollTop + 'px';
			}
			else
			{
				this.InfoBar.style.top = 0;
				if (document.compatMode != 'BackCompat')
				{
					this.InfoBar.style.position = "fixed";
				}
			}

		}
		
	}

}
