LI.define("StyledDropdown");
LI.StyledDropdown=function(c,D){D={name:D.name||null,autoPosition:(D.autoPosition===false)?false:true,align:(D.align)?D.align:"left",containerClass:(D.containerClass)?D.containerClass:"styled-dropdown",listClass:(D.listClass)?D.listClass:null,normalLinkClass:(D.normalLinkClass)?D.normalLinkClass:"normal-link",openOnHover:(D.openOnHover)?D.openOnHover:false,stickyLabel:(D.stickyLabel)?D.stickyLabel:false,applyOptionClassToLabel:(D.applyOptionClassToLabel)?D.applyOptionClassToLabel:false};
var r=c,w=null,C=null,v=[],n=null,o=null,h=40,x=38,t=27,k=13,b=false,z=0,l=-1,i=0,y=0,s=false,d="disabled",q=null,p=null,a="itemSelectEvent",f="focusInputEvent",e,B,m,j,A,F,E,j,g;
w=Y$("select",r,true);
n=Y$("span.label",r,true);
C=Y$("ul",r,true);
if(!C){C=document.createElement("ul");
r.appendChild(C)
}if(!n){if(D.applyOptionClassToLabel){p=['<span class="label">','<span class="',w.options[w.selectedIndex].className,'">',w.options[w.selectedIndex].text,"</span>","</span>"].join("")
}else{p=['<span class="label">',"<span>",w.options[w.selectedIndex].text,"</span>","</span>"].join("")
}A=LI.domify(p);
r.insertBefore(A,w)
}n=Y$("span.label span",r,true);
YDom.addClass(r,D.containerClass);
YDom.addClass(C,D.listClass);
function u(){var M=":false;",L,H,I=w.options,K=C.firstChild,J=0,G;
if(!b){if(YAHOO.env.ua.ie&&YAHOO.env.ua.ie<7){o=document.createElement("iframe");
o.src="javascript"+M;
r.appendChild(o)
}y=w.options.length;
for(J=0;
J<y;
J++){L=I[J];
H=document.createElement("li");
H.innerHTML="<div>"+LI.htmlEncode(L.text)+"</div>";
YDom.addClass(H,L.className+" option");
if(L.selected&&z===0){n.innerHTML=LI.htmlEncode(L.text);
z=J;
i=J
}if(J===0){YDom.addClass(H,"first")
}else{if(J+1===G){YDom.addClass(H,"last")
}}if(K){C.insertBefore(H,K)
}else{C.appendChild(H)
}}v=C.getElementsByTagName("li");
for(J=0,G=v.length;
J<G;
J++){v[J]._index=J
}b=true
}}g=function(){if(s){return
}var H=YDom.getRegion(C),L=YDom.getRegion(n.parentNode),K,J,I,G;
if(D.align==="right"){K=[L.right-C.clientWidth,L.bottom]
}else{K=[L.left,L.bottom]
}YDom.addClass(r,"open");
if(D.autoPosition){YDom.setXY(C,K)
}if(YAHOO.env.ua.ie&&YAHOO.env.ua.ie<7){if(H){o.style.height=H.height+"px";
o.style.width=H.width+"px"
}YDom.setXY(o,YDom.getXY(C))
}J=YDom.getElementsByClassName("highlighted","li",C);
for(I=0,G=J.length;
I<G;
I++){YDom.removeClass(J[I],"highlighted")
}YDom.addClass(v[w.selectedIndex],"highlighted")
};
F=function(){YDom.removeClass(r,"open")
};
E=function(H){H=H||window.event;
var I=w.selectedIndex,L=H.keyCode,K,J,G;
K=YDom.getElementsByClassName("selected","li",C);
for(J=0,G=K.length;
J<G;
J++){YDom.removeClass(K[J],"selected")
}if(H.type==="keydown"){if(L===k){I=z
}else{if(L===h&&z>=y-1){I=z+1
}else{if(L===x&&z>=y){I=z-1;
w.selectedIndex=y-1
}}}}if(!v[I]){I=z
}YDom.addClass(v[I],"selected");
z=I;
g();
if(H.type!=="blur"){e(H)
}};
j=function(){if(!YDom.hasClass(r,"open")&&!D.stickyLabel){n.innerHTML=w.options[w.selectedIndex].text;
for(var I=n.className.split(" "),G=I.length,H=0;
H<G;
H++){if(I[H].indexOf("styled-dropdown-select-")===0){YDom.removeClass(n,I[H])
}}YDom.addClass(n,"styled-dropdown-select-"+w.options[w.selectedIndex].getAttribute("data-li-styled-dropdown-class"))
}};
e=function(H){H=H||window.event;
var J=H.keyCode;
var G=YEvent.getTarget(H);
if(H.type==="mousedown"&&(YDom.hasClass(G.parentNode,"disabled")||YDom.hasClass(G,"disabled"))){YEvent.stopEvent(H);
return
}if(YDom.hasClass(G,D.normalLinkClass)){F();
if(G.href){if(G.target){var I=window.open(G.href,G.target);
I.focus()
}else{window.location=G.href
}}return
}if(J===t||(H.type==="blur"&&z>=y)){F();
w.selectedIndex=i
}else{if(H.type==="blur"&&l!==z){B(z)
}else{if(J===k||H.type==="mousedown"){YEvent.stopEvent(H);
if(H.type==="mousedown"&&YDom.getAncestorByClassName(G,D.containerClass)&&(!YDom.hasClass("label")&&!YDom.getAncestorByClassName(G,"label"))){if(G.nodeName!=="LI"){G=YDom.getAncestorByTagName(G,"li");
if(!G){return
}}z=G._index;
if(z<y){w.selectedIndex=z
}}if(YDom.hasClass(G,"option")||J===k){B(z);
LI.Events.fire(f);
F()
}}}}j()
};
B=function(H){var G,J,I;
if(H>=y){w.selectedIndex=i;
G=LI.StyledDropdown.itemSelectEvent.fire(D.name,v[H]);
if(LI.Events){LI.Events.fire(a,{name:D.name,option:v[H]})
}if(G!==false){I=Y$("div > a",v[H]);
if(I.length===1){if(I[0].target){J=window.open(I[0].href,I[0].target);
J.focus();
F();
w.blur();
return false
}else{document.location.href=I[0].href
}}}}else{i=H;
LI.StyledDropdown.itemSelectEvent.fire(D.name,w.options[H]);
if(LI.Events){LI.Events.fire(a,{name:D.name,option:w.options[H]})
}}l=H;
F();
w.blur()
};
m=function(I){I=I||window.event;
var H=YEvent.getTarget(I),K=YDom.getElementsByClassName("highlighted","li",C),J,G;
for(J=0,G=K.length;
J<G;
J++){YDom.removeClass(K[J],"highlighted")
}if(I.type==="mouseover"&&YDom.getAncestorByClassName(H,D.containerClass)){if(H.nodeName!=="LI"){H=YDom.getAncestorByTagName(H,"li")
}YDom.addClass(H,"highlighted")
}};
this.disableDropdown=function(){if(!s){s=true;
YDom.addClass(c,d)
}};
this.enableDropdown=function(){if(s){s=false;
YDom.removeClass(c,d)
}};
this.getSelectedValue=function(){return w.options[w.selectedIndex].value
};
this.setSelectedValue=function(K,L){u();
var H=w.options,G=H.length,J,I;
for(I=0;
I<G;
I++){J=H[I];
if(K===J.value){J.selected=true;
if(!L){B(I)
}YDom.addClass(v[I],"highlighted");
n.innerHTML=w.options[w.selectedIndex].text;
z=I;
j();
return
}}throw K+" is not a valid value."
};
YEvent.on(w,"focus",function(G){u();
if(!YDom.hasClass(r,"open")){g();
E(G)
}});
if(!D.stickyLabel){YEvent.on(w,"blur",function(G){e(G);
F()
});
YEvent.on(r,"focus",E);
YEvent.on(r,"blur",F)
}YEvent.on(w,"keydown",E);
if(D.openOnHover){YEvent.on(n,"mouseover",function(){w.focus()
});
YEvent.on(r,"mouseover",function(){if(q){window.clearTimeout(q)
}});
YEvent.on(r,"mouseout",function(){if(YDom.hasClass(r,"open")){q=window.setTimeout(function(){w.blur()
},250)
}else{if(q){window.clearTimeout(q)
}}})
}YEvent.on(n,"mousedown",function(G){if(YDom.hasClass(r,"open")){F();
e(G);
w.blur()
}else{u();
g();
E(G);
w.focus()
}});
YEvent.on(w,"change",E);
YEvent.on(C,"mouseover",m);
YEvent.on(C,"mouseout",m);
YEvent.on(C,"mousedown",e);
j();
LI.StyledDropdown.loadEvent.fire(D.name);
LI.StyledDropdown.itemSelectEvent.fire(D.name,w.options[w.selectedIndex]);
if(LI.Events){LI.Events.fire(a,{name:D.name,option:w.options[w.selectedIndex]})
}};
LI.StyledDropdown.loadEvent=new YAHOO.util.CustomEvent("load");
LI.StyledDropdown.itemSelectEvent=new YAHOO.util.CustomEvent("itemSelect");LI.define("GhostLabel");
LI.GhostLabel=function(c,s){var h=YDom.get(c.htmlFor),m=h.type,j,a,g="password",b=!!("placeholder" in document.createElement("input")&&"placeholder" in document.createElement("textarea")),p="ghost-hide",l="ghost-show",e="hint",i="clone-hint",k=this;
s=s||{};
s={placeholder:(YAHOO&&YAHOO.lang&&YAHOO.lang.trim)?YAHOO.lang.trim(s.placeholder||c.firstChild.nodeValue):(s.placeholder||c.firstChild.nodeValue),showLabel:s.showLabel||false,isDefault:s.isDefault||false};
if(b){h.setAttribute("placeholder",s.placeholder)
}var t=function(){if(!b){if(s.placeholder&&h.value===""){if(m===g){if(!j){j=document.createElement("input");
j.type="text";
j.value=s.placeholder;
YDom.addClass(j,e);
YDom.addClass(j,i);
YDom.addClass(j,YDom.getAttribute(h,"class"));
j.setAttribute("tabindex",h.getAttribute("tabindex"));
YDom.insertAfter(j,h);
a=true;
YEvent.on(j,"focus",u)
}if(!a){YDom.removeClass(j,p);
YDom.removeClass(h,l)
}YDom.addClass(j,l);
YDom.addClass(h,p);
a=true
}YDom.addClass(h,e);
if(m!==g){h.value=s.placeholder
}}}};
var u=function(){if(!b){if(s.placeholder&&(m===g||h.value===s.placeholder)&&YDom.hasClass(h,e)){if(j&&m===g){if(a){YDom.removeClass(j,l);
YDom.removeClass(h,p)
}YDom.addClass(j,p);
YDom.addClass(h,l);
a=false;
h.focus()
}if(m!==g){h.value=""
}YDom.removeClass(h,e)
}}};
var d=function(){if(b){if(h.value===""){return true
}}else{if(YDom.hasClass(h,e)){return true
}}return false
};
var q=function(v){s.placeholder=v
};
var r=function(){return s.placeholder
};
var f=function(v){if(b){h.setAttribute("placeholder",s.placeholder)
}else{if(v){if(d()){h.value=s.placeholder
}}else{h.value=s.placeholder;
YDom.addClass(h,e)
}}};
var n=function(){if(s.isDefault){if(h.value===""){h.value=s.placeholder
}}else{u()
}};
var o=function(){var v=h.form;
if(!s.showLabel){LI.hide(c)
}if(!b){if(m!==g){YEvent.on(h,"focus",u)
}YEvent.on(h,"blur",t);
if(s.placeholder&&(h.value===s.placeholder)){h.value="";
YDom.removeClass(h,e)
}t()
}if(v){YEvent.on(v,"submit",n)
}if(v&&v.id&&h.id){LI.GhostLabel.Manager.register(v.id,h.id,k)
}};
o();
this.showGhostLabel=t;
this.hideGhostLabel=u;
this.setLabel=q;
this.getLabel=r;
this.updateLabel=f;
this.isGhostLabelVisible=d
};
LI.GhostLabel.Manager={registry:{},register:function(c,a,b){if(!this.registry[c]){this.registry[c]={}
}this.registry[c][a]=b
},destroy:function(b,a){if(this.registry[b][a]){delete this.registry[b][a]
}},show:function(b){if(this.registry[b]){for(var a in this.registry[b]){if(YAHOO.lang.hasOwnProperty(this.registry[b],a)){this.registry[b][a].showGhostLabel()
}}}},hide:function(b){if(this.registry[b]){for(var a in this.registry[b]){if(YAHOO.lang.hasOwnProperty(this.registry[b],a)){this.registry[b][a].hideGhostLabel()
}}}}};