﻿var dialogFirst=true;
function dialog(titleiffd,contentiffd,width,height,cssName){

if(dialogFirst==true){
  var temp_float=new String;
  temp_float="<div id=\"floatBoxBg\"></div>";
  temp_float+="<div id=\"floatBox\" class=\"floatBox\">";
  temp_float+="<div class=\"titleiffd\"><h4></h4><span>关闭</span></div>";
  temp_float+="<div class=\"contentiffd\"></div>";
  temp_float+="</div>";
  $("body").append(temp_float);
  dialogFirst=false;
  
  $("#floatBox .titleiffd span").click(function(){
    $("#floatBoxBg").hide();
    $("#floatBox").hide();
  });
}

$("#floatBox .titleiffd h4").html(titleiffd);
contentiffdType=contentiffd.substring(0,contentiffd.indexOf(":"));
contentiffd=contentiffd.substring(contentiffd.indexOf(":")+1,contentiffd.length);
switch(contentiffdType){
  case "url":
  var contentiffd_array=contentiffd.split("?");
  $("#floatBox .contentiffd").ajaxStart(function(){
    $(this).html("loading...");
  });
  $.ajax({
    type:contentiffd_array[0],
    url:contentiffd_array[1],
    data:contentiffd_array[2],
	error:function(){
	  $("#floatBox .contentiffd").html("error...");
	},
    success:function(html){
      $("#floatBox .contentiffd").html(html);
    }
  });
  break;
  case "text":
  $("#floatBox .contentiffd").html(contentiffd);
  break;
  case "id":
  $("#floatBox .contentiffd").html($("#"+contentiffd+"").html());
  break;
  case "iframe":
  $("#floatBox .contentiffd").html("<iframe src=\""+contentiffd+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
}

$("#floatBoxBg").css({display:"block",height:$(document).height()});
$("#floatBox").removeClass();
$("#floatBox").attr("class","floatBox "+cssName);
$("#floatBox").css({display:"block",left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()+50)+"px",width:width,height:height});
}
