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) 
{
	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;
		}

		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;
		}

		wndHeight = iLayerHeight + wndVerticalMargins;

		if (wndHeight > maxWndHeight)
		{
			wndHeight = maxWndHeight;
			isScrollbar = 1;
		}

		if (isScrollbar)
		{
			wndWidth += scrollbarWidth;
		}
		
		window.resizeTo(wndWidth, wndHeight);
	}
	else
	{
		//wndHorizontalMargins = 12;
		//wndVerticalMargins = 30;
        
		wndHorizontalMargins = 28;
		wndVerticalMargins = 32;
        
		scrollbarWidth = 17;
		maxWndWidth = screen.availWidth - 30;
		maxWndHeight = screen.availHeight - 60;
		
		if(iLayerWidth > maxWndWidth)
		{
			iLayerWidth = maxWndWidth;
		}
        
		if(iLayerHeight > maxWndHeight)
		{
			iLayerHeight = maxWndHeight;
		}

        wndWidth = iLayerWidth + wndHorizontalMargins + scrollbarWidth;
/*
        if (window.hasScrollbar) {
		    wndWidth = iLayerWidth + wndHorizontalMargins + scrollbarWidth;
        } else {
		    wndWidth = iLayerWidth + wndHorizontalMargins;
        }
*/
        wndHeight = iLayerHeight + 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 init_popup_consumables()
{
	iLayerWidth = sGetLayerWidth("myDiv");
	iLayerHeight = sGetLayerHeight("myDiv");

 	resizeWindow(iLayerWidth, iLayerHeight);
	
 	countdown = 0.5;
 	timer = setTimeout("moveWindow(wndWidth, wndHeight)", countdown * 1000);
}


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 setWindowSize(iLayerWidth, iLayerHeight) 
{
	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;
		}

		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;
		}

		wndHeight = iLayerHeight + 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;
		isScrollbar = 0;

		if(iLayerWidth > maxWndWidth)
		{
			iLayerWidth = maxWndWidth;
		}
        
		if(iLayerHeight > maxWndHeight)
		{
			iLayerHeight = maxWndHeight;
		}

        if (window.hasScrollbar) {
            isScrollbar = 1;
		    wndWidth = iLayerWidth + wndHorizontalMargins + scrollbarWidth;
        } else {
		    wndWidth = iLayerWidth + wndHorizontalMargins;
        }
        wndHeight = iLayerHeight + wndVerticalMargins;

	}
	//window.resizeTo(wndWidth, wndHeight);
    //alert("-->isScrollbar="+isScrollbar);
    return new Array(isScrollbar,wndWidth,wndHeight);
}

function init(type,popup_width)
{
var d=getSize();

//alert("size : width="+d[0]+" ** height="+d[1]);
	iLayerWidth = sGetLayerWidth("myDiv");
	iLayerHeight = sGetLayerHeight("myDiv");
    //alert("width="+iLayerWidth+" - height="+iLayerHeight);

    if (type==1) {
        if (iLayerWidth>=popup_width) {
 	        resizeWindow(iLayerWidth, iLayerHeight);
        }
        else {
 	        resizeWindow(popup_width, iLayerHeight);
        }
	    //ResizeTables(iLayerWidth);
	}
 	//countdown = 0.5;
 	//timer = setTimeout("moveWindow(wndWidth, wndHeight)", countdown * 1000);
}

function initPopup()
{
	iLayerWidth = sGetLayerWidth("myDiv");
	iLayerHeight = sGetLayerHeight("myDiv");
    resizeWindow(iLayerWidth, iLayerHeight);

 	countdown = 0.5;
 	timer = setTimeout("moveWindow(wndWidth, wndHeight)", countdown * 1000);
}