/**
 * Attach this method to the onclick event of a link to have 
 * the link action submitted as a POST request instead of a 
 * regular GET request.
 * 
 * On the server-side the action should validate that the request
 * was sent as a POST and not a GET.
 * 
 * Example: <a href="/index.php" onClick="return linkAsPost(this)">Link</a>
 * 
 * @param Object link
 * @returns {Boolean}
 */
function linkAsPost(link,params) 
{
	var form = document.createElement('form');
	form.setAttribute("method","POST");
	form.setAttribute("action",link.href);
	document.getElementsByTagName("body").item(0).appendChild(form);
	if (params) {
		for (var k in params) {
			var el = document.createElement('input');
			el.setAttribute("type","hidden");
			el.name = k;
			el.value = params[k];
			form.appendChild(el);
		}
	}
	form.submit();
	return false;
}

/**
 * Add a confirmation message to the POST action on a 
 * link using linkAsPost()
 * 
 * @param msg
 * @param link
 * @returns {Boolean}
 */
function doPostAction(msg,link,params) 
{
	if (confirm(msg)) {
		return linkAsPost(link,params);
	}
	return false;
}

/**
 * When a checkbox in a table row is checked, this applies
 * the "selected" class to the row.
 * 
 * @param Checkbox cb
 * @param int row
 */
function highlightParentRow(cb,row)
{
	var cb = $(cb)
	var row = $("#row-"+row);
	
	if (cb.attr("checked")) {
		row.addClass('selected');
	} else {
		row.removeClass('selected');
	}
		
}


