//<![CDATA[

var a_images = new Array();

function addEvent ( o, e, f ) {
	if ( o.addEventListener ) {
		o.addEventListener ( e, f, true);
		return true;
	}
	else if ( o.attachEvent ) {
		return o.attachEvent ( "on" + e, f );
	}
	else {
		return false;
	}
}

function resize_window ( w, i_width, i_height )
{
	if ( i_width > 0 )
	{
		if ( i_width > screen.availWidth )
			i_width = screen.availWidth;
	}
	else
		i_width = screen.availWidth;

	if ( i_height > 0 )
	{
		if ( i_height > screen.availHeight )
			i_height = screen.availHeight;
	}
	else
		i_height = screen.availHeight;

	w.resizeTo ( i_width, i_height );
	w.moveTo ( 0, 0 );
}

function open_window ( s_url, s_name, i_width, i_height, s_param )
{
	s_options = "directories=no,location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=yes";
	if ( s_param > " " )
		s_options += "," + s_param;	//	append parameters so they overwrite options

	s_url = s_url.replace( /\s+/gi, "+" );

	w = window.open ( s_url, s_name, s_options );
	resize_window ( w, i_width, i_height );	// if window contains old content of different size
	w.focus();
}

function preload_images ()
//	preload_images ( "/alias/first.gif", "/alias/second.gif", "/alias/third.gif" );
{
	for ( i = 0; i < preload_images.arguments.length; i++ )
	{
		a_images[i] = new Image();
		a_images[i].src = preload_images.arguments[i];
	}
}

function open_image ( s_url, s_img_url, s_param )
{
	s_options = "directories=no,location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=yes";

	img = new Image();
	img.src = s_img_url;
	s_options += ",width=" + ( img.width + 50 ) + ",height=" + ( img.height + 90 );

	if ( s_param > " " )
		s_options += "," + s_param;	//	append parameters to overwrite defaults

	window.open ( s_url + s_img_url, 'image', s_options );
}

function goto_location ( o_target, s_url )
{
	s_url = s_url.replace( /\s+/gi, "+" );
	o_target.location.href = s_url;
}

function post_form ( f_obj, s_url )
/*	Submit form, facilitating multiple alternative form actions,
	and postponing the definition of the form action
	until after rendering of the HTML body has commenced. */
{
	f_obj.action = s_url;
	f_obj.submit();
}

function serialise_form_input ( f_obj )
{
	e = f_obj.elements;
	s_form = "";
	for ( i = 0; i < e.length; i++ )
	{
		fld = e[i];
		if ( fld.type == "file" ||
		    fld.type == "edit" ||
		    fld.type == "text" ||
		    fld.type == "select-one" ||
		    fld.type == "hidden" )
			s_form += "&" + fld.name + "=" + fld.value;
		else if ( fld.type == "radio" ||
		    fld.type == "checkbox" )
			s_form += "&" + fld.name + "=" + fld.checked;
//		else if ( fld.type == "button" );
//		else
//			alert ( "Field type not supported: type=" + fld.type + ", name= " + fld.name + "=" + fld.value );
	}
//	alert ( s_form );
	return s_form;
}

function get_radio_value ( radio_fld ) {
	if ( !radio_fld )
		return "";

	var radio_length = radio_fld.length;

	if ( radio_length == undefined )
		if ( radio_fld.checked )
			return radio_fld.value;
		else
			return "";

	for ( i = 0; i < radio_length; i++ ) {
		if ( radio_fld[i].checked ) {
			return radio_fld[i].value;
		}
	}

	return "";
}

function toggle_on_off ( obj )
{
	obj.value = ( obj.checked ) ? 1 : 0;
}

function select_table ( s_url )
{
	s_param = validate_input ();
	if ( s_param > " " )
	{
		goto_location ( parent.frames[1], s_url + s_param );
	}
}

function show_local_date ( i_days )
{
	var today = new Date ();
	if ( i_days > 0 )
		today.setDate ( today.getDay () + i_days );

	s_date = today.toLocaleDateString ();
	document.write ( s_date );
	return s_date;
}

function show_local_datetime ( i_seconds )
{
	var today = new Date ();
	if ( i_seconds > 0 )
		today.setSeconds ( today.getSeconds () + i_seconds );

	s_date = today.toLocaleString ();
	document.write ( s_date );
	return s_date;
}

function debug_object ( obj )
{
	s_debug = "";
	for ( i = 0; i < obj.length; i++ )
	{
		fld = obj[i];
		s_debug += "name:" + fld.name + "  id:" + fld.id + "  value:" + fld.value + "\n";
	}
	alert ( "Action:\n" + obj.action + "\n\nFields:\n" + s_debug );
}

//	javascript field validation functions
var type_numeric = '0123456789';
var type_lowercase = 'abcdefghijklmnopqrstuvwxyz';
var type_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

function is_valid ( s_value, s_type )
{
	if ( s_value == "" )
		return true;

	for ( i=0; i < s_value.length; i++ )
	{
		if ( s_type.indexOf ( s_value.charAt (i), 0 ) == -1 )
			return false;
	}
	return true;
}

function is_numeric ( s_value )
{
	return is_valid ( s_value, type_numeric );
}

function is_lowercase ( s_value )
{
	return is_valid ( s_value, type_lowercase );
}

function is_uppercase ( s_value )
{
	return is_valid ( s_value, type_uppercase );
}

function is_alphabetic ( s_value )
{
	return is_valid ( s_value, type_lowercase + type_uppercase );
}

function is_alphanumeric ( s_value )
{
	return is_valid ( s_value, type_lowercase + type_uppercase + type_numeric );
}

//]]>
