/**
 *	Copyright (c) 2005-2009 H2O Solutions (http://www.h2osolutions.org) 
 *
 *	@brief		Various script helpers used within the project.
 *	@version	20081113
 *
 *	@author		Mathew Schofield
 */


//////////////////////////////////////////////////////////////////////////
//
//	Function Group: Errors
//


/**
 *	?
 */
function add_error(error)
{
	// grab our error list
	var errors = document.getElementById("errorList");
	
	// make sure the error list exists
	if (errors != undefined) {
		errors.innerHTML = errors.innerHTML + "<li>" + error + "</li>";
		
		return true;
	}
	
	// we failed to add the error
	return false;
}


/**
 *	?
 */
function clear_errors()
{
	// grab our error list
	var errors = document.getElementById("errorList");
	
	// make sure the error list exists
	if (errors != undefined) {
		errors.innerHTML = "";
		
		return true;
	}
	
	// we failed to clear the errors
	return false;
}


//////////////////////////////////////////////////////////////////////////
//
//	Function Group: Events
//


//	var form = document.getElementById("recoverForm");
//	form.onsubmit = validate_recover;


/**
 *	?
 */
function attach_event_click(obj, func)
{
	// attach the correct event, depending on the browser
	if (window.addEventListener) {
		obj.addEventListener('click', func, false);
	} else {
		obj.attachEvent('onclick', func);
	}
}


/**
 *	?
 */
function attach_event_hover(obj, func)
{
	// attach the correct event, depending on the browser
	if (window.addEventListener) {
		obj.addEventListener('mouseover', event_callback, false);
		obj.callback = func;
	} else {
		obj.attachEvent('onmouseover', event_callback);
		obj.callback = func;
	}
}


/**
 *	?
 */
function attach_event_leave(obj, func)
{
	// attach the correct event, depending on the browser
	if (window.addEventListener) {
		obj.addEventListener('mouseout', event_callback, false);
		obj.callback = func;
	} else {
		obj.attachEvent('onmouseout', event_callback);
		obj.callback = func;
	}
}


/**
 *	?
 */
function attach_event_load(func)
{
	// attach the correct event, depending on the browser
	if (window.opera) {
		func();
	} else if (window.addEventListener) {
		window.addEventListener('load', func, true);
	} else {
		window.attachEvent('onload', func);
	}
}


/**
 *	?
 */
function attach_event_submit(obj, func)
{
	obj.onsubmit = func;
}


/**
 *	?
 */
function event_callback(evt)
{
	if (window.addEventListener) {
		evt.target.callback(evt.target);
	} else {
		evt.srcElement.callback(evt.srcElement);
	}
}