var dialogFirst=true;
function dialog(dialogTitle,content,width,height,cssName)
{   hiddenselect();
	if(dialogFirst==true){	
	  var temp_float=new String;
	  
	  temp_float="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";
	  temp_float+="<div id=\"floatBox\" class=\"floatBox\">";
	  temp_float+="<div class=\"dialogTitle\"><h4></h4><span>关闭</span></div>";
	  temp_float+="<div class=\"content\"></div>";
	  temp_float+="</div>";
	  $("body").append(temp_float);
	  dialogFirst=false;  
	}
	
	$("#floatBox .dialogTitle span").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();});
	  //关闭无动画效果
	  showselect();
	  $("#floatBoxBg").hide();
	  $("#floatBox").hide();
	});
	
	$("#floatBox .dialogTitle h4").html(dialogTitle);
	contentType=content.substring(0,content.indexOf(":"));
	content=content.substring(content.indexOf(":")+1,content.length);
	switch(contentType){  
	  case "url":
	  var content_array=content.split("?");
	  $("#floatBox .content").ajaxStart(function(){
	    $(this).html("loading...");
	  });
	  $.ajax({
	    type:content_array[0],
	    url:content_array[1],
	    data:content_array[2],
		error:function(){
		  $("#floatBox .content").html("error...");
		},
	    success:function(html){
	      $("#floatBox .content").html(html);
	    }
	  });
	  break;
	  case "text":
	  $("#floatBox .content").html(content);
	  break;
	  case "id": 
	  $("#floatBox .content").html($("#"+content+"").html());  
	  break;
	  case "iframe":
	  $("#floatBox .content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" id=\"floatBoxIframe\" onload=\"resizeBoxIframe();\"></iframe>");
	}
	
	$("#floatBoxBg").show();
	$("#floatBoxBg").animate({opacity:"0.5"},"normal");
	$("#floatBox").attr("class","floatBox "+cssName);
	//$("#floatBox").css({display:"block",left:(document.documentElement.clientWidth/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:width,height:height});
    $("#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").css({display:"block",left:"300"+"px",top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:width,height:height});
	$("#floatBox").animate({top:($(document).scrollTop()+50)+"px"},"normal"); 
}

function resizeBoxIframe(){
	var floatBoxIframe = document.getElementById("floatBoxIframe");
	var newHeight = 0;
	if (document.getElementById)
	{
		if (floatBoxIframe && !window.opera)
		{
			if (floatBoxIframe.contentDocument && floatBoxIframe.contentDocument.body.offsetHeight)
			{
				newHeight = floatBoxIframe.contentDocument.body.offsetHeight;
				floatBoxIframe.height = (newHeight + 30) + "px";
				$("#floatBox").css({height:((newHeight + 100)+"px")}); 
			}
			else if(floatBoxIframe.Document && floatBoxIframe.Document.body.scrollHeight)
			{
				newHeight = floatBoxIframe.Document.body.scrollHeight;
				floatBoxIframe.height = (newHeight + 30)+ "px";
				$("#floatBox").css({height:((newHeight + 100)+"px")});
			}else if(floatBoxIframe.contentDocument){
				//火狐，暂时没有找到在火狐下获取Iframe内容的高度
            }else{
            	
            }
		}
	}
}
   
   function showselect(){
	    $("select").each(function(){
	    	if($(this).attr("show") == "true"){
	    		//如果有自定义show属性，则此select不予处理，即select标签为<select show="true">的时候不予处理
	    		//edit by Kevin.Ding
	    		return;
	    	}
	        $(this).parent().display = "block";
			$(this).css("display","block");
		});
   }
	
   function hiddenselect(){
	    $("select").each(function(){
	    	if($(this).attr("show") == "true"){
	    		//如果有自定义show属性，则此select不予处理，即select标签为<select show="true">的时候不予处理
	    		//edit by Kevin.Ding
	    		return;
	    	}
			$(this).parent().display = "none";
			$(this).css("display","none");
		});
  }
