function ParentResize(fixedWidth, fixedHeight, maxWidth, maxHeight)
{
	var xScroll, yScroll;
	
	//alert(document.getElementsByTagName('form')[0].offsetWidth);
	
	if (window.innerHeight && window.scrollMaxY) 
	{	
		xScroll = document.body.scrollWidth;
		//xScroll = document.getElementsByTagName('form')[0].offsetWidth + 20;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac (ie)
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;//hack
	} 
	else 
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) 
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight) 
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) 
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;//hack
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
		//alert('window h' + windowHeight + ':' + yScroll);
	} 
	else 
	{ 
		pageHeight = yScroll;
		//alert('scroll h - ' + windowHeight + ':' + yScroll);
	}
	
	// for small pages with total width less then width of the viewport
	//alert(xScroll + ' : ' + windowWidth);
	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
		//alert('window w' + windowWidth + ':' + xScroll);
	}
	else 
	{
		pageWidth = xScroll;
		//alert('scroll w' + windowWidth + ':' + xScroll);
	}
	var isNav, isIE;
	if (parseInt(navigator.appVersion) >= 4) 
	{
	isNav = (navigator.appName == "Netscape");
	isIE = (navigator.appName.indexOf("Microsoft") != -1);
	} 
	if(isIE)
	{
		pageHeight += 30;
		pageWidth += 30;				
	}
	
	pageHeight += 5;
	
	// TODO: refactor
	if(fixedWidth){
		pageWidth = fixedWidth;
	} else if(maxWidth) {
		pageWidth = (pageWidth > maxWidth) ? maxWidth : pageWidth;	
	}
	if(fixedHeight){
		pageHeight = fixedHeight;
	} else if(maxHeight) {
		pageHeight = (pageHeight > maxHeight) ? maxHeight : pageHeight;
	}
	
	//(pageWidth,pageHeight,windowWidth,windowHeight) 
	if(parent){
		parent.ResizeLightBox(pageHeight,pageWidth);
	}
}

function WrapperParentResize(wrapperId, fixedWidth, fixedHeight, maxWidth, maxHeight){
	var resizeWidth = 0;
	var resizeHeight = 0;
	var wrapperId = (wrapperId == null) ? 'wrapper' : wrapperId;
	var wrapper = document.getElementById(wrapperId);

	if(wrapper != null && wrapper.offsetHeight){
	
		//var dims = Element.getDimensions(wrapper); // requires prototype.js
		//var dims = {height: 0, width: 0};
		//alert(wrapper.offsetWidth + ', ' + wrapper.offsetHeight + '\n' + wrapper.scrollWidth + ', ' + wrapper.scrollHeight + '\n' + dims.width + ', ' + dims.height);
	
		if(fixedHeight != null){
			resizeHeight = fixedHeight;
		} else {
			resizeHeight = wrapper.scrollHeight;
		}

		if(fixedWidth != null){
			resizeWidth = fixedWidth;
		} else {
			resizeWidth = wrapper.scrollWidth;
		}

		if (document.all){
			resizeWidth += 4;	// HACK: fixes IE display issue
		}

		resizeHeight += 5;	// HACK: fixes issues with the linker

		if(maxHeight != null){
			resizeHeight = (maxHeight < resizeHeight) ? maxHeight : resizeHeight;
		}

		if(maxWidth != null){
			resizeWidth = (maxWidth < resizeWidth) ? maxWidth : resizeWidth;
		}
		
		parent.ResizeLightBox(resizeHeight, resizeWidth);
		
	}	
}

function ResizeLightBox(height,width)
{
	//alert(width + ', ' + height) ;
	var objBox = document.getElementById('lightbox');
	var objOverlay = document.getElementById('overlay');


	var arrayPageSize = getPageSize();

	if (document.all)
	{
		xPos = (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		yPos = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	}
	else
	{
		xPos = window.pageXOffset;
		yPos = window.pageYOffset;
	}

	//alert(objBox.style.height);
	//alert(height);
	if(objBox && objBox.style){
		objBox.style.height = height + 'px';
		//alert(objBox.style.height);
		objBox.style.width = width + 'px';
		//alert(objBox.style.width);
		
		var pageLocY = ((arrayPageSize[3]/2) - (height/2) + yPos);
		var pageLocX = ((arrayPageSize[2]/2) - (width/2) + xPos);
		pageLocX = (pageLocX < 0) ? 0 : pageLocX;
		pageLocY = (pageLocY < 0) ? 0 : pageLocY;

		objBox.style.top = pageLocY + 'px';
		objBox.style.left = pageLocX + 'px';
	}
}

function PopBox(url,width,height)
{
	var objOverlay = document.getElementById('overlay');
	var objBox = document.getElementById('lightbox');

	var arrayPageSize = getPageSize();

	if (document.all)
	{
		xPos = (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		yPos = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	}
	else
	{
		xPos = window.pageXOffset;
		yPos = window.pageYOffset;
	}
	
	var pageLocX = ((arrayPageSize[2]/2) - (width/2) + xPos);
	var pageLocY = ((arrayPageSize[3]/2) - (height/2) + yPos);
	pageLocX = (pageLocX < 0) ? 0 : pageLocX;
	pageLocY = (pageLocY < 0) ? 0 : pageLocY;
	
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.width = (arrayPageSize[0] + 'px');
	objOverlay.style.display = 'block';
	objBox.style.height = height + 'px';
	objBox.style.width = width + 'px';
//	objBox.style.top = ((arrayPageSize[3]/2) - (height/2) + document.body.scrollTop) + 'px';
//	objBox.style.left = ((arrayPageSize[2]/2) - (width/2) + document.body.scrollLeft) + 'px';
	objBox.style.top = pageLocY + 'px';
	objBox.style.left = pageLocX + 'px';
	objBox.src = url;
	objBox.style.display = 'block';
}
function KillBox(){
	var objOverlay = document.getElementById('overlay');
	var objBox = document.getElementById('lightbox');
	
	objOverlay.style.display = 'none';
	objBox.style.display = 'none';
	objBox.src = 'javascript:\'\'';
}
function getPageSize()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
