/*
调用方 法dialog(title,content,width,height,cssName); 
1 	    title 	弹出层的标题 	必填，纯文本
2 	    content 弹出层的内容 	:url get或post某一页面里的html，该页面要求只包含body的子标签:text 	直接写入内容:id 	显示页面里某id的子标签:iframe 	层内内容以框架显示
3 	    width 	弹出层的宽 	必填，css值，比如"200px"
4 	    height 	弹出层的高 	如上，但是可用"auto"
5 	    cssName 	弹出层的css 	给id floatBox加入的样式名，层内样式可以通过这个样式名来定制
*/
var dialogFirst=true;
var contentFrom = "";
function dialog(title,content,width,height,cssName,strHeight){

	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=\"floatBoxBg\" style=\"display:none;\"></div>";
	  temp_float+="<div id=\"floatBox\" class=\"floatBox\" style=\"display:none;\">";
	  temp_float+='<div style="float:right; height:22px; width:22px; margin-top:11px; margin-right:11px; cursor:pointer" id="guanbi"></div>';
	  temp_float+="<div class=\"content\"></div>";
	  temp_float+="</div>";
	  $("body").append(temp_float);
	  dialogFirst=false;
	}
	
	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("<img src='./images/loading.gif' /><br><br>");
	  });
	  $.ajax({
		type:content_array[0],
		url:"/"+content_array[1],
		data:content_array[2],
		error:function(){
		  //$("#floatBox .content").html("<img src='./images/loading.gif' /><br><br>");
		},
		success:function(html){
			if(html == "stopIncome") {
				hideDialog();
				alert("该公会已经停止收人");
				return false;
			} else {

				$("#floatBox .title span.left").html(title);

				$("#floatBoxBg").show();
				$("#floatBoxBg").css({display:"block",height:$(document).height()});
				$("#floatBox").removeClass();
				if(cssName ==""){
					$("#floatBox").attr("class","floatBox ");
				}
				else{
					$("#floatBox").attr("class",cssName);
				}

				var iLeft = (($(document).width())/2-(parseInt(width)/2));
				
				var iTop = $(document).scrollTop();
				if(typeof(strHeight) == "undefined"){
				    iTop = ($(document).scrollTop()+100);
				}else{
				    iTop = ($(document).scrollTop()+parseInt(strHeight));
				}
				$("#floatBox").css({display:"block",left:iLeft+"px",top:iTop+"px",width:width,height:height});
				$(".wusdeds").hide();
				$(".ysyiwyd").hide();
				$("#serverid").hide();


				$("#floatBox .content").html(html);

				if(document.getElementById("userInfoDivDetail")) {
					document.getElementById("userInfoDivDetail").style.zIndex = 1;
				}
			}
		}
	  });
	  break;
	  case "text":
	    $("#floatBox .title span.left").html(title);
        
        $("#floatBoxBg").show();
        $("#floatBoxBg").css({display:"block",height:$(document).height()});
        $("#floatBox").removeClass();
        if(cssName ==""){
        	$("#floatBox").attr("class","floatBox ");
        }
        else{
        	$("#floatBox").attr("class",cssName);
        }
        
        var iLeft = (($(document).width())/2-(parseInt(width)/2));
        
        var iTop = $(document).scrollTop();
        if(typeof(strHeight) == "undefined"){
            iTop = ($(document).scrollTop()+100);
        }else{
            iTop = ($(document).scrollTop()+parseInt(strHeight));
        }
        $("#floatBox").css({display:"block",left:iLeft+"px",top:iTop+"px",width:width,height:height});
        $(".wusdeds").hide();
        $(".ysyiwyd").hide();
        $("#serverid").hide();
		var strHtml = '<div style="text-align:center;padding-top: 30px;*padding-top: 0px;" id="army_area">';
		strHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><th scope="col" height="30"></th></tr>';
		strHtml += '<tr><th scope="col" height="50" align="center" valign="middle" style="background:url(/images/gonghui/gonghui_searchbg.gif) repeat-y;">';
		strHtml += '<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td align="center" height="30" valign="top">';
		strHtml += '<span class="bigtitile">'+title+'</span></td></tr><tr><td align="left" class="gray">'+content+'</td></tr>';
		strHtml += '<tr><td align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"><tr><th width="556" align="center" valign="middle" height="30" class="gray"></th></tr></table></td></tr></table></th></tr><tr>';
		strHtml += '<th scope="row" height="63" valign="middle" align="center" style="background:url(/images/gonghui/gonghui_tck4.gif) 0px -233px;">&nbsp;</th></tr></table></div>';
		//alert(content);
		$("#floatBox .content").html(strHtml);
		break;
	  case "id":
		$("#floatBox .content").html($("#"+content+"").html());
		contentFrom = $("#"+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\"></iframe>");
		break;
	}

	$("#guanbi").click(function(){
		if(contentType == "id")
		{
			$("#"+content+"").html(contentFrom);
		}
	   hideDialog();

	});

	$("#floatBoxBg").click(function(){

		if(contentType == "id")
		{
			$("#"+content+"").html(contentFrom);
		}
	    hideDialog();

	});

	
}

function hideDialog(){
	 $("#floatBoxBg").hide();
	 $("#floatBox").hide();
	 $(".wusdeds").show();
	 $(".ysyiwyd").show();
	 $("#serverid").show();
	
	if(document.getElementById("userInfoDivDetail")) {
		document.getElementById("userInfoDivDetail").style.zIndex = 1000;
	}
}