/*
Copyright (c) 2008, Bubbling Library Team. All rights reserved.
Portions Copyright (c) 2008, Yahoo!, Inc. All rights reserved.
Code licensed under the BSD License:
http://www.bubbling-library.com/eng/licence
version: 2.1 
*/
YAHOO.namespace("plugin");(function(){var I=YAHOO.util.Connect,D=YAHOO.lang,F=YAHOO.util.Event,H=YAHOO.util.Dom,E=YAHOO.util.Dom.get;var N={LOADING:1,DISPATCHED:2,ERROR:3,EMPTY:4,proxy:"/dispatcher.php?uri=",CSSNODE:1,JSNODE:2};var L=/<script([^>]*)>([\s\S]*?)<\/script>/igm,A=/src=(['"]?)([^"']*)\1/i,M=/rel=(['"]?)([^"']*)\1/i,C=/<link([^>]*)(>[\s]*<\/link>|>)/igm,K=/href=(['"]?)([^"']*)\1/i,O=/<style([^>]*)>([\s\S]*?)<\/style>/igm,B=new RegExp("([\\w-.]+)\\s*=\\s*(\".*?\"|'.*?'|\\w+)*","im");var J=new RegExp("url\\s*\\(([^\\)]*)","igm");var G=new RegExp("^((?:http|https)://)((?:\\w+[.|-]?)*\\w+)(/.*)$","i");YAHOO.plugin.Dispatcher=function(){var W={},S={},j=[],P={relative:false,baseURI:document.location.toString()},b="loading",c="yui-dispatchable",T={key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}},a=/^\s+|\s+$/g;function h(s,p){var r=T,l=r.parser[p?"strict":"loose"].exec(s),q={},n=14;while(n--){q[r.key[n]]=l[n]||""}q[r.q.name]={};q[r.key[12]].replace(r.q.parser,function(o,m,t){if(m){q[r.q.name][m]=t}});return q}function e(l){var n=document.getElementsByTagName("head")[0]||document.documentElement,m=document.createElement("script");l=l.replace(a,"");if(l){m.type="text/javascript";if(YAHOO.env.ua.ie){m.text=l}else{m.appendChild(document.createTextNode(l))}n.insertBefore(m,n.firstChild);n.removeChild(m)}}function Y(l){if(D.isString(l)){l=l.replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1");l=l.replace(/^(['|"])*(\S*(?:\s+\S+)*)\1$/,"$2")}return l}function Q(o,l){var n=null,m={};l=l||{};if(D.isString(o)){while(n=B.exec(o)){n[2]=(l.hasOwnProperty(n[1])?l[n[1]]:n[2]);if(n[2]){m[n[1]]=Y(n[2])}o=o.replace(B,"")}}return m}function U(l){l=((D.isString(l)&&(l.indexOf("/")>-1))?l:P.baseURI)+"";return l.substr(0,l.lastIndexOf("/")+1)}function k(m,l){if(l&&!G.test(l)&&(l.indexOf("/")!==0)){l=m+l}return l}function R(l){if(l.element&&l.element.setAttribute){l.element.setAttribute("aria-live","polite");l.element.setAttribute("aria-atomic","true");l.element.setAttribute("aria-relevant","all");l.element.setAttribute("aria-busy","true")}l.onStart=l.before||l.onStart;if(D.isFunction(l.onStart)){l.onStart.apply(l,[l.element]);l.onStart=null}if(!l.underground&&YAHOO.Bubbling){YAHOO.Bubbling.fire("onAsyncRequestStart",{element:l.element})}}function g(l,m){if(D.isFunction(l.onChange)){m=m||l.element;l.onChange.apply(l,[m])}}function V(l){l.onLoad=l.after||l.onLoad;if(D.isFunction(l.onLoad)){l.onLoad.apply(l,[l.element])}if(!l.underground&&YAHOO.Bubbling){YAHOO.Bubbling.fire("onAsyncRequestEnd",{element:l.element})}if(l.element&&l.element.setAttribute){l.element.setAttribute("aria-busy","false")}}function i(q,m){var r=null,l=true,p=null,o="",n=0;m=m||{};if(W.isAlive(q)){p=S[q].chunks.shift();if(D.isObject(p)&&p.src){m.hash=j.length;for(n=0;n<j.length;n++){if(j[n].uri==p.src){if((j[n].status==N.DISPATCHED)&&!m.override){l=false}else{}m.hash=n;break}}if(l){o=W.firewall(p.src,m,true);if(D.isString(o)&&(o!=="")){j[m.hash]={uri:p.src,proxy:o,status:N.LOADING};if(p.type===N.JSNODE){W.area=q;W.destroyer=S[q].destroyer;m.handle=YAHOO.util.Get.script(o,{onSuccess:function(){j[m.hash].status=N.DISPATCHED;if(m.rel&&YAHOO.Bubbling){YAHOO.Bubbling.fire("onScriptReady",{module:p.rel,src:p.src,uri:o,hash:m.hash})}m.hash=null;i(q,m)},onFailure:function(){i(q,m)},scope:W,data:m})}else{if(p.type===N.CSSNODE){YAHOO.util.Get.css(o,{});j[m.hash].status=N.DISPATCHED;i(q,m)}}}}else{i(q,m)}}else{m.hash=null;Z(q,p.content,m)}}else{W.kill(q);V(m)}}function Z(o,p,m){var l=N.EMPTY;if(p&&(p!=="")){try{l=N.DISPATCHED;if(!m.hash||(j[m.hash].status!=N.DISPATCHED)){W.area=o;W.destroyer=S[o].destroyer;if(D.isFunction(m.evalRoutine)){m.evalRoutine(p,m)}else{e(p)}}}catch(n){l=N.ERROR;if(D.isFunction(m.error)){m.error.apply(m,[o,p,j,n])}else{throw new Error("Dispacher: Script Execution Error ("+n+")")}}}if(D.isNumber(m.hash)){j[m.hash].status=l;m.hash=null}i(o,m)}function d(m,q,l){l.action=(l.action?l.action:"replace");switch(l.action){case"tabview":f(m.get("contentEl"),l);try{m.set("content",q)}catch(p){return false}g(l,m.get("contentEl"));break;case"update":q=m.innerHTML+q;try{m.innerHTML=q}catch(o){return false}g(l,m);break;case"replace":case"layout":default:f(m,l);try{m.innerHTML=q}catch(n){return false}g(l,m);break}return true}function f(n,l){var o=l.guid,m=0;if(D.isObject(S[o].destroyer)){S[o].destroyer.fire(n,l)}if(H.inDocument(n)){for(m=0;m<n.childNodes.length;m++){F.purgeElement(n.childNodes[m],true)}H.addClass(n,c)}S[o].destroyer=new YAHOO.util.CustomEvent("destroyer");if(D.isFunction(l.onDestroy)){S[o].destroyer.subscribe(l.onDestroy)}}function X(r,p,o){o=o||{};o.uri=o.uri||null;o.relative=o.relative||P.relative;var n=true,l=false,q=U(o.uri);p=p.replace(O,function(w,v,t,u,m){if(t){W.applyCSS(t,Q(v),o)}return""});p=p.replace(C,function(w,v,t,u,m){if(v){l=v.match(K);if(l){if(o.relative){l[2]=k(q,l[2])}S[r].chunks.push({src:l[2],content:"",type:N.CSSNODE,params:Q(v)})}}return""});p=p.replace(L,function(x,w,u,v,t){if(w){l=w.match(A);if(l){var m=w.match(M);m=(m?m[2]:null);if(o.relative){l[2]=k(q,l[2])}S[r].chunks.push({src:l[2],content:"",type:N.JSNODE,rel:m,params:Q(w)})}}if(u){S[r].chunks.push({src:null,content:u,type:N.JSNODE,params:Q(w)})}return""});return p}if(YAHOO.Bubbling){YAHOO.Bubbling.on("onScriptReady",function(){if(this.src&&!this.hash){j[this.hash].status=N.DISPATCHED}})}W.area=null;W.strictMode=true;W.destroyer=null;W.fetch=function(n,o,m){m=m||{};m.uri=o;var q=null,l=null,p={success:function(r){if(r.responseText!="undefined"){W.process(n,r.responseText,m,true)}H.removeClass(n,b)},failure:function(r){if(D.isFunction(m.onError)){m.onError.apply(m,[m.element,r])}H.removeClass(n,b)}};if((D.isObject(n)||(n=E(n)))&&o){l=W.firewall(o,m);H.addClass(n,b);m.handle=I.asyncRequest("GET",l,p);m.element=n;R(m);if(YAHOO.Bubbling){q=m.guid||F.generateId(n);YAHOO.Bubbling.fire("onNavigate",{state:q+escape(o),control:"dispatcher",element:n,uri:o,config:m,restore:function(){W.fetch(n,o,m)}})}return m.handle}return null};W.process=function(n,o,m,l){var p=null;m=m||{};if(D.isObject(n)||(n=E(n))){p=m.guid||F.generateId(n);this.kill(p);m.element=n;m.content=o;m.guid=p;if(!l){R(m)}if(d(n,X(p,o,m),m)){i(p,m)}}return p};W.delegate=function(m,n,l){l=l||{};l.action="tabview";l.uri=m.get("dataSrc")||null;l.tab=m;m.loadHandler.success=function(q){var p=m.get("contentEl");l.tab=p;l.underground=true;W.process(m,q.responseText,l);if(YAHOO.Bubbling){YAHOO.Bubbling.fire("onAsyncRequestEnd",{element:p})}};m.on("activeChange",function(){if(YAHOO.Bubbling&&this.get("active")&&m.get("dataSrc")&&!this.get("cacheData")){YAHOO.Bubbling.fire("onAsyncRequestStart",{element:this.get("contentEl")})}});if(D.isObject(n)){n.addTab(m)}};W.addUnit=function(o,n,l){var p=l||{},m;p.action="layout";if(!o||!n){return false}if(D.isString(o)){o=n.getUnitByPosition(o)}else{if(o.position&&!n.getUnitByPosition(o.position)){o=n.addUnit(o)}}if(p.uri){o.set("dataSrc",p.uri)}if((p.unit=o)&&(p.uri=p.unit.get("dataSrc"))&&(m=p.unit.body)){p.underground=true;p._dispatcherConfig=p;p.unit.loadHandler.success=function(q){W.process(this.body,q.responseText,this._dispatcherConfig);if(YAHOO.Bubbling){YAHOO.Bubbling.fire("onAsyncRequestEnd",{element:this.body})}};if(p.unit.loadContent()&&YAHOO.Bubbling){YAHOO.Bubbling.fire("onAsyncRequestStart",{element:m})}}return p.unit};W.applyCSS=function(m,r,n){r=r||{};var l=document.createElement("style"),p=r.href||"";n=n||{};var o=n.uri||P.baseURI;n.relative=n.relative||P.relative;if(n.relative){o=W.firewall(o,n,true);p=U(o);p=k(p,r.href)}p=U(p);m=m.replace(J,function(w,v,u,t){v=Y(v);v="url("+k(p,v);return v});l.type="text/css";if(D.isObject(l.styleSheet)){l.styleSheet.cssText=m}else{l.appendChild(document.createTextNode(m))}try{document.getElementsByTagName("head")[0].appendChild(l)}catch(q){throw new Error("Dispacher: CSS Processing Error ("+q+")");return false}return true};W.jsLoader=function(m,l){if(D.isString(m)&&(m!=="")){l=l||{};F.generateId(l);W.kill(l.id);S[l.id].chunks=[{src:m,content:"",type:N.JSNODE,params:{href:m}}];l.underground=true;R(l);i(l.id,l);return l.id}return null};W.cssLoader=function(m,l){if(D.isString(m)&&(m!=="")){l=l||{};F.generateId(l);W.kill(l.id);S[l.id].chunks=[{src:m,content:"",type:N.CSSNODE,params:{href:m}}];l.underground=true;R(l);i(l.id,l);return l.id}return null};W.isAlive=function(l){return(l&&D.isObject(S[l])&&(S[l].chunks.length>0))};W.kill=function(l){if(l&&!D.isObject(S[l])){S[l]={chunks:[],destroyer:null}}else{if(this.isAlive(l)){S[l].chunks=[]}}};W.destroy=function(l){this.kill(l);if(l&&!D.isObject(S[l])){S[l].destroyer.fire(E(l),{})}};W.onDestroy=function(n,l,m){var o=(m?[l,m,true]:[l]);if(D.isObject(S[n])&&D.isObject(S[n].destroyer)){if(D.isObject(m)){S[n].destroyer.subscribe(l,m,true)}else{S[n].destroyer.subscribe(l)}return true}return false};W.init=function(l){l=l||{};l.relative=l.relative||false;P=l};W.firewall=function(p,o,r){var n=null,q=null,l=null;while(p.indexOf("&amp;")>-1){p=p.replace("&amp;","&")}o.proxy=o.proxy||N.proxy;if(D.isFunction(o.firewall)){p=o.firewall.apply(o,[p])}else{if(!o.monolithic&&!r&&o.proxy){l=p.match(G);if(l&&(l[2]!==document.domain)){p=o.proxy+escape(p)}}}return p};W.obj2query=function(n){var l="",m;if(D.isObject(n)){for(key in n){if(n.hasOwnProperty(key)){l+=(l==""?"":"&");l+=key+"="+n[key]}}}return l};W.augmentURI=function(p,l){l=l||{};var q=h(p,this.strictMode),n="";q.queryKey=q.queryKey||{};D.augmentObject(q.queryKey,l,true);if(q.protocol){n+=q.protocol+":"}if(this.strictMode){if(/^(?:[^:\/?#]+:)?\/\//.test(q.source)){n+="//"}}else{if(/^(?:(?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?\/\//.test(q.source)){n+="//"}}if(q.authority){if(q.userInfo){if(q.user){n+=q.user}if(q.userInfo.indexOf(":")>-1){n+=":"}if(q.password){n+=q.password}n+="@"}if(q.host){n+=q.host}if(q.port){n+=":"+q.port}}if(q.relative){if(q.path){if(q.directory){n+=q.directory}if(q.file){n+=q.file}}n+="?";for(sName in q.queryKey){if(q.queryKey.hasOwnProperty(sName)){n+=sName+"="+q.queryKey[sName]+"&"}}if(q.anchor){n+="#"+q.anchor}}return n};W.toString=function(){return("YUI Dispatcher Plugin")};return W}()})();YAHOO.util.Dispatcher=YAHOO.plugin.Dispatcher;YAHOO.register("dispatcher",YAHOO.plugin.Dispatcher,{version:"2.1",build:"237"});
