window.onerror = _emEorrHandler;
function _emEorrHandler() {
}

function EM(ns, isPanel){
	 ns = typeof(ns) == 'undefined' ? '':ns;
	//private, static
	var d = document;
	var n = navigator;
	var w = window;
	var detectFlash = function(){var axo;if (n.plugins["Shockwave Flash"] || n.plugins["Shockwave Flash 2.0"]) {var swVer2 = n.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";var desc =  n.plugins["Shockwave Flash" + swVer2].description;var desc_split = desc.split(" ");var version = parseInt(desc_split[2]);return version >= 6?1:0;} else {var hasObject = 0;try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");hasObject = 1;} catch (e) {}if (hasObject == 0) {try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");axo.AllowScriptAccess = "always";hasObject = 1;} catch (e) {}}return hasObject;}}
	var size = typeof( w.innerWidth ) == 'number'?w:(d.documentElement && ( d.documentElement.clientWidth || d.documentElement.clientHeight )?d.documentElement:(d.body && ( d.body.clientWidth || d.body.clientHeight ) ?d.body:null)) ;
	var encode64 = function(inp){var key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var chr1, chr2, chr3, enc3, enc4, i = 0, out = "";while (i < inp.length) {chr1 = inp.charCodeAt(i++);if (chr1 > 127) {chr1 = 88;}chr2 = inp.charCodeAt(i++);if (chr2 > 127) {chr2 = 88;}chr3 = inp.charCodeAt(i++);if (chr3 > 127) {chr3 = 88;}if (isNaN(chr3)) {enc4 = 64;chr3 = 0;} else {enc4 = chr3 & 63;}if (isNaN(chr2)) {enc3 = 64;chr2 = 0;} else {enc3 = ((chr2 << 2) | (chr3 >> 6)) & 63;}out += key.charAt((chr1 >> 2) & 63)+key.charAt(((chr1 << 4) | (chr2 >> 4)) & 63)+key.charAt(enc3) + key.charAt(enc4);}return encodeURIComponent(out);}
	var getLastPageURL = function(){if (d.referrer) {var i = (d.referrer).split('//');if (String(i[1]).indexOf(d.domain) != 0) {return  d.referrer;}}return '';}

	//methods
	this.setCookie = function(c_name, value, sec){var domain = arguments[3];var exdate = new Date();exdate.setTime(exdate.getTime() + sec * 1000);d.cookie = c_name + "=" + escape(value)+ ((sec == 0) ? "" : ";expires=" + exdate.toGMTString())+ ";domain=." + this._domain + ";path=/";return this;}
	this.getCookie = function(c_name){if (d.cookie.length > 0) {var c_start = d.cookie.indexOf(c_name + "=");if (c_start != -1) {c_start = c_start + c_name.length + 1;var c_end = d.cookie.indexOf(";", c_start);if (c_end == -1) {c_end = d.cookie.length;}return unescape(d.cookie.substring(c_start, c_end));}}return typeof(arguments[1])=='undefined'?'':arguments[1];}


	//browser related
	this.scroll = function(){return typeof( w.pageYOffset ) == 'number'?w:(d.body && ( d.body.scrollLeft || d.body.scrollTop )?d.body:(d.documentElement && ( d.documentElement.scrollLeft || d.documentElement.scrollTop )?d.documentElement:null));}
	this.width = function() {return size == null ? 0 : size == w ? size.innerWidth:size.clientWidth;}
	this.height = function() {return size == null ? 0 : size == w ? size.innerHeight:size.clientHeight;}
	this.scrollY = function() {var scroll=this.scroll();return scroll == null ? 0 : scroll == w ? scroll.pageYOffset : scroll.scrollTop;}
	this.scrollX = function() {var scroll=this.scroll();return scroll == null ? 0 : scroll == w ? scroll.pageXOffset : scroll.scrollLeft;}
	this._hasFlash = detectFlash();
	this._isIE =  n.appVersion.indexOf("MSIE") != -1;
	this._isWin = n.appVersion.toLowerCase().indexOf("win") != -1;
	this._isOpera = n.userAgent.indexOf("Opera") != -1;
        this._isFF = n.userAgent.indexOf("Firefox") != -1;
        this._isOpera = n.userAgent.indexOf("Opera") != -1;


	//env
	this._emVersion = 'v3';
	this._emsvVersion = 'v3';
	this._emNS = ns;        
	this._emIsSecure = location.protocol.indexOf('https') > -1;
	this._emSchema = this._emIsSecure ? 'https://' : 'http://';
	this._emHost = this._emSchema+'www3.effectivemeasure.net';
	this._emCdnHost = this._emIsSecure ? this._emHost : this._emSchema+'www3-cdn.effectivemeasure.net';
	this._emsvHost = this._emSchema +'survey-b.effectivemeasure.net';
	this._emsvCdnHost = this._emIsSecure ? this._emsvHost : this._emSchema +'survey-cdn.effectivemeasure.net';
	this._emsvParams = '';

	this._page =  encode64(location.href);
	this._domain = location.hostname;
	this._lastPage =  encode64(getLastPageURL());
	this._surveySwitch = typeof (w._em_survey_on) == "undefined" ? 0 : w._em_survey_on == 1 ? 1 : -1;
	this._optedOut = this.getCookie('_em_opt_out',0);

	//Status
	this._stageLoaded = 0;
	this._jsLoaded = 0;
	this._hlLoaded = 0;


	//Cookie Mutators
	this.setCkOp = function(value){this.setCookie('_em_sv', 0, 0 );this.setCookie('_em_pv', 0, 0 );this.setCookie('_em_hl', 0, 0 );this.setCookie('_em_vt', 0, 0 );this.setCookie('_em_v', 0, 0 );this.setCookie('_em_opt_out', 1, value);}
	this.setCkSv = function(value){this.setCookie('_em_sv', value, 1800);}
	this.setCkV = function(value){this.setCookie('_em_v', value, 1800);}
	this.setCkHl = function(value){this.setCookie('_em_hl', value, 86400);}
	this.setCkPv = function(value){this.setCookie('_em_pv', value, 360*86400);}
	this.setCkVt = function(value){this.setCookie('_em_vt', value, 360*86400);}


	this.getEnvVars = function(flag){ 
		var env = new Object();
		env.flag = typeof(flag) =='undefined'? 0 : ( flag.toString().indexOf('#')==0 ? 1 : flag);
		env.v = this.getCookie('_em_v');
		env.vt = this.getCookie('_em_vt');
		env.hl = this.getCookie('_em_hl');
		var sv = this.getCookie('_em_sv', 0);
		env.sv = this._surveySwitch == 1 ? sv + 1000 : this._surveySwitch == 0 ? sv : -1;
		env.pv = this.getCookie('_em_pv');

                if(typeof(flag) =='undefined' || flag.toString().indexOf('#') < 0){
                    env.p = this._page;
                }else{
                    var temploc = location.href.toString();
                    if(temploc.indexOf('#')<0){
                        env.p = encode64(temploc+flag);
                    }else{
                        env.p = encode64(temploc.substr(0, temploc.indexOf('#'))+flag);
                    }                     
                }

		 
		env.r = this._lastPage;
		env.f = this._hasFlash;
		env.ns = ns;
                env.rnd = Math.random();
                w._em_is_panel = isPanel;
		var uinput = new Object();
		for (uv in w){if(uv.indexOf('_em_')===0&&(typeof(w[uv]) =='number'||typeof(w[uv]) =='string')){uinput[uv.substr(4)] = w[uv];}}
		var u = '';for (x in uinput){u += x+'='+uinput[x]+'&';}
		env.u = escape(u);
		var res = '';for (x in env){res += x+'='+env[x]+'&';}return res;
	}

	this.voidme = function(){}

	this.getStage = function(){
		return d.getElementById('_em_stage_'+ns);
	}

        this.loadStage = function(){
            if(!this._optedOut && !this._stageLoaded){
                var stage = d.createElement("div");
                stage.setAttribute('id', '_em_stage_'+ns);
                stage.setAttribute('style', 'display:none');
                d.body.insertBefore(stage, (this._isIE ? d.body.lastChild: d.body.firstChild));
                this._stageLoaded = 1;

            }
            return this;
        }

        this.loadJs = function(flag){
            if(!this._optedOut && (!this._jsLoaded || flag.toString().indexOf('#') == 0)){
                var script = d.createElement('script');
                script.type = 'text/javascript';
                script.src = this._emHost + '/'+this._emVersion+'/em_js?'+this.getEnvVars(flag);
                var head = d.getElementsByTagName("head")[0];
                if(head){
                    head.appendChild(script);
                }else{
                    d.body.insertBefore(script, d.body.firstChild);
                }
                this._jsLoaded = 1;

          
            }

            return this;
        }


 
        this.trackAjaxPageview = function(pid){             
            pid =typeof(pid) == 'undefined' ? '#' : '#' + pid.toString().replace(/\W/g, '_');
            this.loadJs(pid);
        }


        this.loadHl = function(vars){
            if(!this._optedOut && !this._hlLoaded && this._hasFlash){
                var emsrc = this._emCdnHost + '/'+this._emVersion+ "/em.swf";
                vars = vars + '&ns='+ns;
                var stage = this.getStage();
                stage.setAttribute('style', 'display:block;position:fixed;width: 1px; height: 1px;');
                stage.innerHTML = this.getSwfHtml("src", emsrc, "width", "1", "height", "1", "id", "_em_hilex"+ns, 'quality', 'low',  "name", "_em_hilex"+ns,  "flashVars", vars);
                if(this._isIE){
                    stage.style.top = (this.scrollY()+this.height()/2) + 'px';
                    stage.style.left = (this.scrollX()+this.width()/2) + 'px';
                }
                this._hlLoaded = 1;

            }
            return this;
        }

        this.hideStage = function(){
            var stage = this.getStage();
	    stage.innerHTML = '<img src="'+this._emHost+'/img.gif" />';
            stage.style.display = 'none';
        }

        this.hlCallback = function(flag){
            if(flag >0 && d.images){//need call back
                d['_em_dimg'] = new Image();
                d['_em_dimg'].src = this._emHost+ '/'+this._emVersion + '/em_dimg?' + this.getEnvVars(flag);
            }
            this.hideStage();
        }


        this.optout = function(t){//called by helix
            this.setCkOp(t);
            d['_em_oimg'] = new Image();
            d['_em_oimg'].src = this._emHost+ '/'+this._emVersion + '/em_oimg.php?t='+t;
        }


	this.getSwfHtml  = function(){var i=0;var args = arguments;var embedAttrs = new Object();var params = new Object();var objAttrs = new Object();for ( i = 0; i < args.length; i = i + 2) {var currArg = args[i].toLowerCase();switch (currArg) {case "src":embedAttrs["src"] = args[i + 1];params['movie'] = args[i + 1];break;case "id":case "width":case "height":case "class":case "name":embedAttrs[args[i]] = objAttrs[args[i]] = args[i + 1];break;default:embedAttrs[args[i]] = params[args[i]] = args[i + 1];}}objAttrs["classid"] = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";objAttrs["type"] = embedAttrs["type"] = "application/x-shockwave-flash";embedAttrs["allowScriptAccess"] = params["allowScriptAccess"] = "always";embedAttrs["quality"] = params["quality"] = "high";embedAttrs["align"] = objAttrs["align"] = "middle";var str = '';if (this._isIE && this._isWin && !this._isOpera) {str += '<object ';for ( i in objAttrs){str += i + '="' + objAttrs[i] + '" ';}str += '>';for (i in params){str += '<param name="' + i + '" value="' + params[i] + '" /> ';}str += '</object>';} else {str += '<embed ';for ( i in embedAttrs){str += i + '="' + embedAttrs[i] + '" ';}str += '> </embed>';}return str;}
	
	/*** invitation ***/
	this.loadInvitation = function(id,langId, ids, test){



            var stage = this.getStage();
            stage.setAttribute('style', 'display:block;width:300px;height:200px;padding:0px;margin:0px;right:10px;clear:both');
            stage.style.backgroundColor = 'transparent';
            stage.style.zIndex = 2147483647;
            if(this._isIE){
                stage.style.position = 'absolute';
                svTop = parseInt(this.height() - 200 + this.scrollY());
                svLeft = parseInt(this.width() + this.scrollX() - 300 -10) ;
                ieTop = 	  svTop > 0 ? svTop+'px' : '0px';
                stage.style.top = svTop > 0 ? svTop+400+'px' : '200px';
                stage.style.left = svLeft > 0 ? svLeft+'px': '0px';
            }else{
                stage.style.position = 'fixed';
                stage.style.bottom = '0px';
            }

            var svsrc = this._emsvCdnHost + "/"+this._emsvVersion+(langId==2?"/eminvar.swf":"/eminv.swf");
            var p = new Object();
            p.id = id;
            p.langId = langId;
            p.ids = ids;
            p.domain = this._domain;
            p.test = test;
            p.ns = ns;
            p.version =this._emsvVersion;
            p.ff = this._isFF ? 1:0;
            p.host = this._emsvHost;
            p.cdnHost = this._emsvCdnHost;
            var fvars = '';for (x in p){fvars += x+'='+p[x]+'&';}
            this._emsvParams = fvars;
           
            stage.innerHTML = this.getSwfHtml("src", svsrc, "width", "100%",  "height", "100%", "wmode", "transparent", "id", "_em_inv"+ns,   "name", "_em_inv"+ns,   "flashVars", this._emsvParams);


            if(this._isIE){
                this.posInv4IE();
            }

	}


	this._timeoutFlagPosInv4IE = 1;

        this.posInv4IE  =function() {
            if(this._timeoutFlagPosInv4IE==1){
                var stage = this.getStage();
                var svWidth = 300, svHeight = 200;
                var svLeft=0, svTop=0;
                if (stage) {
                    stage.style.position = 'absolute';
                    stage.style.width = svWidth+'px';
                    stage.style.height = svHeight+'px';
                    stage.style.backgroundColor = 'transparent';
                    svTop = parseInt(this.height() - svHeight+ this.scrollY());
                    svLeft = parseInt(this.width() + this.scrollX() - svWidth-10) ;
                    stage.style.top = svTop > 0 ? svTop+'px' : '0px';
                    stage.style.left = svLeft > 0 ? svLeft+'px': '0px';
                }

                setTimeout( this._emNS+'.posInv4IE()', 200);
            }
        }

        this.hideInvitation = function(){

            if(this._isIE){
                this._timeoutFlagPosInv4IE = 0;
            }
            this.hideStage();
        }

        /*** main ***/
        this.unloadSurvey = function() {


            this._timeoutFlagPosMain =0;
            this.hideStage();

            if(this._isIE ){
                var stags = d.getElementsByTagName('select');

                if(stags!=null){
                    for   (var i=0; i<stags.length; i++){
                        stags[i].style.visibility = 'visible';
                    }
                }
            }

        }

	this._timeoutFlagPosMain = 1;


        this.posMain = function(){
            if(this._timeoutFlagPosMain==1){
                var stage = this.getStage();
                var svWidth = 700, svHeight = 620 ;
                var svLeft=0, svTop=0;
                stage.style.width = svWidth+'px';
                stage.style.height = svHeight+'px';
                svTop = parseInt((this.height() - svHeight) / 2 + this.scrollY());
                svLeft = parseInt((this.width() - svWidth) / 2) ;
                if(this._isIE){
                    stage.style.position = 'absolute';
                    stage.style.top = svTop > 0 ? svTop+'px' : '0px';
                }else{
                    stage.style.position = 'fixed';
                    stage.style.bottom = parseInt((this.height()-svHeight)/2) + 'px'  ;
                }
                stage.style.left = svLeft > 0 ? svLeft+'px': '0px';


                setTimeout(this._emNS+'.posMain()', 200);
            }
        }


        this.loadSurvey  =function(tcolor, ttxtcolor, title) {
            if(!this._isOpera){this.setStageVisible(0);}            
            var stage = this.getStage();
            var p = "themeColor="+tcolor+'&themeTextColor='+ttxtcolor+'&headerText='+title+'&';

            if(this._emsvParams != ''){
                p = p + this._emsvParams;
                var svsrc = this._emsvCdnHost + "/"+this._emsvVersion+"/emsv.swf";
                stage.innerHTML = this.getSwfHtml("src", svsrc, "width", "100%",  "height", "100%",  "id", "_em_survey"+ns,   "name", "_em_survey"+ns,   "flashVars", p);
                
            }

            
             

        }

        this.setStageVisible = function(v){
            if(!this._isIE){
            var stage = this.getStage();
            stage.style.visibility = v == 1?'visible':'hidden';}
        }


        this.showSurvey=function(){
            this.setStageVisible(1);
            this._timeoutFlagPosInv4IE = 0;
            if(this._isIE   ){
                var stags = d.getElementsByTagName('select');
                if(stags){
                    for ( i=0; i<stags.length; i++){
                        stags[i].style.visibility = 'hidden';
                    }
                }

            }

            this.posMain();
        }

        this.showFFArrow=function(str){
            var stage = d.createElement("div");
                stage.setAttribute('id', '_em_ff_arrow_'+ns);
                stage.setAttribute('style', 'display:block;position:fixed;top:0px;right:0px;width:200px;padding:0px;margin:0;border:1px solid #bf8a01;border-top:0px;-moz-border-radius-bottomleft: 10px;-moz-border-radius-bottomright: 10px; background-color:#ffc703; background-image: -moz-linear-gradient(top, #ffc703, #ffe970, #ffd016, #ffc703 ); height:100px;');
                stage.style.zIndex = 2147483647;
                var p = '<div style="width:100%;height:100%;background:transparent url('+this._emsvCdnHost + "/"+this._emsvVersion+'/images/plugin_arrow_bg_sm.gif) no-repeat 50px;2px;"><p style="padding:5px;width:100px;">'+str+'</p></div>';
                stage.innerHTML = p;


                d.body.insertBefore(stage, d.body.firstChild);
     
        }
}




if(typeof(document['_em_is_panel']) != 'undefined' && !window['_emp']){
    var _emp = new EM('_emp', 1);
    _emp.loadStage().loadJs().voidme();
}

if(typeof(document['_em_is_panel']) == 'undefined' && !window['_em']){
    var _em = new EM('_em', 0);
    _em.loadStage().loadJs().voidme();
}

 
