$.fn.getdict = function(){
    var s = [];
    $('input[name], select[name], textarea[name]', this).each(function (){
        if(this.disabled || (this.type == 'checkbox' || this.type == 'radio') && !this.checked)
            return;
        if (this.type == 'select-multiple'){
            var name = this.name;
            $('option:selected', this).each(function(){
                var item = {name:name, value:this.value};
                s.push(item);
            });
        }
        else{
            var item = {name:this.name, value:this.value};
            s.push(item);
        }
    });
    return s;
};
(function($){
	
	$.getWin=function(){
        var win=window;
        while(win.location!=win.parent.location)
	        win=win.parent;
	    win.$.tagWin=window;
        return win;
    };
	$.hideDialog=function(){
		if($.xDlg !=null){
			if($.xDlg.parentObject.length>0)
				$.xDlg.parentObject.append($.xDlg.obj);
				//$.xDlg.parentObject.append($.xDlg.dialog.find('.dialog-body').children());
		
			$.xDlg.dialog.find("*").unbind().remove();
			$.xDlg.dialog.remove();
			$(".dialog-mask").remove();
			$.xDlg=null;
		}
	};
	$.alertMsg=function(caption, msg, callback){
		if(arguments.length==1) {
			msg = caption;
			caption = "提示";
		}
		if(arguments.length==2) {
			if (typeof(msg)=="function") {
				callback = msg;
				msg = caption;
				caption = "提示";
			}
		}
		$('<div class="alert_msg">'+msg+'</div>').xDialog({caption:caption, btn:[{text:'确定',func:callback}]});
	};
	$.xDialog=function(url,settings){
        return $.getWin().$("<iframe frameborder='no' width='100%' height='"+settings.height+"' src='"+url+"' scrolling="+(settings.scrolling||"auto")+" id='ifrDialog' name='ifrDialog'></iframe>").xDialog(settings);
    };
	$.fn.taskDialog=function(s){
		var self = this;
		s = $.extend({caption:"提示",
					 width:400},s);
		
		var dlg=$("<div class='dialog'><div class='dialog-main'><div class='dialog-tr'><div class='dialog-tl'><div class='dialog-t'></div></div></div>"
				  +"<div class='dialog-md'><div class='dialog-mb'><div class='dialog-header'>"
				  +"<span>"+s.caption+"</span></div>"
				  +"<div class='dialog-body'></div><div class='dialog-footer'>"
				  +"</div></div></div><div class='dialog-br'><div class='dialog-bl'>"
				  +"<div class='dialog-b'></div></div></div></div></div>").width(s.width).appendTo(document.body);
		//+"<div id='icon-close' style='position:absolute; top:-5px;left:5px;cursor:pointer;'><img src='/site_media/dialog/close.gif' /></div>"
		//保存实体
		$.xDlg=$.extend({parentObject:self.parent(),dialog:dlg,obj:self.clone()},s);//保存实体
		//添加具体内容
		dlg.find('.dialog-body').append(self.show());
		//设置关闭事件
		dlg.find('#icon-close').click(function(){
			$.hideDialog();
		});
	
		var left=s.left||(document.documentElement.clientWidth-dlg.width())/2;
		var top=s.top||(document.documentElement.clientHeight-dlg.height())/2+document.documentElement.scrollTop;
		
		dlg.css({left:left,top:top});//调整位置
		var frameHeight = Math.max(document.documentElement.clientHeight,document.documentElement.scrollHeight);
		
		$("<div class='dialog-mask'><iframe id='TB_HideSelect'></iframe></div>").appendTo(document.body);
		
		$(".dialog-mask").height(frameHeight);
		return dlg;
	}; 
	//重直弹出框位置
	$.fn.resetPosition=function(){
		var self = this;
		var left=(document.documentElement.clientWidth-self.width())/2;
		var top=(document.documentElement.clientHeight-self.height())/2+document.documentElement.scrollTop;
		self.css({left:left,top:top});//调整位置
	};
	
	$.fn.xDialog=function(s){
		var self = this;
		s = $.extend({caption:"提示",
					 width:400,
					 height:80,
					 hideBtn:false,
					 btn:[]},s);
		
		var dlg=$("<div class='dialog'><div class='dialog-main'><div class='dialog-tr'><div class='dialog-tl'><div class='dialog-t'></div></div></div>"
				  +"<div class='dialog-md'><div class='dialog-mb'><div class='dialog-header'>"
				  
				  +"<span>"+s.caption+"</span></div>"
				  +"<div class='dialog-body'></div><div class='dialog-footer'>"
				  +"</div></div></div><div class='dialog-br'><div class='dialog-bl'>"
				  +"<div class='dialog-b'></div></div></div></div></div>").width(s.width).appendTo(document.body);
		//+"<div id='icon-close' style='position:absolute; top:-5px;left:5px;cursor:pointer;'><img src='/site_media/dialog/close.gif' /></div>"
		var footer=dlg.find(".dialog-footer").height(22);
		//隐藏按钮区
		if(s.hideBtn)
			dlg.find(".dialog-footer").remove();
		$("<span id='dlgMsg'></span>").appendTo(footer);
		if(s.btn.length>0){
			
			$.each(s.btn,function(){
//				var btn = $("<span class='button button-main'><button type='button' class='sure'>"+this.text+"</button></span></span>").bind("click",this,function(e){
				var btn = $("<button type='button' class='sure'>"+this.text+"</button>").bind("click",this,function(e){
					
					if($.isFunction(e.data.func)){
						if(e.data.func.call()!=false){
							$.hideDialog();
						}
					}
					else
						$.hideDialog();
				  }).appendTo(footer);				  
			
			});	
		}
		//保存实体
		$.xDlg=$.extend({parentObject:self.parent(),dialog:dlg,obj:self.clone()},s);//保存实体
		//添加具体内容
		dlg.find('.dialog-body').append(self.show());
		//dlg.find('.dialog-body').height(s.height).append(self.show());
		//设置关闭事件
		dlg.find('#icon-close').click(function(){
			$.hideDialog();
		});
		var left=s.left||(document.documentElement.clientWidth-dlg.width())/2;
		var top=s.top||(document.documentElement.clientHeight-dlg.height())/2+document.documentElement.scrollTop;
		
		dlg.css({left:left,top:top});//调整位置
		var frameHeight = Math.max(document.documentElement.clientHeight,document.documentElement.scrollHeight);
		
		$("<div class='dialog-mask'><iframe id='TB_HideSelect'></iframe></div>").appendTo(document.body);
		
		$(".dialog-mask").height(frameHeight);
	}; 
		  
})(jQuery);
