function isUsingFirefox() {
	try {
        return (-1 != navigator.userAgent.indexOf('Firefox'));
	} catch (ex) {
		return false;
	}
}
	
var OSDetect = {
    init: function () {
        this.OS = this.searchString(this.dataOS) || false;
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    dataOS : [
        {
            string: navigator.platform,
            subString: "Win",
            identity: "windows"
        },
        {
            string: navigator.platform,
            subString: "Mac",
            identity: "mac"
        },
        {
            string: navigator.platform,
            subString: "Linux",
            identity: "linux"
        }
    ]

};

function showfor_detect_os() {
    OSDetect.init();
	return OSDetect.OS;
}

function showfor_detect_browser() {
    if (!isUsingFirefox()) return false;
    var match = /Firefox\/(\d\.\d)/.exec(navigator.userAgent);
    switch (match[1]) {
    case "2.0":
        return "firefox2";
    case "3.0":
        return "firefox3.0";
    case "3.1":
    case "3.5":
    case "3.6":
        return "firefox3.6";
    default:
        return false;
    }
}

function showfor_start_os( os, detect ) {
	if ( detect == true ) {
		var saved_os = getCookie('showfor_os');
		if (saved_os) {
			showfor(saved_os);
			return true;
		}
		var detected_os = showfor_detect_os();
	} else {
		var detected_os = false;
	}
	if (!detected_os) {
		showfor(os);
	} else {
		showfor(detected_os);
	}
	return true;
}

function showfor_start_browser( browser, detect ) {
	if ( detect == true ) {
		var saved_browser = getCookie('showfor_browser');
		if (saved_browser) {
			showfor_alert_fx2eol(saved_browser);
			showfor(saved_browser);
			return true;
		}
		var detected_browser = showfor_detect_browser();
	} else {
		var detected_browser = false;
	}
	if (!detected_browser) {
		showfor_alert_fx2eol(browser);
		showfor(browser);
	} else {
		showfor_alert_fx2eol(detected_browser);
		showfor(detected_browser);
	}
	return true;
}

function showfor_save_os(tab) {
	setCookie('showfor_os', tab, '', '', '/');
	return true;
}

function showfor_save_browser(tab) {
	showfor_alert_fx2eol(tab);
	setCookie('showfor_browser', tab, '', '', '/');
	return true;
}

function showfor_alert_fx2eol(tab) {
	if (document.getElementById("fx2eol")) {
		if (tab == "firefox2") {
			document.getElementById("fx2eol").style.display = 'block';
		}
		else {
			document.getElementById("fx2eol").style.display = 'none';
		}
	}
}
