// Lee dialog 1.0 http://www.xij.cn/blog/?p=68

var dialogFirst=true;
function dialog(title,content,width,height,cssName){

if(dialogFirst==true){
  var temp_float=new String;
  temp_float="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=10);opacity:0;\"></div>";
  temp_float+="<div id=\"floatBox\" class=\"floatBox\">";
  temp_float+="<div class=\"title\"><h4></h4><span>关闭</span></div>";
  temp_float+="<div class=\"content\"></div>";
  temp_float+="</div>";
  temp_float="<div id=\"floatBoxBg\" style=\"position:absolute;top:0px;left:0px;width:100%;height:100%;background:url(/Jmhd/System/images/blank.gif);z-index:<#ZINDEX1#>;\"></div>";
  temp_float+="<div id=\"dialogBox\">";
  temp_float+="<table cellpadding=\"0\" cellspacing=\"1\" style=\"width:100%;border:0;background-color:#709cd2;\" id=\"floatBox\"><tbody>";
  temp_float+="		<tr style=\"background-color:#709cd2;\"><td>";
  temp_float+="			<table style=\"width:100%;height:22px;border:0;\" cellpadding=\"0\" cellspacing=\"0\"><tbody>";
  temp_float+="				<tr><td style=\"width:6px;\"></td>";
  temp_float+="				<td id=\"dialogBoxTitle\" style=\"text-align:left;color:#FFFFFF;font-size:14px;font-weight:bold;\"><div id=\"floatBoxTitleText\"></div></td>";
  temp_float+="				<td style=\"width:40px;text-align:right;vertical-align:middle;\"><div id=\"floatBoxClose\"></div></td>";
  temp_float+="				<td style=\"width:6px;\"></td>";
  temp_float+="				</tr>";
  temp_float+="			</tbody></table>";
  temp_float+="		</td></tr>";
  temp_float+="		<tr style=\"vertical-align:top;background-color:#ffffff;height:35px;\"><td id=\"dialogBody\">";
  temp_float+="			<div id=\"dialogText\" style=\"font-size:14px;line-height:16px;color:#000000;text-align:center;\"></div>";
  temp_float+="		</td></tr>";
  temp_float+="</tbody></table></div>";
  temp_float+="<div id=\"dialogBoxShadow<#ADDID#>\" style=\"display:none;z-index:<#ZINDEX2#>;\"></div>";
  $("body").append(temp_float);
  dialogFirst=false;
}

$("#floatBoxTitleText").html(title);
$("#floatBoxClose").html("<span id=\"dialogClose\" style=\"font-weight:bold;font-size:11pt;cursor:pointer;color:#FFFFFF;\">关闭</span>");

$("#dialogClose").click(function(){
  $("#floatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
  $("#floatBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"normal",function(){$(this).hide();}); 
});


contentType=content.substring(0,content.indexOf(":"));
content=content.substring(content.indexOf(":")+1,content.length);
switch(contentType){
  case "url":
	  var content_array=content.split("?");
	  $("#dialogText").ajaxStart(function(){
		$(this).html("loading...");
	  });
	  $.ajax({
		type:content_array[0],
		url:content_array[1],
		data:content_array[2],
		error:function(){
		  $("#dialogText").html("error...");
		},
		success:function(html){
		  $("#dialogText").html(html);
		}
	  });
	  break;
  case "text":
	  $("#dialogText").html(content);
	  break;
  case "id":
	  $("#dialogText").html($("#"+content+"").html());
	  break;
  case "iframe":
	  $("#dialogText").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
}

$("#floatBoxBg").show();
$("#floatBoxBg").animate({opacity:"0.5"},"normal");
$("#floatBox").attr("class","floatBox "+cssName);
$("#floatBox").css({display:"block",left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:width,height:height});
$("#floatBox").animate({top:($(document).scrollTop()+205)+"px"},"normal"); 
}
