(function($){$.fn.alerts={verticalOffset:-75,horizontalOffset:0,repositionOnResize:true,overlayOpacity:.01,overlayColor:'#FFF',draggable:true,okButton:'&nbsp;OK&nbsp;',cancelButton:'&nbsp;Cancel&nbsp;',dialogClass:null,showIt:function(header,msg,value,type,callback){$("#alert_holder").remove();$.fn.alerts.overlay();$("BODY").append('<div id="alert_holder"><h1 id="alert_header"></h1>'+'<div id="alert_content"><div id="alert_message"></div></div></div>');var pos=($.browser.msie&&parseInt($.browser.version)<=6)?'absolute':'fixed';$("#alert_holder").css({position:pos,zIndex:99999,padding:0,margin:0});$("#alert_header").text(header);$("#alert_content").addClass(type);$("#alert_message").text(msg);$("#alert_message").html($("#alert_message").text().replace(/\n/g,'<br />'));$("#alert_holder").css({minWidth:$("#alert_holder").outerWidth(),maxWidth:$("#alert_holder").outerWidth()});$.fn.alerts.position();switch(type){case'alert':$("#alert_message").after('<div id="alert_panel"><input type="button" value="'+$.fn.alerts.defaults.okBtn+'" id="alert_ok" /></div>');$("#alert_ok").click(function(){$("#alert_holder").remove();$("#popup_overlay").remove();callback(true)});$("#alert_ok").focus();$("#alert_ok").keypress(function(e){if(e.keyCode==13){$("#alert_ok").trigger('click')}});break;case'confirm':$("#alert_message").after('<div id="alert_panel"><input type="button" class="ui-input-button cyan" value="'+$.fn.alerts.defaults.okBtn+'" id="alert_ok" /> <input type="button" class="ui-input-button" value="'+$.fn.alerts.defaults.cancelBtn+'" id="alert_cancel" /></div>');$("#alert_ok").click(function(){$("#alert_holder").remove();$("#popup_overlay").remove();if(callback){callback(true)}});$("#alert_ok").focus();$("#alert_cancel").click(function(){$("#alert_holder").remove();$("#popup_overlay").remove();if(callback){callback(false)}});$("#alert_ok, #alert_cancel").keypress(function(e){if(e.keyCode==13){$("#alert_ok").trigger('click')}});break;case'prompt':$("#alert_message").append('<br /><input type="text" size="30" id="alert_prompt" />').after('<div id="alert_panel"><input type="button" value="'+$.fn.alerts.defaults.okBtn+'" id="alert_ok" /> <input type="button" value="'+$.fn.alerts.defaults.cancelBtn+'" id="alert_cancel" /></div>');$("#alert_prompt").width($("#alert_message").width());$("#alert_ok").click(function(){var val=$("#alert_prompt").val();$("#alert_holder").remove();$("#popup_overlay").remove();if(callback)callback(val)});$("#alert_cancel").click(function(){$("#alert_holder").remove();$("#popup_overlay").remove();if(callback)callback(null)});$("#alert_ok").focus();$("#alert_prompt, #alert_ok, #alert_cancel").keypress(function(e){if(e.keyCode==13){$("#alert_ok").trigger('click')}});if(value){$("#alert_prompt").val(value)}$("#alert_prompt").select();break}},position:function(){var top=(($(window).height()/2)-($("#alert_holder").outerHeight()/2))+$.fn.alerts.defaults.topOffset;var left=(($(window).width()/2)-($("#alert_holder").outerWidth()/2))+$.fn.alerts.defaults.leftOffset;if(top<0)top=0;if(left<0)left=0;if($.browser.msie&&parseInt($.browser.version)<=6)top=top+$(window).scrollTop();$("#alert_holder").css({top:top+'px',left:left+'px'});$("#popup_overlay").css({height:$(document).height()})},overlay:function(){$("#popup_overlay").remove();$("BODY").append('<div id="popup_overlay"></div>');$("#popup_overlay").css({height:$(document).height(),opacity:'0.3'})}};$.fn.bmjAlert=function(message,header,callback){$.fn.alerts.showIt(header,message,null,'alert',function(result){if(callback)callback(result)})};$.fn.bmjPrompt=function(message,value,header,callback){$.fn.alerts.showIt(header,message,value,'prompt',function(result){if(callback)callback(result)})};$.fn.bmjConfirm=function(message,header,callback){$.fn.alerts.showIt(header,message,null,'confirm',function(result){if(callback)callback(result)})};$.fn.alerts.defaults={okBtn:'&nbsp;OK&nbsp;',cancelBtn:'&nbsp;Cancel&nbsp;',topOffset:-75,leftOffset:0}})(jQuery);
