function tstring_trim(string)
{// We are not using \s because we don't want "non-breaking spaces to be caught".
	return string.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '');
}






function tiframe_resize_height(name, extra)
{
	if(extra+'' === 'undefined')
		extra = 0;

	//find the height of the internal page
	var the_height = document.getElementById(name).contentWindow.document.body.scrollHeight;

	//change the height of the iframe
	document.getElementById(name).height = the_height + extra;
	document.getElementById(name).onload = function () { tiframe_resize_height(name); }; //for IE
}


function tiframe_go(name, url)
{
	document.getElementById(name).src = url;
}

function link_target(url, target)
{
	if(target === '_top')
		top.location.href = url;
	else
		location.href = url;
}
function running(url)
{
	tiframe_go('run', url);
}

function delete_id(element_prefix, count, url)
{
	var buffer = '';
	var checked_n = 0;
	for(var i=0; i<count; i++)
	{
		var checkbox = document.getElementById(element_prefix+i);
		if(checkbox.checked)
		{
			buffer += checkbox.value + ',';
			checked_n ++;
		}
	}
	var ids = (buffer===''? '': buffer.substring(0, buffer.length-1));
	if(ids === '')
		alert('Warning: 您尚未勾選欲刪除項目。');
	else if(confirm('Info: 您確定要刪除所勾選的「'+checked_n+'個」項目？'))
		running(url+'&ids='+ids);
}