﻿//获取滚动的边框值
var bodyScrollWidth=0;
var bodyScrollHeight=0;
function reCalBodySize(){
	//bodyScrollWidth=document.body.scrollWidth;
	//bodyScrollHeight=document.body.scrollHeight;
	
	//bodyScrollWidth=document.documentElement.clientWidth;
	//bodyScrollHeight=window.screen.availHeight;
	
	//获取网页可见区域窗口宽度
    if (window.innerWidth)
    bodyScrollWidth = window.innerWidth;
    else if ((document.body) && (document.body.clientWidth))
    bodyScrollWidth = document.body.clientWidth;
    
	//获取窗口高度    
	if (window.innerHeight)
    bodyScrollHeight = window.innerHeight;
    else if ((document.body) && (document.body.clientHeight))
    bodyScrollHeight = document.body.clientHeight;           

	//通过深入Document内部对body进行检测，获取窗口大小
    if (document.documentElement  && document.documentElement.clientHeight && document.documentElement.clientWidth)
    {
     bodyScrollHeight = document.documentElement.clientHeight;
     bodyScrollWidth = document.documentElement.clientWidth;
    }
}

//判断客户端浏览器的类型
if(navigator.appName.indexOf("Explorer") > -1){//ie
	var exp=1;
} 
else{//for ff
	var exp=2;
}

//*********************
//隐藏元素
function HideElement(strElementTagName){
	try{
		for(i=0;i<window.document.all.tags(strElementTagName).length; i++){
			var objTemp = window.document.all.tags(strElementTagName)[i];
			objTemp.style.visibility = "hidden";
		}
	}catch(e){
		alert(e.message);
	}
}

//显示元素
function ShowElement(strElementTagName){
	try{
		for(i=0;i<window.document.all.tags(strElementTagName).length; i++){
			var objTemp = window.document.all.tags(strElementTagName)[i];
			objTemp.style.visibility = "visible";
		}
	}catch(e){
		alert(e.message);
	}
}

function hideElementAll(){
	HideElement("SELECT");
	HideElement("OBJECT");
	HideElement("IFRAME");
}

function showElementAll(){
	ShowElement("SELECT");
	ShowElement("OBJECT");
	ShowElement("IFRAME");
}

//层的属性赋值
function set_div_style(obj,id,top,left,width,height,position,border,cursor,background) {
        var obj = obj;
        obj.id = id?id:null;
        obj.style.top = top?top:'0px';
        obj.style.left = left?left:'0px';
        obj.style.width = width?width:'0px';
        obj.style.height = height?height:'0px';
        obj.style.position = position?position:"static";
        obj.style.border = border?border:"1px #000 solid";
        obj.style.cursor = cursor?cursor:"default";
        obj.style.background = background?background:"";
        return obj;
}

// 创建滤镜
function CreGlobalDiv(){
		var DivWidth=document.documentElement.clientWidth;
		var DivHeight=document.documentElement.scrollHeight>bodyScrollHeight?document.documentElement.scrollHeight:bodyScrollHeight;
		var globalDiv=document.createElement('div');
		globalDiv.id='globalDiv';
		globalDiv.style.display='none';
		globalDiv.style.zIndex='98';
		globalDiv = set_div_style(globalDiv,'globalDiv','0px','0px',DivWidth+'px',DivHeight+'px',"absolute"," #333333 0px solid","default","darkgray");
		globalDiv.onselectstart=function(){return false}
		if ( 1 == exp ) {
			globalDiv.style.filter="alpha(opacity=30)";
		}
		else {
			globalDiv.style.opacity=30/100;
		}
		document.body.appendChild(globalDiv);
}

//滤镜定位
function LocGlobalDiv() {
	//reCalBodySize();
	var argArr=LocGlobalDiv.arguments;
	for ( var i=0;i<argArr.length;i++ ) {
		if ( document.getElementById(argArr[i]) != null ) {
			document.getElementById(argArr[i]).style.width = (bodyScrollWidth)+'px';
			document.getElementById(argArr[i]).style.height = (bodyScrollHeight)+'px';
		}
	}
}

//显示操作定义
function dis(){	
	reCalBodySize();
	CreGlobalDiv();
	LocGlobalDiv();
	document.getElementById("globalDiv").style.display = "block";		
	GetCenterXY_ForLayer(document.getElementById("onpnl"));
	if ( 1 == exp ) {
		hideElementAll();
	}	
	//return;
}

function cls(){
	document.getElementById("onpnl").style.display = "none";
	document.getElementById("globalDiv").style.display = "none";
	if ( 1 == exp ) {
		showElementAll();
	}
	return false;
}
//将悬浮层的位置定位在body可见区域中央
function GetCenterXY_ForLayer(objdiv){	
	objdiv.style.display="block";	
	var styleWidth=objdiv.style.width.substring(0,objdiv.style.width.length-2);
	if (objdiv.firstChild.clientWidth>styleWidth)
	{
		objdiv.style.width=objdiv.firstChild.clientWidth+'px';
		styleWidth=objdiv.firstChild.clientWidth;
	}
	
	var styleHeight=objdiv.style.height.substring(0,objdiv.style.width.length-2);
	if (objdiv.firstChild.clientHeight>styleHeight)
	{
		objdiv.style.height=objdiv.firstChild.clientHeight+'px';
		styleHeight=objdiv.firstChild.clientHeight;
	}
	var objLeft = parseInt(document.documentElement.scrollLeft+(bodyScrollWidth - styleWidth)/2)+'px';
	var relTop=(bodyScrollHeight-styleHeight)/2 > 0 ? (bodyScrollHeight-styleHeight)/2:0;
	var objTop = parseInt(document.body.scrollTop+relTop)+'px';
	objdiv.style.top = objTop;	
	objdiv.style.left = objLeft;

	//checkAndResetStyleTop(objdiv);			// 调整高度	
}

function checkAndResetStyleTop (obj) {
	var clientHeight=obj.firstChild.clientHeight;
	var styleTop=parseInt(obj.style.top.substring(0,obj.style.top.length-2));
	if (clientHeight+styleTop>bodyScrollHeight ) {
		obj.style.top=(bodyScrollHeight- clientHeight)+'px';
	}
}