/*
* Browser Check Utility - determines the version of Internet Explorer viewing the current page. 
*
* @author       Tim Dennis   2-14-2007 
*/
function BrowserChk() {
	var b = navigator.appName;
	if (b=="Netscape")
		this.b = "ns";
	else if (b=="Microsoft Internet Explorer") 
		this.b = "ie";
	else 
		this.b = b;
	if(navigator.appVersion.toUpperCase().indexOf("SAFARI") >= 0){
		this.b = "safari";
	}
	this.v = parseInt(navigator.appVersion);
	this.ns = (this.b=="ns" && this.v >= 4);
	this.ns4 = (this.b=="ns" && this.v == 4);
	this.ns5 = (this.b=="ns" && this.v == 5);
	this.ie = (this.b=="ie" && this.v >= 4);
	this.safari = (this.b == "safari");
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0);
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0);
	this.ie7 = (navigator.userAgent.indexOf('MSIE 7')>0);
	if (this.ie4)
		this.v=5;
	if (this.ie5)
		this.v=5;
	if (this.ie6)
		this.v=6;
	if (this.ie7)
		this.v=7;
}

var BrowserCheck = new BrowserChk();


/*
* Protocol & Secure Connection Check - Check the page, detemine if the ceonnection needs to be secure (define in the checkHTTPSProtocol() function)
* 
* @author       Joe Mallory   8-27-2008 
*/
function getFullURL() {
	var locURL = window.location.href;
	return locURL;	
}

function getURLParts() {
	var urlParts = getFullURL();
	var urlSplit = urlParts.split("//");
	var urlFinal = urlSplit[1];
	return urlFinal;
}

function getURLDirectory() {
	var urlParts = getURLParts();
	var urlSplit = urlParts.split("/");
	var urlFinal = urlSplit[(urlSplit.length - 2)];
	return urlFinal;
}

function getURLPage() {
	var urlParts = getURLParts();
	var urlSplit = urlParts.split("/");
	var urlFinal = urlSplit[(urlSplit.length - 1)];
	return urlFinal;
}

function getURLQuryString() {
	var fullURL = getFullURL();
	var qString = fullURL.split("?");
	return qString;
}

function getPageURL(url) {
	var fn = url.match(/\/([a-z0-9_-]+\.\w+)/i);
    return (fn == null) ? "" : fn[1];
}

function forceHTTPSProtocol() {
	var currURL = getFullURL();
	var currProtocol = currURL.split(":");
	if (currProtocol[0] === "http") {
		location.href = "https:" + currProtocol[1];
	}
}

function forceHTTPProtocol() {
	var currURL = getFullURL();
	var currProtocol = currURL.split(":");
	if (currProtocol[0] === "https") {
		location.href = "http:" + currProtocol[1];
	}
}

function checkHTTPSProtocol(currDirectory, currPage) {
	if (currDirectory === "store" || currPage === "store.aspx" || currPage === "itemList.aspx") {
		forceHTTPSProtocol();
	} else {
		forceHTTPProtocol();
	}
}

// First Check if Secure Connections are Needed from List in customFunctions.js
//checkHTTPSProtocol(getURLDirectory(), getURLPage());
