﻿var CLdialogFirst=true;
//打开弹出层
function CLdialog(title,content,width,height,btlink,icontype){
    //初始化模板HTML代码
    if(CLdialogFirst==true){       
        var temp_float=new String;
        //css代码
        temp_float="<style type=\"text/css\">";
        temp_float+="#floatBoxBg";
        temp_float+="{";
        temp_float+="    display: none;";
        temp_float+="    width: 100%;";
        temp_float+="    height: 100%;";
        temp_float+="    background: #000;";
        temp_float+="    position: absolute;";
        temp_float+="    top: 0;";
        temp_float+="    left: 0;";
        temp_float+="}";
        temp_float+=".floatBox";
        temp_float+="{";
        temp_float+="    width: 251px;";
        temp_float+="    position: absolute;";
        temp_float+="    top: 50px;";
        temp_float+="    left: 40%;";
        temp_float+="}";
        temp_float+="</style>";
        
        //遮罩层HTML
        temp_float+="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";        
        //弹出层HTML
        temp_float+="<div id=\"floatBox\" style=\"width:100%; height:auto; float:left; background-color:#FFFFFF; padding-bottom:0px;\">";
        temp_float+="      <div class=\"chuangko_bj\">";
        temp_float+="          <div class=\"chuangko_nr_kj\">";
        if(icontype!=undefined&&icontype!='')
            temp_float+="          <div class=\"chuangko_nr_tu\"><img src=\"/Content/newhapa/ciling/images/chuangko_tu_"+icontype+".png\" width=\"28\" height=\"29\" /></div>";
        else        
            temp_float+="          <div class=\"chuangko_nr_tu\"><img src=\"/Content/newhapa/ciling/images/chuangko_tu.gif\" width=\"28\" height=\"29\" /></div>";
        temp_float+="              <div class=\"chuangko_nr_wz\">fdfdfdf</div>";
       // temp_float+="              <div class=\"chuangko_link_wz\"></div>";
        temp_float+="          </div>";
        if(btlink!=undefined&&btlink!='')
            temp_float+="      <div class=\"chuangko_banner_1\"><a href=\""+btlink+"\"><div class=\"chuangko_kong\"></div></a></div>";
        else
            temp_float+="      <div class=\"chuangko_banner_1\"><a href=\"javascript:CLdialogClose()\"><div class=\"chuangko_kong\"></div></a></div>";
        temp_float+="      </div>";      
        temp_float+="</div>";
      
        $("body").append(temp_float);
        CLdialogFirst=false;        
    }
    
//    //初始化关闭按钮
//    $("#floatBox .level2_1 .level3_3 img").click(function(){
//         dialogClose(); 
//    });

//    //初始化title数据
//    if(title!=null&&title!='')
//        $("#floatBox .level3_2").html(title);
        
    //分隔内容类型及内容数据
    contentType=content.substring(0,content.indexOf(":"));
    content=content.substring(content.indexOf(":")+1,content.length);
    
    //根据类型选择相应的内容数据填充
    switch(contentType){
      case "url"://通过url获取显示内容
          var content_array=content.split("?");
          $("#floatBox .chuangko_bj .chuangko_nr_kj .chuangko_nr_wz").ajaxStart(function(){
            $(this).html("loading...");
          });
          $.ajax({
            type:content_array[0],
            url:content_array[1],
            data:content_array[2],
	        error:function(){
	          $("#floatBox .chuangko_bj .chuangko_nr_kj .chuangko_nr_wz").html("error...");
	        },
            success:function(html){
              $("#floatBox .chuangko_bj .chuangko_nr_kj .chuangko_nr_wz").html(html);
            }
          });
          break;
      case "text": //通过传入的文字显示内容
          $("#floatBox .chuangko_bj .chuangko_nr_kj .chuangko_nr_wz").html(content);
          break;
      case "id"://通过页面中的某个DIV获取显示内容
          $("#floatBox .chuangko_bj .chuangko_nr_kj .chuangko_nr_wz").html($("#"+content+"").html());
          break;
      case "iframe"://显示Iframe中的内容
          $("#floatBox .chuangko_bj .chuangko_nr_kj .chuangko_nr_wz").html("<iframe id=\"iframeID\" width=\"99%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"yes\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\ style=\"overflow-x:hidden\"></iframe>" );
          $("#iframeID").attr("src",content);
          break;          
    }
    
    
    correctPNG();
    
    $("#floatBoxBg").show();//显示遮罩
     
    $("select").each(function(i){$(this).css('visibility','hidden')});//过滤页面中的select控件
    //显示弹出层
     $("#floatBox").css({display:"block",left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()-(height=="auto"?148:parseInt(height)))+"px",width:width,height:height});   
    $("#floatBox").css({top:($(document).scrollTop()+200)+"px"},"normal"); 
    $("#floatBoxBg").css({opacity:"0.5"},"normal");
    $("#floatBox").attr("class","floatBox ");   
   
}
//关闭弹出层
function CLdialogClose(){
  $("select").each(function(i){$(this).css('visibility','visible')});
  $("#floatBoxBg").css('display','none');  
  $("#floatBox").css({top:"-1000px"},"normal",function(){$(this).hide();});
}