function sGetLayerWidth(sLayerName)
{
	if (isNS4)
	{
		oLayer = document.layers[sLayerName];
		iLayerWidth = oLayer.clip.width;
	}
	else if (isNS)
	{
		oLayer = document.getElementById(sLayerName);
		iLayerWidth = oLayer.offsetWidth;
	}
	else
	{
		oLayer = document.all(sLayerName);
		iLayerWidth = oLayer.offsetWidth;
	}
	return iLayerWidth;
}


function sGetLayerHeight(sLayerName)
{
	if (isNS4)
	{
		oLayer = document.layers[sLayerName];
		iLayerHeight = oLayer.clip.height;
	}
	else if (isNS)
	{
		oLayer = document.getElementById(sLayerName);
		iLayerHeight = oLayer.offsetHeight;
	}
	else
	{
		oLayer = document.all(sLayerName);
		iLayerHeight = oLayer.offsetHeight;
	}
	return iLayerHeight;
}


function resizeWindow(iLayerWidth, iLayerHeight,old_height) 
{
	if (isNS4)
	{
		wndHorizontalMargins = 0;
		wndVerticalMargins = 0;
		isScrollbar = 0;
		scrollbarWidth = 17;
		maxWndWidth = screen.availWidth - 30;
		maxWndHeight = screen.availHeight - 60;
		
		elm = document.myDiv;
		
		if (iLayerWidth > maxWndWidth)
		{
			iLayerWidth = maxWndWidth;
		}
		/*
		if (iLayerHeight > maxWndHeight)
		{
			iLayerHeight = maxWndHeight;
			isScrollbar = 1;
		}
		*/

        if (old_height < iLayerHeight)
        {
            isScrollbar = 1;
        }

		if (old_height > maxWndHeight)
		{
			old_height = maxWndHeight;
			isScrollbar = 1;
		}
        
        iLayerHeight = old_height;

		wndWidth = iLayerWidth + wndHorizontalMargins;
		if (isScrollbar)
		{
			wndWidth += scrollbarWidth;
		}
		
		wndHeight = iLayerHeight + wndVerticalMargins;
	}
	else if (isNS)
	{
		wndHorizontalMargins = 18;
		wndVerticalMargins = 28;
		isScrollbar = 0;
		scrollbarWidth = 15;
		maxWndWidth = screen.availWidth - 30;
		maxWndHeight = screen.availHeight - 30;
				
		wndWidth = iLayerWidth + wndHorizontalMargins;
		if (wndWidth > maxWndWidth)
		{
			wndWidth = maxWndWidth;
		}
        

        if (old_height < iLayerHeight)
        {
            isScrollbar = 1;
        }		

		wndHeight = old_height + wndVerticalMargins;

		if (wndHeight > maxWndHeight)
		{
			wndHeight = maxWndHeight;
			isScrollbar = 1;
		}

		if (isScrollbar)
		{
			wndWidth += scrollbarWidth;
		}
		
		window.resizeTo(wndWidth, wndHeight);
	}
	else
	{
		wndHorizontalMargins = 28;
		wndVerticalMargins = 32;
		scrollbarWidth = 17;
		maxWndWidth = screen.availWidth - 30;
		maxWndHeight = screen.availHeight - 60;
		
		if(iLayerWidth > maxWndWidth)
		{
			iLayerWidth = maxWndWidth;
		}
        /*
		if(iLayerHeight > maxWndHeight)
		{
			iLayerHeight = maxWndHeight;
		}*/
		if (old_height > maxWndHeight)
        {
            old_height = maxWndHeight;
        }

        if (window.hasScrollbar) {
		wndWidth = iLayerWidth + wndHorizontalMargins + scrollbarWidth;
        } else {
		wndWidth = iLayerWidth + wndHorizontalMargins;
        }
		//wndHeight = iLayerHeight + wndVerticalMargins;
        wndHeight = old_height + wndVerticalMargins;

	}
	//alert("resize ("+wndWidth+","+wndHeight+")");
	window.resizeTo(wndWidth, wndHeight);
}


function ResizeTables(iWidth)
{
	if (isNS4)
	{
	
	}
	else if (isNS)
	{
		elt = document.getElementsByTagName("table");
		for (i = 0; i < elt.length; i++)
		{
			if (elt[i].className == "tableStyle2")
			{
				elt[i].style.width = iWidth - 5;
			}
		}
	}
	else
	{
		for (i = 0; i < document.all.length; i++)
		{
			if (document.all(i).tagName == "TABLE" && document.all(i).className == "tableStyle2")
			{
				document.all(i).width = iWidth;
			}
		}
	}
}


function moveWindow(wndWidth, wndHeight) {
	iLeft = (screen.availWidth - wndWidth) / 2;
	iTop = (screen.availHeight - wndHeight) / 2;
	
	self.moveTo(iLeft, iTop);
	self.focus();
}

function getSize()
{
  var myWidth = 0, myHeight = 0;
  if (typeof(window.innerWidth) == 'number')
  { // Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }
  else
  {
    if (document.documentElement &&
        (document.documentElement.clientWidth ||
         document.documentElement.clientHeight))
    { // IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    }
    else
    {
      if (document.body &&
          (document.body.clientWidth || document.body.clientHeight))
      { // IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
    }
  }
  return [myWidth, myHeight];
}


function init(type)
{
var d=getSize();
//alert("width="+d[0]+" ** height="+d[1]);
	iLayerWidth = sGetLayerWidth("myDiv");
	iLayerHeight = sGetLayerHeight("myDiv");
    if (type==1) {
 	    resizeWindow(iLayerWidth, iLayerHeight,d[1]);
	    ResizeTables(iLayerWidth);
	}
 	//countdown = 0.5;
 	//timer = setTimeout("moveWindow(wndWidth, wndHeight)", countdown * 1000);
}