
var iCurrentFlashVersion  = null;
var iRequiredFlashVersion = 8;
var iMaximumFlashVersion  = 15;
var forwardUrl = "index.jsp";
var startUrl = "index2.jsp";

/* cookie Object
---------------------------------------------------------------------*/

function Cookie(){

	var COOKIE_EXPIRE_DATE = new Date(2030,12,31);

	Cookie.prototype.work = function(){
		this.set("test", "true");
		retVal = this.get("test") != null;
		this.delCookie("test");
		return retVal;
	}

	Cookie.prototype.set = function(sAttribute, mValue){
		document.cookie = sAttribute + "=" + mValue + "; path=/";
	}

	Cookie.prototype.setPersistent = function(sAttribute, mValue, dDate){
		if(!dDate) dDate = COOKIE_EXPIRE_DATE;
		document.cookie = sAttribute + "=" + mValue + "; expires=" + dDate.toGMTString() + "; path=/";
	}

	Cookie.prototype.get = function(sAttribute){
		var i = document.cookie.indexOf( sAttribute + "=" );
		if( -1 != i ){
			var e = document.cookie.slice( i ).indexOf( ";" );
			mValue = document.cookie.slice(i + sAttribute.length + 1, (-1 != e) ? e + i : document.cookie.length );
			return mValue;
		}
		return null;
	}

	Cookie.prototype.delCookie = function(sAttribute){
		document.cookie = sAttribute + "=; expires="+((new Date((new Date()).getTime()+(-10000))).toGMTString())+"; path=/";
	}
}

function ClientInfo(newCheck){

	if(!newCheck) newCheck = false;

	// public attributes
	this.userPlatform        = "unknown";
	this.userAgentName       = "unknown";
	this.userAgentVersion    = 0;
	this.isAcceptedBrowser   = false;
	this.isRestrictedBrowser = false;
	this.acceptCookies       = false;
	this.hasFlash            = false;
	this.acceptPureHTML      = false;
	this.displayFlash        = false;    // CHANGE THIS TO true FOR FLASHUI !!! KILL COOKIE AND CACHE ! 
	
	// private variables
	var myCookie = new Cookie();

	// public methods
	ClientInfo.prototype.setDisplayFlash = function(displayFlash){
		alert(displayFlash);
		this.displayFlash = displayFlash;
	}
	
	ClientInfo.prototype.setUserPlatform = function(){
		var retVal = "unknown";
		var myUserAgent = navigator.userAgent.toLowerCase();
		var myPlatform  = navigator.platform.toLowerCase();
		if(myUserAgent.indexOf("win") != -1 && myPlatform.indexOf("win") != -1)
			retVal = "win";
		else if(myUserAgent.indexOf("mac") != -1 && myPlatform.indexOf("mac") != -1)
			retVal = "mac";
		else
			retVal = "unknown";

		this.userPlatform = retVal;
	}

	ClientInfo.prototype.setUserAgentName = function(){
		var retVal = "unknown";
		var myUserAgent = navigator.userAgent.toLowerCase();
		if(myUserAgent.indexOf("opera") != -1)
			retVal = "opera";
		else if(myUserAgent.indexOf("safari") != -1)
			retVal = "safari";
		else if(myUserAgent.indexOf("firefox") != -1)
			retVal = "firefox";
		else if(myUserAgent.indexOf("msie") != -1)
			retVal = "msie";
		else if(myUserAgent.indexOf("gecko") != -1)
			retVal = "mozilla";
		else
			retVal = "unknown";

		this.userAgentName = retVal;
	}

	ClientInfo.prototype.setUserAgentVersion = function(){
		var retVal = "0.0";
		var vSearch = /./;
		var myUserAgent = navigator.userAgent.toLowerCase();
		switch(this.userAgentName){
			case "opera":
				vSearch = /opera\s(\d\.\d)\d*|opera\/(\d\.\d)\d*/i;
				version = vSearch.exec(myUserAgent);
				if(version != null)
					retVal = (version[1]) ? version[1] : version[2];
			break;
			case "safari":
				vSearch = /Safari\/(\d{3})\.\d+/i;
				version = vSearch.exec(myUserAgent);
				if(version != null)
					retVal = (version[1] >= 125) ? 1.0 : 0;
			break;
			case "firefox":
				vSearch = /Firefox\/(\d\.\d)/i;
				version = vSearch.exec(myUserAgent);
				if(version != null)
					retVal = version[1];
			break;
			case "msie":
				vSearch = /MSIE\s(\d\.\d)/i;
				version = vSearch.exec(myUserAgent);
				if(version != null)
					retVal = version[1];
			break;
			case "mozilla":
				vSearch = /rv:(\d\.\d)/i;
				version = vSearch.exec(myUserAgent);
				if(version != null)
					retVal = version[1];
			break;
			default:
				retVal = "0.0";
			break;
		}

		this.userAgentVersion = retVal;
	}

	ClientInfo.prototype.setIsAcceptedBrowser = function(){
		this.isAcceptedBrowser = (
									(this.userAgentName == "msie" && this.userAgentVersion >= 6) || // Microsoft Internet Explorer 6
									(this.userAgentName == "firefox" && this.userAgentVersion >= 1) || // Firefox 1.0
									(this.userAgentName == "safari") || // Safari
									(this.userAgentName == "mozilla" && this.userAgentVersion >= 1.6) // Mozilla 1.6
								);
	}

	ClientInfo.prototype.setIsRestrictedBrowser = function(){
		this.isRestrictedBrowser = (
										!this.isAcceptedBrowser &&
										(
											(this.userPlatform == "mac" && this.userAgentName == "msie" && this.userAgentVersion >= 5.2) || // Mac IE 5.2
											(this.userAgentName == "mozilla" && this.userAgentVersion <= 1.5) || // Mozilla 1.6
											(this.userAgentName == "opera" && this.userAgentVersion <= 7.5)
										)
									);
	}

	ClientInfo.prototype.setAcceptCookies = function(){
		this.acceptCookies = myCookie.work();
	}

	ClientInfo.prototype.setHasFlash = function(){
		if(this.userAgentName == "msie" && this.userPlatform == "win" && (myCookieValue = myCookie.get("clientinfo")) != null){
			iCurrentFlashVersion = vbGetFlashVersion(); //this throws an error (object expected) if no cookies present..
		}
		if(navigator.plugins){
			if(navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){
				var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
				iCurrentFlashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
			}
		}
		//alert ("iCurrentFlashVersion = " + iCurrentFlashVersion + "\niRequiredFlashVersion = " + iRequiredFlashVersion + "\n$1 >= $2 ??: " + (iCurrentFlashVersion >= iRequiredFlashVersion));
		this.hasFlash = (iCurrentFlashVersion >= iRequiredFlashVersion);
	}

	ClientInfo.prototype.setAcceptPureHTML = function(){
		// this flag will be set to "true" just if the user accept this limitation at the following warning page!
		if((myCookieValue = myCookie.get("clientinfo")) != null){
			myKeyValues = myCookieValue.split("|");
			for(var i = 0; i < myKeyValues.length; i++){
				myKeyValue = myKeyValues[i];
				key = myKeyValue.split(":")[0];
				value = myKeyValue.split(":")[1];
				if(key == "acceptPureHTML")
					this.acceptPureHTML = eval(value);
			}
		}
		else
			this.acceptPureHTML = false;
	}

	// constructing this object:
	if(!newCheck && (myCookieValue = myCookie.get("clientinfo")) != null){
		myKeyValues = myCookieValue.split("|");
		for(var i = 0; i < myKeyValues.length; i++){
			myKeyValue = myKeyValues[i];
			key = myKeyValue.split(":")[0];
			value = myKeyValue.split(":")[1];
			if(key == "userPlatform" || key == "userAgentName") eval("this." + key + " = '" + value + "'");
			else eval("this." + key + " = " + value);
		}
	}
	else{
		this.setAcceptCookies();
		this.setUserPlatform();
		this.setUserAgentName();
		this.setUserAgentVersion();
		this.setIsAcceptedBrowser();
		this.setIsRestrictedBrowser();
		this.setHasFlash();
		this.setAcceptPureHTML();
		
		var myCookieValue =	"" +
							"displayFlash:" + this.displayFlash + "|" +
							"userPlatform:" + this.userPlatform + "|" +
							"userAgentName:" + this.userAgentName + "|" +
							"userAgentVersion:" + this.userAgentVersion + "|" +
							"isAcceptedBrowser:" + this.isAcceptedBrowser + "|" +
							"isRestrictedBrowser:" + this.isRestrictedBrowser + "|" +
							"acceptCookies:" + this.acceptCookies + "|" +
							"hasFlash:" + this.hasFlash + "|" +
							"acceptPureHTML:" + this.acceptPureHTML 
						;

		myCookie.setPersistent("clientinfo", myCookieValue);
	}
}

function setAcceptPureHTML(accept){
	var myCookie = new Cookie();
	var myClientInfo = new ClientInfo();
	var myCookieValue =	"" +
						"displayFlash:" + myClientInfo.displayFlash + "|" +
						"userPlatform:" + myClientInfo.userPlatform + "|" +
						"userAgentName:" + myClientInfo.userAgentName + "|" +
						"userAgentVersion:" + myClientInfo.userAgentVersion + "|" +
						"isAcceptedBrowser:" + myClientInfo.isAcceptedBrowser + "|" +
						"isRestrictedBrowser:" + myClientInfo.isRestrictedBrowser + "|" +
						"acceptCookies:" + myClientInfo.acceptCookies + "|" +
						"hasFlash:" + myClientInfo.hasFlash + "|" +
						"acceptPureHTML:" + accept
					;

	myCookie.setPersistent("clientinfo", myCookieValue);
	if(forwardUrl){
		forwardUrl = (accept) ? startUrl : forwardUrl;
	}
}

function setDisplayFlash(accept){
	var myCookie = new Cookie();
	var myClientInfo = new ClientInfo();
	var myCookieValue =	"" +
						"displayFlash:" + accept + "|" +
						"userPlatform:" + myClientInfo.userPlatform + "|" +
						"userAgentName:" + myClientInfo.userAgentName + "|" +
						"userAgentVersion:" + myClientInfo.userAgentVersion + "|" +
						"isAcceptedBrowser:" + myClientInfo.isAcceptedBrowser + "|" +
						"isRestrictedBrowser:" + myClientInfo.isRestrictedBrowser + "|" +
						"acceptCookies:" + myClientInfo.acceptCookies + "|" +
						"hasFlash:" + myClientInfo.hasFlash + "|" +
						"acceptPureHTML:" + myClientInfo.acceptPureHTML
					;

	myCookie.setPersistent("clientinfo", myCookieValue);
	if(forwardUrl){
		forwardUrl = (accept) ? startUrl : forwardUrl;
	}
}

function warningProceed(){
	top.location.href= forwardUrl;
}

var myClientInfo = new ClientInfo();