﻿/*FUNKCIJA PROVJERAVA TIP OS-A KOJEG KORISNIK KORISTI*/
function detectOS() {
	var versions = new Array(
	    { id:'Windows NT 6.1', name:'Windows 7; Windows Server 2008 R2' },
		{ id:'Windows NT 6.0', name:'Windows Vista; Windows Server 2008' },
		{ id:'Windows NT 5.2', name:'Windows Server 2003; Windows XP x64 Edition' },
		{ id:'Windows NT 5.1', name:'Windows XP' },
		{ id:'Windows NT 5.01', name:'Windows 2000' },
		{ id:'Windows NT 5.0', name:'Windows 2000' },
		{ id:'Windows NT 4.0', name:'Windows NT 4.0' },
		{ id:'Windows 98; Win 9x 4.90', name:'Windows ME' },
		{ id:'Windows 98', name:'Windows 98' },
		{ id:'Windows 95', name:'Windows 95' },
		{ id:'Windows CE', name:'Windows CE' },
		{ id:'Macintosh', name:'Macintosh' },
		{ id:'Linux', name:'Linux' }
	);


	for (var i=0; i<versions.length; i++) 
	{
	    if (navigator.userAgent.indexOf(versions[i].id) != -1) {    
			return versions[i].name;				
		}	
	}	
	return 'Other';
}

/*FUNKCIJA PROVJERAVA TIP BROWSERA KOJEG KORISNIK KORISTI*/

function detectBrowser() {
	var ua=navigator.userAgent, uaMatch='';
	var versions = new Array(
		{ id:'MSIE',name:'Internet Explorer' },
		{ id:'Firefox/',name:'Mozilla Firefox' },
		{ id:'Chrome',name:'Google Chrome' },
		{ id:'Safari',name:'Safari' },
		{ id:'Opera/',name:'Opera' },
		{ id:'Navigator/',name:'Netscape Navigator' }          
	);

	for (var i=0; i<versions.length; i++) {
		if (ua.indexOf(versions[i].id) != -1) {
		   uaMatch=versions[i];
		   break;
		}
	}
     
	switch (uaMatch.name) {
		case 'Internet Explorer':
			if (ua.indexOf('Trident/4.0') != -1) {				
				return uaMatch.name;				
			} else {
				var v='; Windows';
				return uaMatch.name+ua.substr(ua.indexOf(uaMatch.id)+uaMatch.id.length,ua.indexOf(v)-(ua.indexOf(uaMatch.id)+uaMatch.id.length));
			}
		case 'Mozilla Firefox':
			return uaMatch.name+' '+(ua.substring(ua.indexOf(uaMatch.id)+uaMatch.id.length));
		case 'Google Chrome':			
			return uaMatch.name;
		case 'Safari':
			var v='Version/';
			return uaMatch.name+' '+(ua.substring(ua.indexOf(v)+v.length, ua.indexOf(uaMatch.id)));
		case 'Opera':
			return uaMatch.name+' '+(ua.substring(ua.indexOf(uaMatch.id)+uaMatch.id.length, ua.indexOf('.')-ua.indexOf(uaMatch.id)));
		default:
			return 'Other';
	}
	return 'Other';
}

function detectBrowserMicrosoftScript() {
	var OpSys = detectOS();
	var ua = navigator.userAgent;
	var browser = detectBrowser();
	var button = document.getElementById('linkOS');
	/*PRVO PROVJERAVA JELI TIP PREGLEDNIKA IE*/

	if (browser == 'Internet Explorer') {
		if (ua.indexOf('Trident/4.0') != -1) {
			button.href = 'http://go.microsoft.com/?LinkID=9700594';
			document.getElementById('txt').innerHTML = 'Trenutno koristite preglednik Internet Explorer 8. Prilagodite preglednik vašim potrebama.';
			document.getElementById("bttnImg").src = '/croatia/internet-explorer8/images/preuzmiteAddOn.jpg';
		}
		else {
			if (OpSys == 'Windows XP') {
				//button.href = 'http://go.microsoft.com/fwlink/?LinkID=142198';
				button.href = 'http://go.microsoft.com/?LinkID=9700582';
				document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
			}
			else if (OpSys == 'Windows Server 2003; Windows XP x64 Edition' || OpSys == 'Windows ME') {
				//button.href = 'http://go.microsoft.com/fwlink/?LinkID=142199';
				button.href = 'http://go.microsoft.com/?LinkID=9700583';
				document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
			}
			else if (OpSys == 'Windows Vista; Windows Server 2008') {
				//button.href = 'http://go.microsoft.com/fwlink/?LinkID=142200';
				button.href = 'http://go.microsoft.com/?LinkID=9700584';
				document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
			}
			else if (OpSys == 'Windows 2000') {
				//button.href = 'http://go.microsoft.com/fwlink/?LinkID=142200';
				button.href = 'http://go.microsoft.com/?LinkID=9700593';
				document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
			}
			else if (OpSys == 'Windows 7; Windows Server 2008 R2') {
				//button.href = 'http://ieaddons.com/hr/';
				button.href = 'http://go.microsoft.com/?LinkID=9700594';
				document.getElementById('txt').innerHTML = 'Trenutno koristite preglednik Internet Explorer 8. Prilagodite preglednik vašim potrebama.';
				document.getElementById("bttnImg").src = '/croatia/internet-explorer8/images/preuzmiteAddOn.jpg';
			}
			else {
				button.href = 'http://www.microsoft.com/croatia/windows/internet-explorer/';
			}

		}

	}
	/*AKO JE BROWSER RAZLIČIT OD IE8*/
	else if (browser != 'Internet Explorer') {
		if (OpSys == 'Windows XP') {
			//button.href = 'http://go.microsoft.com/fwlink/?LinkID=142198';
			button.href = 'http://go.microsoft.com/?linkid=9702686';
			document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
		}
		else if (OpSys == 'Windows Server 2003; Windows XP x64 Edition' || OpSys == 'Windows ME') {
			//button.href = 'http://go.microsoft.com/fwlink/?LinkID=142199';
			button.href = 'http://go.microsoft.com/?linkid=9702689';
			document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
		}
		else if (OpSys == 'Windows Vista; Windows Server 2008') {
			//button.href = 'http://go.microsoft.com/fwlink/?LinkID=142200';
			button.href = 'http://go.microsoft.com/?linkid=9702688';
			document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
		}
		else if (OpSys == 'Windows 2000') {
			//button.href = 'http://go.microsoft.com/fwlink/?LinkID=142200';
			button.href = 'http://go.microsoft.com/?linkid=9702687';
			document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
		}
		else if (OpSys == 'Windows 7; Windows Server 2008 R2') {
			//button.href = 'http://ieaddons.com/hr/';
			button.href = 'http://go.microsoft.com/?linkid=9702690';
			document.getElementById('txt').innerHTML = 'Trenutno ne koristite Internet Explorer 8. Preuzmite najnoviju verziju preglednika.';
		}
		else {
			button.href = 'http://www.microsoft.com/croatia/windows/internet-explorer/';
		}

	}
}



function getBrowser() {
	var OpSys = detectOS();
	var ua = navigator.userAgent;
	var browser = detectBrowser();
	var button = document.getElementById('linkOS');
	var browserType = "other";
	/*PRVO PROVJERAVA JELI TIP PREGLEDNIKA IE*/
	if (browser == 'Internet Explorer') {
		if (ua.indexOf('Trident/4.0') != -1) {
			browserType = "ie8";
		}
		else {
			if (OpSys == 'Windows XP') {
				browserType = "ie67";
			}
			else if (OpSys == 'Windows Server 2003; Windows XP x64 Edition' || OpSys == 'Windows ME') {
				browserType = "ie67";
			}
			else if (OpSys == 'Windows Vista; Windows Server 2008') {
				browserType = "ie67";
			}
			else if (OpSys == 'Windows 2000') {
				browserType = "ie67";
			}
			else if (OpSys == 'Windows 7; Windows Server 2008 R2') {
				browserType = "ie8";
			}
			else {
				browserType = "ie67";
			}
		}
	}
	/*AKO JE BROWSER RAZLIČIT OD IE8*/
	else if (browser != 'Internet Explorer') {
		if (OpSys == 'Windows XP') {
			browserType = "other";
		}
		else if (OpSys == 'Windows Server 2003; Windows XP x64 Edition' || OpSys == 'Windows ME') {
			browserType = "other";
		}
		else if (OpSys == 'Windows Vista; Windows Server 2008') {
			browserType = "other";
		}
		else if (OpSys == 'Windows 2000') {
			browserType = "other";
		}
		else if (OpSys == 'Windows 7; Windows Server 2008 R2') {
			browserType = "other";
		}
		else {
			browserType = "none";
		}
	}
	return browserType;
}


function getBrowser2() {
	var browserType = "other";

	if (jQuery.browser.msie) {
		if (jQuery.browser.version == "8.0") {
			browserType = "ie8";
		} else {
			browserType = "ie67";
		}
	} else {
		browserType = "other";
	}	
	return browserType;
}


function ie8BannerCheck() {
	// get cookie data
	if (readCookie("ie8upgrade") == null) {
		// display ie8 banner
		jQuery("div.ie8upgrade > div.ie8right > a.close").click(function() {
			if (window.confirm("Podsjeti me kasnije?")) {
				// set cookie: 24h
				createCookie("ie8upgrade", 1, 1);
			} else {
				// set cookie: 100 (14) days
				createCookie("ie8upgrade", 1, 100);
			}
			jQuery('div.ie8upgrade').slideUp();
		});

		var detectedBrowser = getBrowser2();
		switch (detectedBrowser) {
			case "ie8":
				// ie8
				jQuery("#ieupg_ie8").show();
				jQuery("#ieupg_more_ie8").show();
				jQuery("#ieupg_down_ie8").show();
				jQuery("div.ie8upgrade").show();
				break;
			case "ie67":
				// less than ie8
				jQuery("#ieupg_ie67").show();
				jQuery("#ieupg_more_ie67").show();
				jQuery("#ieupg_down_ie67").show();
				jQuery("div.ie8upgrade").show();
				break;
			case "none":
				// not on windows OS
				break;
			default:
				// other browser
				jQuery("#ieupg_other").show();
				jQuery("#ieupg_more_other").show();
				jQuery("#ieupg_down_ie67").show();
				jQuery("div.ie8upgrade").show();
		}
	}
}
