// Constructor for Browser object
// Detects if client browser is IE or not
// If IE, returns other properties
function Browser() {

    var x
    var n = navigator
    var ua = n.userAgent.toLowerCase();

    var browserName = n.appName
    var browserVersion = ""
    var isIE = false
    var OS = ""
    var screenRes = screen.width + "x" + screen.height
    var colorDepth = screen.colordepth
	var cookieEnabled = navigator.cookieEnabled;

    if (ua.indexOf('msie') > 0) {
        browserVersion = parseInt(ua.charAt(ua.indexOf('msie') + 5));
        isIE = true

        x = (n.appVersion.indexOf(';') + 1);
        y = n.appVersion.indexOf(')');
        msiestring = n.appVersion.substring(x,y);
        msiestart = msiestring.indexOf(';')+1;
        OS = msiestring.substring(msiestart);

    } else {
        isIE = false
    }

    this.browserName = browserName
    this.browserVersion = browserVersion
    this.isIE = isIE
    this.OS = OS
    this.screenRes = screenRes
    this.colorDepth = colorDepth
	this.cookieEnabled = cookieEnabled

}

function setBrowserCookie() {

    var expires = new Date()
    // Cookies will be set to expire in 24 hours
    var tomorrow = expires.getTime() + (24 * 60 * 60 * 1000)
	expires.setTime(tomorrow)

    var c

    // save Browser Name
    c = "browserName=" + escape(browser.browserName) + "; "
	document.cookie = c

    // save Browser Version
    c = "browserVersion=" + escape(browser.browserVersion) + "; "
	document.cookie = c

    // save Operating System
    c = "OS=" + escape(browser.OS) + "; "
	document.cookie = c

    // save Screen Resolution
    c = "screenRes=" + escape(browser.screenRes) + "; "
	document.cookie = c

    // save Color Depth
    c = "colorDepth=" + escape(browser.colorDepth) + "; expires=" + expires.toGMTString()
	document.cookie = c

}

function checkBrowser() {

    if (browser.isIE) {
		if (browser.cookieEnabled) {
	        setBrowserCookie()
		} else {
			window.location.href = "cookies_not_enabled.htm"
		}
    } else {
        window.location.href = "browser_not_supported.htm"
    }

}

var browser = new Browser()

checkBrowser()

