/* Window tools
© 2007 Analytic Soft, www.analytic.com.ua
--------------------------------------------------------------------------------------
*/


function WND_resize(intWidth, intHeight, to_center) 
{
 try 
 {	
 	intWidth	= Math.min(intWidth,  screen.width -20);
	intHeight	= Math.min(intHeight, screen.height-30);
	window.resizeTo(intWidth,intHeight); //Change window size
	
	//Move window
	if (!to_center) return true;
	var x_left_center = Math.round((screen.width  - intWidth)/2);
	var y_left_center = Math.round((screen.height - intHeight)/2);
	window.moveTo(x_left_center,y_left_center); // переместить окно в середину экрана
 } catch(e) {}
	
	return true;
}

function WND_fitHeight()
{
	try 
	{	
		window.resizeBy(0,document.documentElement.scrollHeight-WND_height()); //Change window size
	} catch (e) {}
}

function WND_fitWidth()
{
	try 
	{	
		window.resizeBy(document.documentElement.scrollWidth-WND_width(), 0); //Change window size
	} catch (e) {}
}


function WND_height()
{
	if (window.innerHeight) height = window.innerHeight;
	else	if(document.documentElement && document.documentElement.clientHeight) height = document.documentElement.clientHeight;
			else  height = document.body.clientWidth;

	return height;
}

function WND_width()
{
	if (window.innerWidth) width = window.innerWidth;
	else	if(document.documentElement && document.documentElement.clientWidth) width = document.documentElement.clientWidth;
			else  width = document.body.clientWidth;

	return width;
}

var WND_fitModalHeightID = false;
function WND_fitModalHeight()
{
	if (document.body.parentElement.scrollHeight)  
	{	
//		var scroll_h	= document.body.parentElement.scrollHeight;
		var scroll_h	= document.body.offsetHeight;
//		var client_h	= document.body.parentElement.clientHeight;
		var client_h	= document.body.parentElement.offsetHeight;
//		alert(document.body.parentElement.scrollHeight+','+document.body.scrollHeight+','+document.body.parentElement.clientHeight+','+document.body.clientHeight);
//		return;
		var new_h		= parseInt(window.dialogHeight)+scroll_h-client_h;
		if (scroll_h != client_h)	window.dialogHeight=(new_h+'px');
		WND_fitModalHeightID = setTimeout("WND_fitModalHeight()", 500);
	}
	else 
	{
		if (WND_fitModalHeightID) clearTimeout(WND_fitModalHeightID);
		WND_fitModalHeightID = setTimeout("WND_fitModalHeight()", 100);
	}
}




