(function(a){a.prompt=function(c,b){b=a.extend({},a.prompt.defaults,b);a.prompt.currentPrefix=b.prefix;var l=a.browser.msie&&a.browser.version<7,t=a(document.body),m=a(window),o='<div class="'+b.prefix+'box" id="'+b.prefix+'box">';if(b.useiframe&&(a("object, applet").length>0||l))o+='<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+b.prefix+'fade" id="'+b.prefix+'fade"></iframe>';else{l&&a("select").css("visibility","hidden");o+='<div class="'+b.prefix+
'fade" id="'+b.prefix+'fade"></div>'}o+='<div class="'+b.prefix+'" id="'+b.prefix+'"><div class="'+b.prefix+'container"><div class="';o+=b.prefix+'close">X</div><div id="'+b.prefix+'states"></div>';o+="</div></div></div>";var g=a(o).appendTo(t),h=g.children("#"+b.prefix),n=g.children("#"+b.prefix+"fade");if(c.constructor==String)c={state0:{html:c,buttons:b.buttons,focus:b.focus,submit:b.submit}};var q="";a.each(c,function(d,e){e=a.extend({},a.prompt.defaults.state,e);c[d]=e;q+='<div id="'+b.prefix+
"_state_"+d+'" class="'+b.prefix+'_state" style="display:none;"><div class="'+b.prefix+'message">'+e.html+'</div><div class="'+b.prefix+'buttons">';a.each(e.buttons,function(f,i){q+='<button name="'+b.prefix+"_"+d+"_button"+f+'" id="'+b.prefix+"_"+d+"_button"+f+'" value="'+i+'">'+f+"</button>"});q+="</div></div>"});h.find("#"+b.prefix+"states").html(q).children("."+b.prefix+"_state:first").css("display","block");h.find("."+b.prefix+"buttons:empty").css("display","none");a.each(c,function(d,e){var f=
h.find("#"+b.prefix+"_state_"+d);f.children("."+b.prefix+"buttons").children("button").click(function(){var i=f.children("."+b.prefix+"message"),p=e.buttons[a(this).text()],k={};a.each(h.find("#"+b.prefix+"states :input").serializeArray(),function(y,j){if(k[j.name]===undefined)k[j.name]=j.value;else if(typeof k[j.name]==Array)k[j.name].push(j.value);else k[j.name]=[k[j.name],j.value]});var u=e.submit(p,i,k);if(u===undefined||u)r(true,p,i,k)});f.find("."+b.prefix+"buttons button:eq("+e.focus+")").addClass(b.prefix+
"defaultbutton")});var v=function(){g.css({top:m.scrollTop()})},w=function(){if(b.persistent){var d=0;g.addClass(b.prefix+"warning");var e=setInterval(function(){g.toggleClass(b.prefix+"warning");if(d++>1){clearInterval(e);g.removeClass(b.prefix+"warning")}},100)}else r()},x=function(d){var e=window.event?event.keyCode:d.keyCode;e==27&&r();if(e==9){var f=a(":input:enabled:visible",g),i=d.shiftKey&&d.target==f[0];if(!d.shiftKey&&d.target==f[f.length-1]||i){setTimeout(function(){if(f){var p=f[i===true?
f.length-1:0];p&&p.focus()}},10);return false}}},s=function(){g.css({position:l?"absolute":"fixed",height:m.height(),width:"100%",top:l?m.scrollTop():0,left:0,right:0,bottom:0});n.css({position:"absolute",height:m.height(),width:"100%",top:0,left:0,right:0,bottom:0});h.css({position:"absolute",top:b.top,left:"50%",marginLeft:h.outerWidth()/2*-1})},r=function(d,e,f,i){h.remove();l&&t.unbind("scroll",v);m.unbind("resize",s);n.fadeOut(b.overlayspeed,function(){n.unbind("click",w);n.remove();d&&b.callback(e,
f,i);g.unbind("keypress",x);g.remove();l&&!b.useiframe&&a("select").css("visibility","visible")})};s();(function(){n.css({zIndex:b.zIndex,display:"none",opacity:b.opacity});h.css({zIndex:b.zIndex+1,display:"none"});g.css({zIndex:b.zIndex})})();l&&m.scroll(v);n.click(w);m.resize(s);g.bind("keydown keypress",x);h.find("."+b.prefix+"close").click(r);n.fadeIn(b.overlayspeed);h[b.show](b.promptspeed,b.loaded);h.find("#"+b.prefix+"states ."+b.prefix+"_state:first ."+b.prefix+"defaultbutton").focus();b.timeout>
0&&setTimeout(a.prompt.close,b.timeout);return g};a.prompt.defaults={prefix:"jqi",buttons:{Ok:true},loaded:function(){},submit:function(){return true},callback:function(){},opacity:0.6,zIndex:999,overlayspeed:"slow",promptspeed:"fast",show:"fadeIn",focus:0,useiframe:false,top:"15%",persistent:true,timeout:0,state:{html:"",buttons:{Ok:true},focus:0,submit:function(){return true}}};a.prompt.currentPrefix=a.prompt.defaults.prefix;a.prompt.setDefaults=function(c){a.prompt.defaults=a.extend({},a.prompt.defaults,
c)};a.prompt.setStateDefaults=function(c){a.prompt.defaults.state=a.extend({},a.prompt.defaults.state,c)};a.prompt.getStateContent=function(c){return a("#"+a.prompt.currentPrefix+"_state_"+c)};a.prompt.getCurrentState=function(){return a("."+a.prompt.currentPrefix+"_state:visible")};a.prompt.getCurrentStateName=function(){return a.prompt.getCurrentState().attr("id").replace(a.prompt.currentPrefix+"_state_","")};a.prompt.goToState=function(c){a("."+a.prompt.currentPrefix+"_state").slideUp("slow");
a("#"+a.prompt.currentPrefix+"_state_"+c).slideDown("slow",function(){a(this).find("."+a.prompt.currentPrefix+"defaultbutton").focus()})};a.prompt.nextState=function(){var c=a("."+a.prompt.currentPrefix+"_state:visible").next();a("."+a.prompt.currentPrefix+"_state").slideUp("slow");c.slideDown("slow",function(){c.find("."+a.prompt.currentPrefix+"defaultbutton").focus()})};a.prompt.prevState=function(){var c=a("."+a.prompt.currentPrefix+"_state:visible").prev();a("."+a.prompt.currentPrefix+"_state").slideUp("slow");
c.slideDown("slow",function(){c.find("."+a.prompt.currentPrefix+"defaultbutton").focus()})};a.prompt.close=function(){a("#"+a.prompt.currentPrefix+"box").fadeOut("fast",function(){a(this).remove()})}})(jQuery);
