function callLater(f,obj){return(function(){return f(obj);});}function __contains(a,obj){for(var i=0;i<a.length;i++){if(a[i]===obj){return true;}}return false;}function FLHub(site,elementId){this.zis=this;this.dim=1;this.wmode="opaque";this.debug=false;this.messagePrefix="vw:";this.flHub={};this.initialized=false;
this.retryCount=0;this.executeRunning=false;this.commands=[];this.flashvars={};this._params={};this.busy=false;this._attributes={};this.callbacks={};this.elementId=elementId;this.site=site;this.flHubId="FLHub"+Math.floor(Math.random()*99999);this.html5=(window.postMessage)?true:false;this.subscribers={};
this.registered={};this.retainedMsgs=[];this.serverFound=false;this.isServer=false;}FLHub.prototype.log=function(){if(this.debug&&typeof(console)!="undefined"){console.log(arguments);}};FLHub.obj2JSON=function(data){return JSON.stringify(data);};FLHub.query2Obj=function(q){if(q!=null&&q!=""){return JSON.parse(q);
}else{return null;}};FLHub.getWindow=function(){if(window.opener==null||window.opener==window){return top;}return window.opener.top;};FLHub.prototype.swfInit=function(e,zis){if(zis.initialized){return true;}if(e!=null&&e.success){zis.flHub=e.ref;}else{++zis.retryCount;if(navigator.appName.indexOf("Microsoft")!=-1){zis.flHub=window[zis.flHubId];
}else{zis.flHub=document[zis.flHubId];}}if(typeof(zis.flHub)!="undefined"&&(zis.flHub.publish!=null)&&(typeof(zis.flHub.publish)=="function")){zis.initialized=true;}return true;};FLHub.prototype.handleJSCalls=function(topic,params){params=unescape(params);try{params=eval(params);}catch(e){}var retval=false;
try{this.busy=true;retval=this.doService(topic,params);this.busy=false;}catch(e){this.log("handleJSCalls failed:"+e.message);this.busy=false;}return retval;};FLHub.prototype.doService=function(topic,params){if(typeof(params)=="string"){params=FLHub.query2Obj(params);}if(this.callbacks[topic]!=null&&typeof(this.callbacks[topic])=="function"){this.log(window," executing callback for topic "+topic+" with params:",params);
return this.callbacks[topic](params);}else{if(this.isServer&&typeof(VIRTUALWEB.getActions()[topic])=="function"){VIRTUALWEB.getActions()[topic](params);}}};FLHub.prototype.service=function(topic,params){try{return this.doService(topic,params);}catch(e){this.log(e.message);}return false;};FLHub.prototype.trimRetainedMessages=function(){var now=new Date().getTime(),start=-1;
for(var i=0;i<this.retainedMsgs.length;i++){if(this.retainedMsgs[i].time<now-60000){start=i;}}start+=1;if(start>0){this.retainedMsgs=this.retainedMsgs.slice(start);}start=i=now=null;};FLHub.prototype.retainMessage=function(request){var now=new Date().getTime(),start=0;this.retainedMsgs.push({time:now,topic:request.topic,origin:request.origin,data:request.data});
this.trimRetainedMessages();now=null;};FLHub.prototype.fireRetainedMessages=function(topic,subscriber){this.trimRetainedMessages();for(var i=0;i<this.retainedMsgs.length;i++){if(this.retainedMsgs[i].topic==topic){var cmd={action:"service",topic:topic,origin:this.retainedMsgs[i].origin,target:subscriber,data:this.retainedMsgs[i].data};
this.commands.push(cmd);this.executeCommands();}}};FLHub.prototype.embedServer=function(objectName,serverId){if(!this.html5){this.flashvars={server:"1",serverId:serverId,requestCallback:objectName+".handleJSCalls",debug:this.debug};this._params={allowscriptaccess:"always",wmode:this.wmode,menu:"false"};
this._attributes={id:this.flHubId,name:this.flHubId,styleclass:"flHub2"};}this.isServer=true;this.serverFound=true;if(!this.html5){this.doEmbed();}else{var obj=this;var onMessageFunc=function(e){var request;if(e.data!=""&&e.data.indexOf(obj.messagePrefix)==0){request=eval("("+e.data.substring(obj.messagePrefix.length)+")");
var href=request.origin;if(request.action=="register"){var cmd={action:"registered",topic:request.topic,origin:document.location.href,target:e.source};obj.commands.push(cmd);obj.executeCommands();return;}var subs=obj.subscribers[request.topic];if(request.action=="subscribe"){obj.log("Server got Subscribe request for topic:",request.topic," source:",e.source);
if(typeof(subs)=="undefined"){obj.subscribers[request.topic]=[];subs=obj.subscribers[request.topic];}if(!__contains(subs,e.source)){subs.push(e.source);}obj.fireRetainedMessages(request.topic,e.source);}else{if(request.action=="publish"){obj.log("window ",window," is publishing ",request.topic," data:",request.data," to:",subs);
if(typeof(subs)!="undefined"){for(var s=0;s<subs.length;++s){obj.log("sending request to ",subs[s]," request : ",request);try{var cmd={action:"service",topic:request.topic,target:subs[s],data:request.data};obj.commands.push(cmd);obj.executeCommands();cmd=null;}catch(e){obj.log("There was a problem publishing the request::",e,subs[s]);
}}if(request.retain=="true"){obj.retainMessage(request);}}}else{if(request.action=="service"){obj.service(request.topic,request.data);}}}}subs=request=null;};if(window.addEventListener){window.addEventListener("message",onMessageFunc,false);}else{if(window.attachEvent){window.attachEvent("onmessage",onMessageFunc);
}}}};FLHub.prototype.embedClient=function(objectName,serverId,clientId){if(!this.html5){this.flashvars={server:"0",serverId:serverId,clientId:clientId,requestCallback:objectName+".handleJSCalls",debug:this.debug};this._params={allowscriptaccess:"always",wmode:this.wmode,menu:"false"};this._attributes={id:this.flHubId,name:this.flHubId,styleclass:"flHub2"};
}if(!this.html5){this.doEmbed();}else{var obj=this;var onMessageFunc=function(e){var request;if(e.data!=""&&e.data.indexOf(obj.messagePrefix)==0){request=eval("("+e.data.substring(obj.messagePrefix.length)+")");if(request.action=="service"){obj.log("client executing service:",request.topic," data:",request.data);
obj.service(request.topic,request.data);}else{if(request.action=="registered"||(!obj.serverFound&&request.action=="service")){obj.log("client",window," found its server");obj.serverFound=true;obj.executeCommands();}}}};if(window.addEventListener){window.addEventListener("message",onMessageFunc,false);
}else{if(window.attachEvent){window.attachEvent("onmessage",onMessageFunc);}}this.register(this);}};FLHub.prototype.register=function(zis){if(!zis.serverFound){var cmd={action:"register",params:"",origin:document.location.href,data:""};zis.commands.push(cmd);var pending=[];zis.executeSingleCommand(zis,cmd,pending);
zis.commands=zis.commands.concat(pending);var functRef=callLater(zis.register,zis);setTimeout(functRef,1000);}};FLHub.prototype.doEmbed=function(){var zis=this;var initFunct=function(e){return zis.swfInit(e,zis);};if(!this.html5){swfobject.embedSWF(this.site+"/static/js/flHub/FlHub"+(this.debug?"_debug":"")+".swf",this.elementId,this.dim,this.dim,"9.0.0",this.site+"/static/js/flHub/expressInstall.swf",this.flashvars,this._params,this._attributes,initFunct);
}};FLHub.prototype.executeSingleCommand=function(zis,command,pending){if(!zis.html5){if(command&&command.action){for(var i=0;i<command.params.length;i++){if(typeof(command.params[i])=="undefined"){command.params[i]="";}}try{if(command.params.length==0){zis.log(window,this.flHubId+" executing "+command.action);
zis.flHub[command.action]();}else{if(command.params.length==1){zis.log(window,this.flHubId+" executing "+command.action+" ["+command.params[0]+"]");zis.flHub[command.action](command.params[0]);}else{if(command.params.length==2){zis.log(window,this.flHubId+" executing "+command.action+" ["+command.params[0]+", "+command.params[1]+"]");
zis.flHub[command.action](command.params[0],escape(FLHub.obj2JSON(command.params[1])));}else{if(command.params.length==3){zis.log(window,this.flHubId+" executing "+command.action+" ["+command.params[0]+", "+command.params[1]+", "+command.params[2]+"]");zis.flHub[command.action](command.params[0],escape(FLHub.obj2JSON(command.params[1])),command.params[2]);
}}}}}catch(e){zis.log(window," executeAllPendingCommands "+e.toString());}}}else{delete command.params;command.prefix=this.messagePrefix;var target=command.target;if(command.target==null){if(command.targetId==null){target=FLHub.getWindow();}else{var frame_el=document.getElementById(command.targetId);
if(frame_el==null){pending.push(command);return;}else{target=frame_el.contentWindow;}}}try{delete command.target;target.postMessage(zis.messagePrefix+FLHub.obj2JSON(command),"*");}catch(e){command.target=target;pending.push(command);}}};FLHub.prototype.executeAllPendingCommands=function(zis){var pending=[];
while(zis.commands.length>0){var command=zis.commands.shift();zis.executeSingleCommand(zis,command,pending);}zis.commands=zis.commands.concat(pending);};FLHub.prototype.executeCommands2=function(zis){if((zis.html5&&zis.serverFound)||(!zis.html5&&typeof(zis.flHub)!="undefined"&&typeof(zis.flHub.publish)=="function"&&!zis.busy)){zis.executeRunning=true;
zis.executeAllPendingCommands(zis);zis.executeRunning=false;}else{if(!zis.html5){if(typeof(zis.flHub)=="undefined"||!zis.flHub.publish||typeof(zis.flHub.publish)=="undefined"){zis.swfInit(null,zis);}}var functRef=callLater(zis.executeCommands2,zis);setTimeout(functRef,1000);}};FLHub.prototype.executeCommands=function(zis){if(zis==null){zis=this;
}if(zis.commands.length>1&&zis.executeRunning){return;}zis.executeCommands2(zis);};FLHub.prototype.publish=function(topic,msg,retain){var cmd={action:"publish",params:[topic,msg,retain],origin:document.location.href,topic:topic,data:msg,retain:retain};this.commands.push(cmd);this.executeCommands();};
FLHub.prototype.subscribe=function(topic,callback){if(typeof(callback)!="undefined"){this.callbacks[topic]=callback;}var cmd={action:"subscribe",params:[topic],origin:document.location.href,topic:topic};this.commands.push(cmd);this.executeCommands();};FLHub.prototype.unsubscribe=function(frameId){};FLHub.prototype.requestFrom=function(clientId,topic,msg,frameId){this.log("Requesting from clientId:",clientId," frameId:",frameId,topic,msg);
if(!this.html5){this.commands.push({action:"requestFrom",params:[clientId,msg,topic]});this.executeCommands();}else{this.log("The iframe is with id::",frameId);this.commands.push({action:"service",topic:topic,origin:document.location.href,data:msg,targetId:frameId});this.executeCommands();}};FLHub.prototype.requestService=function(topic,msg){this.log("Requesting Service::",msg);
var cmd={action:"service",params:[topic,msg],topic:topic,origin:document.location.href,data:msg};this.commands.push(cmd);this.executeCommands();};