/**
 * Package main JavaScript
 *
 * @package myEASYbackup
 * @author Ugo Grandolini
 * @version 0.0.6
 */

/**
 * Return an array with the page dimensions [width, height]
 */
function getPageDimensions() {
	var body = document.getElementsByTagName('body')[0];
	var bodyOffsetWidth = 0, bodyOffsetHeight = 0, bodyScrollWidth = 0, bodyScrollHeight = 0, this_pagedim = [0,0];

	if(typeof document.documentElement!='undefined' && typeof document.documentElement.scrollWidth!='undefined')
	{
		this_pagedim[0] = document.documentElement.scrollWidth;
		this_pagedim[1] = document.documentElement.scrollHeight;
	}
	bodyOffsetWidth  = body.offsetWidth;
	bodyOffsetHeight = body.offsetHeight;
	bodyScrollWidth  = body.scrollWidth;
	bodyScrollHeight = body.scrollHeight;

	if(bodyOffsetWidth>this_pagedim[0])  { this_pagedim[0] = bodyOffsetWidth; }
	if(bodyOffsetHeight>this_pagedim[1]) { this_pagedim[1] = bodyOffsetHeight; }
	if(bodyScrollWidth>this_pagedim[0])  { this_pagedim[0] = bodyScrollWidth; }
	if(bodyScrollHeight>this_pagedim[1]) { this_pagedim[1] = bodyScrollHeight; }

	return this_pagedim;
}

function set_waiting_message(typ) {

	document.body.style.cursor = 'wait';

	var popWin = document.getElementById('myeasybackup_popWin');
	if(popWin)
	{
		if(typ=='up')	//	0.0.5
		{
			document.getElementById('wait_upload').style.display='block';	//	0.0.6
		}
		else
		{
			document.getElementById('wait_backup').style.display='block';	//	0.0.6
		}

		var this_pagedim = getPageDimensions();
		popWin.style.top    = '0px';
		popWin.style.left   = '0px';
		popWin.style.width  = this_pagedim[0] + 'px';
		popWin.style.height = this_pagedim[1] + 'px';
		popWin.style.display= 'block';
	}
	else
	{
		setTimeout("set_waiting_message('" + typ +"');", 250);
		return;
	}
}

function hide_waiting_message() {
	//
	//	@since 0.0.5
	//
	document.body.style.cursor = 'default';
	var popWin = document.getElementById('myeasybackup_popWin');
	if(popWin)
	{
		popWin.style.display= 'hide';
	}
	else
	{
		setTimeout('hide_waiting_message()', 250);
		return;
	}
}
