/*
* easyXDM
* http://easyxdm.net/
* Copyright(c) 2009, Øyvind Sean Kinsey, oyvind@kinsey.no.
*
* MIT Licensed - http://easyxdm.net/license/mit.txt
*
*/
(function(D,c,i,C,f,A){var a=this;var h=0;var k=Function.prototype;var H=/^(http.?:\/\/([^\/\s]+))/,I=/[\-\w]+\/\.\.\//,y=/([^:])\/\//g;var b=/msie [67]/.test(navigator.userAgent.toLowerCase());function w(M,O){var N=typeof M[O];return N=="function"||(!!(N=="object"&&M[O]))||N=="unknown"}function o(M,N){return !!(typeof(M[N])=="object"&&M[N])}var p,s;if(w(D,"addEventListener")){p=function(O,M,N){O.addEventListener(M,N,false)};s=function(P,N,O,M){P.removeEventListener(N,O,M)}}else{if(w(D,"attachEvent")){p=function(M,O,N){M.attachEvent("on"+O,N)};s=function(M,O,N){M.detachEvent("on"+O,N)}}else{throw new Error("Browser not supported")}}var m=false,B=[];if("readyState" in c){m=(c.readyState=="complete"||c.readyState=="loaded")}else{if(c.body){m=true}}function l(){if(m){return}m=true;for(var M=0;M')}else{N=c.createElement("IFRAME")}if(M.props.name){N.id=N.name=M.props.name;delete M.props.name}if(M.onLoad){N.loadFn=function(){M.onLoad(N.contentWindow)};p(N,"load",N.loadFn)}if(typeof M.container=="string"){M.container=c.getElementById(M.container)}if(!M.container){N.style.position="absolute";N.style.left="-2000px";N.style.top="0px";M.container=c.body}N.border=N.frameBorder=0;M.container.insertBefore(N,M.container.firstChild);K(N,M.props);return N}var G=(function(){if(w(D,"XMLHttpRequest")){return function(){return new XMLHttpRequest()}}else{var M=(function(){var O=["Microsoft","Msxml2","Msxml3"],N=O.length;while(N--){try{M=O[N]+".XMLHTTP";var Q=new ActiveXObject(M);return M}catch(P){}}}());return function(){return new ActiveXObject(M)}}}());function q(N){var P=G(),R=[],Q,M;K(N,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest"},success:k,error:function(T){throw new Error(T)},data:{},type:"plain"},true);M=N.method=="POST";for(var O in N.data){if(N.data.hasOwnProperty(O)){R.push(A(O)+"="+A(N.data[O]))}}Q=R.join("&");P.open(N.method,N.url+(M?"":"?"+Q),true);for(var S in N.headers){if(N.headers.hasOwnProperty(S)){P.setRequestHeader(S,N.headers[S])}}P.onreadystatechange=function(){if(P.readyState==4){var T,U;if(N.type=="json"){try{T=P.responseText;T=E().parse(T)}catch(V){U="An error occured while parsing the JSON: "+V.message}}else{T=P.responseText}if(P.status<200||P.status>=300){U="The server did not return a valid status code."}if(U){N.error({message:U,status:P.status,data:T,toString:function(){return this.message+" Status: "+this.status}})}else{N.success(T)}P.onreadystatechange=k;P=null}};P.send(M?Q:"")}function L(P,O){if(typeof P=="string"){P=[P]}var N,M=P.length;while(M--){N=P[M];N=new RegExp(N.substr(0,1)=="^"?N:("^"+N.replace(/(\*)/g,".$1").replace(/\?/g,".")+"$"));if(N.test(O)){return true}}return false}function g(O){var T=O.protocol,N;O.isHost=O.isHost||n(J.xdm_p);if(!O.props){O.props={}}if(!O.isHost){O.channel=J.xdm_c;O.secret=J.xdm_s;O.remote=J.xdm_e;T=J.xdm_p;if(O.acl&&!L(O.acl,O.remote)){throw new Error("Access denied for "+O.remote)}}else{O.remote=v(O.remote);O.channel=O.channel||"default"+h++;O.secret=Math.random().toString(16).substring(2);if(n(T)){if(e(i.href)==e(O.remote)){T="4"}else{if(w(D,"postMessage")||w(c,"postMessage")){T="1"}else{if(w(D,"ActiveXObject")&&w(D,"execScript")){T="3"}else{if(navigator.product==="Gecko"&&"frameElement" in D&&navigator.userAgent.indexOf("WebKit")==-1){T="5"}else{if(O.remoteHelper){O.remoteHelper=v(O.remoteHelper);T="2"}else{T="0"}}}}}}}switch(T){case"0":K(O,{interval:100,delay:2000,useResize:true,useParent:false,usePolling:false},true);if(O.isHost){if(!O.local){var R=i.protocol+"//"+i.host,M=c.body.getElementsByTagName("img"),S;var P=M.length;while(P--){S=M[P];if(S.src.substring(0,R.length)===R){O.local=S.src;break}}if(!O.local){O.local=D}}var Q={xdm_c:O.channel,xdm_p:0};if(O.local===D){O.usePolling=true;O.useParent=true;O.local=i.protocol+"//"+i.host+i.pathname+i.search;Q.xdm_e=O.local;Q.xdm_pa=1}else{Q.xdm_e=v(O.local)}if(O.container){O.useResize=false;Q.xdm_po=1}O.remote=F(O.remote,Q)}else{K(O,{channel:J.xdm_c,remote:J.xdm_e,useParent:!n(J.xdm_pa),usePolling:!n(J.xdm_po),useResize:O.useParent?false:O.useResize})}N=[new easyXDM.stack.HashTransport(O),new easyXDM.stack.ReliableBehavior({timeout:O.interval*1.5}),new easyXDM.stack.QueueBehavior({encode:true,maxLength:4000-O.remote.length}),new easyXDM.stack.VerifyBehavior({initiate:O.isHost})];break;case"1":N=[new easyXDM.stack.PostMessageTransport(O)];break;case"2":N=[new easyXDM.stack.NameTransport(O),new easyXDM.stack.QueueBehavior(),new easyXDM.stack.VerifyBehavior({initiate:O.isHost})];break;case"3":N=[new easyXDM.stack.NixTransport(O)];break;case"4":N=[new easyXDM.stack.SameOriginTransport(O)];break;case"5":N=[new easyXDM.stack.FrameElementTransport(O)];break}N.push(new easyXDM.stack.QueueBehavior({lazy:O.lazy,remove:true}));return N}function x(P){var Q,O={incoming:function(S,R){this.up.incoming(S,R)},outgoing:function(R,S){this.down.outgoing(R,S)},callback:function(R){this.up.callback(R)},init:function(){this.down.init()},destroy:function(){this.down.destroy()}};for(var N=0,M=P.length;N<\/script>')}}};(function(){var M={};easyXDM.Fn={set:function(N,O){M[N]=O},get:function(O,N){var P=M[O];if(N){delete M[O]}return P}}}());easyXDM.Socket=function(N){var M=x(g(N).concat([{incoming:function(Q,P){N.onMessage(Q,P)},callback:function(P){if(N.onReady){N.onReady(P)}}}])),O=e(N.remote);this.destroy=function(){M.destroy()};this.postMessage=function(P){M.outgoing(P,O)};M.init()};easyXDM.Rpc=function(O,N){if(N.local){for(var Q in N.local){if(N.local.hasOwnProperty(Q)){var P=N.local[Q];if(typeof P==="function"){N.local[Q]={method:P}}}}}var M=x(g(O).concat([new easyXDM.stack.RpcBehavior(this,N),{callback:function(R){if(O.onReady){O.onReady(R)}}}]));this.destroy=function(){M.destroy()};M.init()};easyXDM.stack.SameOriginTransport=function(N){var O,Q,P,M;return(O={outgoing:function(S,T,R){P(S);if(R){R()}},destroy:function(){if(Q){Q.parentNode.removeChild(Q);Q=null}},onDOMReady:function(){M=e(N.remote);if(N.isHost){K(N.props,{src:F(N.remote,{xdm_e:i.protocol+"//"+i.host+i.pathname,xdm_c:N.channel,xdm_p:4})});Q=u(N);easyXDM.Fn.set(N.channel,function(R){P=R;C(function(){O.up.callback(true)},0);return function(S){O.up.incoming(S,M)}})}else{P=parent.easyXDM.Fn.get(N.channel,true)(function(R){O.up.incoming(R,M)});O.up.callback(true)}},init:function(){z(O.onDOMReady,O)}})};easyXDM.stack.PostMessageTransport=function(P){var R,S,N,O;function M(T){if(T.origin){return T.origin}if(T.uri){return e(T.uri)}if(T.domain){return i.protocol+"//"+T.domain}throw"Unable to retrieve the origin of the event"}function Q(U){var T=M(U);if(T==O&&U.data.substring(0,P.channel.length+1)==P.channel+" "){R.up.incoming(U.data.substring(P.channel.length+1),T)}}return(R={outgoing:function(U,V,T){N.postMessage(P.channel+" "+U,V||O);if(T){T()}},destroy:function(){s(D,"message",Q);if(S){N=null;S.parentNode.removeChild(S);S=null}},onDOMReady:function(){O=e(P.remote);if(P.isHost){p(D,"message",function T(U){if(U.data==P.channel+"-ready"){N=("postMessage" in S.contentWindow)?S.contentWindow:S.contentWindow.document;s(D,"message",T);p(D,"message",Q);C(function(){R.up.callback(true)},0)}});K(P.props,{src:F(P.remote,{xdm_e:i.protocol+"//"+i.host,xdm_c:P.channel,xdm_p:1})});S=u(P)}else{p(D,"message",Q);N=("postMessage" in D.parent)?D.parent:D.parent.document;N.postMessage(P.channel+"-ready",O);C(function(){R.up.callback(true)},0)}},init:function(){z(R.onDOMReady,R)}})};easyXDM.stack.FrameElementTransport=function(N){var O,Q,P,M;return(O={outgoing:function(S,T,R){P.call(this,S);if(R){R()}},destroy:function(){if(Q){Q.parentNode.removeChild(Q);Q=null}},onDOMReady:function(){M=e(N.remote);if(N.isHost){K(N.props,{src:F(N.remote,{xdm_e:i.protocol+"//"+i.host+i.pathname,xdm_c:N.channel,xdm_p:5})});Q=u(N);Q.fn=function(R){delete Q.fn;P=R;C(function(){O.up.callback(true)},0);return function(S){O.up.incoming(S,M)}}}else{if(c.referrer&&c.referrer!=J.xdm_e){D.parent.location=J.xdm_e}else{if(c.referrer!=J.xdm_e){D.parent.location=J.xdm_e}P=D.frameElement.fn(function(R){O.up.incoming(R,M)});O.up.callback(true)}}},init:function(){z(O.onDOMReady,O)}})};easyXDM.stack.NixTransport=function(N){var P,R,Q,M,O;return(P={outgoing:function(T,U,S){Q(T);if(S){S()}},destroy:function(){O=null;if(R){R.parentNode.removeChild(R);R=null}},onDOMReady:function(){M=e(N.remote);if(N.isHost){try{if(!w(D,"getNixProxy")){D.execScript("Class NixProxy\n Private m_parent, m_child, m_Auth\n\n Public Sub SetParent(obj, auth)\n If isEmpty(m_Auth) Then m_Auth = auth\n SET m_parent = obj\n End Sub\n Public Sub SetChild(obj)\n SET m_child = obj\n m_parent.ready()\n End Sub\n\n Public Sub SendToParent(data, auth)\n If m_Auth = auth Then m_parent.send(CStr(data))\n End Sub\n Public Sub SendToChild(data, auth)\n If m_Auth = auth Then m_child.send(CStr(data))\n End Sub\nEnd Class\nFunction getNixProxy()\n Set GetNixProxy = New NixProxy\nEnd Function\n","vbscript")}O=getNixProxy();O.SetParent({send:function(U){P.up.incoming(U,M)},ready:function(){C(function(){P.up.callback(true)},0)}},N.secret);Q=function(U){O.SendToChild(U,N.secret)}}catch(T){throw new Error("Could not set up VBScript NixProxy:"+T.message)}K(N.props,{src:F(N.remote,{xdm_e:i.protocol+"//"+i.host+i.pathname+i.search,xdm_c:N.channel,xdm_s:N.secret,xdm_p:3})});R=u(N);R.contentWindow.opener=O}else{if(c.referrer&&c.referrer!=J.xdm_e){D.parent.location=J.xdm_e}else{if(c.referrer!=J.xdm_e){D.parent.location=J.xdm_e}try{O=D.opener}catch(S){throw new Error("Cannot access window.opener")}O.SetChild({send:function(U){a.setTimeout(function(){P.up.incoming(U,M)},0)}});Q=function(U){O.SendToParent(U,N.secret)};C(function(){P.up.callback(true)},0)}}},init:function(){z(P.onDOMReady,P)}})};easyXDM.stack.NameTransport=function(Q){var R;var T,X,P,V,W,N,M;function U(aa){var Z=Q.remoteHelper+(T?"#_3":"#_2")+Q.channel;X.contentWindow.sendMessage(aa,Z)}function S(){if(T){if(++V===2||!T){R.up.callback(true)}}else{U("ready");R.up.callback(true)}}function Y(Z){R.up.incoming(Z,N)}function O(){if(W){C(function(){W(true)},0)}}return(R={outgoing:function(aa,ab,Z){W=Z;U(aa)},destroy:function(){X.parentNode.removeChild(X);X=null;if(T){P.parentNode.removeChild(P);P=null}},onDOMReady:function(){T=Q.isHost;V=0;N=e(Q.remote);Q.local=v(Q.local);if(T){easyXDM.Fn.set(Q.channel,function(Z){if(T&&Z==="ready"){easyXDM.Fn.set(Q.channel,Y);S()}});M=F(Q.remote,{xdm_e:Q.local,xdm_c:Q.channel,xdm_p:2});K(Q.props,{src:M+"#"+Q.channel,name:Q.channel});P=u(Q)}else{Q.remoteHelper=Q.remote;easyXDM.Fn.set(Q.channel,Y)}X=u({props:{src:Q.local+"#_4"+Q.channel},onLoad:function(){s(X,"load",X.loadFn);easyXDM.Fn.set(Q.channel+"_load",O);(function Z(){if(typeof X.contentWindow.sendMessage=="function"){S()}else{C(Z,50)}}())}})},init:function(){z(R.onDOMReady,R)}})};easyXDM.stack.HashTransport=function(O){var R;var W=this,U,P,M,S,ab,Q,aa;var V,N;function Z(ad){if(!aa){return}var ac=O.remote+"#"+(ab++)+"_"+ad;((U||!V)?aa.contentWindow:aa).location=ac}function T(ac){S=ac;R.up.incoming(S.substring(S.indexOf("_")+1),N)}function Y(){if(!Q){return}var ac=Q.location.href,ae="",ad=ac.indexOf("#");if(ad!=-1){ae=ac.substring(ad)}if(ae&&ae!=S){T(ae)}}function X(){P=setInterval(Y,M)}return(R={outgoing:function(ac,ad){Z(ac)},destroy:function(){D.clearInterval(P);if(U||!V){aa.parentNode.removeChild(aa)}aa=null},onDOMReady:function(){U=O.isHost;M=O.interval;S="#"+O.channel;ab=0;V=O.useParent;N=e(O.remote);if(U){O.props={src:O.remote,name:"local_"+O.channel};if(V){O.onLoad=function(){Q=D;X();R.up.callback(true)}}else{var ae=0,ac=O.delay/50;(function ad(){if(++ae>ac){throw new Error("Unable to reference listenerwindow")}try{Q=aa.contentWindow.frames["remote_"+O.channel]}catch(af){}if(Q){X();R.up.callback(true)}else{C(ad,50)}}())}aa=u(O)}else{Q=D;X();if(V){aa=parent;R.up.callback(true)}else{K(O,{props:{src:O.remote+"#"+O.channel+new Date(),name:"remote_"+O.channel},onLoad:function(){R.up.callback(true)}});aa=u(O)}}},init:function(){z(R.onDOMReady,R)}})};easyXDM.stack.ReliableBehavior=function(O){var P,M,T,R,V=0,Q=0,S=O.tries||5,U=O.timeout,N=0,W;return(P={incoming:function(Z,X){var Y=Z.indexOf("_"),ab=parseInt(Z.substring(0,Y),10),aa;Z=Z.substring(Y+1);Y=Z.indexOf("_");aa=parseInt(Z.substring(0,Y),10);Y=Z.indexOf("_");Z=Z.substring(Y+1);if(M&&ab===V){D.clearTimeout(M);M=null;if(W){C(function(){W(true)},0)}}if(aa!==0){if(aa!==N){N=aa;Z=Z.substring(aa.length+1);P.down.outgoing(aa+"_0_ack",X);C(function(){P.up.incoming(Z,X)},O.timeout/2)}else{P.down.outgoing(aa+"_0_ack",X)}}},outgoing:function(Z,X,Y){W=Y;Q=0;T={data:N+"_"+(++V)+"_"+Z,origin:X};(function aa(){M=null;if(++Q>S){if(W){C(function(){W(false)},0)}}else{P.down.outgoing(T.data,T.origin);M=C(aa,O.timeout)}}())},destroy:function(){if(M){D.clearInterval(M)}P.down.destroy()}})};easyXDM.stack.QueueBehavior=function(O){var R,S=[],V=true,P="",U,M=0,N=false,Q=false;function T(){if(O.remove&&S.length===0){r(R);return}if(V||S.length===0||U){return}V=true;var W=S.shift();R.down.outgoing(W.data,W.origin,function(X){V=false;if(W.callback){C(function(){W.callback(X)},0)}T()})}return(R={init:function(){if(n(O)){O={}}if(O.maxLength){M=O.maxLength;Q=true}if(O.lazy){N=true}else{R.down.init()}},callback:function(X){V=false;var W=R.up;T();W.callback(X)},incoming:function(Z,X){if(Q){var Y=Z.indexOf("_"),W=parseInt(Z.substring(0,Y),10);P+=Z.substring(Y+1);if(W===0){if(O.encode){P=f(P)}R.up.incoming(P,X);P=""}}else{R.up.incoming(Z,X)}},outgoing:function(aa,X,Z){if(O.encode){aa=A(aa)}var W=[],Y;if(Q){while(aa.length!==0){Y=aa.substring(0,M);aa=aa.substring(Y.length);W.push(Y)}while((Y=W.shift())){S.push({data:W.length+"_"+Y,origin:X,callback:W.length===0?Z:null})}}else{S.push({data:aa,origin:X,callback:Z})}if(N){R.down.init()}else{T()}},destroy:function(){U=true;R.down.destroy()}})};easyXDM.stack.VerifyBehavior=function(Q){var R,P,N,O=false;function M(){P=Math.random().toString(16).substring(2);R.down.outgoing(P)}return(R={incoming:function(U,S){var T=U.indexOf("_");if(T===-1){if(U===P){R.up.callback(true)}else{if(!N){N=U;if(!Q.initiate){M()}R.down.outgoing(U)}}}else{if(U.substring(0,T)===N){R.up.incoming(U.substring(T+1),S)}}},outgoing:function(U,S,T){R.down.outgoing(P+"_"+U,S,T)},callback:function(S){if(Q.initiate){M()}}})};easyXDM.stack.RpcBehavior=function(S,N){var P,U=N.serializer||E();var T=0,R={};function M(V){V.jsonrpc="2.0";P.down.outgoing(U.stringify(V))}function Q(V,X){var W=Array.prototype.slice;return function(){var Y=arguments.length,aa,Z={method:X};if(Y>0&&typeof arguments[Y-1]==="function"){if(Y>1&&typeof arguments[Y-2]==="function"){aa={success:arguments[Y-2],error:arguments[Y-1]};Z.params=W.call(arguments,0,Y-2)}else{aa={success:arguments[Y-1]};Z.params=W.call(arguments,0,Y-1)}R[""+(++T)]=aa;Z.id=T}else{Z.params=W.call(arguments,0)}M(Z)}}function O(V,X,aa,Y){if(!aa){if(X){M({id:X,error:{code:-32601,message:"Procedure not found."}})}return}var ac=false,ab,Z;if(X){ab=function(ae){if(ac){return}ac=true;M({id:X,result:ae})};Z=function(ae){if(ac){return}ac=true;var af={id:X,error:{code:-32099,message:"Application error: "+ae}};if(typeof ae=="object"&&"data" in ae){af.data=ae.data}M(af)}}else{ab=Z=k}try{var ad=aa.method.apply(aa.scope,Y.concat([ab,Z]));if(!n(ad)){ab(ad)}}catch(W){Z(W.message)}}return(P={incoming:function(W,V){var X=U.parse(W);if(X.method){if(N.handle){N.handle(X,M)}else{O(X.method,X.id,N.local[X.method],X.params)}}else{var Y=R[X.id];if(X.error){if(Y.error){Y.error(X.error)}}else{if(Y.success){Y.success(X.result)}}delete R[X.id]}},init:function(){if(N.remote){for(var V in N.remote){if(N.remote.hasOwnProperty(V)){S[V]=Q(N.remote[V],V)}}}P.down.init()},destroy:function(){for(var V in N.remote){if(N.remote.hasOwnProperty(V)&&S.hasOwnProperty(V)){delete S[V]}}P.down.destroy()}})}})(window,document,location,window.setTimeout,decodeURIComponent,encodeURIComponent);