
function clickWait(waitID, submitID) {
	// load the wait image
	var wait_img = document.getElementById(waitID);
	var old_src = wait_img.src;
	wait_img.src = old_src.substring(0, old_src.lastIndexOf('/') + 1) + "wait.gif";
	
	// disappear the submit button
	var submit_div = document.getElementById(submitID);
	if ( submit_div ) {
		submit_div.style.filter = "alpha(Opacity=20);";
	}
}

function clickReset(waitID, submitID) {
	// load the wait image
	var wait_img = document.getElementById(waitID);
	var old_src = wait_img.src;
	wait_img.src = old_src.substring(0, old_src.lastIndexOf('/') + 1) + "odot.gif";
	
	// disappear the submit button
	var submit_div = document.getElementById(submitID);
	if ( submit_div ) {
		submit_div.style.filter = "alpha(Opacity=100);";
	}
}

function toggle(elemID) {
	var bg_elem = document.getElementById('background');
	var elem = document.getElementById(elemID);
	if ( elem.style.display = '' ) {
		elem.style.display = 'none';
		bg_elem.style.display = 'none';
	} else {
		elem.style.display = '';
		bg_elem.style.display = '';
	}
}

function formatDate(d) {
	return d.getFullYear() + '/' + (d.getMonth() + 1) + '/' + d.getDate();
}

function buildURL(workerPath) {
	var url = window.location;
	var path = '';
	var index = url.pathname.indexOf('faces');
	if ( index > 1 ) {
		// this will be true if the webapp is deployed in the root context
		path = url.pathname.substring(0, index);
	}
	return url.protocol + '//' + url.host + path + '/' + workerPath;
}

function addLoadHandler(func) {
	var old_onload = window.onload;
	window.onload = new function() {
		if ( old_onload ) old_onload();
		func();
	};
}