// list of regular expressions. Can be used in the checks //
var	containsdigits = /\d/;
var	containscharactersotherthandigits = /[^0-9\.]/;

// array of tests //
var	test = new Array();
// array of forms //
var	form_obj = new Array();
// should the form be submitted, or returned //
var dont_submit_form = new Array();

function add_to_array(form_id, data, message, object)
// object for the object array (holds one error check) //
{
	this.form_id = form_id;
 	this.data = data;
 	this.message = message;
 	this.object = object;
}

function new_form(form_object_path, submit_it)
// creates and returns an id for the passed form //
{
    // set the default return value //
	var return_num = -1;
	// if the form exists //
	if(form_object_path!=null)
	{
        // add the form to the form array //
		form_obj[form_obj.length] = form_object_path;
	}
	else
	{
	    // the form_id = the first form in the page //
		form_obj[form_obj.length] = document.forms[0];
	}
	// get the next id for the form //
	return_num = form_obj.length-1;

	// check to see if this form has to be submitted //
	if(arguments.length > 1)
	{
		if(submit_it == true)
		{
			dont_submit_form[return_num] = false;
		}
		else
		{
			dont_submit_form[return_num] = true;
		}
	}
	else
	{
		dont_submit_form[return_num] = false;
	}
	return return_num;
}

function add_check(form_id, data, message, object)
// adds a new check to the array, for the passed form //
{
    // if the passed object exists //
	if (object!='')
	{
	    // add the check to the lists of checks //
		test[test.length] = new add_to_array(form_id, data, message, object);
	}
	else
	{
		test[test.length] = new add_to_array(form_id, data, message, form_obj);
	}
}

function check_it(form_id)
// runs through the list of error checks for the passed form //
{
var	loop = 0;
var	err = false;
var	message_str = '';
var	line_str='_________________________________________';
var	spaces='                                                                           ';
	do
	{
	    // if the the test is true (i.e. creates an error) and the test belongs to the form //
		if (eval(test[loop].data) && (test[loop].form_id==form_id))
		{
		    // display the appropriate message //
			message_str = line_str+"\n\nScotland On L!ne.com\n"+line_str+"\n\nWARNING:\n\n" + test[loop].message + "\n\n"+line_str+"";
			alert(message_str);
			test[loop].object.focus();
			err = true;
		}
	loop = loop+1;
	}
	while ((loop<test.length) && (!err))
	// keep going until all the tests are carried out, or the current test is trapped //


    // if there is no errors trapped then submit the relevant form //
	if (!err)
	{
		if(dont_submit_form[form_id] == true)
		{
			return true;
		}
		else
		{
			form_obj[form_id].submit();
		}
	}
	else
	{
		if(dont_submit_form[form_id] == true)
		{
			return false;
		}
	}
}
