//****************
//**  FUNCTIONS **
//****************

//Makes Sure User Is Using HTTPS
function clicksecure(sSecureDir) {
	var sSecure = "";
	var iPos = 0;
	var sHost = location.host.toLowerCase();

	sSecure = "https://ssl.scribebase.com/secure/mobile"

	if (browsercheck()) {
		//INTRANET
		if (sHost.indexOf(".") == -1) 
			sSecure = "http://" + sHost + "/" + sSecureDir;
		else
			sSecure = "https://ssl.scribebase.com/" + sSecureDir;
	}

	top.location = sSecure;
}

function makesecure() {
	var sSecure = "";
	var iPos = 0;

	//Only Do this if protocol is not https
	if (location.protocol.toUpperCase() == "HTTPS:")
		return;

	var sLoc = location.href;
	var sHost = location.host.toLowerCase();

	//Need Secure Connection On Internet
	if (sHost.indexOf(".") != -1) {
		iPos = sLoc.indexOf("//")
		if (iPos > 0) {
			sLoc = sLoc.substring(iPos+1,sLoc.length);

			if (sLoc.charAt(sLoc.length-1) != "/")
				sLoc = sLoc + "/"	;
			if (sLoc.charAt(0) == "/")
				sSecure = "https:/" + sLoc 
			else
				sSecure = "https://" + sLoc
		}
	}


	if (sSecure != "")
		top.location = sSecure;
}

function browsercheck() {
	var bValid = false

	if (safari() >= 1.0)
		bValid = true;

	if (msieversion() >= 6.0)
		bValid = true;

	if (!bValid) 
		if(netgecko("fire") >= 3.0)
			bValid = true;
	
	//Is This A Phone
	if (PhoneCheck())
		bValid = false;

	if (bValid)
		return (true);
	else
		return (false);
}

function PhoneCheck() {
	var sAgt = navigator.userAgent.toLowerCase();

	if (sAgt.indexOf("mobile") != -1 || sAgt.indexOf("windows ce") != -1 || sAgt.indexOf("up.") != -1)
		return (true);
	if (sAgt.indexOf("pda") != -1 || sAgt.indexOf("pocket") != -1 || sAgt.indexOf("wap") != -1)
		return (true);
	if (sAgt.indexOf("palm") != -1 || sAgt.indexOf("symbian") != -1 || sAgt.indexOf("android") != -1)
		return (true);
	if (sAgt.indexOf("iphone") != -1 || sAgt.indexOf("ipod") != -1 || sAgt.indexOf("mini") != -1)
		return (true);
	if (sAgt.indexOf("midp") != -1 || sAgt.indexOf("psp") != -1 || sAgt.indexOf("mmp") != -1)
		return (true);

	return (false);
}

function msieversion() {
	var ua = window.navigator.userAgent
	var msie = ua.indexOf("MSIE ");

	// If IE, return version number
	if (msie > 0)
		return parseFloat(ua.substring (msie+5, ua.indexOf(";",msie)))
	
	 // If another browser, return 0
	return (0)
}

function netgecko(sBrowser) {
	var agt = navigator.userAgent.toLowerCase();

	if (agt.indexOf("gecko") != -1) {
		if (sBrowser == "nav" && agt.indexOf("navigator/") != -1) {
			var i = agt.indexOf("navigator/")
			return parseFloat(agt.substring(i+10,i+13));
		}
		if (sBrowser == "fire" && agt.indexOf("firefox/") != -1) {
			var i = agt.indexOf("firefox/")
			return parseFloat(agt.substring(i+8,i+13));
		}
	}
	
	return (0);
}

function safari() {
	var agt = navigator.userAgent.toLowerCase();
	
	if (agt.indexOf("safari/") != -1)
		return (1.0)
	
	return (0);
}