/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 3.0.0pr2
*/
YUI.add("io-base",function(D){var d="io:start",N="io:complete",B="io:success",G="io:failure",Z="io:abort",W=0,M={"X-Requested-With":"XMLHttpRequest"},X={};w=D.config.win;function b(g,l){var l=l||{},k=V((arguments.length===3)?arguments[2]:null,l),Y=(l.method)?l.method.toUpperCase():"GET",j=(l.data)?l.data:null,h;if(l.form){if(l.form.upload){u=D.io._upload(k,g,l);return u;}h=D.io._serialize(l.form);if(j){h+="&"+j;}if(Y==="POST"){j=h;U("Content-Type","application/x-www-form-urlencoded");}else{if(Y==="GET"){g=O(g,h);}}}else{if(j&&Y==="GET"){g=O(g,l.data);}else{if(j&&Y==="POST"){U("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");}}}if(l.xdr){D.io._xdr(g,k,l);return k;}if(l.timeout){P(k,l);}k.c.onreadystatechange=function(){c(k,l);};try{E(k.c,Y,g);}catch(i){}C(k.c,(l.headers||{}));k.abort=function(){Q(k,l);};k.isInProgress=function(){return k.c.readyState!==4&&k.c.readyState!==0;};T(k,(j||""),l);return k;}function A(f,g){var Y=new D.Event.Target().publish("transaction:"+f);Y.subscribe(g.on[f],(g.context||this),g.arguments);return Y;}function R(h,g){g.on=g.on||{};var Y=D.io._fn||{},e=(Y&&Y[h])?Y[h]:null,f;if(e){g.on.start=e.start;delete e;}D.fire(d,h);if(g.on.start){f=A("start",g);f.fire(h);}}function H(e,f){f.on=f.on||{};var Y;D.fire(N,e.id,e.c);if(f.on.complete){Y=A("complete",f);Y.fire(e.id,e.c);}}function S(g,h){h.on=h.on||{};var Y=D.io._fn||{},e=(Y&&Y[g.id])?Y[g.id]:null,f;if(e){h.on.success=e.success;delete e;g.c.responseText=decodeURI(g.c.responseText);}D.fire(B,g.id,g.c);if(h.on.success){f=A("success",h);f.fire(g.id,g.c);}I(g,(h.xdr)?true:false);}function J(g,h){h.on=h.on||{};var Y=D.io._fn||{},e=(Y&&Y[g.id])?Y[g.id]:null,f;if(e){h.on.failure=e.failure;delete e;g.c.responseText=decodeURI(g.c.responseText);}D.fire(G,g.id,g.c);if(h.on.failure){f=A("failure",h);f.fire(g.id,g.c);}I(g,(h.xdr)?true:false);}function Q(g,h){h.on=h.on||{};var Y=D.io._fn||{},e=(Y&&Y[g.id])?Y[g.id]:null,f;if(g&&g.c&&!h.xdr){g.c.abort();if(h){if(h.timeout){L(g.id);}}}if(e){h.on.abort=e.abort;delete e;}D.fire(Z,g.id);if(h.on.abort){f=A("abort",h);f.fire(id);}I(g,(h.xdr)?true:false);}function F(){var Y=W;W++;return Y;}function V(Y,f){var e={};e.id=D.Lang.isNumber(Y)?Y:F();if(f.xdr){e.c=D.io._transportMap[f.xdr.use];}else{if(f.form&&f.form.upload){e.c={};}else{e.c=K();}}return e;}function K(){return(w.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");}function O(Y,e){Y+=((Y.indexOf("?")==-1)?"?":"&")+e;return Y;}function U(Y,e){if(e){M[Y]=e;}else{delete M[Y];}}function C(f,Y){var e;for(e in M){if(M.hasOwnProperty(e)){if(Y[e]){break;}else{Y[e]=M[e];}}}for(e in Y){if(Y.hasOwnProperty(e)){f.setRequestHeader(e,Y[e]);}}}function E(f,Y,e){f.open(Y,e,true);}function T(e,Y,f){e.c.send(Y);R(e.id,f);}function P(Y,e){X[Y.id]=w.setTimeout(function(){Q(Y,e);},e.timeout);}function L(Y){w.clearTimeout(X[Y]);delete X[Y];}function c(Y,e){if(Y.c.readyState===4){if(e.timeout){L(Y.id);}H(Y,e);a(Y,e);}}function a(g,h){var Y;try{if(g.c.status&&g.c.status!==0){Y=g.c.status;}else{Y=0;}}catch(f){Y=0;}if(Y>=200&&Y<300||Y===1223){w.setTimeout(function(){S(g,h);},0);}else{w.setTimeout(function(){J(g,h);},0);}}function I(e,Y){if(w.XMLHttpRequest&&!Y){if(e.c){e.c.onreadystatechange=null;}}e.c=null;e=null;}b.start=R;b.complete=H;b.success=S;b.failure=J;b.abort=Q;b._id=F;b._timeout=X;b.header=U;D.io=b;},"3.0.0pr2");