var MAX_CHARACTERS = 400;

function show_prizes() {
	
	Modalbox.show('/inc/modal_prizes.htm', {
		title :this.title,
		width :486,
		beforeLoad: forceScrollToTop()
	});
}

function show_rules() {
	
	Modalbox.show('/inc/modal_rules.htm', {
		title :this.title,
		width :486,
		beforeLoad: forceScrollToTop()
	});
}

function view(entry_id) {

	var URL = "rpc.php";
	new Ajax.Request(URL, {
		postBody :'action=view&entry_id=' + escape(entry_id),
		onSuccess : function(transport, json) {
		
//			// Do they need to login to view?
//			if ('login' == json.content) {
//				show_login(2, true);
//
//			} else {
				$('entry_' + String(entry_id)).innerHTML = nl2br(json.content);
//			}
		}
	});
}

function sort(order) {
	window.location = '?order=' + escape(order);
}

function load_page(page_no) {
	window.location = '?order=' + escape($F('order')) + '&page='
			+ escape(page_no);
}

function update() {
	load_page($F('page_no'));
}

function modalUpdate() {
	Modalbox.hide();
	update();
}

function show_message(message, refresh) {
	
	forceScrollToTop();
	Modalbox.show('/inc/modal_message.htm', { title :this.title, width :300, params: {'message': message, 'refresh': refresh }});
}

function cancel_changes() {
	update();
}

function forceScrollToTop() {
	scroll(0,0); 
}

// http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_nl2br/
function nl2br(str) {
	// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// + improved by: Philip Peterson
	// + improved by: Onno Marsman
	return (str + '').replace(/([^>])\n/g, '$1<br />\n');
}