﻿
function dialog(){
}
//关闭对话框
dialog.close=function(callback){
    if(this!=top){ 
        parent.$.unblockUI();
    }
    else{
        $.unblockUI();
    }
}
//弹出确认框
dialog.show=function(message,option){
	   var width=100;
	   if(option.type=='confirm'){
	    width=190;
	   }
	   var html=new Array();        
        html.push('<div class="pop" >');
        html.push('<div class="pop_main" style="padding-bottom:15px;">');
	    html.push('<div class="pop_title" style="position:relative;text-align:left;">系统提示：<div style="position:absolute; top:7px; right:10px;"><img src="../images/default/pop_del.gif" onclick="parent.dialog.close()" /></div></div>')
        html.push('<div style="padding-top:15px; text-align:center;">')        
        html.push('<div style="font-size:14px; line-height:30px;" id="dvMessage">'+ message + '</div></div>')
        
        html.push('<div style="padding-top:30px; text-align:center;"><div style="margin:0 auto; width:' + width +'px;"><div class="buttom_wk" style="margin-right:10px;display:inline;"><input id="btn_blockUI_ok" type="button" value="确定" class="buttom_1" onmouseover="this.className=\'buttom_2\'" onmouseout="this.className=\'buttom_1\'" /></div>');
        if(option.type=='confirm'){
            html.push(' <div class="buttom_wk"><input type=\'button\' value=\'取消\' id=\'btn_blockUI_cancel\' class="buttom_1" onmouseover="this.className=\'buttom_2\'" onmouseout="this.className=\'buttom_1\'" /></div>');
        }
        html.push('</div><div class="clear"></div></div>');
        html.push('</div></div>');
       
	$.blockUI({message:html.join(""),showOverlay: option.overlay==false?false:true,timeout:option.timeout});  
	if(option.type=='confirm'){	
	    $("#btn_blockUI_cancel").click(function(){        
            $.unblockUI(); 
        });  
    }
    $("#btn_blockUI_ok").click(function(){        
        $.unblockUI();   
        if(option.callback!=undefined){    
            setTimeout(option.callback,500);
        }
    });  
}
//弹出确认框
dialog.alert=function(message,callback){
    dialog.show(message,{callback:callback});
    
}
//弹出提示框
dialog.prompt=function(message){
    dialog.show(message,{overlay:false,timeout: 5000});
}
//弹出链接确认框
dialog.showUrl=function(url,option){ 
    var left="40%";
    var top="25%";
    var width=420;
    var height=480;    
    if(option!=undefined && option.left!=undefined){
        left=option.left;
    }
    if(option!=undefined && option.top!=undefined){
        top=option.top;
    }
    if(option!=undefined && option.width!=undefined){
        width=option.width;
    }    
    if(option!=undefined && option.height!=undefined){
        height=option.height;
    }
    if($("#divDialog")[0] == undefined){
	    $(document.body).append("<div id='divDialog' style='background:none;display:none;width:" + width + "px;height:" + height + "px;'></div>");
	}
	//$("#divDialog").load(url);
	$("#divDialog").html("<iframe name='showhtml'  src='" + url + "' frameborder='0' width='" + width + "' height='" + height + "' allowtransparency='true' noresize='noresize' style='background:none;' marginwidth='0' marginheight='0' scrolling='no'></iframe>");	
	$.blockUI.defaults.css.left=left;
	$.blockUI.defaults.css.top = top;	
	$.blockUI({ message: $("#divDialog"), move: $(".pop_title") });
	
}
dialog.showUrlAjax=function(url,option){ 
    var left="40%";
    var top="25%";
    var width=650;
    var height=500;    
    if(option!=undefined && option.left!=undefined){
        left=option.left;
    }
    if(option!=undefined && option.top!=undefined){
        top=option.top;
    }
    if(option!=undefined && option.width!=undefined){
        width=option.width;
    }    
    if(option!=undefined && option.height!=undefined){
        height=option.height;
    }
    if($("#divDialog")[0] == undefined){
	    $(document.body).append("<div id='divDialog' style='background:none;display:none;width:" + width + "px;height:" + height + "px;'></div>");
	}
	$("#divDialog").load(url);
	//$("#divDialog").html("<iframe  src='" + url + "' frameborder='0' width='" + width + "' height='" + height + "' allowtransparency='true' noresize='noresize' style='background:none;' marginwidth='0' marginheight='0' scrolling='no'></iframe>");	
	$.blockUI.defaults.css.left=left;
	$.blockUI.defaults.css.top=top;
	$.blockUI({message:$("#divDialog")});
}
//弹出确定取消对话框
dialog.confirm=function(message,callback){
    dialog.show(message,{callback:callback,type:'confirm'});
}
