// class for managing psyma cookies
var psymaCookieManager = {
	"psyma_show":1,
	"init":function(show){
		if(show == 1) {
			psyma_cookie_id = "psyma_participation";
			psyma_participation = this.get_psyma_cookie(psyma_cookie_id);
			psyma_cookie_exp = this.psyma_get_expiration_date("30");
		}
		else {
			psyma_cookie_id = "psyma_participation";
			psyma_participation = this.get_psyma_cookie(psyma_cookie_id);
			psyma_cookie_exp = this.psyma_get_expiration_date("30");
		}
		if(psyma_participation != 1 && psyma_participation != 2)
		{
			this.set_psyma_cookie(psyma_cookie_id, 1, "/", "", "", psyma_cookie_exp);
		}
		else {
			this.psyma_show = 0;
		}	

	},
	// write specific cookie
	"switch_cookie" :function(type){
		if(type == "accept") {
			psyma_cookie_id = "psyma_participation";
			psyma_cookie_exp = this.psyma_get_expiration_date("30");
		}	
		else if(type == "deny") {
			psyma_cookie_id = "psyma_participation";
			psyma_cookie_exp = this.psyma_get_expiration_date("30");
		}	
		else if(type == "close") {
			psyma_cookie_id = "psyma_participation";
			psyma_cookie_exp = this.psyma_get_expiration_date("30");
		}	
		else if(type == "delay") {
			psyma_cookie_id = "psyma_participation";
			psyma_cookie_exp = this.psyma_get_expiration_date("30");
		}	
		this.set_psyma_cookie(psyma_cookie_id, 2, "/", "", "", psyma_cookie_exp);
	},
	// get expiration date
	"psyma_get_expiration_date":function(psyma_day_offset){
		if(psyma_day_offset == "None" || psyma_day_offset == "none")
			return -1;
		if(psyma_day_offset == "Session" || psyma_day_offset == "session")
			return 0;
		var psyma_milli_offset = psyma_day_offset * 1000 * 60 * 60 * 24;
		var psyma_now = new Date();
		psyma_participation_exp = new Date(psyma_now.valueOf() + psyma_milli_offset);
		return psyma_participation_exp;
	},
		
	// get cookie
	"get_psyma_cookie":function(a)
	{
		var c=document.cookie.split(a+"=");
		return (c.length>1)?unescape(c[1].split(";")[0]):"";
	},

	// set cookie
	"set_psyma_cookie":function(name, value, path, domain, secure, expires)
	{
		if(expires != -1)
		{
			document.cookie =
			name + "="
			+ escape(value)
			+ ((path) ? "; path=" + path : "")
			+ ((expires) ? "; expires=" + expires.toGMTString() : "")
			+ ((domain) ? "; domain=" + domain : "")
			+ ((secure) ? "; secure" : "");
		}
	}

}// SWFObject
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

var psymaLayer = {
	"psyma_flash_version" : deconcept.SWFObjectUtil.getPlayerVersion(),
	"psyma_domain_check_text" : "",
	"psyma_js_loaded" : 0,
	"psyma_layer" : document.createElement('DIV'),
	"psyma_left" : 0,
	"psyma_top" : 0,
	"init":function() {
					this.psyma_layer.id = "psyma_layer";
			this.append_script(this.psyma_layer);
				
				if ((this.psyma_flash_version['major'] != 0) && (false == 1 || false == "true")){
					// flash detected, start flash layer
					var so = new SWFObject('http://scripts.psyma.com/html/flash/dynamic.swf','flashContent','500','450','9');
					so.addParam('allowfullscreen','false');
					so.addParam('wmode','transparent');
					so.addParam('flashvars',"xmlpath=http://scripts.psyma.com/scripts/abfr/abfr_seat.xml&psymaTest=");
					so.write('psyma_layer');
					
					var psyma_layer_script = document.createElement('script');
					psyma_layer_script.type = 'text/javascript';
					psyma_layer_script.src = 'http://scripts.psyma.com/lib/loaddc.php?xmlPath=http://scripts.psyma.com/scripts/abfr/abfr_seat.xml';
					this.append_script(psyma_layer_script);
				}
				else if(true == 1) {
					// no flash detected, start html layer
					var psyma_layer_script = document.createElement('script');
					psyma_layer_script.type = 'text/javascript';
					psyma_layer_script.src = 'http://scripts.psyma.com/html/layer/json.php?xmlPath=http://scripts.psyma.com/scripts/abfr/abfr_seat.xml&psyma_test=false';
					this.append_script(psyma_layer_script);
				}
				},
	"append_script":function(script)
	{
		if(document.body)
			document.body.appendChild(script);	
		else
			setTimeout(function () { psymaLayer.append_script(script); }, 500);
	},

	"psyma_wtp":function(locale)
	{
		this.psyma_open_link(locale,"wtp");
	},

	"psyma_privacy":function(locale)
	{
		this.psyma_open_link(locale,"privacy");	
	},

	"psyma_info":function(locale)
	{
		this.psyma_open_link(locale,"info");
	},

	"psyma_open_link":function(locale, type) {
		var link = "";
		var dimensions = "width=500,height=350";	
		switch(type)
		{
			case "wtp":
				link = "wtp/wtp.php";
				dimensions = "width=500,height=350";
			break;
			case "privacy":
				link = "privacy/privacy.php";
				dimensions = "width=600,height=680";
			break;
			case "info":
				link = "por/por.php";
				dimensions = "width=500,height=480";
			break;
		}
		window.open(
			"http://scripts.psyma.com/documents/" + link + '?lang=' + locale, 
			'por_' + type, 
			'toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,' + dimensions + ',top=0,left=0');
	},
	"psyma_accept_button":function()
	{
		psymaCookieManager.switch_cookie('accept');			// open window with domain_check
			var survey_window = window.open('', '',  'toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,width=470,height=300,top=0,left=0');
			if (survey_window)
			{
				survey_window.document.write(this.psyma_domain_check_text);
				survey_window.blur();
				survey_window.opener.focus();
			}
				this.psyma_hidelayer();
	},

	"psyma_deny_button":function() {
		this.psyma_hidelayer();
		psymaCookieManager.switch_cookie('deny');	},

	"psyma_close_button":function() {
		this.psyma_hidelayer();
		psymaCookieManager.switch_cookie('close');	},

	"psyma_delay_button":function() {
		this.psyma_hidelayer();
		psymaCookieManager.switch_cookie('delay');	},
	"psyma_updateLayer":function(html, domain_check_text, style, style_html, top, left) {
	
		var psyma_layer = document.getElementById('psyma_layer');
		this.psyma_layer.setAttribute('style',style);		this.psyma_left = left;
		this.psyma_top = top;
		
		var poswidth = this.psyma_getHorizontalAlignment(left,parseInt(psyma_layer.style.width));
		var posheight = this.psyma_getVerticalAlignment(top,parseInt(psyma_layer.style.width));
		this.psyma_layer.style.position = "absolute";
		this.psyma_layer.style.left = poswidth + "px";
		this.psyma_layer.style.top = posheight + "px";
		// special case for ie6 and below
				var psyma_html_layer = document.createElement('DIV');
		psyma_html_layer.id = "psyma_html_layer";
		
		psyma_html_layer.innerHTML = html;
		psyma_html_layer.setAttribute('style',style_html);		psyma_layer.appendChild(psyma_html_layer);
		this.psyma_domain_check_text = domain_check_text;
		this.psyma_showlayer();


		var psyma_layercount_script = document.createElement('script');
		psyma_layercount_script.type = 'text/javascript';
		psyma_layercount_script.src = 'http://scripts.psyma.com/scripts/count_json.php?type=layercount&id=1973&cr=100&code=0';
		this.append_script(psyma_layercount_script);

			},

	"psyma_updateDomainCheck":function(domain_check_text, style, top, left) {
		var psyma_layer = document.getElementById('psyma_layer');
		this.psyma_layer.setAttribute('style',style);		var poswidth = this.psyma_getHorizontalAlignment(left);
		var posheight = this.psyma_getVerticalAlignment(top);
		this.psyma_layer.style.left = poswidth + "px";
		this.psyma_layer.style.top = posheight + "px";
		
		this.psyma_domain_check_text = domain_check_text;
		this.psyma_showlayer();
	},

	"psyma_showlayer":function() {
		this.psyma_layer.style.display = "block";
		this.psyma_layer.style.visibility = "visible";
	},

	"psyma_hidelayer":function() {
		//var psyma_div = document.getElementById('psyma_layer');
		document.body.removeChild(this.psyma_layer);
	},
	
	"psyma_getHorizontalAlignment":function(left, width){
		width = width;
		if(left == "center"){
			var myWidth = 0;
			var poswidth = left;
			if(typeof(window.innerWidth) == 'number'){
				//Non-IE
				myWidth = window.innerWidth;
			}
			else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
			}
			else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
				//IE 4 compatible
				myWidth = document.body.clientWidth;
			}
			poswidth = (myWidth - width) / 2;
		}
		else
		{
			var poswidth = left;
		}
		return poswidth;
	},
	
	"psyma_getVerticalAlignment":function(top, width){
		// get height by width category
		if(width > 500)
			height = 460;
		else if(width >= 250)
			height = 300;
		else
			height = 150;
		
		if(top == "center"){
			var myHeight = 0;
			if(typeof(window.innerWidth) == 'number'){
				//Non-IE
				myHeight = window.innerHeight;
			}
			else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
				//IE 6+ in 'standards compliant mode'
				myHeight = document.documentElement.clientHeight;
			}
			else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
				//IE 4 compatible
				myHeight = document.body.clientHeight;
			}
			posheigth = (myHeight - height) / 2;
		}
		else {
			var posheigth = top;
		}
		
		if(posheigth <= 0)
			posheigth = 10;
		
		
		return posheigth;
	},
	"updateOrientation":function() {
		/*window.orientation returns a value that indicates whether iPhone is in portrait mode, landscape mode with the screen turned to the
		  left, or landscape mode with the screen turned to the right. */
		
		var psyma_layer = document.getElementById('psyma_layer');
		var poswidth = psymaLayer.psyma_getHorizontalAlignment(psymaLayer.psyma_left,parseInt(psyma_layer.style.width));
		var posheight = psymaLayer.psyma_getVerticalAlignment(psymaLayer.psyma_top,parseInt(psyma_layer.style.width));
		psyma_layer.style.left = poswidth + "px";
		psyma_layer.style.top = posheight + "px";
	}
};
if(window.addEventListener) {
	window.addEventListener('resize',psymaLayer.updateOrientation, false);
}	// in case of emergency, overwrite functions here, e.g. psymaLayer.psyma_info = function {}
	psymaCookieManager.init(1);if(psymaCookieManager.psyma_show) psymaLayer.init();
