function attachEventOnLoad(event) {
	if (window.addEventListener) {
		window.addEventListener("load", event, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", event);
	} else if (document.getElementById) {
		window.onload = event;
	}
}

function check_all_checkboxes(state) {
	var elements = document.getElementsByTagName('input');
	for (element in elements) {
		if (elements[element].type == "checkbox") {
			elements[element].checked = state;
		}
	}
}

function human_time_left(seconds) {
	var days = 0;
	var hours = 0;
	var minutes = 0;
	var result = "";

	days = Math.floor(seconds/86400);
	if (days > 0){
		seconds -= days * 86400;
	}

	hours = Math.floor(seconds/3600);
	if (hours > 0){
		seconds -= hours * 3600;
	}

	minutes = Math.floor(seconds/60);
	if (minutes > 0){
		seconds -= minutes * 60;
	}

	if (days > 0) result = result + days + "d ";
	if (hours > 0) result = result + hours + "h ";
	if (minutes > 0) result = result + minutes + "m ";
	if (days == 0 && hours == 0 && minutes <= 3) {
		result = result + seconds + "s ";
	}
	return result;
}

function countdown_human_time_left(seconds) {
	var days = 0;
	var hours = 0;
	var minutes = 0;
	var result = "";

	if (seconds > 0) {
		days = Math.floor(seconds/86400);
		if (days > 0){
			seconds -= days * 86400;
		}

		hours = Math.floor(seconds/3600);
		if (hours > 0){
			seconds -= hours * 3600;
		}

		minutes = Math.floor(seconds/60);
		if (minutes > 0){
			seconds -= minutes * 60;
		}

		if (days > 0) result = result + days + "d ";
	}
	result = hours.toPaddedString(2) + ":" + minutes.toPaddedString(2) + ":" + seconds.toPaddedString(2);
	return result;
}

function getForm(form_id) {
	var request = new Object();
	var nodes = $A(Form.getElements(form_id));
	nodes.each(
		function(node) {
			switch (node.type.toLowerCase()){
				case 'checkbox':
					if (node.checked) {
						request[node.name] = node.value;
					}
				break;
				case 'radio':
					request[node.name] = node.checked;
				break;
				case 'password':
				case 'text':
				case 'textfield':
				case 'textarea':
				case 'select-one':
				case 'select-multiple':
				case 'image':
				case 'hidden':
					if (node.name != "") {
						request[node.name] = node.value;
					}
				break;
			}
		}
	);
	return request;
}

function ProcessingMessage() {
	var element = null;
	var text_element = null;
	var width = 0;
	var height = 0;
	this.construct();
}

ProcessingMessage.prototype.construct = function() {

}

ProcessingMessage.prototype.create = function(width, height) {
	var element = document.getElementById('proccessing_message');
	element.innerHTML = "Loading...";
	element.style.width = width + "px";
	element.style.height = height + "px";

	ProcessingMessage.prototype.element = element;
	ProcessingMessage.prototype.width = width;
	ProcessingMessage.prototype.height = height;
}

ProcessingMessage.prototype.setText = function (text) {
	var element = ProcessingMessage.prototype.element;
	element.innerHTML = text;
}

ProcessingMessage.prototype.setTextWidthHeight = function (text, width, height) {
	var element = ProcessingMessage.prototype.element;
	element.innerHTML = text;
	element.style.width = width + "px";
	element.style.height = height + "px";
}

ProcessingMessage.prototype.show = function (doNotScrollToTop) {
	if (doNotScrollToTop != true) window.scrollTo(0, 0);
	ProcessingMessage.prototype.element.style.display = '';
}

ProcessingMessage.prototype.hide = function () {
	ProcessingMessage.prototype.element.style.display = 'none';
}