/*
 * Copyright (c) 1995-2012 by 4system Polska Sp. z o.o.
 * All Rights Reserved.
 */
if (typeof(moduleDone) != "undefined") moduleDone("browser.js");

//pg2-output info:
//	this.ie
//	this.moz  (all mozilla based)
//	this.firefox
//	this.ns  (netscape)
//	this.safari
//	this.chrome
//	this.opera
//	this.browserVersion  (version of the browsers listed above)
//	this.operatingSystem  (WindowsXP, WindowsVista, Windows7)

function Browser() {
	//***old
	var b = navigator.appName;
	if (b.indexOf('Netscape') != -1) this.b = "ns"; else
	if ((b == "Opera") || (navigator.userAgent.indexOf("Opera") > 0)) this.b = "opera"; else
	if (b == "Microsoft Internet Explorer") this.b = "ie"; else
	if (b == "MSIE") this.b = "ie";

	this.version = navigator.appVersion;
	this.v = parseInt(this.version);
	this.ns = (this.b == "ns" && this.v >= 4);
	this.ns4 = (this.b == "ns" && this.v == 4);
	this.ns6 = (this.b == "ns" && this.v == 5);
	this.ns7 = (this.b == "ns" && this.v == 5);
	this.ie = (this.b == "ie" && this.v >= 4);
	this.ie4 = (this.version.indexOf('MSIE 4') > 0);
	this.ie5 = (this.version.indexOf('MSIE 5') > 0);
	this.ie55 = (this.version.indexOf('MSIE 5.5') > 0);
	this.ie6 = (this.version.indexOf('MSIE 6') > 0);
	this.ie7 = (this.version.indexOf('MSIE 7') > 0);
	this.ie8 = (this.version.indexOf('MSIE 8') > 0);
	this.ie9 = (this.version.indexOf('MSIE 9') > 0);
	this.ie10 = (this.version.indexOf('MSIE 10') > 0); //pg2

	this.ie11 = false; //pg2-ie11 and up
	this.ie11up = false;

	this.ie55UP = this.ie55 || this.ie6 || this.ie7;
	this.ie7UP = this.ie7;
	this.opera = (this.b == "opera");
	this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	this.def = (this.ie || this.dom); // most used browsers, for faster if loops
	var ua = navigator.userAgent.toLowerCase();

	this.winXPPlatform = false;
	if (ua.indexOf("win") >- 1) {
		this.platform = "win32";
		this.winXPPlatform = ( ua.indexOf( "NT 5.1" ) > -1 );
	} else
	if (ua.indexOf("mac")>-1) this.platform = "mac"; else this.platform = "other";
	//***old

	//***new
	var agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.mobile = (navigator.appVersion.indexOf("Mobile") > -1 || agent.indexOf('android') > -1); //pg2-PCEN_DND
	this.android = agent.indexOf('android') > -1; //pg2-PCEN_DND

	// NETSCAPE SNIFFS
	this.ns = ((agent.indexOf('mozilla') != -1) && (agent.indexOf('spoofer') == -1)
		&& (agent.indexOf('compatible') == -1) && (agent.indexOf('opera') == -1)
		&& (agent.indexOf('webtv') == -1));
	this.ns2 = (this.ns && (this._major == 2));
	this.ns3 = (this.ns && (this.major == 3));
	this.ns4 = (this.ns && (this.major == 4));
	this.ns40 = (this.ns && (this.major == 4) && (agent.indexOf('4.0 ') != -1));
	this.ns401 = (this.ns && (this.major == 4) && (agent.indexOf('4.01') != -1));
	this.ns02 = (this.ns && (this.major == 4) && (agent.indexOf('4.02') != -1));
	this.ns03 = (this.ns && (this.major == 4) && (agent.indexOf('4.03') != -1));
	this.ns04 = (this.ns && (this.major == 4) && (agent.indexOf('4.04') != -1));
	this.ns05 = (this.ns && (this.major == 4) && (agent.indexOf('4.05') != -1));
	this.ns06 = (this.ns && (this.major == 4) && (agent.indexOf('4.06') != -1));
	this.ns07 = (this.ns && (this.major == 4) && (agent.indexOf('4.07') != -1));
	this.ns08 = (this.ns && (this.major == 4) && (agent.indexOf('4.08') != -1));
	this.ns450 = (this.ns && (this.major == 4) && (agent.indexOf('4.50') != -1));
	this.ns451 = (this.ns && (this.major == 4) && (agent.indexOf('4.51') != -1));
	this.ns46 = (this.ns && (this.major == 4) && (agent.indexOf('4.6') != -1));
	this.ns461 = (this.ns && (this.major == 4) && (agent.indexOf('4.61') != -1));
	this.ns47 = (this.ns && (this.major == 4) && (agent.indexOf('4.7') != -1));
	this.ns472 = (this.ns && (this.major == 4) && (agent.indexOf('4.72') != -1));
	this.ns473 = (this.ns && (this.major == 4) && (agent.indexOf('4.73') != -1));
	this.ns474 = (this.ns && (this.major == 4) && (agent.indexOf('4.74') != -1));
	this.ns475 = (this.ns && (this.major == 4) && (agent.indexOf('4.75') != -1));
	this.ns476 = (this.ns && (this.major == 4) && (agent.indexOf('4.76') != -1));
	this.ns48 = (this.ns && (this.major == 4) && (agent.indexOf('4.8') != -1));
	this.ns6 = (this.ns && (this.major == 6));
	this.ns7 = (this.ns && (this.major == 7));
	this.ns7up = (this.ns && (this.major >= 6));
	this.ns7x = (this.ns && (this.major == 5));

	//MOZILLA-SPECIFIC CHECK
	this.ns6pr1 = (this.ns && (this.major == 5)&&(agent.indexOf('6.0b1') != -1));
	this.ns6pr2 = (this.ns && (this.major == 5)&&(agent.indexOf('6.0b2') != -1));
	this.ns6pr3 = (this.ns && (this.major == 5)&&(agent.indexOf('6.0b3') != -1));
	this.ns6gold = (this.ns && (this.major == 5) && (agent.indexOf('netscape') != -1) && !this.ns6pr1 && !this.ns6pr2 && !this.ns6pr3);
	this.moz = (this.ns && (this.major >= 5) && (agent.indexOf('netscape') == -1));

	if (this.ns7x) this.moz = true;

	if	(this.ns6) {
		if (agent.indexOf('; m') != -1) {
			MSnumStart = agent.indexOf('; m') + 3;
			MSnumEnd = MSnumStart + 2;
			MSnum = agent.substring(MSnumStart, MSnumEnd);
			mozmile = Number(MSnum);
		} else {
			mozmile = 'cannot obtain milestone number';
		};
	} else {
		mozmile = 'not a mozilla or netscape user agent';
	};

	this.mozBased = (agent.indexOf('gecko') != -1);
	if (this.mozBased) {
		GeckoBuildIDStart = agent.indexOf('gecko') + 6;
		GeckoBuildIDEnd = GeckoBuildIDStart + 8;
		GeckoBuildIDnum = agent.substring(GeckoBuildIDStart, GeckoBuildIDEnd);
		GeckoBuildID = Number(GeckoBuildIDnum);
	} else {
		GeckoBuildID = 'cannot obtain gecko build #';
	};

	//MSIE CHECK
	this.ie = ((agent.indexOf("msie") != -1)&& (agent.indexOf('opera') == -1));
	this.winie = (this.win && this.ie);
	this.ie3 = (this.ie && (this.major < 4) && !this.ie6);
	this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 4") != -1) );
	this.ie401 = (this.ie && (this.major == 4) && (agent.indexOf("msie 4.01") != -1) );
	this.ie4up = (this.ie && (this.major >= 4));
	this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5") != -1) );
	this.ie51 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.01") != -1) );
	this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5") != -1) );
	this.ie5up = (this.ie && !this.ie3 && !this.ie4);
	this.ie6 = (this.ie && (agent.indexOf("msie 6.0") != -1) );
	this.ie7 = (this.ie && (agent.indexOf("msie 7.0") != -1) );

	// AOL CHECKS
	this.aol = (agent.indexOf("aol") != -1);
	this.aolandie3 = (this.aol && this.ie3);
	this.aolandie4 = (this.aol && this.ie4);
	this.aolandie5 = (this.aol && this.ie5);
	this.aol3 = (agent.indexOf("aol 3") != -1);
	this.aol4 = (agent.indexOf("aol 4") != -1);
	this.aol5 = (agent.indexOf("aol 5") != -1);
	this.aol6 = (agent.indexOf("aol 6") != -1);
	this.aol7 = (agent.indexOf("aol 7") != -1);
	this.aol8 = (agent.indexOf("aol 8") != -1);

	//MAC CHECK
	this.mac = (agent.indexOf("mac") != -1);
	this.mac68k = (this.mac && ((agent.indexOf("68k") != -1) || (agent.indexOf("68000") != -1)));
	this.macppc = (this.mac && ((agent.indexOf("ppc") != -1) || (agent.indexOf("powerpc") != -1)));
	//MAC MSIE CHECK
	this.macie = (this.mac && this.ie);
	this.macie4 = (this.mac && (agent.indexOf("msie 4") != -1));
	this.macie401 = (this.mac && (agent.indexOf("msie 4.01") != -1));
	this.macie45 = (this.mac && (agent.indexOf("msie 4.5") != -1));
	this.macie5 = (this.mac && (agent.indexOf("msie 5.0") != -1));
	this.macie6 = (this.mac && (agent.indexOf("msie 6.0") != -1));
	// MAC SAFARI
	//this.safari = (this.mac && (agent.indexOf("safari")!=-1)); //pg2-removed
	this.safari = (agent.indexOf("safari") != -1 && agent.indexOf("chrome") == -1); //pg2-safari is now also for windows //pg2-completion- string shouldn't contain 'chrome'

	//OPERA CHECK
	this.opera = (agent.indexOf("opera") != -1);
	this.opera3 = (this.opera && (agent.indexOf(") 3.0") != -1));
	this.opera321 = (this.opera && (agent.indexOf(") 3.21") != -1));
	this.opera351 = (this.opera && (agent.indexOf(") 3.51") != -1));
	this.opera360 = (agent.indexOf("opera 3.60") != -1);
	this.opera361 = (agent.indexOf("opera 3.61") != -1);
	this.opera362 = (agent.indexOf("opera 3.62") != -1);
	this.opera4 = (agent.indexOf("opera 4") != -1);
	this.opera5 = (agent.indexOf("opera 5") != -1);
	this.opera51 = (agent.indexOf("opera 5.1") != -1);
	this.opera52 = (agent.indexOf("opera 5.2") != -1);
	this.opera6 = (agent.indexOf("opera 6") != -1);
	this.opera7 = (agent.indexOf("opera 7") != -1);

	//WEB TV CHECK
	this.webtv = (agent.indexOf("webtv") != -1);
	this.webtv12 = this.webtv && (agent.indexOf("1.2") != -1);
	this.webtv22 = this.webtv && (agent.indexOf("2.2") != -1);

	//WINDOWS CHECK
	this.win = ((agent.indexOf("win") != -1) || (agent.indexOf("16bit") != -1));
	this.win95 = ((agent.indexOf("win95") != -1) || (agent.indexOf("windows 95") != -1));
	this.win16 = ((agent.indexOf("win16") != -1) || (agent.indexOf("16bit") != -1)
		|| (agent.indexOf("windows 3.1") != -1) || (agent.indexOf("windows 16-bit") != -1));
	this.win31 = ((agent.indexOf("windows 3.1") != -1) || (agent.indexOf("win16") != -1)
		|| (agent.indexOf("windows 16-bit") != -1));
	this.win98 = ((agent.indexOf("win98") != -1) || (agent.indexOf("windows 98") != -1));
	this.winnt = ((agent.indexOf("winnt") != -1) || (agent.indexOf("windows nt") != -1));
	this.winnt4 = (agent.indexOf("windows nt 4.0") != -1);
	this.winnt5 = (agent.indexOf("windows nt 5.0") != -1);
	this.winnt6 = (agent.indexOf("windows nt 6.0") != -1);
	this.win2pro = (agent.indexOf("win2000pro") != -1);
	this.win21 = (agent.indexOf("windows 2001") != -1);
	this.wince = (agent.indexOf("windows ce") != -1);
	this.winxp = (agent.indexOf("windows xp") != -1);

	this.chrome = (agent.indexOf("chrome") != -1 || agent.indexOf("Chrome") != -1); //pg2
	if (RegExp("firefox").test(agent) && !RegExp("navigator").test(agent)) {
		this.firefox = true;
		this.ns = false;
	} else
	if (RegExp("navigator").test(agent) && RegExp("firefox").test(agent) && !RegExp("safari").test(agent) && !RegExp("chrome").test(agent)) {
		this.firefox = false;
		this.ns = true;
	} else {
		this.firefox = false;
		this.ns = false;
	};

	this.browserVersion = '0.0'; //pg2-browser version
	if (this.ie) this.browserVersion = navigator.appVersion.replace(/(.*)(MSIE )([0-9.]+)(.*)/,"$3"); else
	if (this.firefox) this.browserVersion = navigator.userAgent.replace(/(.*)(Firefox\/)(.*)/,"$3"); else
	if (this.ns) this.browserVersion = navigator.userAgent.replace(/(.*)(Navigator\/)(.*)/,"$3").substring(0, 3); else
	if (this.safari) this.browserVersion = navigator.userAgent.replace(/(.*)(Version\/)(.*)/,"$3"); else
	if (this.chrome) this.browserVersion = navigator.userAgent.replace(/(.*)(Chrome\/)(.*)/,"$3"); else
	if (this.opera) this.browserVersion = navigator.userAgent.replace(/(.*)(Version\/)(.*)/,"$3");
	if (this.browserVersion.indexOf('.') == 2) this.browserVersion = this.browserVersion.substring(0, 4); else this.browserVersion = this.browserVersion.substring(0, 3); //pg2

	//pg2-ie11 and up
	if (!this.ie && this.moz && !this.firefox && !this.safari && !this.chrome && !this.opera && this.browserVersion == '0.0' && agent.indexOf('trident') > 0) {
		//this.ie = true;  //pg2-it can not be like this - most properties (DOM) are'nt the same, some have been removed by Microsoft
		this.ie11up = true;
		var s = '';
		try {
			var iv = agent.indexOf('rv:');
			if (iv > -1) {
				s = agent.substr(iv+3);
				iv = s.indexOf('.');
				//alert(s + ' , ' + iv)
				if (iv > -1) s = s.substr(0, iv+2); else s = '';
				this.browserVersion = s;
			};
			this.ie11 = (s.indexOf('11.') != -1);
		} catch(e) {
			s = '';
		};
		//this.browserVersion = navigator.userAgent.replace(/(.*)(rv\:)(.*)/,"$3");
	};

	this.operatingSystem = '';
	if (agent.indexOf('windows nt 5.1') != -1) this.operatingSystem = 'WindowsXP'; else
	if (agent.indexOf('windows nt 6.0') != -1) this.operatingSystem = 'WindowsVista'; else
	if (agent.indexOf('windows nt 6.1') != -1) this.operatingSystem = 'Windows7'; else
	if (agent.indexOf('windows nt 6.2') != -1) this.operatingSystem = 'Windows8'; else //pg2-ie11 and up
	if (agent.indexOf('windows nt 6.3') != -1) this.operatingSystem = 'Windows8.1';

	this.str = 'ie       : ' + this.ie + '\n' + //pg2-test
	          'moz      : ' + this.moz + '\n' +
	          'firefox  : ' + this.firefox + '\n' +
			  'netscape : ' + this.ns + '\n' +
			  'safari   : ' + this.safari + '\n' +
			  'chrome   : ' + this.chrome + '\n' +
			  'opera    : ' + this.opera + '\n\n' +
			  'VERSION  : ' + this.browserVersion + '\n\n' +
			  'mobile   : ' + this.mobile + '\n\n' +
			  'OS : ' + this.operatingSystem + '\n\n' +
			  'IE 11 : ' + this.ie11 + '\n\n' +
			  'IE 11up: ' + this.ie11up;
	//alert(this.str);
};

if (typeof(top.is) == 'undefined') { //pg2-ie11 and up -don't create it many times over
	is = new Browser();
	top.is = is;
} else is = top.is;
