/* 
子框架窗口操作iframe自动适应页面 
注意：嵌入页面不能带DOCTYPE声明
*/
var G_parent=window.parent;
var F_H;
var moz=!document.all;
//var G_parent=document.parentWindow;
function autoHeight(){
	if (!!G_parent){
		for (var i=0;i<G_parent.frames.length;i++){
			if (G_parent.frames[i].location==self.document.location){
				//alert(document.location);
				//F_H = Math.max(self.document.body.offsetHeight,self.document.body.scrollHeight);
				//F_H = Math.max(F_H,self.document.body.clientHeight);
				F_H=moz?(self.document.body.offsetHeight+20):self.document.body.scrollHeight;
				G_parent.document.getElementsByTagName("iframe")[i].setAttribute("height",F_H);
				self.document.body.style.overflow="hidden";
				window.status="Auto height:"+G_parent.document.getElementsByTagName("iframe")[i].getAttribute("height");
				//alert("offsetHeight=="+self.document.body.offsetHeight+"\nscrollHeight=="+self.document.body.scrollHeight+"\nclientHeight=="+self.document.body.clientHeight);
			}
		}
	}
}
//自动添加到载入完成动作中
if (window.addEventListener)
	window.addEventListener("load", autoHeight, false);
else if (window.attachEvent)
	window.attachEvent("onload", autoHeight);
else
	window.onload=autoHeight;

/*父框架窗口中操作iframe自动适应高度,IE5.0中测试通过
body中onLoad="CFAutoHeight();"
iframe中onLoad="CFAutoHeight();"
按钮中onClick="CFAutoHeight('FrameName');"
*/
function CFAutoHeight(P_obj){
	var V_childH,G_obj,G_ID;
	if (typeof P_obj=="undefined"){
		for (var i=0;i<window.frames.length;i++){
			G_obj=window.frames[i];
			G_ID=document.getElementById(G_obj.name);
			if (moz){
				V_childH=G_obj.document.body.offsetHeight;
			}else{
				V_childH=G_obj.document.body.scrollHeight;
			}	
			//alert(V_childH);
			G_ID.setAttribute("height",V_childH);
			G_obj.document.body.style.overflow="hidden";
			window.status=G_obj.name+" height:"+G_ID.getAttribute("height");
				
		}
	}else{
		G_obj=window.frames[P_obj];
		G_ID=document.getElementById(P_obj);
		if (moz){
			V_childH=G_obj.document.body.offsetHeight;
		}else{
			V_childH=G_obj.document.body.scrollHeight;
		}	
		//alert(V_childH);
		G_ID.setAttribute("height",V_childH);
		G_obj.document.body.style.overflow="hidden";
		window.status=P_obj+" height:"+G_ID.getAttribute("height");
	}
}

//对父窗口的父窗口进行自动匹配高度
var G_Grand=window.parent.parent;
function autoHeightGrand(){
	if(!!G_Grand){
		for (var i=0;i<G_Grand.frames.length;i++){
			if (G_Grand.frames[i].location==G_parent.document.location){
				//alert(document.location);
				//F_H = Math.max(self.document.body.offsetHeight,self.document.body.scrollHeight);
				//F_H = Math.max(F_H,self.document.body.clientHeight);
				F_H=moz?(G_parent.document.body.offsetHeight+20):G_parent.document.body.scrollHeight;
				try{
				G_Grand.document.getElementsByTagName("iframe")[i].setAttribute("height",F_H);
				G_parent.document.body.style.overflow="hidden";
				window.status="Auto height:"+G_Grand.document.getElementsByTagName("iframe")[i].getAttribute("height");
				//alert("offsetHeight=="+G_parent.document.body.offsetHeight+"\nscrollHeight=="+G_parent.document.body.scrollHeight+"\nclientHeight=="+G_parent.document.body.clientHeight);
				}catch(e){}
			}
		}
	}
}