﻿(function($){$.extend($.fn,{_idoModalIndex:0,_idoModalZIndex:200000,hideIdoModal:function(indexId){$("#idomodal-overlay-"+indexId).remove();$("#idomodal-frame-"+indexId).remove();$("#idomodal-backmask-"+indexId).remove();$("#idomodal-movemask-"+indexId).remove();var idomodal=$("#idomodal-"+indexId);var timer=idomodal.data("disposeTimer");var interval=idomodal.data("autoHeightInterval");var ps=idomodal.data("ps");if(ps&&ps.hideSelect){$("select").show()}if(timer>0){window.clearTimeout(timer)}if(interval>0){window.clearInterval(interval)}idomodal.remove()},_getModalExpOpt:function(o,extOpt){if(!extOpt){return o}for(var i in extOpt){o[i]=extOpt[i]}return o},idoProcess:function(indexId,msg,extOpt){var $o=$("#idomodal-"+indexId);msg="<img src='http://img1.ido360.com/img/loading1.gif' valign='absmiddle'/>&nbsp;"+msg;if($o.size()>0){o.find(".idomodal-content").html(msg);return indexId}else{return $.fn.idoModal($.fn._getModalExpOpt({buttonText:{},content:msg,indexId:indexId,initWidth:300,showBottom:false,showClose:false,showTop:false,contentCss:{padding:"20px 12px","line-height":"18px"},_type:"process"},extOpt))}},idoAlert:function(msg,fn,extOpt){var fn1=function(data,args){if(fn){setTimeout(function(){fn(data,args)},0)}args.complete()};var title=!extOpt?"":extOpt.title;if(!title){title="\u7231\u90FD\u5C0F\u8D34\u58EB"}return $.fn.idoModal($.fn._getModalExpOpt({buttonText:{ok:"\u786E\u5B9A"},content:msg,okEvent:fn1,cancelEvent:fn1,title:title,initWidth:300,contentCss:{padding:"20px 12px","line-height":"18px"},_type:"alert"},extOpt))},idoConfirm:function(msg,fnOk,fnCancel,extOpt){var fn1=function(data,args){if(fnOk){setTimeout(function(){fnOk(data,args)})}args.complete()};var fn2=function(data){if(fnCancel){setTimeout(function(){fnCancel(data)})}};var title=!extOpt?"":extOpt.title;if(!title){title="\u7231\u90FD\u5C0F\u8D34\u58EB"}return $.fn.idoModal($.fn._getModalExpOpt({content:msg,okEvent:fn1,cancelEvent:fn2,title:title,initWidth:300,contentCss:{padding:"20px 12px","line-height":"18px"},_type:"confirm"},extOpt))},idoModalFrame:function(setting,scrolling,frameborder){setting._type="iframe";setting.content.autoHeight=true;var c=setting.content;if(c.data){if(c.url.indexOf("?")==-1){c.url+="?"}else{c.url+="&"}c.url+=$.param(c.data)}setting.content=function(e){var id="t_loading_"+Math.random();id=id.replace(".","");e.html("<p style='padding:30px;' id='"+id+"'><img src='http://img1.ido360.com/img/loading1.gif' style='vertical-align:middle'/>&nbsp;\u6B63\u5728\u52A0\u8F7D\u5185\u5BB9\uFF0C\u8BF7\u7A0D\u4FAF...</p>");setTimeout(function(){var $frm=$("<iframe src='about:blank' width=\""+c.width+'" height="'+c.height+'" scrolling="'+(scrolling==undefined?"no":scrolling)+'" frameborder="'+(frameborder==undefined?"no":frameborder)+'" />');$frm.hide().bind("load",function(){e.find("#"+id).remove();$(this).show();e.holder.show();e.overlay.show();if(c.autoHeight){var height1=$frm.contents().height();var heightw1=$(window).height();if(heightw1>0&&height1>heightw1-67){height1=heightw1-67}$frm.height(height1)}setTimeout(function(){try{$($frm[0].contentWindow).resize(function(){var height1=$frm.contents().height();var heightw1=$(window).height();if(heightw1>0&&height1>heightw1-67){height1=heightw1-67}$frm.height(height1)})}catch(e2){}try{$frm.contents().find("input[type=text], input[type=password], textarea :eq(0)").focus()}catch(e1){}e.holder.resize();var autoHeightInterval=window.setInterval(function(){var fh=$frm.height();var fch=$frm.contents().height();window.parent.trace(fh+","+fch);if(fh==fch){return}var w1=$(window).height();if(w1>0&&fch>w1-67){fch=w1-67}$frm.height(fch);e.holder.resize()},1000);e.holder.data("autoHeightInterval",autoHeightInterval)},1)}).appendTo(e).attr("src",c.url)},0)};return $.fn.idoModal(setting)},idoModalLoad:function(setting){setting.content.autoHeight=true;var c=setting.content;if(!c.type){if(!c.data){c.type="GET"}else{c.type="POST"}}setting.content=function(e){var id="t_loading_"+Math.random();id=id.replace(".","");e.html("<p style='padding:30px;' id='"+id+"'><img src='http://img1.ido360.com/img/loading1.gif' style='vertical-align:middle'/>&nbsp;\u6B63\u5728\u52A0\u8F7D\u5185\u5BB9\uFF0C\u8BF7\u7A0D\u4FAF...</p>");setTimeout(function(){$.ajax({url:c.url,type:c.type,data:c.data,success:function(msg){e.html(msg)},error:function(){e.html("\u52A0\u8F7D\u5185\u5BB9\u5931\u8D25")},complete:function(){if(!Ido.IE){e.holder.resize()}}})},1)};return $.fn.idoModal(setting)},idoModalDrop:function(setting,offset){if(isNaN(offset)){offset=25}if(offset<10){offset=10}if(!setting.pos){setting.pos={left:offset,top:0}}setting.pos.left=setting.pos.left-offset;setting._dropOffset=offset;setting._type="drop";setting.skinId="idomodal2";setting.isMove=false;setting.hideSelect=false;if(setting.showMask==undefined){setting.showMask=false}if(typeof(setting.content)=="string"){return $.fn.idoModal(setting)}else{return $.fn.idoModalLoad(setting)}},idoModal:function(setting){var ps=$.fn.extend({data:{},marginTop:"auto",buttonText:{ok:"\u786E\u5B9A",cancel:"\u53D6\u6D88"},okEvent:function(e){},cancelEvent:function(e){},initWidth:400,fixed:true,title:"\u7231\u90FD\u5C0F\u8D34\u58EB",content:"",showBottom:true,showClose:true,showMask:true,showTop:true,isMove:true,pos:null,move:true,skinId:"idomodal1",dispose:0,showOnLoad:false,_type:null,hideSelect:true},setting);var allSel=null;if(ps.hideSelect){allSel=$("select").hide()}ps.marginTop="auto";ps.docWidth=$(window).width();ps.docHeight=$(window).height();var index=ps.indexId?ps.indexId:$.fn._idoModalIndex++;ps.indexId=index;ps.fixed=false;$.hideIdoModal(index);var bottomIndex=ps.showBottom?1:2;var s="";s+='<div id="idomodal-overlay-'+index+'" class="idomodal-overlay" style="background-color:#000;">';s+='<iframe id="idomodal-frame-'+index+'" frameBorder="0" style="width:100%;height:100%;overflow:hidden;display:block;" onmousemove="return false"></iframe>';s+="</div>";s+='<div id="idomodal-backmask-'+index+'" class="idomodal-backmask">&nbsp;</div>';s+='<div id="idomodal-movemask-'+index+'" class="idomodal-movemask">&nbsp;</div>';s+='<div id="idomodal-'+index+'" class="idomodal-main">';if(ps._type=="drop"){s+='<div class="idomodal-offarrow-cont" style="padding-left:'+ps._dropOffset+'px"><div class="idomodal-offarrow idomodal-m"></div></div>'}s+='<table class="idomodal-tb" cellpadding="0" cellspacing="0">';if(ps.showTop){s+="<tr>";s+='<td class="idomodal-top-left idomodal-m">&nbsp;</td>';s+='<td class="idomodal-top-mid idomodal-vm">';s+='	<div class="idomodal-title-cont">';if(ps.showClose){s+='	<a class="idomodal-close idomodal-m" unselectable="on" href="javascript:void(0)"></a>'}if(ps.isMove){s+='	<a class="idomodal-move" href="javascript:void(0)"></a>'}s+='		<span class="idomodal-title"></span>';s+="	</div>";s+="</td>";s+='<td class="idomodal-top-right idomodal-m">&nbsp;</td>';s+="</tr>"}else{s+="<tr>";s+='<td class="idomodal-top-left2 idomodal-m">&nbsp;</td>';s+='<td class="idomodal-top-mid2 idomodal-vm"><div class="idomodal-title-cont" style="height:25px;"><a class="idomodal-close idomodal-m" unselectable="on" href="javascript:void(0)"></a></div></td>';s+='<td class="idomodal-top-right2 idomodal-m">&nbsp;</td>';s+="</tr>"}s+="</table>";s+='<table class="idomodal-tb" cellpadding="0" cellspacing="0">';s+="<tr>";s+='<td class="idomodal-mid-left idomodal-hm">&nbsp;</td>';s+='<td class="idomodal-mid-mid">';if(ps._type=="drop"&&!ps.showTop&&ps.showClose){s+='<div class="idomodal-close-cont" unselectable="on" style="padding-top:10px;"><div class="i_clear">&nbsp;</div></div>'}s+='	<div class="idomodal-content"></div>';if(ps.showBottom){if(ps._type=="drop"){s+='<div class="idomodal-line idomodal-vm"></div>'}s+='<div class="idomodal-opts">';var _count=0;var _s="";for(var i in ps.buttonText){if(_count++>0){s+="&nbsp;&nbsp;"}_s=ps.buttonText[i];if(i=="ok"){s+='<a m="'+i+'" href="javascript:void(0)" class="idomodal-m">'+_s+"</a>"}else{if(_s.length==1){_s="\u3000"+_s+"\u3000"}else{if(_s.length==2){_s="&nbsp;"+_s+"&nbsp;"}}s+='<a m="'+i+'" href="javascript:void(0)"><table cellpadding="0" cellspacing="0" border="0"><tr><td class="idomodal-opt-other-tdl idomodal-m"></td><td class="idomodal-opt-other-tdm idomodal-m" unselectable="on">'+_s+'</td><td class="idomodal-opt-other-tdr idomodal-m"></td></tr></table></a>'}}s+="</div>"}s+="</td>";s+='<td class="idomodal-mid-right idomodal-hm">&nbsp;</td>';s+="</tr>";s+="</table>";s+='<table class="idomodal-tb" cellpadding="0" cellspacing="0">';s+="<tr>";s+='<td class="idomodal-bot-left idomodal-m">&nbsp;</td>';s+='<td class="idomodal-bot-mid idomodal-vm">&nbsp;</td>';s+='<td class="idomodal-bot-right idomodal-m">&nbsp;</td>';s+="</tr>";s+="</table>";s+="</div>";$(document.body).append(s);var idomodal=$("#idomodal-"+index);var overlay=$("#idomodal-overlay-"+index);var frame=$("#idomodal-frame-"+index);var backmask=$("#idomodal-backmask-"+index);var movemask=$("#idomodal-movemask-"+index);overlay.css("z-index",$.fn._idoModalZIndex++);backmask.css("z-index",$.fn._idoModalZIndex++);idomodal.css("z-index",$.fn._idoModalZIndex++);movemask.css("z-index",$.fn._idoModalZIndex++);idomodal.attr("class",ps.skinId+" idomodal0");if(ps.showOnLoad){idomodal.hide();overlay.hide()}idomodal.data("ps",ps);var overlayOpacity=ps.showMask?0.2:0;overlay.css({opacity:0,position:(ps.fixed?"fixed":"absolute")}).animate({opacity:overlayOpacity},200);frame.css("opacity",0);movemask.css({position:(ps.fixed?"fixed":"absolute"),opacity:0.5});var otherWidth=ps.skinId=="idomodal2"?6:22;var tLeft;if(ps.pos){tLeft=ps.pos.left}else{tLeft=(ps.docWidth-ps.initWidth-otherWidth)/2;if(window.IdoMain){tLeft=(ps.docWidth-220-ps.initWidth-otherWidth)/2}}idomodal.css({position:(ps.fixed?"fixed":"absolute"),width:ps.initWidth+otherWidth,left:tLeft});idomodal.resize(function(){if(!ps.showMask){var top=0;if(ps.pos){top=ps.pos.top}else{top=idomodal.offset().top;if(ps.fixed){top-=$(document).scrollTop()}}overlay.css({height:idomodal.height(),width:idomodal.width(),left:idomodal.offset().left,top:top})}if(ps.marginTop=="auto"&&!ps.pos){var scrollTop=ps.fixed?0:$(document).scrollTop();var marginTop=($(window).height()-idomodal.height())/2+scrollTop;if(marginTop<0){marginTop=0}if(idomodal.offset().top<1){idomodal.css("top",marginTop,function(){if(!ps.showMask){overlay.css("top",marginTop)}})}else{idomodal.animate({top:marginTop},"fast",function(){if(!ps.showMask){overlay.css("top",marginTop)}})}}});var tType1=ps.showTop?"":"2";idomodal.find(".idomodal-top-mid"+tType1+", .idomodal-bot-mid").width(ps.initWidth-4);idomodal.find(".idomodal-mid-mid").width(ps.initWidth+4);idomodal.find(".idomodal-move").width(ps.initWidth-50);var $con=idomodal.find(".idomodal-content");if(ps.contentCss){$con.css(ps.contentCss)}if(typeof ps.content=="string"){$con.html(ps.content)}if(typeof ps.content=="function"){var e=$con;e.holder=idomodal;e.overlay=overlay;ps.content(e)}if(ps.marginTop=="auto"){var marginTop=0;if(ps.pos){marginTop=ps.pos.top}else{var scrollTop=ps.fixed?0:$(document).scrollTop();var marginTop=($(window).height()-idomodal.height())/2+scrollTop;if(marginTop<0){marginTop=0}}idomodal.css("top",marginTop)}if(ps.showMask){overlay.css({height:$(document).height(),width:"100%"})}else{var top=0;if(ps.pos){top=ps.pos.top}else{top=idomodal.offset().top;if(ps.fixed){top-=$(document).scrollTop()}}overlay.css({height:idomodal.height(),width:idomodal.width(),left:idomodal.offset().left,top:top})}idomodal.find(".idomodal-title").html(ps.title);if(ps.showBottom){if(ps.buttonText.ok){var $ok=idomodal.find("a[m=ok]").bind("click",function(e){var args={complete:function(){$.fn.hideIdoModal(index)}};if(ps.hideSelect){allSel.show()}ps.okEvent(ps.data,args,idomodal)});$.fn._idoModalOptBtn($ok,ps,"ok")}if(ps.buttonText.cancel){var $cancel=idomodal.find("a[m=cancel]").one("click",function(e){ps.cancelEvent(ps.data);$.fn.hideIdoModal(ps.indexId)});$.fn._idoModalOptBtn($cancel,ps,"cancel")}for(var i in ps.buttonText){if(i=="ok"||i=="cancel"){continue}var $btn=idomodal.find("a[m="+i+"]").click(function(e){var f=eval("ps."+$(this).attr("m")+"Event");var args={complete:function(){$.fn.hideIdoModal(index)}};if(typeof(f)=="function"){if(ps.hideSelect){allSel.show()}f(ps.data,args,idomodal)}});$.fn._idoModalOptBtn($btn,ps,i)}}if(ps.showClose){idomodal.find(".idomodal-close").bind("click",function(e){if(ps._type=="alert"){var args={complete:function(){$.fn.hideIdoModal(index)}};if(ps.hideSelect){allSel.show()}ps.okEvent(ps.data,args)}else{ps.cancelEvent(ps.data);$.fn.hideIdoModal(ps.indexId)}return false})}var offX=0,offY=0,isDrag=false;idomodal.find(".idomodal-move").mousedown(function(e){backmask.show();var x=idomodal.offset().left;var y=idomodal.offset().top;offX=e.pageX-x;offY=e.pageY-y;if(ps.fixed){y-=$(document).scrollTop()}movemask.show().css({top:y,left:x,width:idomodal.width(),height:idomodal.height()});isDrag=true;return false});$(document).mouseup(function(e){if(!isDrag){return true}isDrag=false;var x=e.pageX,y=e.pageY;if(x<0){x=0}if(y<0){y=0}var top=y-offY;if(ps.fixed){top-=$(document).scrollTop()}idomodal.css({top:top,left:x-offX});if(!ps.showMask){overlay.css({left:idomodal.offset().left,top:top})}backmask.hide();movemask.hide();return false}).mousemove(function(e){if(!isDrag){return true}var top=e.pageY-offY;if(ps.fixed){top-=$(document).scrollTop()}movemask.css({top:top,left:e.pageX-offX});return false});if(ps.dispose>0){var disposeTimer=window.setTimeout(function(){var $o=$("#idomodal-"+index);if($o.size()>0){$o.hide("fast",function(){$.fn.hideIdoModal(index)})}idomodal.removeData("disposeTimer")},ps.dispose*1000);idomodal.data("disposeTimer",disposeTimer)}return index},_idoModalOptBtn:function($btn,ps,type){$btn.addClass("idomodal-opt-"+(type=="ok"?"ok":"other"))}});$.idoModal=$.fn.idoModal;$.idoAlert=$.fn.idoAlert;$.idoConfirm=$.fn.idoConfirm;$.hideIdoModal=$.fn.hideIdoModal;$.idoProcess=$.fn.idoProcess;$.idoModalFrame=$.fn.idoModalFrame;$.idoModalLoad=$.fn.idoModalLoad;$.idoModalDrop=$.fn.idoModalDrop})(jQuery);
