(function($){$.jbox=function(content,options){options=$.extend({},$.jbox.defaults,options);options.showfade=options.opacity>0;options.istip=options.istip||false;options.ismessager=options.ismessager||false;if(content==undefined){content=""}if(options.border<0){options.border=0}if(options.id==undefined){options.id="jbox_"+math.floor(math.random()*1000000)}var isie6=($.browser.msie&&parseint($.browser.version)<7);var prevbox=$("#"+options.id);if(prevbox.length>0){options.zindex=$.jbox.defaults.zindex++;
prevbox.css({zindex:options.zindex});prevbox.find("#jbox").css({zindex:options.zindex+1});return prevbox}var data={url:"",type:"",html:"",isobject:content.constructor==object};if(!data.isobject){content=content+"";var tempcontent=content.tolowercase();if(tempcontent.indexof("id:")==0){data.type="id"}else{if(tempcontent.indexof("get:")==0){data.type="get"}else{if(tempcontent.indexof("post:")==0){data.type="post"}else{if(tempcontent.indexof("iframe:")==0){data.type="iframe"}else{if(tempcontent.indexof("html:")==0){data.type="html"
}else{content="html:"+content;data.type="html"}}}}}content=content.substring(content.indexof(":")+1,content.length)}var withtitle=!options.istip&&!(options.title==undefined);var isrequest=data.type=="get"||data.type=="post"||data.type=="iframe";var titlewidth=typeof options.width=="number"?(options.width-50)+"px":"90%";var boxhtml=[];boxhtml.push('
');if(options.showfade){if((isie6&&$("iframe").length>0)||$("object, applet").length>0){boxhtml.push('
')
}else{if(isie6){$("select").css("visibility","hidden")}boxhtml.push('
')}}boxhtml.push('
');if(options.draggable){boxhtml.push('
')}boxhtml.push('
');
boxhtml.push('
');boxhtml.push('
');boxhtml.push('
');if(options.border>0){boxhtml.push("");boxhtml.push(' | ');
boxhtml.push(' | ');boxhtml.push(' | ');boxhtml.push("
")}boxhtml.push("");boxhtml.push(' | ');boxhtml.push('');
boxhtml.push('');boxhtml.push(' ');if(withtitle){boxhtml.push(' ');
boxhtml.push(' '+(options.title==""?" ":options.title)+" ");boxhtml.push(" ")}boxhtml.push(' ');boxhtml.push("");boxhtml.push(" | ");boxhtml.push(' | ');
boxhtml.push("
");if(options.border>0){boxhtml.push("");boxhtml.push(' | ');boxhtml.push(' | ');boxhtml.push(' | ');
boxhtml.push("
")}boxhtml.push("
");boxhtml.push("
");boxhtml.push("
");var iframehtml='';var $window=$(window);var $body=$(document.body);var $boxbody=$(boxhtml.join("")).appendto($body);var $box=$boxbody.children("#jbox");var $boxfade=$boxbody.children("#jbox-fade");var $boxtemp=$boxbody.children("#jbox-temp");
if(!data.isobject){switch(data.type){case"id":data.html=$("#"+content).html();break;case"get":case"post":data.html="";data.url=content;break;case"html":data.html=content;break;case"iframe":data.html=iframehtml;if(content.indexof("#")==-1){data.url=content+(content.indexof("?")==-1?"?___t=":"&___t=")+math.random()}else{var arr=content.split("#");data.url=arr[0]+(arr[0].indexof("?")==-1?"?___t=":"&___t=")+math.random()+"#"+arr[1]}break}content={state0:{content:data.html,buttons:options.buttons,buttonsfocus:options.buttonsfocus,submit:options.submit}}
}var states=[];var helptitleheight=$box.find(".jbox-help-title").outerheight(true);var helpbuttonheight=$box.find(".jbox-help-button").outerheight(true);var iebuttonfix=$.browser.msie?"line-height:19px;padding:0px 6px 0px 6px;":"padding:2px 10px 2px 10px;";$.each(content,function(statename,stateoptions){if(data.isobject){stateoptions=$.extend({},$.jbox.statedefaults,stateoptions)}content[statename]=stateoptions;if(stateoptions.buttons==undefined){stateoptions.buttons={}}var withbuttons=false;$.each(stateoptions.buttons,function(k,v){withbuttons=true
});var contentheight="auto";if(typeof options.height=="number"){contentheight=options.height;if(withtitle){contentheight=contentheight-helptitleheight}if(withbuttons){contentheight=contentheight-helpbuttonheight}contentheight=(contentheight-1)+"px"}var loadinghtml="";var loadingimagetop="25px";if(!data.isobject&&isrequest){var loadingheight=options.height;if(typeof options.height=="number"){if(withtitle){loadingheight=loadingheight-helptitleheight}if(withbuttons){loadingheight=loadingheight-helpbuttonheight
}loadingimagetop=((loadingheight/5)*2)+"px";loadingheight=(loadingheight-1)+"px"}loadinghtml=['"].join("")}states.push('');states.push('
'+loadinghtml+'
'+stateoptions.content+"
");
states.push('
');if(!options.istip){states.push('')}$.each(stateoptions.buttons,function(k,v){states.push('")});states.push("
")});$box.find("#jbox-states").html(states.join("")).children(".jbox-state:first").css("display","block");
if(isrequest){var $iframe=$box.find("#jbox-content").css({position:(isie6)?"absolute":"fixed",left:-10000})}$.each(content,function(statename,stateoptions){var $state=$box.find("#jbox-state-"+statename);$state.children(".jbox-button-panel").children("button").click(function(){var object=$state.find("#jbox-content");var clicked=stateoptions.buttons[$(this).text()];var forminputs={};$.each($box.find("#jbox-states :input").serializearray(),function(i,obj){if(forminputs[obj.name]===undefined){forminputs[obj.name]=obj.value
}else{if(typeof forminputs[obj.name]==array){forminputs[obj.name].push(obj.value)}else{forminputs[obj.name]=[forminputs[obj.name],obj.value]}}});var closed=stateoptions.submit(clicked,object,forminputs);if(closed===undefined||closed){removebox()}}).bind("mousedown",function(){$(this).addclass("jbox-button-active")}).bind("mouseup",function(){$(this).removeclass("jbox-button-active")}).bind("mouseover",function(){$(this).addclass("jbox-button-hover")}).bind("mouseout",function(){$(this).removeclass("jbox-button-active").removeclass("jbox-button-hover")
});$state.find(".jbox-button-panel button:eq("+stateoptions.buttonsfocus+")").addclass("jbox-button-focus")});var ie6scroll=function(){$boxbody.css({top:$window.scrolltop()});if(options.ismessager){$box.css({position:(isie6)?"absolute":"fixed",right:1,bottom:1})}};var fadeclicked=function(){if(!options.showfade){return}if(options.persistent){var i=0;$boxbody.addclass("jbox-warning");var intervalid=setinterval(function(){$boxbody.toggleclass("jbox-warning");if(i++>1){clearinterval(intervalid);$boxbody.removeclass("jbox-warning")
}},100)}else{removebox()}};var keypresseventhandler=function(e){if(options.istip||options.ismessager){return false}var key=(window.event)?event.keycode:e.keycode;if(key==27){removebox()}if(key==9){var $inputels=$(":input:enabled:visible",$boxbody);var fwd=!e.shiftkey&&e.target==$inputels[$inputels.length-1];var back=e.shiftkey&&e.target==$inputels[0];if(fwd||back){settimeout(function(){if(!$inputels){return}var el=$inputels[back===true?$inputels.length-1:0];if(el){el.focus()}},10);return false}}};
var setfade=function(){if(options.showfade){$.jbox.fadeboxcount++;$boxfade.css({position:"absolute",height:options.istip?5000:$window.height(),width:isie6?$window.width():"100%",top:0,left:0,right:0,bottom:0})}};var positionbox=function(){if(options.ismessager){$box.css({position:(isie6)?"absolute":"fixed",right:1,bottom:1})}else{$boxtemp.css({top:options.top});$box.css({position:"absolute",top:$boxtemp.offset().top+(options.istip?$window.scrolltop():0),left:(($window.width()-$box.outerwidth())/2)})
}if((options.showfade&&!options.istip)||(!options.showfade&&!options.istip&&!options.ismessager)){$boxbody.css({position:(isie6)?"absolute":"fixed",height:options.showfade?$window.height():0,width:"100%",top:(isie6)?$window.scrolltop():0,left:0,right:0,bottom:0})}setfade()};var settop=function(){options.zindex=$.jbox.defaults.zindex++;$boxbody.css({zindex:options.zindex});$box.css({zindex:options.zindex+1})};var stylebox=function(){options.zindex=$.jbox.defaults.zindex++;$boxbody.css({zindex:options.zindex});
$box.css({display:"none",zindex:options.zindex+1});if(options.showfade){$boxfade.css({display:"none",zindex:options.zindex,opacity:options.opacity})}};var dodown=function(e){var dragdata=e.data;dragdata.target.find("iframe").hide();if(options.dragclone){dragdata.target.prev().css({left:dragdata.target.css("left"),top:dragdata.target.css("top"),marginleft:-2,margintop:-2,width:dragdata.target.width()+2,height:dragdata.target.height()+2}).show()}return false};var domove=function(e){var dragdata=e.data;
var left=dragdata.startleft+e.pagex-dragdata.startx;var top=dragdata.starttop+e.pagey-dragdata.starty;if(options.draglimit){var mintop=1;var maxtop=document.documentelement.clientheight-e.data.target.height()-1;var minleft=1;var maxleft=document.documentelement.clientwidth-e.data.target.width()-1;if(topmaxtop){top=maxtop-(options.dragclone?2:0)}if(leftmaxleft){left=maxleft-(options.dragclone?2:0)
}}if(options.dragclone){dragdata.target.prev().css({left:left,top:top})}else{dragdata.target.css({left:left,top:top})}return false};var doup=function(e){$(document).unbind(".draggable");if(options.dragclone){var drag=e.data.target.prev().hide();e.data.target.css({left:drag.css("left"),top:drag.css("top")}).find("iframe").show()}else{e.data.target.find("iframe").show()}return false};var onmousedown=function(e){var position=e.data.target.position();var data={target:e.data.target,startx:e.pagex,starty:e.pagey,startleft:position.left,starttop:position.top};
$(document).bind("mousedown.draggable",data,dodown).bind("mousemove.draggable",data,domove).bind("mouseup.draggable",data,doup)};var removebox=function(){if(options.showfade){if($.jbox.fadeboxcount==1){$($.browser.msie?"html":"body").removeattr("style")}$.jbox.fadeboxcount--}if(options.istip){var tip=$(document.body).data("tip");if(tip&&tip.next==true){$boxtemp.css("top",tip.options.top);var top=$boxtemp.offset().top+$window.scrolltop();if(top==$box.offset().top){removeboximpl()}else{$box.find("#jbox-content").html(tip.options.content.substr(5)).end().css({left:(($window.width()-$box.outerwidth())/2)}).animate({top:top,opacity:0.1},500,removeboximpl)
}}else{$box.animate({top:"-=200",opacity:0},500,removeboximpl)}}else{switch(options.showtype){case"slide":$box.slideup(options.showspeed,removeboximpl);break;case"fade":$box.fadeout(options.showspeed,removeboximpl);break;case"show":default:$box.hide(options.showspeed,removeboximpl);break}}};var removeboximpl=function(){$window.unbind("resize",setfade);if(options.draggable&&!options.istip&&!options.ismessager){$box.find(".jbox-title-panel").unbind("mousedown",onmousedown)}if(data.type!="iframe"){$box.find("#jbox-iframe").attr({src:"about:blank"})
}$box.html("").remove();if(isie6&&!options.istip){$body.unbind("scroll",ie6scroll)}if(options.showfade){$boxfade.fadeout("fast",function(){$boxfade.unbind("click",fadeclicked).unbind("mousedown",settop).html("").remove()})}$boxbody.unbind("keydown keypress",keypresseventhandler).html("").remove();if(isie6&&options.showfade){$("select").css("visibility","visible")}if(typeof options.closed=="function"){options.closed()}};var autoclosing=function(){if(options.timeout>0){$box.data("autoclosing",window.settimeout(removebox,options.timeout));
if(options.ismessager){$box.hover(function(){window.cleartimeout($box.data("autoclosing"))},function(){$box.data("autoclosing",window.settimeout(removebox,options.timeout))})}}};var loaded=function(){if(typeof options.loaded=="function"){options.loaded($box.find(".jbox-state:visible").find(".jbox-content"))}};if(!data.isobject){switch(data.type){case"get":case"post":$.ajax({type:data.type,url:data.url,data:options.ajaxdata==undefined?{}:options.ajaxdata,datatype:"html",cache:false,success:function(data,textstatus){$box.find("#jbox-content").css({position:"static"}).html(data).show().prev().hide();
loaded()},error:function(){$box.find("#jbox-content-loading").html('loading error.
')}});break;case"iframe":$box.find("#jbox-iframe").attr({src:data.url}).bind("load",function(event){$(this).parent().css({position:"static"}).show().prev().hide();$box.find("#jbox-states .jbox-state:first .jbox-button-focus").focus();loaded()});break;default:$box.find("#jbox-content").show();break}}positionbox();stylebox();if(isie6&&!options.istip){$window.scroll(ie6scroll)
}if(options.showfade){$boxfade.click(fadeclicked)}$window.resize(setfade);$boxbody.bind("keydown keypress",keypresseventhandler);$box.find(".jbox-close").click(removebox);if(options.showfade){$boxfade.fadein("fast")}var showfunc="show";if(options.showtype=="slide"){showfunc="slidedown"}else{if(options.showtype=="fade"){showfunc="fadein"}}if(options.ismessager){$box[showfunc](options.showspeed,autoclosing)}else{var tip=$(document.body).data("tip");if(tip&&tip.next==true){$(document.body).data("tip",{next:false,options:{}});
$box.css("display","")}else{if(!data.isobject&&isrequest){$box[showfunc](options.showspeed)}else{$box[showfunc](options.showspeed,loaded)}}}if(!options.istip){$box.find(".jbox-bottom-text").html(options.bottomtext)}else{$box.find(".jbox-container,.jbox-content").addclass("jbox-tip-color")}if(data.type!="iframe"){$box.find("#jbox-states .jbox-state:first .jbox-button-focus").focus()}else{$box.focus()}if(!options.ismessager){autoclosing()}$boxbody.bind("mousedown",settop);if(options.draggable&&!options.istip&&!options.ismessager){$box.find(".jbox-title-panel").bind("mousedown",{target:$box},onmousedown).css("cursor","move")
}return $boxbody};$.jbox.version=2.3;$.jbox.defaults={id:null,top:"15%",zindex:1984,border:5,opacity:0.1,timeout:0,showtype:"fade",showspeed:"fast",showicon:true,showclose:true,draggable:true,draglimit:true,dragclone:false,persistent:true,showscrolling:true,ajaxdata:{},iframescrolling:"auto",title:"jbox",width:350,height:"auto",bottomtext:"",buttons:{"确定":"ok"},buttonsfocus:0,loaded:function(h){},submit:function(v,h,f){return true},closed:function(){}};$.jbox.statedefaults={content:"",buttons:{"确定":"ok"},buttonsfocus:0,submit:function(v,h,f){return true
}};$.jbox.tipdefaults={content:"",icon:"info",top:"40%",width:"auto",height:"auto",opacity:0,timeout:3000,closed:function(){}};$.jbox.messagerdefaults={content:"",title:"jbox",icon:"none",width:350,height:"auto",timeout:3000,showtype:"slide",showspeed:600,border:0,buttons:{},buttonsfocus:0,loaded:function(){},submit:function(v,h,f){return true},closed:function(){}};$.jbox.languagedefaults={close:"关闭",ok:"确定",yes:"是",no:"否",cancel:"取消"};$.jbox.setdefaults=function(configs){$.jbox.defaults=$.extend({},$.jbox.defaults,configs.defaults);
$.jbox.statedefaults=$.extend({},$.jbox.statedefaults,configs.statedefaults);$.jbox.tipdefaults=$.extend({},$.jbox.tipdefaults,configs.tipdefaults);$.jbox.messagerdefaults=$.extend({},$.jbox.messagerdefaults,configs.messagerdefaults);$.jbox.languagedefaults=$.extend({},$.jbox.languagedefaults,configs.languagedefaults)};$.jbox.getbox=function(){return $(".jbox-body").eq($(".jbox-body").length-1)};$.jbox.getiframe=function(jboxid){var box=(typeof jboxid=="string")?$("#"+jboxid):$.jbox.getbox();return box.find("#jbox-iframe").get(0)
};$.jbox.getcontent=function(){return $.jbox.getstate().find(".jbox-content").html()};$.jbox.setcontent=function(content){return $.jbox.getstate().find(".jbox-content").html(content)};$.jbox.getstate=function(statenmae){if(statenmae==undefined){return $.jbox.getbox().find(".jbox-state:visible")}else{return $.jbox.getbox().find("#jbox-state-"+statenmae)}};$.jbox.getstatename=function(){return $.jbox.getstate().attr("id").replace("jbox-state-","")};$.jbox.gotostate=function(statename,statecontent){var box=$.jbox.getbox();
if(box!=undefined&&box!=null){var $next;statename=statename||false;box.find(".jbox-state").slideup("fast");if(typeof statename=="string"){$next=box.find("#jbox-state-"+statename)}else{$next=statename?box.find(".jbox-state:visible").next():box.find(".jbox-state:visible").prev()}$next.slidedown(350,function(){window.settimeout(function(){$next.find(".jbox-button-focus").focus();if(statecontent!=undefined){$next.find(".jbox-content").html(statecontent)}},20)})}};$.jbox.nextstate=function(statecontent){$.jbox.gotostate(true,statecontent)
};$.jbox.prevstate=function(statecontent){$.jbox.gotostate(false,statecontent)};$.jbox.close=function(token,boxtype){token=token||false;boxtype=boxtype||"body";if(typeof token=="string"){$("#"+token).find(".jbox-close").click()}else{var boxs=$(".jbox-"+boxtype);if(token){for(var i=0,l=boxs.length;i0){boxs.eq(boxs.length-1).find(".jbox-close").click()}}}};$.jbox.open=function(content,title,width,height,options){var defaults={content:content,title:title,width:width,height:height};
options=$.extend({},defaults,options);options=$.extend({},$.jbox.defaults,options);$.jbox(options.content,options)};$.jbox.prompt=function(content,title,icon,options){var defaults={content:content,title:title,icon:icon,buttons:eval('({ "'+$.jbox.languagedefaults.ok+'": "ok" })')};options=$.extend({},defaults,options);options=$.extend({},$.jbox.defaults,options);if(options.border<0){options.border=0}if(options.icon!="info"&&options.icon!="warning"&&options.icon!="success"&&options.icon!="error"&&options.icon!="question"){padding="";
options.icon="none"}var top=options.title==undefined?10:35;var minheight=options.icon=="none"?"height:auto;":"min-height:30px;"+(($.browser.msie&&parseint($.browser.version)<7)?"height:auto !important;height:100%;_height:30px;":"height:auto;");var html=[];html.push("html:");html.push('');html.push('');
html.push(options.content);html.push("
");options.content=html.join("");$.jbox(options.content,options)};$.jbox.alert=function(content,title,options){$.jbox.prompt(content,title,"none",options)};$.jbox.info=function(content,title,options){$.jbox.prompt(content,title,"info",options)};$.jbox.success=function(content,title,options){$.jbox.prompt(content,title,"success",options)};$.jbox.error=function(content,title,options){$.jbox.prompt(content,title,"error",options)};$.jbox.confirm=function(content,title,submit,options){var defaults={buttons:eval('({ "'+$.jbox.languagedefaults.ok+'": "ok", "'+$.jbox.languagedefaults.cancel+'": "cancel" })')};
if(submit!=undefined&&typeof submit=="function"){defaults.submit=submit}else{defaults.submit=function(v,h,f){return true}}options=$.extend({},defaults,options);$.jbox.prompt(content,title,"question",options)};$.jbox.warning=function(content,title,submit,options){var defaults={buttons:eval('({ "'+$.jbox.languagedefaults.yes+'": "yes", "'+$.jbox.languagedefaults.no+'": "no", "'+$.jbox.languagedefaults.cancel+'": "cancel" })')};if(submit!=undefined&&typeof submit=="function"){defaults.submit=submit}else{defaults.submit=function(v,h,f){return true
}}options=$.extend({},defaults,options);$.jbox.prompt(content,title,"warning",options)};$.jbox.tip=function(content,icon,options){var defaults={content:content,icon:icon,opacity:0,border:0,showclose:false,buttons:{},istip:true};if(defaults.icon=="loading"){defaults.timeout=0;defaults.opacity=0.1}options=$.extend({},defaults,options);options=$.extend({},$.jbox.tipdefaults,options);options=$.extend({},$.jbox.defaults,options);if(options.timeout<0){options.timeout=0}if(options.border<0){options.border=0
}if(options.icon!="info"&&options.icon!="warning"&&options.icon!="success"&&options.icon!="error"&&options.icon!="loading"){options.icon="info"}var html=[];html.push("html:");html.push('');html.push('');html.push(options.content);
html.push("
");options.content=html.join("");if($(".jbox-tip").length>0){$(document.body).data("tip",{next:true,options:options});$.jbox.closetip()}if(options.focusid!=undefined){$("#"+options.focusid).focus();top.$("#"+options.focusid).focus()}$.jbox(options.content,options)};$.jbox.closetip=function(){$.jbox.close(false,"tip")};$.jbox.messager=function(content,title,timeout,options){$.jbox.closemessager();var defaults={content:content,title:title,timeout:(timeout==undefined?$.jbox.messagerdefaults.timeout:timeout),opacity:0,showclose:true,draggable:false,ismessager:true};
options=$.extend({},defaults,options);options=$.extend({},$.jbox.messagerdefaults,options);var tempdefaults=$.extend({},$.jbox.defaults,{});tempdefaults.title=null;options=$.extend({},tempdefaults,options);if(options.border<0){options.border=0}if(options.icon!="info"&&options.icon!="warning"&&options.icon!="success"&&options.icon!="error"&&options.icon!="question"){padding="";options.icon="none"}var top=options.title==undefined?10:35;var minheight=options.icon=="none"?"height:auto;":"min-height:30px;"+(($.browser.msie&&parseint($.browser.version)<7)?"height:auto !important;height:100%;_height:30px;":"height:auto;");
var html=[];html.push("html:");html.push('');html.push('');html.push(options.content);html.push("
");options.content=html.join("");$.jbox(options.content,options)};$.jbox.closemessager=function(){$.jbox.close(false,"messager")
};$.jbox.fadeboxcount=0;window.jbox=$.jbox})(jquery);