undefined;

// ---------------------------------------------------------------------------- //
/*	$
*/
// ---------------------------------------------------------------------------- //

function $()
{
	if( arguments.length == 1 )
	{
		if( arguments[0] == '' )
			alert( 2 );

		if( typeof( arguments[0] ) == 'string' )
			return document.getElementById( arguments[0] );
		else
			return undefined;
	}
	else
	{
		var		elems = [];
		
		for( var i = 0; i < arguments.length; i++)
		{
			if( typeof( arguments[i] ) == 'string' )
				elems[elems.length] = document.getElementById( arguments[i] );
		}
		
		return elems;
	}
}


// ---------------------------------------------------------------------------- //
/*	String.trim()
*/
// ---------------------------------------------------------------------------- //

String.prototype.trim = function()
{
	var	str = this.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}


// ---------------------------------------------------------------------------- //
/*	lz_add_to_onload
*/
// ---------------------------------------------------------------------------- //

function lz_add_to_onload( f )
{
	if( typeof( window.onload ) != 'function')
		window.onload = f;
	else
	{
		var		old_onload = window.onload;
		
		window.onload = function()
		{
			old_onload();
			f();
		}
	}
}

// ---------------------------------------------------------------------------- //
/*	lz_force_numeric_input
	
	Originally: ForceNumericInput by Gary Dryden. Licensed under CPOL.
*/
// ---------------------------------------------------------------------------- //

function lz_force_numeric_input(This, AllowDot, AllowMinus)
{
	if(arguments.length == 1)
	{
		var s = This.value;
		// if "-" exists then it better be the 1st character
		var i = s.lastIndexOf("-");
		if(i == -1)
			return;
		if(i != 0)
			This.value = s.substring(0,i)+s.substring(i+1);
		return;
	}
	
	var code = event.keyCode;
	switch(code)
	{
		case 8:     // backspace
		case 9:     // tab
		case 37:    // left arrow
		case 39:    // right arrow
		case 46:    // delete
			event.returnValue=true;
			return;
	}
	if(code == 189)     // minus sign
	{
		if(AllowMinus == false)
		{
			event.returnValue=false;
			return;
		}

		// wait until the element has been updated to see if the minus is in the right spot
		var s = "ForceNumericInput(document.getElementById('"+This.id+"'))";
		setTimeout(s, 250);
		return;
	}
	
	if(AllowDot && (code == 190 || code == 110))
	{
		if(This.value.indexOf(".") >= 0)
		{
			// don't allow more than one dot
			event.returnValue=false;
			return;
		}
		event.returnValue=true;
		return;
	}
	
	// allow character of between 0 and 9
	if(code >= 48 && code <= 57)
	{
		event.returnValue=true;
		return;
	}
	if(code >= 96 && code <= 105) // 0-9 from a keypad
	{
		event.returnValue=true;
		return;
	}
	event.returnValue=false;
}
	
// ---------------------------------------------------------------------------- //
/*	lz_validate_ids
	
*/
// ---------------------------------------------------------------------------- //

function lz_validate_ids( ids )
{
	var			inputs = [];
	var			id_count = ids.length;
	
	for( var i = 0; i < id_count; i++ )
	{
		var		elem = document.getElementById( ids[i] );
		
		if( elem != undefined )
			inputs[inputs.length] = elem;
		else
			alert( ids[i] );
	}
	
	return validate_inputs( inputs );
}


// ---------------------------------------------------------------------------- //
/*	lz_validate_inputs
	
	This function accepts a series of HTML objects and checks their value.
	
	It assumes these fields will have <label>s with ids that are the same as 
	the field + "_req" (e.g., f_name & f_name_req) if that field is required.
	
	It also assumes any email address in the form will end with '_email'.
	
	In the case of radio buttons, the first element should have an id the same
	as the name, but no others should have ids. Other input types should have
	the same name and id.
	
	Any field that does not contain data will have its label's class changed
	to "required". The class name is cleared every time data is found in a 
	required fields, so class names shouldn't carry class names of their own.
*/
// ---------------------------------------------------------------------------- //

function lz_validate_inputs( inputs )
{
	var			n = inputs.length;
	var			form_ok = true;
	
	for( var i = 0; i < n; i++ )
	{
		var		id = inputs[i].id;
		var		req = $( id + "_req" );
		
		if( req != undefined )
		{
			var		value = '';
			
			if( inputs[i].type == 'radio' )	// Note: Radio Group name must be same as id.
				value = get_radio_value( inputs[i].name );
			
			else if( inputs[i].type == 'checkbox' )
				value = inputs[i].checked ? inputs[i].value : '';
			
			else
				value = inputs[i].value;
				
			if( value.trim() == '' )
			{
				req.className = 'required';
				form_ok = false;
			}
			else
			{
				if( id.substr( id.length-6, 6 ) == '_email' )
				{
					if( value.search( "^[A-Za-z0-9._\\-]+@[A-Za-z0-9._\\-]+\\.[A-Za-z]{2,4}$" ) == -1 )
					{
						req.className = 'required';
						form_ok = false;
					}
					else
						req.className = '';
				}
				else
					req.className = '';
			}
		}
	}
	
	if( !form_ok )
		alert( "Please complete the required fields, highlighted in red." );
	
	return form_ok;
}


// -------------------------------------------------------------------------- //
/*	lz_cookies_enabled

*/
// -------------------------------------------------------------------------- //

function lz_cookies_enabled()
{
	lz_set_cookie( 'cookie_test', '1' );
	var result = lz_get_cookie( 'cookie_test' );
	
	if( result )
	{
		lz_delete_cookie( 'cookie_test' );
		return true;
	}
	
	return false;
}
	

// -------------------------------------------------------------------------- //
/*	lz_get_cookie

*/
// -------------------------------------------------------------------------- //

function lz_get_cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;

	if( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
		return null;

	if( start == -1 )
		return null;

	var end = document.cookie.indexOf( ";", len );
	if( end == -1 )
		end = document.cookie.length;

	return unescape( document.cookie.substring( len, end ) );
}
	
// -------------------------------------------------------------------------- //
/*	lz_set_cookie

*/
// -------------------------------------------------------------------------- //

function lz_set_cookie( name, value, expires, path, domain, secure )
{
	var today = new Date();

	today.setTime( today.getTime() );
	if( expires )
		expires = expires * 1000 * 60 * 60 * 24;
	
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" + escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// -------------------------------------------------------------------------- //
/*	lz_delete_cookie
*/
// -------------------------------------------------------------------------- //

function lz_delete_cookie( name, path, domain )
{
	if( lz_get_cookie( name ) )
	{
		document.cookie = name + "=" + 
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +	
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}


// ---------------------------------------------------------------------------- //
/*	lz_go_to
	
	Takes the window base into consideration for browsers that 
	don't think to (i.e., IE).
*/
// ---------------------------------------------------------------------------- //

function lz_go_to( relative_path )
{
	var		base_tags = document.getElementsByTagName( 'base' );
	var		base = '';
	
	if( base_tags != undefined )
		base = base_tags[0].href;
	
	window.location.href = base + relative_path
}


// ---------------------------------------------------------------------------- //
/*	lz_toggle_visibility -> lz_swap
*/
// ---------------------------------------------------------------------------- //

// ---------------------------------------------------------------------------- //
/*	lz_swap
*/
// ---------------------------------------------------------------------------- //

function lz_swap( hide, show )
{
	lz_hide( hide );
	lz_show( show );
}


// ---------------------------------------------------------------------------- //
/*	lz_hide
*/
// ---------------------------------------------------------------------------- //

function lz_hide( id )
{
	if( $(id) != undefined )
	{
		$(id).old_display = $(id).style.display;
		$(id).style.display = 'none';
	}
}


// ---------------------------------------------------------------------------- //
/*	lz_show
*/
// ---------------------------------------------------------------------------- //

function lz_show( id )
{
	if( $(id) != undefined )
	{
		var old_display = $(id).style.display;
		
		if( arguments.length > 1 )		
			$(id).style.display = arguments[1];

		else if( $(id).old_display == undefined || $(id).old_display == '' )
			$(id).style.display = 'block';

		else
			$(id).style.display = $(id).old_display;
			
		$(id).old_display = old_display;
	}
}

// ---------------------------------------------------------------------------- //
/*	lz_add_class
*/
// ---------------------------------------------------------------------------- //

function lz_add_class( row_elem, class_name )
{
	row_elem.className += ' ' + class_name;
}

// ---------------------------------------------------------------------------- //
/*	lz_hover_row
*/
// ---------------------------------------------------------------------------- //

function lz_remove_class( row_elem, class_name )
{
	if( row_elem.className == class_name )
		row_elem.className = '';
	else
		row_elem.className = row_elem.className.replace( ' ' + class_name, '' );
}


// -------------------------------------------------------------------------- //
/*	lz_form_get_float

*/
// -------------------------------------------------------------------------- //

function lz_form_get_float( id, reset_value )
{
	var			id_elem = document.getElementById( id );
	var			id_value = 0;
	
	if( id_elem !== undefined )
	{
		id_value = parseFloat( id_elem.value );
		
		if( isNaN( id_value ) || (id_value < 0) )
		{
			id_value = 0;
			id_elem.value = reset_value;
			try{ id_elem.focus(); } catch (e) {} 
		}
		else
			id_elem.value = id_value; // Send back the parsed data to clean the field.
	}
	
	return id_value;
}

// -------------------------------------------------------------------------- //
/*	lz_form_get_int

*/
// -------------------------------------------------------------------------- //

function lz_form_get_int( id, reset_value )
{
	var			id_elem = document.getElementById( id );
	var			id_value = 0;
	
	if( id_elem !== undefined )
	{
		id_value = parseInt( id_elem.value );

		if( isNaN( id_value ) || (id_value < 0) )
		{
			id_value = reset_value;
			id_elem.value = reset_value;
			try{ id_elem.focus(); } catch (e) {} 
		}
		else
			id_elem.value = id_value; // Send back the parsed data to clean the field.
	}
	
	return id_value;
}


//	-----------------------------------------------------------------------	//
//	lz_form_get_radio
//	
//	Get the value of a radio button by element name.
//	-----------------------------------------------------------------------	//

function lz_form_get_radio( element_name )
{
	var		elem = document.getElementsByName( element_name );
	
	for( var i=0; i < elem.length; i++)
	{
		if( elem.item(i).checked )
			return elem.item(i).value;
	}
	
	return '';
}

//	-----------------------------------------------------------------------	//
//	lz_form_set_radio
//	
//	Set the value of a radio button by element name.
//	-----------------------------------------------------------------------	//

function lz_form_set_radio( element_name, element_value )
{
	var		elem = document.getElementsByName( element_name );
	
	for( var i=0; i < elem.length; i++)
	{
		alert( elem.item(i).value + ' - ' + element_value );
		if( elem.item(i).value == element_value )
			elem.item(i).checked = true;
		else
			elem.item(i).checked = false;
	}
}

//	-----------------------------------------------------------------------	//
//	lz_form_disable_radio
//	
//	Set the value of a radio button by element name.
//	-----------------------------------------------------------------------	//

function lz_form_disable_radio( element_name, state )
{
	var		elem = document.getElementsByName( element_name );
	var		len = elem.length;
	
	for( var i=0; i < len; i++)
	{
		if( state == true )
			elem.item(i).checked = false;
		elem.item(i).disabled = state;
	}
}




// ---------------------------------------------------------------------------- //
/*	News_Editor Class
	
	
*/
// ---------------------------------------------------------------------------- //

function NewsEditor( tbl_name )
{
	
	this.base_id = "lz_" + tbl_name;
	this.current_menu = this.base_id + "_index_" + ($( this.base_id + '_start_year' ).value);
	
	this.edit = function( msg_id )
	{
		var id = msg_id.substr( msg_id.lastIndexOf("_") + 1, 6 );
		
		$( this.base_id + "_form_" + id ).style.display = "block";
		$( this.base_id + "_" + id ).style.display = "none";
	}
	
	this.cancel_edit = function( msg_id )
	{
		var id = msg_id.substr( msg_id.lastIndexOf("_") + 1, 6 );
		
		$( this.base_id + "_form_" + id ).style.display = "none";
		$( this.base_id + "_" + id ).style.display = "block";
	}
	
	this.toggle_menu = function( toggle_id )
	{
		if( toggle_id != this.current_menu )
		{
			if( this.current_menu )
			{
				$( this.current_menu + "_box" ).style.display='none';
				$( this.current_menu ).className = "toggle_menu_box";
			}
			
			$( toggle_id + "_box" ).style.display='block';
			$( toggle_id ).className = "toggle_menu_box selected";
			
			this.current_menu = toggle_id;
		}
	}
}


// ---------------------------------------------------------------------------- //
/*	lz_change_image
*/
// ---------------------------------------------------------------------------- //

function lz_change_image( id, value )
{
	var			img = $(id);
	
	if( (img != undefined) && (value != '') )
	{
		var		path = img.src;
		var		pos = path.lastIndexOf( '/' );
		
		if( pos < 0 )
			path = '';
		else
			path = path.substr( 0, pos + 1 );
		
		img.src = path + value;
	}
}


// -------------------------------------------------------------------------- //
/*	MESSAGE CLASS (PHP)

	These functions are used in conjuction with the PHP Message class.
*/
// -------------------------------------------------------------------------- //

var		lz_ids_to_clear = [];

function lz_add_id_to_clear( id )
{
	if( _lz_ids_to_clear.length == 0 )
		setTimeout( clear_ids, 3000 );
	
	_lz_ids_to_clear[ _lz_ids_to_clear.length ] = id;
}

function lz_clear_ids()
{
	var	n = _lz_ids_to_clear.length;
	
	for( var i = 0; i < n; i++ )
	{
		var elem = document.getElementById( _lz_ids_to_clear[i] );
		if( elem != undefined )
			elem.style.display='none';
	}
}

// -------------------------------------------------------------------------- //
/*	lz_draw_ml

*/
// -------------------------------------------------------------------------- //

function lz_draw_ml( to )
{
	document.write("<a href='javascript:lz_send_ml(\"" + to + "\");'>" + to + "@liv" + "clean.ca</a>" );
}


// -------------------------------------------------------------------------- //
/*	lz_send_ml

*/
// -------------------------------------------------------------------------- //

function lz_send_ml( to )
{
	document.location = "mai" + "lt" + "o:" + to + "@liv" + "clean.ca";
}


