/*
 * LNK WCB Framework v2.5
 * (c) 2010 Linkeo.com
 * Use and redistribution are permitted. No warranty.
 * 
 * Core utilities and components
 */
var LnkLog,LnkWcb,removeScript,debordementsTest={};LnkLog=LnkLog||{};LnkLog.log=LnkLog.log||function(){};LnkWcb=LnkWcb||{};(function(){var e,a,g=LnkWcb.Tests&&LnkWcb.Tests.testables,f,h,k,d,j,i,b,c;e=LnkWcb.util=LnkWcb.util||{};e.putAll=function(l,m){var n;for(n in m){l[n]=m[n]}return l};e.putAll(e,{object:function(m){var l=function(){};l.prototype=m;return new l()
},isArray:function(l){return typeof l==="object"&&Object.prototype.toString.call(l)==="[object Array]"},cloneObject:function(m,l){var n=e.isArray(m)?[]:{};if(l){e.putAll(n,l)}e.putAll(n,m);return n},indexOf:function(o,m){var l=o.length>>>0,n=Number(arguments[2])||0;n=(n<0)?Math.ceil(n):Math.floor(n);if(n<0){n+=l}for(;n<l;++n){if(n in o&&o[n]===m){return n}}return -1},toPaddedString:function(o,n,m){var l=o.toString(m||10);while(n>l.length){l="0"+l}return l},formatDateTime:function(m){var l=e.toPaddedString;
return l(m.getDate(),2)+"/"+l(m.getMonth()+1,2)+"/"+l(m.getFullYear(),2)+" "+l(m.getHours(),2)+":"+l(m.getMinutes(),2)},buildTimeZone:function(l){var q=l||new Date(),p,n,o,m=e.toPaddedString;p=q.getTimezoneOffset();n=Math.floor(Math.abs(p)/60);o=Math.abs(p)%60;return"GMT"+(p<=0?"+":"-")+m(n,2)+":"+m(o,2)},countDefined:function(m){var l,n=0;if(e.isArray(m)){for(l=0;l<m.length;++l){if(m[l]!==undefined){++n}}}else{for(l in m){if(m.hasOwnProperty(l)&&m[l]!==undefined){++n}}}return n},keySet:function(n){var m,l=[];
for(m in n){if(n.hasOwnProperty(m)){l[l.length]=m}}return l},accu:function(m,l,n){if(m[l]===undefined){m[l]=[n]}else{if(e.isArray(m[l])){m[l].push(n)}else{m[l]=[m[l],n]}}return m},createMarkupNode:function(t){var n=this.document||arguments[1]||document,l,m,p,r,o,s=arguments.callee;if(typeof t==="string"){return n.createTextNode(t)}else{if(t&&typeof t==="object"){try{for(l in t){m=n.createElement(l);p=t[l];if(e.isArray(p)){if(p[0]&&typeof p[0]==="object"){for(r in p[0]){try{m.setAttribute(r,p[0][r])
}catch(q){}}}if(e.isArray(p[1])){for(o=0;o<p[1].length;++o){if(p[1][o]){m.appendChild(s.call(this,p[1][o]))}}}else{if(p[1]){m.appendChild(s.call(this,p[1]))}}}else{if(p){m.appendChild(s.call(this,p))}}return m}}catch(q){}}}},urlDecode:function(s){var r={},o,q=decodeURIComponent,m,p,l,n;if(s){o=s.split("&");for(m=0;m<o.length;++m){p=o[m].split("=");l=q(p[0]);n=q(p[1]);if(r[l]===undefined){r[l]=n}else{e.accu(r,l,n)}}}return r}});a=LnkWcb.core=LnkWcb.core||{};(function(){function l(n){var o="",m=0;for(m=0;
m<n;++m){o+=Math.floor(Math.random()*10)}return o}if(g){g.randomString=l}a.createRegistry=function(n){var m={};return{register:function(p){var q=l(12),o=0;while(m[q]&&++o<1000){q=l(12)}m[q]=p;if(n){this[q]=p}return q},finish:function(o){if(m[o]!==undefined){if(typeof m[o].finish==="function"){m[o].finish()}delete m[o];if(n){delete this[o]}}}}}})();f=LnkWcb.Requests=a.createRegistry();removeScript=f.finish;(function(){function l(s){var t="",q,r,p=encodeURIComponent;try{for(q in s){r=s[q];if(r!==null&&r!==undefined){if(t){t+="&"
}t+=p(q)+"="+p(r)}}}catch(o){LnkLog.log("LnkWcb.Request#composeQueryString",o)}return t}function n(p,t){var r=(t&&t.document)||this.document||document,q,s;try{q=r.getElementsByTagName("head")[0];s=r.createElement("script");s.type="text/javascript";s.defer=false;s.id=p.id;p.params.scriptId=p.id;s.src=p.baseUrl+"?"+l(p.params);q.appendChild(s)}catch(o){LnkLog.log("LnkWcb.Request#injectScriptElem",o)}}function m(s,r){var p=(r&&r.document)||this.document||document,q;try{q=p.getElementById(s);if(q){q.parentNode.removeChild(q)
}}catch(o){LnkLog.log("LnkWcb.Request#removeElem",o)}}if(g){g.composeQueryString=l;g.injectScriptElem=n;g.removeElem=m}h=LnkWcb.Request=function(){this.id=f.register(this);this.isSent=false};h.prototype.send=function(q,r,p){try{r=r||{};if(p){r.callback=p}n({id:this.id,baseUrl:q,params:r},this);this.isSent=true}catch(o){LnkLog.log("LnkWcb.Request.send",o)}};h.prototype.finish=function(){m(this.id,this)}})();k=LnkWcb.Event=function(l){this.target=l;this.listeners=[]};k.prototype={rethrow:false,register:function(m){this.listeners[this.listeners.length]=m
},unregister:function(n){var o=e.indexOf,m=o(this.listeners,n);while(m>=0){this.listeners.splice(m,1);m=o(this.listeners,n,m)}},fire:function(){var n,m;for(n=0;n<this.listeners.length&&m!==false;++n){if(this.listeners[n]){try{m=this.listeners[n].apply(this.target,arguments)}catch(l){LnkLog.log("LnkWcb.Event.fire, while calling listeners["+n+"]",l);if(this.rethrow){if(typeof l==="string"){try{({}).crash()}catch(o){o.message=l;throw o}}throw l}}}}}};d=LnkWcb.events=LnkWcb.events||{};d.create=function(n,o){var m,l={};
for(m=0;m<o.length;++m){if(o[m]){l[o[m]]=new k(n)}}return l};d.register=function(m,n){var l;for(l=0;l<n.length;++l){if(n[l]){m[n[l]]=(function(){var o=n[l];return function(p){var q=this.events[o];if(q){q.register(p)}}})()}}};j=LnkWcb.Boutons=a.createRegistry(true);i=j.referencerMethode=function(m,l){return'LnkWcb.Boutons["'+m.id+'"].'+l};(function(){var n="http://",r="wcb.linkeo.com",s="/wcbFrontal/services.do",l="/extranet/bouton/",t=n+r+s,o=n+r+l,q={canal:null,statusPollingTimeout:1000,validator:function(){return true
},frontUrl:t,backUrl:o},m=["onSendCall","onPollStatus","onDigit","onStatus","onEnded","onError"];function p(u){return u.createRequest?u.createRequest():new LnkWcb.Request()}b=LnkWcb.Bouton=function(u){this.id=j.register(this);this.cfg=e.cloneObject(u,q);this.events=d.create(this,m);b.onCreate.fire(this)};b.onCreate=new k(b);c=b.prototype;d.register(c,m);e.putAll(c,{getDefaultSettings:function(){return e.cloneObject(q)},rappeler:function(v){var x,w,y;try{x=this.cfg.validator;if(x&&!x.apply(this,arguments)){return
}delete this.callId;w={t:"call",codeBouton:this.cfg.canal,callee:v};this.receivedUserStatus={};this.receivedAgentStatus={};this.events.onSendCall.fire(Array.prototype.slice.call(arguments,0),w);y=p(this);y.send(this.cfg.frontUrl,w,i(this,"reponseRappeler"))}catch(u){LnkLog.log("LnkWcb.Bouton.rappeler",u)}},reponseRappeler:function(z,x){var v,y,w;try{v=z.responseObj;y=x.params;w=v.error;if(w){this.traiterErreur(w,v.excObj,v,y)}else{this.callId=v.callId;if(String(y.t)==="call"||String(y.behavior)==="poll"){this.suivreAppel()
}else{this.events.onEnded.fire(v,y)}}}catch(u){LnkLog.log("LnkWcb.Bouton.reponseRappeler",u)}},suivreAppel:function(){var v,w,z,x=this.window||window,y=this;try{if(!this.callId){return}v=x.setTimeout(function(){return y.suivreAppel()},this.cfg.statusPollingTimeout);w={t:"lastEvent",callId:this.callId,timerId:v};this.events.onPollStatus.fire(w);z=p(this);z.send(this.cfg.frontUrl,w,i(this,"reponseSuivreAppel"))}catch(u){LnkLog.log("LnkWcb.Bouton.suivreAppel",u)}},reponseSuivreAppel:function(v,B){var x,w,u=this.window||window,A=this.receivedUserStatus,z=this.receivedAgentStatus,D="TOUCHE_APPUYEE",y;
try{x=v.responseObj;w=B.params;if(x.ended!=="1"){if(x.uStatus===D||x.aStatus===D){this.events.onDigit.fire(x,w)}y=false;if(!A[x.uStatus]){A[x.uStatus]=0;y=true}if(!z[x.aStatus]){z[x.aStatus]=0;y=true}if(y){++A[x.uStatus];++z[x.aStatus];this.events.onStatus.fire(x,w)}}else{u.clearTimeout(Number(w.timerId));this.events.onEnded.fire(x,w);delete this.callId}}catch(C){LnkLog.log("LnkWcb.Bouton.reponseSuivreAppel",C)}},traiterErreur:function(x,u,v,w){try{this.events.onError.fire(x,u,v,w)}catch(u){LnkLog.log("LnkWcb.Bouton.traiterErreur",u)
}}});(function(){var v=null,x=[{code:v,regexp:v,msg:"Le code bouton est invalide.",msgCode:"techError",errCode:"I001"},{code:v,regexp:/^La date est invalide/,msg:v,msgCode:"userErrorDate",errCode:"U001"},{code:v,regexp:v,msg:"Erreur: un appel est deja en cours.",msgCode:"userErrorDuplicateCall",errCode:"U002"},{code:"CONFIG_SCENARIO",regexp:v,msg:v,msgCode:"techError",errCode:"F001"},{code:v,regexp:v,msg:"Invalid track id.",msgCode:"techError",errCode:"F002"},{code:v,regexp:v,msg:"This track id already exists.",msgCode:"techError",errCode:"F003"},{code:v,regexp:/^Socket closed/,msg:v,msgCode:"techError",errCode:"F004"},{code:"PROBLEME_REQUETE_HTTP",regexp:v,msg:v,msgCode:"techError",errCode:"E001"},{code:"PROBLEME_PARSING_REPONSE_BO",msg:v,regexp:v,msgCode:"techError",errCode:"E002"},{code:v,regexp:/^Message erreur back office pour codeBouton=.* userPhone=.*\s*:\s*AucunCanal$/,msg:v,msgCode:"techError",errCode:"I003"},{code:v,regexp:/^Message erreur back office pour codeBouton=.* userPhone=.*\s*:\s*TypeCanalNonRequ\S+table$/,msg:v,msgCode:"techError",errCode:"I004"},{code:v,regexp:/^Message erreur back office pour codeBouton=.* userPhone=.*\s*:\s*TypeCanalNonG\S+r\S+$/,msg:v,msgCode:"techError",errCode:"E003"},{code:"MESSAGE_ERREUR_BO",msg:v,regexp:v,msgCode:"techError",errCode:"B002"},{code:v,regexp:/^Le nom du scenario est null ou vide\s+\(codeBouton=.*,\s*userPhone=.*\).$/,msg:v,msgCode:"techError",errCode:"C001"},{code:v,regexp:/^Le scenario .* est indefini\s+\(codeBouton=.*,\s*userPhone=.*\).$/,msg:v,msgCode:"techError",errCode:"C002"},{code:"QUOTA_DEPASSE",regexp:v,msg:v,msgCode:"techError",errCode:"Q001"},{code:v,regexp:v,msg:"Erreur: un appel de priorite superieure est deja en cours.",msgCode:"userErrorDuplicateCall",errCode:"U003"},{code:"TELEPHONE_INTERNAUTE_INVALIDE",regexp:v,msg:v,msgCode:"userErrorTelephone",errCode:"U004"},{code:"CLE_CONFIDENTIELLE_INVALIDE",regexp:v,msg:v,msgCode:"techError",errCode:"F005"},{code:"CHECKSUM_INVALIDE",regexp:v,msg:v,msgCode:"techError",errCode:"I002"},{code:"TELEPHONE_AGENT_INVALIDE",regexp:v,msg:v,msgCode:"techError",errCode:"C003"},{code:v,regexp:/.*/,msg:v,msgCode:"techError",errCode:"B001"}],u=[{code:"CAUSE_BLOQUE",regexp:v,msg:v,msgCode:"debErrorBlocked",errCode:"D001"},{code:"CAUSE_FERME",regexp:v,msg:v,msgCode:"debErrorClosedHour",errCode:"D002"},{code:"CAUSE_FERIE",regexp:v,msg:v,msgCode:"debErrorClosedDay",errCode:"D003"},{code:"CAUSE_SATURE",regexp:v,msg:v,msgCode:"debErrorOverwhelmed",errCode:"D004"}],y=e.cloneObject;
function w(A,C,D){var z,B;for(z=0;z<A.length;++z){B=A[z];if(B&&((B.code&&B.code===C)||(B.regexp&&B.regexp.test(D))||(B.msg&&B.msg===D))){return B}}return null}b.getRawErrors=function(){return y(x)};b.getFallbackRawErrors=function(){return y(u)};b.addRawError=function(z){x.splice(-1,0,z)};b.addFallbackRawError=function(z){u.push(z)};b.findRawError=function(z,A){return w(x,z,A)};b.findFallbackRawError=function(z,A){return w(u,z,A)}})();(function(){var v=["onFallback"],u=["INABOUTI_AGENT","INVERSE_INABOUTI_AGENT","NON_CONFIRMATION_APPEL_AGENT","RACCROCHE_AGENT_AVANT_INTERNAUTE"];
e.putAll(q,{serverSideManagedFallbacks:false,forceFallbacks:true});m=m.concat(v);d.register(c,v);e.putAll(c,{deborder:function(A,y){var x,z;try{x=A.responseObj;z=y.params;this.events.onFallback.fire(x,z)}catch(w){LnkLog.log("LnkWcb.Bouton.deborder",w)}}});b.onCreate.register(function(w){w.onSendCall(function(y,x){if(this.cfg.serverSideManagedFallbacks){x.debordementHandler=i(this,"deborder")}});w.onPollStatus(function(x){if(this.cfg.serverSideManagedFallbacks){x.debordementHandler=i(this,"deborder")
}});w.onEnded(function(x,y){if(!this.cfg.serverSideManagedFallbacks){if(x.debordementType){x.debordementCause=x.debordementCause||"CAUSE_DEBORDE";this.events.onFallback.fire(x,y);return false}else{if(this.cfg.forceFallbacks&&x.status==="KO"&&e.indexOf(u,x.cause)>=0){x.debordementCause="CAUSE_DEBORDE";this.events.onFallback.fire(x,y);return false}}}});w.onError(function(C,x,y,B){var z,A;if(!this.cfg.serverSideManagedFallbacks&&this.cfg.forceFallbacks){A=x&&x.cause;z=b.findFallbackRawError(A,C);if(z){y.debordementCause=A;
this.events.onFallback.fire(y,B);return false}}})})})();(function(){e.putAll(q,{timeZone:e.buildTimeZone()});b.onCreate.register(function(u){u.onSendCall(function(x,w){var v=x[1];if(v){w.t="delay";w.planedDate=v;w.tz=this.cfg.timeZone}})})})();(function(){var v="https://";function u(x){var w=x.cfg;w.frontUrl=w.https?w.frontUrlHttps:w.frontUrlHttp;w.backUrl=w.https?w.backUrlHttps:w.backUrlHttp}e.putAll(q,{frontUrlHttp:t,backUrlHttp:o,frontUrlHttps:v+r+s,backUrlHttps:v+r+l,https:false});b.onCreate.register(function(w){w.cfg.https=(document.location.protocol==="https:");
u(w)});c.useHttps=function(w){this.cfg.https=w;u(this)}})();(function(){m.push("onChannelState");d.register(c,["onChannelState"]);e.putAll(c,{estOuvert:function(){var w,v;try{w=p(this);v=this.cfg.backUrl+"estOuvert/"+this.cfg.canal;w.send(v,null,i(this,"reponseEstOuvert"))}catch(u){LnkLog.log("LnkWcb.Bouton.estOuvert",u)}},reponseEstOuvert:function(w){var v;try{if(!w.error){v=!w.estActif?"INACTIF":(!w.peutRecevoirAppel?"HORS_LIMITES":(w.estSature?"SATURE":w.etatOuverture));this.events.onChannelState.fire(w,v)
}}catch(u){LnkLog.log("LnkWcb.Bouton.reponseEstOuvert",u)}}})})();(function(){function w(D){var y={},A=this.document||document,B,z,C;try{B=A.getElementById(D);if(B&&B.elements){for(z=0;z<B.elements.length;++z){C=B.elements[z];if(C&&C.name&&C.value!==undefined){y[C.name]=C.value}}}}catch(x){LnkLog.log("LnkWcb.Bouton#grabFormFields",x)}return y}function u(){var y=[],z=this.window||window;try{while(z){y[y.length]=z.location;z=z.opener}}catch(x){LnkLog.log("LnkWcb.Bouton#collectOpeners",x)}return y}function v(y){var A="[",z;
try{if(!y){return null}if(y.length){for(z=y.length-1;z>=0;--z){A+='"'+y[z]+'"';if(z>0){A+=","}}}}catch(x){LnkLog.log("LnkWcb.Bouton#serializeArrayReverse",x)}return A+"]"}if(g){g.grabFormFields=w;g.collectOpeners=u;g.serializeArrayReverse=v}e.putAll(q,{grabbedFormId:null});b.onCreate.register(function(x){x.onSendCall(function(A,z){var y;if(this.cfg.grabbedFormId){y=w(this.cfg.grabbedFormId);y.userUrls=v(u());e.putAll(z,y)}})})})();(function(){c.raccrocher=function(){var v,w;try{if(!this.callId){return
}v={t:"hangup",callId:this.callId};w=p(this);w.send(this.cfg.frontUrl,v)}catch(u){LnkLog.log("LnkWcb.Bouton.hangup",u)}}})();(function(){m.push("onOpenHours");d.register(c,["onOpenHours"]);e.putAll(c,{horaires:function(){var x,w,v;try{x=p(this);w=this.cfg.backUrl+"horaires/"+this.cfg.canal;v={tz:this.cfg.timeZone};x.send(w,v,i(this,"reponseHoraires"))}catch(u){LnkLog.log("LnkWcb.Bouton.horaires",u)}},reponseHoraires:function(v){try{if(!v.error){this.events.onOpenHours.fire(v)}}catch(u){LnkLog.log("LnkWcb.Bouton.reponseHoraires",u);
if(k.prototype.rethrow){throw u}}}})})();(function(){m.push("onErrorDigest");d.register(c,["onErrorDigest"]);b.onCreate.register(function(u){u.onError(function(A,v,w,z){var x,y=v&&v.cause;x=b.findFallbackRawError(y,A)||b.findRawError(y,A);if(x){this.events.onErrorDigest.fire(x.msgCode,x.errCode,w,z)}})})})()})()})();
