// Developed by www.matijabozic.com
// Feel free to use, view and improve the code of IE6Notification
// If you improve this code, or create a new theme, contact me: mail@matijabozic.com

window.onload = function() {
	
	// Change this to custumize your IE6 notification
	var headerText = "Jūsų naršyklė pasenusi!";
	var notificationInfo = "Jūs naudojate Internet Explorer 6 ar senesnę naršyklę.";
	var notificationText = "Jūsų naudojama naršyklė yra pasenusi: neatitinka saugumo reikalavimų, neteisingai atvaizduojanti bei lėtai užkraunanti svetainės puslapius, todėl siūlome iš žemiau pateikto sąrašo pasirinkti naują naršyklę.";
	
	/////////////////////////////
	///// Detecting Browser /////
	/////////////////////////////
	
	var userAgent = navigator.userAgent.toLowerCase();
	var browser = "";
	if (userAgent.indexOf('msie 6.1') != -1) { browser = "IE"; }
	if (userAgent.indexOf('msie 6.0') != -1) { browser = "IE"; }
	if (userAgent.indexOf('msie 6.01') != -1) { browser = "IE"; }
	if (userAgent.indexOf('msie 6.0b') != -1) { browser = "IE"; }
	if (userAgent.indexOf('msie 5.5') != -1) { browser = "IE"; }
	if (userAgent.indexOf('msie 5.0') != -1) { browser = "IE"; }
	if (userAgent.indexOf('msie 4.5') != -1) { browser = "IE"; }
	if (userAgent.indexOf('msie 4.01') != -1) { browser = "IE"; }
	if (userAgent.indexOf('msie 4.0') != -1) { browser = "IE"; }
	
	if ( browser == "IE" ) {

		//////////////////////////////
		///// Cookie Value Check /////
		//////////////////////////////
		
		var cookieName = "IE6Notification";
		var cookieValue = "";
		var cookieAll = document.cookie;
		var cookieArray = cookieAll.split(';');
		for ( n = 0; n < cookieArray.length; n++ ) {
			var cookie = cookieArray[n];
				if (cookie.indexOf(cookieName) != -1) {
				var cookieNameEnd = cookie.indexOf("=") + 1;
				cookieValue = cookie.substring(cookieNameEnd);
			}
		}
		
		if ( cookieValue != 'dontShow' ) {
			
			///////////////////
			///// Global  /////
			///////////////////
			
			var HTMLbody = document.getElementsByTagName('body')[0];
			var HTMLhead = document.getElementsByTagName('head')[0];
			
			///////////////////////////
			///// Adding CSS file /////
			///////////////////////////
			
			//CSS can be added dynamically, joust uncomment this and there's no need to include IE6Notification.css in header 
			
			var css = document.createElement('link');
			css.setAttribute('rel', 'stylesheet');
			css.setAttribute('type', 'text/css');
			css.setAttribute('href', 'IE6Notification/IE6Notification.css');
			HTMLhead.appendChild(css);
			
			/////////////////////////////
			///// Building Notifier /////
			/////////////////////////////
			
			var IE6NotificationWrapper = document.createElement('div');
			IE6NotificationWrapper.setAttribute('id', 'IE6NotificationWrapper');
			HTMLbody.appendChild(IE6NotificationWrapper);
			
			var IE6NotificationHeader = document.createElement('h1');
			var IE6NotificationHeaderText = document.createTextNode(headerText);
			IE6NotificationHeader.setAttribute('id', 'IE6NotificationHeader');
			IE6NotificationHeader.appendChild(IE6NotificationHeaderText);
			IE6NotificationWrapper.appendChild(IE6NotificationHeader);
			
			var IE6NotificationInfo1 = document.createElement('p');
			var IE6NotificationInfo1Text = document.createTextNode(notificationInfo);
			IE6NotificationInfo1.setAttribute('id', 'IE6NotificationInfo1');
			IE6NotificationInfo1.appendChild(IE6NotificationInfo1Text);
			IE6NotificationWrapper.appendChild(IE6NotificationInfo1);
			
			var IE6NotificationInfo2 = document.createElement('p');
			var IE6NotificationInfo2Text = document.createTextNode(notificationText);
			IE6NotificationInfo2.setAttribute('id', 'IE6NotificationInfo2');
			IE6NotificationInfo2.appendChild(IE6NotificationInfo2Text);
			IE6NotificationWrapper.appendChild(IE6NotificationInfo2);
			
			var browserFirefox = document.createElement('a');
			browserFirefox.setAttribute('id', 'browserFirefox');
			browserFirefox.setAttribute('href', 'http://www.firefox.com');
			browserFirefox.setAttribute('target', '_blank');
			IE6NotificationWrapper.appendChild(browserFirefox);
			
			var browserChrome = document.createElement('a');
			browserChrome.setAttribute('id', 'browserChrome');
			browserChrome.setAttribute('href', 'http://www.google.com/chrome');
			browserChrome.setAttribute('target', '_blank');
			IE6NotificationWrapper.appendChild(browserChrome);
			
			var browserSafari = document.createElement('a');
			browserSafari.setAttribute('id', 'browserSafari');
			browserSafari.setAttribute('href', 'http://www.apple.com/safari/');
			browserSafari.setAttribute('target', '_blank');
			IE6NotificationWrapper.appendChild(browserSafari);
			
			var browserOpera = document.createElement('a');
			browserOpera.setAttribute('id', 'browserOpera');
			browserOpera.setAttribute('href', 'http://www.opera.com/');
			browserOpera.setAttribute('target', '_blank');
			IE6NotificationWrapper.appendChild(browserOpera);
			
			var browserIE = document.createElement('a');
			browserIE.setAttribute('id', 'browserIE');
			browserIE.setAttribute('href', 'http://www.microsoft.com/nz/windows/internet-explorer/default.aspx');
			browserIE.setAttribute('target', '_blank');
			IE6NotificationWrapper.appendChild(browserIE);
		
			/////////////////////////
			///// Kill Notifier /////
			/////////////////////////
			
			var killIE6Notification = document.createElement('a');
			var killIE6NotificationText = document.createTextNode("Uždaryti ir nebepriminti");
			killIE6Notification.setAttribute('id', 'killIE6Notification');
			killIE6Notification.setAttribute('href', '#');
			killIE6Notification.appendChild(killIE6NotificationText);
			IE6NotificationWrapper.appendChild(killIE6Notification);
			
			killIE6Notification.onclick = function() {

				///////////////////////////
				///// Setting Cookie //////
				///////////////////////////
				
				var date = new Date();
				var milisecunds = date.getTime();
				var future = milisecunds + (1000 * 60 * 60 * 24 * 30);
				exp = new Date(future);
				exp = exp.toGMTString();
				document.cookie = "IE6Notification=dontShow; expires=" + exp;
				
				HTMLbody.removeChild(IE6NotificationWrapper);
			
			};
			
			//////////////////////////
			///// Close Notifier /////
			//////////////////////////
			
			var closeIE6Notification = document.createElement('a');
			var closeIE6NotificationText = document.createTextNode('Uždaryti');
			closeIE6Notification.setAttribute('id', 'closeIE6Notification');
			closeIE6Notification.setAttribute('href', '#');
			closeIE6Notification.appendChild(closeIE6NotificationText);
			IE6NotificationWrapper.appendChild(closeIE6Notification);
			
			closeIE6Notification.onclick = function() {
				HTMLbody.removeChild(IE6NotificationWrapper);
			};
			
		}
	}
};