/*
infobar.js v1.7
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.
© Copyright 2010-2012 Microsoft Corporation. Alle Rechte vorbehalten.
*/

main();

function main() 
{

	var ieVer = getIeVersion();
	var isXP = (navigator.userAgent.indexOf('Windows NT 5.1') > -1);

	/* evalmode cropped */

	if (ieVer >= 9)
	{
		return;
	}

	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 = (ieVer && !isIEMobile)

	if (!isIE)
	{
		return;
	}

	if (document.cookie.indexOf('notificationdisplayed=true') == -1 || queryParam('shownotificationbar') == 'always')
	{

		if (ieVer == 8)
		{
			if (!isXP)
			{
				var nBar = new ieInfoBar({message: 'Installieren Sie jetzt den kostenlosen <a href="http://go.microsoft.com/?linkid=9742840" target="_blank"><strong>Internet Explorer&nbsp;9</strong></a>! Mit dem standardkonformen IE9 wird das Internet schneller, einfacher und ansprechender.', icon: 'http://www.microsoft.com/germany/msdn/components/ie/alert.gif'});
				nBar.show(50);
				createDocCookie('notificationdisplayed', 'true', 3 * 24);
			}
		}

		if (ieVer <= 7 && ieVer >= 4)
		{

			if (!isXP)
			{
				var nBar = new ieInfoBar({message: '<font color="red"><strong>ACHTUNG:</strong></font> Mit Ihrer veralteten Version von Internet Explorer gehen Sie unn&ouml;tige Risiken ein: <a href="http://go.microsoft.com/?linkid=9742840" target="_blank">Installieren Sie <strong><u>jetzt</u></strong> den kostenlosen Internet Explorer&nbsp;9</a>, der ein deutlich <strong>h&ouml;heres Schutzniveau</strong> bietet: <i>standardkonform, schneller, einfacher und sicherer</i>!', icon: 'http://www.microsoft.com/germany/msdn/components/ie/alert.gif'});
				nBar.show(50);
				createDocCookie('notificationdisplayed', 'true', 6);
			}
			else
			{
				var nBar = new ieInfoBar({message: '<font color="red"><strong>ACHTUNG:</strong></font> Mit Ihrer veralteten Version von Internet Explorer gehen Sie unn&ouml;tige Risiken ein: <a href="http://go.microsoft.com/?linkid=9742839" target="_blank">Installieren Sie <strong><u>jetzt</u></strong> den kostenlosen Internet Explorer&nbsp;8</a>, der ein deutlich <strong>h&ouml;heres Schutzniveau</strong> bietet: <i>schneller, einfacher und sicherer</i>!', icon: 'http://www.microsoft.com/germany/msdn/components/ie/alert.gif'});
				nBar.show(50);
				createDocCookie('notificationdisplayed', 'true', 6);
			}
		}

		/*@cc_on
			 @if (@_jscript_version <= 5.6 && @_jscript_version >= 3.0)
				window.onscroll = legacySetBar;
				window.onresize = legacySetBar;
			 /*@end
		@*/	

	}

}


function getIeVersion()
{

	var ieVer = null;

	/*@cc_on
		 @if   (@_jscript_version == 9)		ieVer = 9;
		 @elif (@_jscript_version == 5.8)	ieVer = 8;
		 @elif (@_jscript_version == 5.7)	ieVer = 7;
 		 @elif (@_jscript_version == 10)	ieVer = 10;
		 @elif (@_jscript_version == 5.6)	ieVer = 6;
		 @elif (@_jscript_version == 5.5)	ieVer = 5.5;
		 @elif (@_jscript_version == 5)		ieVer = 5;
		 @elif (@_jscript_version == 5.01)	ieVer = 5;
		 @elif (@_jscript_version == 3)		ieVer = 4;
		 @elif (@_jscript_version == 1)		ieVer = 3;
		 @else @*/						//	ieVer = null;
		/*@end
	@*/

	if (ieVer == 7 && !window.XMLHttpRequest)
	{
		ieVer = 6;
	}

	return ieVer;

}


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 createDocCookie(name, value, hours)
{

	if (hours)
	{
		var date = new Date();
		date.setTime(date.getTime() + hours * 3600000);
		var expires = '; expires=' + date.toGMTString();
	}
	else
	{
		var expires = '';
	}
	document.cookie = name + '=' + value + expires + '; path=/';

}


function queryParam(param)
{

	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(param + '=') > -1)
			{
				var aParam = queryStringArray[i].split('=');
				retVal = aParam[1];
				break;
			}
		}
	}

	return retVal;

}


function ieInfoBar(params)
{

	var ieVer = getIeVersion();

	if (!document.createElement || !ieVer)
	{
		return;
	}

	if(!params)
	{
		params = {};
	}

	var ibTag = document.createElement('div');
	ibTag.id = 'ieInfoBar';
	ibTag.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%;';
	ibTag.style.backgroundColor = params.backColor || '#ffffe1';
	ibTag.style.fontColor = params.foreColor || '#000000';
	if (ieVer <= 6 && ieVer >= 4)
	{
		if (document.documentElement && document.documentElement.clientWidth)
		{
			ibTag.style.width = document.documentElement.clientWidth;
		}
		else if (document.body && document.body.clientWidth)
		{
			ibTag.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 || 'http://www.microsoft.com/germany/msdn/components/ie/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 = 'http://www.microsoft.com/germany/msdn/components/ie/x.gif';
	closeTag.onclick = function()
	{
		ibTag.style.display = 'none';
	};

	ibTag.appendChild(closeTag);
	ibTag.appendChild(iconTag);
	ibTag.appendChild(textTag);

	this.InfoBar = ibTag;
	document.body.insertBefore(ibTag, document.body.firstChild);
	ibTag.style.top = document.body.scrollTop - parseInt(this.InfoBar.offsetHeight) + 'px';

	this.show = function(speed)
	{
		var me=this;
		if (parseInt(this.InfoBar.style.top) < 0)
		{
			ibTag.style.top = parseInt(ibTag.style.top) + 2 + 'px';
			setTimeout(function(){me.show(speed)}, speed || 50);
		}
		else
		{
			if (ieVer <= 6 && ieVer >= 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";
				}
			}

		}

	}

}
