﻿//global.js
Type.registerNamespace('CVN68.Settings');
var $UI = CVN68.Settings;

var pageMgr = Sys.WebForms.PageRequestManager.getInstance();

CVN68.Settings.apply = function(target, src, def) {
	if (def) {
		CVN68.Settings.apply(target, def);
	}

	if (target && src && typeof src == 'object') {
		for (var p in src) {
			target[p] = src[p];
		}
	}
	return target;
};

(function() {
	var ua = navigator.userAgent.toLowerCase();
	var isStrict = document.compatMode == "CSS1Compat",
        isOpera = ua.indexOf("opera") > -1,
        isSafari = (/webkit|khtml/).test(ua),
        isSafari3 = isSafari && ua.indexOf('webkit/5') != -1,
        isIE = !isOpera && ua.indexOf("msie") > -1,
        isIE7 = !isOpera && ua.indexOf("msie 7") > -1,
		isIE8 = !isOpera && ua.indexOf("msie 8") > -1,
        isGecko = !isSafari && ua.indexOf("gecko") > -1,
        isFirefox2 = isGecko && ua.indexOf("firefox/2") > 1,
        isFirefox3 = isGecko && ua.indexOf("firefox/3") > 1,
        isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
        isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
        isSecure = window.location.href.toLowerCase().indexOf("https") === 0;

	//This puts the browser and platform into the class attribute of HTML tag to allow browser sniffing in CSS.
	//Not worth try to refactor to use the vars above - based on http://rafael.adm.br/css_browser_selector/
	var h = document.getElementsByTagName('html')[0];
	var is = function(t) { return ua.indexOf(t) != -1; };
	var b = (!(/opera|webtv/i.test(ua)) && /msie (\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('gecko/') ? 'gecko' : is('opera/9') ? 'opera opera9' : /opera (\d)/.test(ua) ? 'opera opera' + RegExp.$1 : is('konqueror') ? 'konqueror' : is('applewebkit/') ? 'webkit safari' : is('mozilla/') ? 'gecko' : '';
	var os = (is('x11') || is('linux')) ? ' linux' : is('mac') ? ' mac' : is('win') ? ' win' : '';

	// Added to determine the current section of the website as it loads    
	var str = window.location.pathname;
	var ar = str.split('/');
	var xr = ar[1].split('.'); //trim off the .aspx

	var cls = b + os + ' js';
	h.className += h.className ? ' ' + cls : cls;


	// this block is applied inside the fn because we're accessing the private vars above to create the public properties.
	CVN68.Settings.apply(CVN68.Settings, {
		/**
		* True if the browser is in strict mode
		* @type Boolean
		*/
		isStrict: isStrict,
		/**
		* True if the page is running over SSL
		* @type Boolean
		*/
		isSecure: isSecure,
		/** @type Boolean */
		isOpera: isOpera,
		/** @type Boolean */
		isSafari: isSafari,
		/** @type Boolean */
		isSafari3: isSafari3,
		/** @type Boolean */
		isSafari2: isSafari && !isSafari3,
		/** @type Boolean */
		isIE: isIE,
		/** @type Boolean */
		isIE6: isIE && (!isIE7 && !isIE8),
		/** @type Boolean */
		isIE7: isIE7,
		isIE8: isIE8,
		/** @type Boolean */
		isGecko: isGecko,
		/** @type Boolean */
		isFirefox2: isFirefox2,
		/** @type Boolean */
		isFirefox3: isFirefox3,
		/** @type Boolean */
		isWindows: isWindows,
		/** @type Boolean */
		isMac: isMac
	}
	);
})();