
/*
	Knowledge 111 Ltd Browser Check Script
	Auth: ivar Abrahamsen

*/
var _DEBUG = 0;
var minFlashVersion = 5;

function specObj(){
	this.msgError = "Your browser settings did not pass our requirements.\n"
		+ "You can still try to log into Aktiv,\n"
		+ "however we are concerned the session will not be succesfull.\n"
		+ "These tests were not succesfull in your browser:\n\n";
	this.msgWarn = "Your browser settings are not optimal for accessing the Aktiv system.\n"
		//+ "Although you will be able to access the system,\n"
		+ "Although it may still work, you may not view the System as intended.\n"
		//+ "The session may be able to view the System as intended.\n"
		+ "\nThese tests were not succesfull in your browser:\n \n \n \n";
	this.msgEnd = "\n\n\nPlease read the next page more thorough explanation of these\n"
		+ "requirements and then you may try to log in on the bottom of that page.\n";
	this.pageError = "/ConfigError.html";
	this.pageWarn = "/ConfigWarning.html";
	this.pageLogin = "";
}

	//based on Get cookie routine by Shelley Powers
function getCookie(sName) {

	var aCookie = document.cookie.split(/ *; */);
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split(/ *= */);
		if (sName == aCrumb[0]) {
			return unescape(aCrumb[1]);
		}
	}
	return null;
}

function setTheCookie(){
	document.cookie = "K111_TEST_=SUCCESS; path=/";
}

function setNoCheckCookie(){
	//this.date = new Date(3001,1,2,3,4,5);
	this.dater = new Date();
	this.dater = new Date( this.dater.getTime() + 1000*60*60*12*1 );
	document.cookie = "K111_CHECK_=FALSE; expires=" + this.dater.toGMTString();
}

function popper(spec,errs,warns){
	this.msg = "";
	if(errs != "" && warns != "")
		this.msg = spec.msgError + errs + spec.msgEnd;
	else if(errs != "" && warns == "")
		this.msg = spec.msgError + errs + spec.msgEnd;
	else if(warns != "")
		this.msg = spec.msgWarn + warns + spec.msgEnd;
	else
		return;
	alert(this.msg);
}

function relocate(specs,errs,warns ){
	if(errs != "" )
		return specs.pageError;
	else if (warns != "")
		return specs.pageWarn;
	else if (specs.pageLogin != "")
		return specs.pageLogin;
	else
		return "";
}

function BCloader(flashWarn){
	this.specs = new specObj();
		setTheCookie();
		this.Date = new Date();
		this.warnMsg = flashWarn || "";
		this.errorMsg = "";
		if( getCookie( "K111_TEST_" ) != "SUCCESS" )
			this.errorMsg += "*\tCookies could not be stored.\n" ;
		popper(this.specs, this.errorMsg,this.warnMsg);
		return relocate(this.specs, this.errorMsg,this.warnMsg);//alert( this.searches.indexOf( "browsecheck=false" ) );
	//}
	//return ""
}
//var flashVersion = getFlashVersion();
function flashBrowseLoader() {
	this.searches = document.location.search;
	if( this.searches.indexOf( "browsecheck=false" ) > 0 ){
		setNoCheckCookie();
		return "";
	} else if ( getCookie( "K111_CHECK_" ) != null )
		return "";
	this.flashVersion = getFlashVersion();
	this.flashSpec = new specObj();
	this.warn = ( this.flashVersion < minFlashVersion )
		? ( this.flashVersion >= 1 )
			? "Your Flash PlugIn version (" + this.flashVersion
				+ ") is too low.\nThis Aktiv version requires version "
				+ minFlashVersion + " or higher.\n"
			: "We could not detect that you had Flash installed.\n"
				+ "If you think you do have it installed,\nand it is above version "
				+ minFlashVersion + " then you may try to access the system."
		: "" ;
	return BCloader(this.warn);
}


//##### IEA K111 @ 2K3
