function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function find_ancestor(element, tagname)
{
	if (element.tagName=='BODY') return false;
	if (element.parentNode.tagName==tagname.toUpperCase())
	{
		return element.parentNode;
	}
	else
	{
		return find_ancestor(element.parentNode, tagname);
	}
}

function toggle_display(element, display)
{
	if ( element )
	{
		element.style.display = display ? "inline" : "none";
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function below checks fields are not blank. Pass in field names seperated by commas eg fieldname1, fieldname2        //
function checkFieldsNotBlank(fields)
{
	// Create an array to hold problematic fields
	error_fields_array = new Array();

	// Create the top part of error message which will be used if fields are left blank
	var error_message = 'Please fill in the fields highlighted in red';

	// Strip out spaces in fields supplied
	fields = fields.replace(' ','');

	// Make an array splitting supplied fields on commas
	fields_array = fields.split(",");

	// Count how many fields we're processing
	var num_fields = fields_array.length;

	// Loop thru all our fields and check their value
	for (var i = 0; i < num_fields; i++)
	{
		var current_field = fields_array[i];

		// No hilite object by default
		var current_hilite_object = '';

		// If this field has as optional hilite_object nominated (if : is present in current_field string)
		if (current_field.indexOf(':') > -1)
		{
			current_field_array = current_field.split(":");
			current_field = current_field_array[0];	
			current_hilite_object = current_field_array[1];			
		}
		// Else if this field has other fields attached which will bypass checking this field
		else if (current_field.indexOf('|') > -1)
		{
			current_field_array = current_field.split("|");
			current_field = current_field_array[0];
			current_hilite_object = current_field_array[1];
		}

		// Only do the following if the field actually exists on the page
		if (document.getElementById(current_field) != null)
		{
			// object exists...
			
			// If current_field is too short (ie it has no value)...
			if (document.getElementById(current_field).value.length < 1)
			{
				// Add current_field to our error_message
				//error_message = error_message+'\n'+current_field;

				// If current_field has a nominated hilite object attached to it, hilite that object instead of itself
				// Use the hilite object from here on in
				// and only use current_hilite_object if the object exists on the page
				if (current_hilite_object != '' && document.getElementById(current_hilite_object) != null)
				{
					current_field = current_hilite_object;					
				}

				// add current_field to our error_fields_array 
				error_fields_array.push(current_field);

				// Hi-lite this field 
				// If it's a select box make the bg red as we cannot add borders to select fields in IE (Firefox you can tho)				
				if (document.getElementById(current_field).type == 'select-one')
				{
					document.getElementById(current_field).className = 'input_error_select';
				}
				else // Else give the field a red border
				{
					document.getElementById(current_field).className = 'input_error';
				}
			}
			else
			{
				if (current_hilite_object != '')
				{
					current_field = current_hilite_object;
				}
				// Un-Hi-lite this field (make default style) cause it's ok
				document.getElementById(current_field).className = 'aclassthatdoesnotexist';
			}
		}
	}	
	
	// If we have errors tell them so and do not submit form.
	if (error_fields_array.length > 0)
	{
		// Focus on the first problematic field
		document.getElementById(error_fields_array[0]).focus();

		alert(error_message);
		return false;
	}
	else
	{
		return true;
	}
}
//                                                                                                                      //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////