(function(A){A.prompt=function(P,Q){Q=A.extend({},A.prompt.defaults,Q);A.prompt.currentPrefix=Q.prefix;var E=(A.browser.msie&&A.browser.version<7);var G=A(document.body);var C=A(window);var B='<div class="'+Q.prefix+'box" id="'+Q.prefix+'box">';if(Q.useiframe&&((A("object, applet").length>0)||E)){B+='<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+Q.prefix+'fade" id="'+Q.prefix+'fade"></iframe>'}else{if(E){A("select").css("visibility","hidden")}B+='<div class="'+Q.prefix+'fade" id="'+Q.prefix+'fade"></div>'}B+='<div class="'+Q.prefix+'" id="'+Q.prefix+'"><div class="'+Q.prefix+'container"><div class="';B+=Q.prefix+'close">X</div><div id="'+Q.prefix+'states"></div>';B+="</div></div></div>";var O=A(B).appendTo(G);var L=O.children("#"+Q.prefix);var M=O.children("#"+Q.prefix+"fade");if(P.constructor==String){P={state0:{html:P,buttons:Q.buttons,focus:Q.focus,submit:Q.submit}}}var N="";A.each(P,function(S,R){R=A.extend({},A.prompt.defaults.state,R);P[S]=R;N+='<div id="'+Q.prefix+"_state_"+S+'" class="'+Q.prefix+'_state" style="display:none;"><div class="'+Q.prefix+'message">'+R.html+'</div><div class="'+Q.prefix+'buttons">';A.each(R.buttons,function(U,T){N+='<button name="'+Q.prefix+"_"+S+"_button"+U+'" id="'+Q.prefix+"_"+S+"_button"+U+'" class="btnSecondary" value="'+T+'"><span>'+U+"</span></button>"});N+="</div></div>"});L.find("#"+Q.prefix+"states").html(N).children("."+Q.prefix+"_state:first").css("display","block");L.find("."+Q.prefix+"buttons:empty").css("display","none");A.each(P,function(T,S){var R=L.find("#"+Q.prefix+"_state_"+T);R.children("."+Q.prefix+"buttons").children("button").click(function(){var W=R.children("."+Q.prefix+"message");var U=S.buttons[A(this).text()];var X={};A.each(L.find("#"+Q.prefix+"states :input").serializeArray(),function(Y,Z){if(X[Z.name]===undefined){X[Z.name]=Z.value}else{if(typeof X[Z.name]==Array){X[Z.name].push(Z.value)}else{X[Z.name]=[X[Z.name],Z.value]}}});var V=S.submit(U,W,X);if(V===undefined||V){D(true,U,W,X)}});R.find("."+Q.prefix+"buttons button:eq("+S.focus+")").addClass(Q.prefix+"defaultbutton")});var F=function(){O.css({top:C.scrollTop()})};var J=function(){if(Q.persistent){var S=0;O.addClass(Q.prefix+"warning");var R=setInterval(function(){O.toggleClass(Q.prefix+"warning");if(S++>1){clearInterval(R);O.removeClass(Q.prefix+"warning")}},100)}else{D()}};var H=function(U){var T=(window.event)?event.keyCode:U.keyCode;if(T==27){D()}if(T==9){var V=A(":input:enabled:visible",O);var S=!U.shiftKey&&U.target==V[V.length-1];var R=U.shiftKey&&U.target==V[0];if(S||R){setTimeout(function(){if(!V){return }var W=V[R===true?V.length-1:0];if(W){W.focus()}},10);return false}}};var I=function(){O.css({position:(E)?"absolute":"fixed",height:C.height(),width:"100%",top:(E)?C.scrollTop():0,left:0,right:0,bottom:0});M.css({position:"absolute",height:C.height(),width:"100%",top:0,left:0,right:0,bottom:0});L.css({position:"absolute",top:Q.top,left:"50%",marginLeft:((L.outerWidth()/2)*-1)})};var K=function(){M.css({zIndex:Q.zIndex,display:"none",opacity:Q.opacity});L.css({zIndex:Q.zIndex+1,display:"none"});O.css({zIndex:Q.zIndex})};var D=function(T,S,U,R){L.remove();if(E){G.unbind("scroll",F)}C.unbind("resize",I);M.fadeOut(Q.overlayspeed,function(){M.unbind("click",J);M.remove();if(T){Q.callback(S,U,R)}O.unbind("keypress",H);O.remove();if(E&&!Q.useiframe){A("select").css("visibility","visible")}})};I();K();if(E){C.scroll(F)}M.click(J);C.resize(I);O.bind("keydown keypress",H);L.find("."+Q.prefix+"close").click(D);M.fadeIn(Q.overlayspeed);L[Q.show](Q.promptspeed,Q.loaded);L.find("#"+Q.prefix+"states ."+Q.prefix+"_state:first ."+Q.prefix+"defaultbutton").focus();if(Q.timeout>0){setTimeout(A.prompt.close,Q.timeout)}return O};A.prompt.defaults={prefix:"jqi",buttons:{Ok:true},loaded:function(){},submit:function(){return true},callback:function(){},opacity:0.7,zIndex:999,overlayspeed:"slow",promptspeed:"fast",show:"fadeIn",focus:0,useiframe:false,top:"35%",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(B){A.prompt.defaults=A.extend({},A.prompt.defaults,B)};A.prompt.setStateDefaults=function(B){A.prompt.defaults.state=A.extend({},A.prompt.defaults.state,B)};A.prompt.getStateContent=function(B){return A("#"+A.prompt.currentPrefix+"_state_"+B)};A.prompt.getCurrentState=function(){return A("."+A.prompt.currentPrefix+"_state:visible")};A.prompt.getCurrentStateName=function(){var B=A.prompt.getCurrentState().attr("id");return B.replace(A.prompt.currentPrefix+"_state_","")};A.prompt.goToState=function(B){A("."+A.prompt.currentPrefix+"_state").slideUp("slow");A("#"+A.prompt.currentPrefix+"_state_"+B).slideDown("slow",function(){A(this).find("."+A.prompt.currentPrefix+"defaultbutton").focus()})};A.prompt.nextState=function(){var B=A("."+A.prompt.currentPrefix+"_state:visible").next();A("."+A.prompt.currentPrefix+"_state").slideUp("slow");B.slideDown("slow",function(){B.find("."+A.prompt.currentPrefix+"defaultbutton").focus()})};A.prompt.prevState=function(){var B=A("."+A.prompt.currentPrefix+"_state:visible").prev();A("."+A.prompt.currentPrefix+"_state").slideUp("slow");B.slideDown("slow",function(){B.find("."+A.prompt.currentPrefix+"defaultbutton").focus()})};A.prompt.close=function(){A("#"+A.prompt.currentPrefix+"box").fadeOut("fast",function(){A(this).remove()})}})(jQuery);
