﻿// JScript File

function CenterLayer(id)
{
    var ele = document.getElementById(id);
	ele.style.left = CenterX(ele) + 'px';
	ele.style.top = CenterY(ele) + 'px';
}
function CenterX(ele)
{
	if(ScrollLeft() == 0)
		return (WinWidth()/2 - ElementWH(ele.style.width)/2);
	else
		return ScrollLeft() + (WinWidth()/2 - ElementWH(ele.style.width)/2);
}
function CenterY(ele)
{
	if(ScrollTop() == 0)
		return (WinHeight()/2 - ElementWH(ele.style.height)/2);
	else
		return ScrollTop() + (WinHeight()/2 - ElementWH(ele.style.height)/2);
}
function WinWidth()
{
	var myWidth = 0;
	if( typeof(window.innerWidth) == 'number') //Non-IE
	    myWidth = window.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth) 
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	else if(document.body && document.body.clientWidth) 
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
  
  	return myWidth;
}
function WinHeight()
{
	var myHeight = 0;
	if(typeof(window.innerWidth) == 'number') //Non-IE
	    myHeight = window.innerHeight;
  	else if(document.documentElement && document.documentElement.clientHeight)
	    //IE 6+ in 'standards compliant mode'
	    myHeight = document.documentElement.clientHeight;
	else if(document.body && document.body.clientHeight) 
	    //IE 4 compatible
	    myHeight = document.body.clientHeight;

	return myHeight;
}
function ElementWH(widthheight)
{
	var len = widthheight.length;
	return	widthheight.substring(0,len-2); 
}
function MaxWidth()
{
	return ScrollLeft() + WinWidth(); 
}
function MaxHeight()
{	
	return ScrollTop() + WinHeight();	
}

function ScrollWidth()
{
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	return document.all? iebody.scrollWidth : iebody.clientWidth
}
function ScrollHeight()
{
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	return document.all? iebody.scrollHeight :  iebody.clientHeight
}

function ScrollLeft()
{
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	return document.all? iebody.scrollLeft : pageXOffset
}
function ScrollTop()
{
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	return document.all? iebody.scrollTop : pageYOffset
}