﻿//页面不能加入xhtml的dtd定义
//外部变量G_BodyCenter控制body居中显示, false | true
//外部变量G_BodyWidth表示页面的宽度,775|1000
if (typeof G_BodyCenter=="undefined") G_BodyCenter=false;
if (typeof G_BodyWidth=="undefined") G_BodyWidth=775;
$(flushElement);
function flushElement(){
	window.status="init...";
	var F_RECTOBJ=$("#RECTOBJ");	//绘图框容器ID，其css="position:relative;"
	var F_Container=$("#ContainerRECT");
	if (F_Container.length>0){
		window.status="load...";
		//id为guide的导航栏，id为top的页眉固定到顶部，其css没有"position:absolute;"属性
		var F_guide=$("#guide");
		if (F_guide && /[^ ]+/.test(F_guide.html())){F_RECTOBJ.prepend(F_guide);F_guide.show();}
		var F_top=$("#top");
		if (F_top && /[^ ]+/.test(F_top.html())){	F_RECTOBJ.prepend(F_top);F_top.show();}
		//自动高度
		autoClient();
		showBottom(F_Container);
		//是否自动居中
		if (G_BodyWidth=="100%") G_BodyCenter=false;
		if (G_BodyCenter){
			flushPosition();
			window.onresize = flushPosition;
		}
		$(".rectDIV").css("visibility","visible");
		if (document.readyState) showDIV(F_Container);
	}else{
		setTimeout(flushElement,1000);
	}
}
function showDIV(P_container){
	var V_container=P_container;
	if (document.readyState=="complete"){
		$(".rectDIV").css("visibility","visible");
		showBottom(V_container);
		window.status="loaded...";
	}else{
		window.status="loading......";
		setTimeout(function(){showDIV(V_container);},1000);
	}
}
function showBottom(P_container){
	//id为bottom的页脚固定到页面底部,其css="position:absolute;"
	var F_bottom=$("#bottom");
	var V_container=P_container;
	if ((!$.browser.msie) || document.readyState=="complete"){
		if (F_bottom.length>0){
			if (V_container.find("#bottom").length>0){
				F_bottom.show();
			}else{
				P_container.append(F_bottom);
				F_bottom.show();
			}
			F_bottom.css("top",SortRECT(".rectDIV")-1);
			//页脚的链接域名验证
			var F_url="/WEBS/admini/webMNG";
			$("a", F_bottom).each(function(i){
				if(this.href.lastIndexOf(F_url)>-1){
					this.href=F_url;
				}
			});
		}else{
			setTimeout(function(){showBottom(V_container);},1000);
		}
	}else{setTimeout(function(){showBottom(V_container);},1000);}
	
}
/*
<div style="position:relative;left:1px; top:1px;" id="RECTOBJ"><div style="position:absolute" > 
	<DIV class=rectDIV id=rect_3 ondblclick=RECT_Click(this) style="LEFT: 356px; WIDTH: 419px; TOP: 119px; HEIGHT: 334px">绘图框对象,rectDIV类css="position:absolute;"</DIV>
</div></div>
*/
//刷新body居中
function flushPosition(){
	var F_RECTOBJ=$("#RECTOBJ");	
	var _w=$("body").get(0).clientWidth;
	var n=0;
	if ($.browser.msie){
		n=1;	//不同浏览器的误差像素
	}
	if (_w>G_BodyWidth){
		F_RECTOBJ.css("left",(_w-G_BodyWidth)/2+n);
	}else{
		F_RECTOBJ.css("left","1px");
	}

}
function SortRECT(P_OBJ){
  var F_TopHeight=0;
  $(P_OBJ).each(function(i){
  	F_this=$(this);
		F_TopHeight=Math.max(parseInt(F_this.css("top"))+F_this.height(),F_TopHeight);
  });
  return F_TopHeight;
}
function autoClient(){
	$(".autoheight").each(function(i){
		var _this=$(this);
		_this.parent().eq(0).css("height",this.clientHeight);
	});
}
//子页面执行的自动匹配容器高度动作
function autoContainer(){
	autoClient();
	$("#bottom").css("top",SortRECT(".rectDIV")-1);
	if (G_BodyCenter)	flushPosition();
}