/**
 * 1.0 Original article and Script is from: http://think2loud.com/build-an-unsupported-browser-warning-with-jquery/
 * 1.1 Then the script was extended here: http://blog.team-noir.net/2009/06/fight-old-browsers-warning-with-jquery/
 * 1.2 And finally Fleshgrinder had a look at it and also minified it: http://www.nervenhammer.com/
 * 1.3 Google Chrome & new Safari detect added by www.team-noir.net
 */

function badBrowser() {
	var userAgent = navigator.userAgent.toLowerCase();
	
	// Check for Microsoft Internet Explorer 8.0
	if ($.browser.msie && parseInt($.browser.version, 10) >= 8) {
		return false;
	} else if ($.browser.msie && parseInt($.browser.version, 10) <= 6) {
		return true;
	}
	// Check for Opera 9.5
	if ($.browser.opera && ($.browser.version *10) <= 95) {
		return true;
	}
	// Check for Mozilla Firefox 2.0
	if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
		var ffversion = Number(RegExp.$1);
		if (ffversion < 3) {
			return true;
		}
	}
	// Check for Safari < Version 4.0
	if (/safari[\/\s](\d+\.\d+)/.test(userAgent) && !/chrome[\/\s](\d+\.\d+)/.test(userAgent)) {
		var safari = userAgent.indexOf('version');
		if (safari > -1) {
			var snip1 = safari+8;
			var version = userAgent.substring(snip1, (snip1+1));
			if (version < 4) {
				return true;
			}
		}
	}
	// Check for Chrome < Version 2.0
	var chrome = userAgent.indexOf('chrome');
	if (chrome > -1) {
		var snip1 = chrome+7;
		var version = userAgent.substring(snip1, (snip1+1));
		if (version < 2) {
			return true;
			}
	}
	
    return false;
}

function getBadBrowser(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end   = document.cookie.indexOf(";",c_start);
			if (c_end == -1) {
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function setBadBrowser(c_name,value,expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) + ((expiredays === null) ? "" : ";expires=" + exdate.toGMTString());
}

if(badBrowser() && getBadBrowser('browserWarning') != 'seen') {
	$(function() {
		// Here you go with translating the content of the box

		if (lang == "en") {
			var htmlText = "<div id='browserWarning'><div id='browserWarning_text'><h1>Attention! Your browser is out of date.</h1><br /><img src='/fm/7633/achtung_browserhinweis.gif' />It may <strong>not display all features</strong> of this and other websites.<br /><br />Update your browser:<br /><br /><a href='http://getfirefox.com' style='text-decoration:underline;' target='_blank'>FireFox</a><br /><a href='http://www.microsoft.com/windows/downloads/ie/getitnow.mspx' style='text-decoration:underline;' target='_blank'>Internet Explorer</a><br /><a href='http://www.apple.com/safari/' style='text-decoration:underline;' target='_blank'>Safari</a><div id='browserWarning_close'><a href='#' id='warningClose'>&nbsp;</a></div></div></div>";
		} else if (lang == "cz")  {
			var htmlText = "<div id='browserWarning'><div id='browserWarning_text'><h1>INFORMACE: M&#283;li byste si aktualizovat V&aacute;&scaron; prohl&iacute;&#382;e&#269;!</h1><br /><img src='/fm/7633/achtung_browserhinweis.gif' />V sou&#269;asnosti pou&#382;&iacute;v&aacute;te  starou verzi prohl&iacute;&#382;e&#269;e. Na&scaron;e str&aacute;nky budou fungovat l&eacute;pe, jestli&#382;e si budete  instalovat nejnov&#283;j&scaron;&iacute; verzi prohl&iacute;&#382;e&#269;e, nebo jej vym&#283;n&iacute;te.<br /><br /><a href='http://getfirefox.com' style='text-decoration:underline;' target='_blank'>za FireFox</a><br /><a href='http://www.microsoft.com/windows/downloads/ie/getitnow.mspx' style='text-decoration:underline;' target='_blank'>za Internet Explorer</a><br /><a href='http://www.apple.com/safari/' style='text-decoration:underline;' target='_blank'>za Safari</a><div id='browserWarning_close'><a href='#' id='warningClose'>&nbsp;</a></div></div></div>";	
		} else if (lang == "hu")  {
			var htmlText = "<div id='browserWarning'><div id='browserWarning_text'><h1>Figyelmeztet&eacute;s:  A b&ouml;ng&eacute;sz&#337;j&eacute;t friss&iacute;tenie kell!</h1><br /><img src='/fm/7633/achtung_browserhinweis.gif' />&Ouml;n jelenleg a  b&ouml;ng&eacute;sz&#337;je r&eacute;gi verzi&oacute;j&aacute;t haszn&aacute;lja. Az oldalaink jobban m&#369;k&ouml;dnek, ha  b&ouml;ng&eacute;sz&#337;je leg&uacute;jabb verzi&oacute;j&aacute;t haszn&aacute;lja, vagy b&ouml;ng&eacute;sz&#337;j&eacute;t m&aacute;s fajt&aacute;ra cser&eacute;li.<br /><br /><a href='http://getfirefox.com' style='text-decoration:underline;' target='_blank'>FireFox</a><br /><a href='http://www.microsoft.com/windows/downloads/ie/getitnow.mspx' style='text-decoration:underline;' target='_blank'>Internet Explorer</a><br /><a href='http://www.apple.com/safari/' style='text-decoration:underline;' target='_blank'>Safari</a><div id='browserWarning_close'><a href='#' id='warningClose'>&nbsp;</a></div></div></div>";	
		} else {
			var htmlText = "<div id='browserWarning'><div id='browserWarning_text'><h1>Hinweis: Sie sollten Ihren Browser aktualisieren!</h1><br /><img src='/fm/7633/achtung_browserhinweis.gif' />Sie verwenden zurzeit eine alte Browser-Version. Unsere Seite funktioniert besser, wenn Sie die neueste Version des Browsers installieren oder den Browser wechseln.<br /><br /><a href='http://getfirefox.com' style='text-decoration:underline;' target='_blank'>zu FireFox</a><br /><a href='http://www.microsoft.com/windows/downloads/ie/getitnow.mspx' style='text-decoration:underline;' target='_blank'>zu Internet Explorer</a><br /><a href='http://www.apple.com/safari/' style='text-decoration:underline;' target='_blank'>zu Safari</a><div id='browserWarning_close'><a href='#' id='warningClose'>&nbsp;</a></div></div></div>";
		}
		
		$(htmlText)
			// Delete the following to get full control over the style
			// of the warning box and style it through your stylesheet
			.css({
			})
			// Last step is to prepend the just created DIV to the
			// opening <body>-Tag
			.prependTo("body");
		// This generates the "close" link
		// You have the possibility to set up the closing speed of the box
		// just enter something different to the slow statement at slideUp
		$('#warningClose').click(function(){
			setBadBrowser('browserWarning','seen');
			$('#browserWarning').slideUp('slow');
			return false;
		});
				
	});
}