$(document).ready(function(){
    $("body").append("<div class='backgroundDiv'>&nbsp;</div>");
});

/**
 * 
 * @param ShowId   展现按钮ID                          
 * @param CloseId  关闭按钮ID
 * @param ModelId  展现内容的ID
 * @param X   出现坐标X      default 200
 * @param Y   出现坐标Y      default 200
 * @param opacity 透明度     default 0.5
 */
function Modal(ShowId,CloseId,ModelId,width,height,opacity){
    var opacityNum=0.3;
    var w='auto';
    var h='auto';
    if(width!=null)
    w=width;
    if(height!=null)
    h=height;


    if(ModelId==null){
        return;
    }else{
        $("[id="+ModelId+"]").css({"display":"none"});
    }

    var pageHeight=document.body.scrollHeight+30;

    if(opacity!=null){
        opacityNum=opacity;
    }
                                                             
    $("#"+ShowId+"").click(function(){
        $(".backgroundDiv").css({"opacity":opacityNum,"height":pageHeight}).fadeIn('fast');//,"margin-left":"-450px","margin-top":"-200px"
          $(".ui-dialog").fadeIn('fast');
        $("#"+ModelId+"").dialog({
            width:w,
            height:h,
            resizable: true,
            autoResize: true,
            closeText: '',
            close: function(event, ui) {}
        });
        $("#"+ModelId+"").dialog('open');
    });

    $("#"+CloseId+"").click(function(){
        $(".backgroundDiv").fadeOut('fast');
         $(".ui-dialog").fadeOut('fast');
        $("#"+ModelId+"").dialog("close");
        $("#"+ModelId+"").find(".inpBase").val("");
        $("#"+ModelId+"").find("em").text("");
    });
}

function closeModal(ModelId){
    $(".backgroundDiv").fadeOut('fast');
     $(".ui-dialog").fadeOut('fast');
    $("#"+ModelId+"").dialog("close");
    $("#"+ModelId+"").find(".inpBase").val("");
    $("#"+ModelId+"").find("em").text("");
}

function alert(body,title){
    var pageHeight=document.body.scrollHeight+30;
    $("#alertDIV span").attr("innerHTML",body);
    if(title!=null){
        $("#alertDIV h2").attr("innerHTML",title);
    }
    $(".backgroundDiv").css({"opacity":"0.5","height":pageHeight}).fadeIn('fast');

    $("#alertDIV").dialog({
        width:300,
       // height:100,
        resizable: false,
        autoResize: true,
        closeText: ''
    });
    $("#alertDIV").dialog('open');
    ////$("#alertDIV").css({"height":"80px"});

    $("#alertDIV input").click(function(){
        $(".backgroundDiv").fadeOut('fast');
        $("#alertDIV").attr("display","none");
        $("#alertDIV").dialog('close');
    });
}

function alertCart(body,title){
    var pageHeight=document.body.scrollHeight+30;
    $("#alertCartDIV span").attr("innerHTML",body);
    if(title!=null){
        $("#alertCartDIV h2").attr("innerHTML",title);
    }
    $(".backgroundDiv").css({"opacity":"0.5","height":pageHeight}).fadeIn('fast');

    $("#alertCartDIV").dialog({
        width:300,
       // height:100,
        resizable: false,
        autoResize: true,
        closeText: ''
    });
    $("#alertCartDIV").dialog('open');
    ////$("#alertDIV").css({"height":"80px"});

    $("#alertCartDIV input").click(function(){
        $(".backgroundDiv").fadeOut('fast');
        $("#alertCartDIV").attr("display","none");
        $("#alertCartDIV").dialog('close');
    });
}

function confirm(body,title,success,failed){
    var pageHeight=document.body.scrollHeight+30;
    $("#confirmDIV span").attr("innerHTML",body);
    if(title!=null){
        $("#confirmDIV h2").attr("innerHTML",title);
    }
    $(".backgroundDiv").css({"opacity":"0.5","height":pageHeight}).fadeIn('fast');

    $("#confirmDIV").dialog({
        width:400,
       // height:100,
        resizable: false,
        autoResize: true,
        closeText: ''
    });
    $("#confirmDIV").dialog('open');

    $("#confirmDIV input").click(function(){
        $(".backgroundDiv").fadeOut('fast');
        $("#confirmDIV").attr("display","none");
        $("#confirmDIV").dialog('close');
        if($(this).val()=="确定"){
            if(success!=null)
            success();
        }else{
            if(failed!=null)
            failed();
        }
    });
}


