function MegapixelsToPrintSize(mp, aspect_num, aspect_denom, dpi)
{
	if (typeof aspect_num == 'undefined') aspect_num = 3;
	if (typeof aspect_denom == 'undefined') aspect_denom = 2;
	if (typeof dpi == 'undefined') dpi = 240;
	var width = Math.floor(Math.sqrt((mp*1048576*aspect_num)/(dpi*dpi*aspect_denom)));
	var height = Math.floor(width*aspect_denom/aspect_num);
	return width + '" x ' + height + '"';
}

function ProblemReportPopup()
{
	var href = 'report_problem.php?';
	href = href + 'url=' + encodeURIComponent(window.location);
	window.open(href, 'report_problem', 'width=554,height=840');
}

// Icon input to form functions
function ToggleIcon(node)
{
	var input = node.getElementsByTagName("input")[0];
	var cover = node.getElementsByTagName("div")[0];
	if (input.value != 0)
	{
		input.value = 0;
		cover.style.display = "block";
	}
	else
	{
		input.value = 1;
		cover.style.display = "none";
	}
}

function SelectIcon(node)
{
	for (var current = node.parentNode.firstChild; current; current = current.nextSibling)
		if (current != node && current.nodeName == 'DIV')
		{
			current.getElementsByTagName("input")[0].value = 0;
			current.getElementsByTagName("div")[0].style.display = "block";
		}
	ToggleIcon(node);
}

function notice_resize(current_height, target_height)
{
	var outer = document.getElementById("notice_frame");
	var inner = document.getElementById("notice_area");

	if (current_height != target_height)
	{
		var dist = Math.abs(current_height - target_height);
		var step = dist > 20 ? 4 : 1;
		if (current_height < target_height)
			current_height += step;
		else
			current_height -= step;
		inner.style.height = current_height+"px";
		setTimeout("notice_resize("+current_height+", "+target_height+")", 5);
	}
	else if (target_height == 0)
	{
		notice_remove();
	}
	else
	{
		// Give 30 seconds to read the content.
		// setTimeout("notice_request()", 30000);
	}
}

function notice_receive()
{
	var response = notice_async.responseText;
	if (response)
	{
		var outer = document.getElementById("notice_frame");
		outer.style.display = "block";

		var inner = document.getElementById("notice_area");
		var current_height = inner.offsetHeight ? inner.offsetHeight : 1;
		inner.innerHTML = response;
		inner.style.height = 'auto';
		inner.style.visibility = 'hidden';
		inner.style.overflow = 'hidden';
		inner.style.display = 'block';

		var target_height = inner.offsetHeight;
		inner.style.height = current_height+"px";
		inner.style.visibility = "visible";
		inner.style.position = "static";

		setTimeout("notice_resize("+current_height+", "+target_height+")", 5);
	}
	else
	{
		// Nothing for this page, try one hour later.
		setTimeout("notice_request()", 3600000);
	}
}

function notice_setup()
{
	notice_async = new XMLHttpRequest();
	notice_async.onreadystatechange = function()
	{
		if (notice_async.readyState == 4 && notice_async.status == 200)
			notice_receive();
	}
}

function notice_request(ref)
{
	notice_async.open("GET", "/notice.php?ref="+ref, true);
	notice_async.send();
}

function notice_start(ref)
{
	notice_setup();
	setTimeout("notice_request('"+ref+"')", 0);
}

function notice_show(ref)
{
	notice_setup();
	notice_async.open("GET", "/notice.php?ref="+ref, false);
	notice_async.send();
	notice_receive();
}

function notice_remove()
{
	var outer = document.getElementById("notice_frame");
	outer.style.display = "none";
}

function notice_hide()
{
	var inner = document.getElementById("notice_area");
	var current_height = inner.offsetHeight;
	var target_height = 0;
	inner.style.height = current_height+"px";
	setTimeout("notice_resize("+current_height+", "+target_height+")", 5);
}
