 function select(obj)
 {
	 document.getElementById('tab1').className = "tab";
	 document.getElementById('tab2').className = "tab";
	 document.getElementById('tab3').className = "tab";
	 document.getElementById('tab4').className = "tab";
	 document.getElementById('tab5').className = "tab";

	 obj.className = "selectedtab";

	 document.getElementById('page1').style.display = "none";
	 document.getElementById('page2').style.display = "none";
	 document.getElementById('page3').style.display = "none";
	 document.getElementById('page4').style.display = "none";
	 document.getElementById('page5').style.display = "none";

	switch(obj.id)
	{
		case 'tab1':
			document.getElementById('page1').style.display = "block";
			break;
		case 'tab2':
			document.getElementById('page2').style.display = "block";
			break;
		case 'tab3':
			document.getElementById('page3').style.display = "block";
			break;
		case 'tab4':
			document.getElementById('page4').style.display = "block";
			break;
		case 'tab5':
			document.getElementById('page5').style.display = "block";
			break;
	}
 }

//****************************************************************************//
//****                Form Validator Objects                              ****//
//****                                      Dave Smith  23/04/2007        ****//
//****************************************************************************//

var formValidator = Class.create();
formValidator.prototype =
{
	initialize: function(form)
	{
		this.form = $(form);
	    this.form.onsubmit = this.run.bindAsEventListener(this);
	    this.validators = Array();
	    this.items = Array();
	    this.status = true;
	},

    setValidator: function(what,parser, messenger)
	{
	   var what = $(what);
	   this.items.push(what);
	   myValidator = new validator(parser,messenger);
	   this.validators.push(myValidator);
	},

	setOrValidator: function(what,parser,messenger,what2,parser2,messenger2)
	{
	   var what = $(what);
	   var what2 = $(what2);
	   var whats = Array(what,what2);
	   this.items.push(whats);

	   myValidator = new orConditionValidator(parser,messenger,parser2,messenger2);
	   this.validators.push(myValidator);
	},

	run: function(evt)
	{

	    this.status = true;
	    for(var i=0;i<this.validators.length;i++)
		{
	      this.validators[i].clear();
	    }

		for(var i=0;i<this.validators.length;i++)
		{
			//alert("Value : "+this.items[i].value);
			 var result = this.validators[i].validate(this.items[i]);
			 if (!result)
			 {
				//alert("Status set to false")
				this.status = false;
			 }
		}
		return this.status;
	}
};
//****************************   Validators  *********************************//
var validator = Class.create();
validator.prototype =
{
 	initialize: function(parser,messenger)
	{
	  this.value = null;
	  this.parser = parser;
	  this.parser.setParent(this);
	  this.messenger = messenger;
	},

	validate: function(obj)
	{
		this.obj = obj;
		try
		{
		var success = this.parser.parse();
		}
		catch(err)
		{
			alert(err);
		}
		if(!success)
		{
			////alert("no Parse")
			this.messenger.display();
			return false;
		}
		//alert("Parse OK")
		return true;
	},
	clear: function()
	{
		this.messenger.clear()
	}
};

var orConditionValidator = Class.create();
orConditionValidator.prototype =
{
	initialize: function(parser,messenger,parser2,messenger2)
	{
		  this.value = null;
		  this.parser = parser;
		  this.parser.setParent(this);
		  this.messenger = messenger;
		  this.parser2 = parser2;
		  this.parser2.setParent(this);
		  this.messenger2 = messenger2;
	},
	validate: function(objary)
	{
		this.objary = objary;
		this.obj1 = this.objary[0];
		this.obj2 = this.objary[1];
		try
		{
		this.obj = this.obj1
		var success1 = this.parser.parse();
		this.obj = this.obj2
		var success2 = this.parser2.parse();
		}
		catch(err)
		{
			alert(err);
		}
		if(!success1 && !success2)
		{
			//alert("failed Parse")
			if(!success1)
			{
				this.messenger.display();
			//alert("one failed Parse")
			}
			if(!success2)
			{
				this.messenger2.display();
				//alert("two failed Parse")
			}
			//alert('here');
			return false;
		}
		//alert("Parse OK")
		return true;
	},
	clear: function()
	{
		this.messenger.clear()
		this.messenger2.clear()
	}
}
//****************************   Parserers   *********************************//
var regExpParser = Class.create();
regExpParser.prototype =
{
	initialize: function(pattern)
	{
	this.pattern = pattern;
	this.parent = null;
	},

	setParent: function(parent)
	{
		this.parent = parent;
	},

	parse: function()
	{
		//alert("parsing "+this.parent.obj.value+" with "+this.pattern)
		var re = new RegExp(this.pattern);
		//alert("parent" + this.parent)
		var result = this.parent.obj.value.match(re);
	    //alert(result)

		if (result === null) {
			//alert("No Match")
			return false;
		}
		//alert("match")
		return true;
	}
};

var selectParser = Class.create();
selectParser.prototype =
{
	initialize: function(pattern,condition)
	{
	 this.parent = null;
	 this.pattern = pattern;
	 this.condition = condition;
	},

	setParent: function(parent)
	{
		this.parent = parent;
	},

	parse: function(value)
	{
	    //alert("parsing "+this.parent.obj.value+" with "+this.pattern)
		var re = new RegExp(this.pattern);
		//alert("parent" + this.parent)
		var result = this.parent.obj.value.match(re);
		//alert(this.condition.toLowerCase())

		if(this.condition.toLowerCase() == "match")
		{
		  	if (result === null)
			{
				//alert("No Match")
				return false;
			}
		//alert("match")
		return true;
		}
		else if (this.condition.toLowerCase() == "notmatch")
		{
			if (result === null)
			{
				//alert("No match")
		        return true;
			}
			//alert("Match")
			return false;
		}
		else
		{
			//throw error
			throw "Contition must be 'match' or 'notmatch'"
		}
	}
};

var checkBoxGroupParser = Class.create();
checkBoxGroupParser.prototype =
{
	initialize: function(identifier,condition)
	{
	this.identifier = identifier;
	this.condition = condition;
	this.parent = null;
	},

	setParent: function(parent)
	{
		this.parent = parent;
	},

	parse: function()
	{
		//get an array of the checkbokes
		var aryBoxes = Array();
        var result = false

		aryBoxes = document.getElementsByTagName("input");
		for(var i = 0;i<aryBoxes.length;i++)
		{
			var id = aryBoxes[i].id;
			if(id.substring(0,this.identifier.length) == this.identifier)
			{
				if(aryBoxes[i].checked)
				{
					result = true;
				}
			}
		}


		if(this.condition.toLowerCase() == "checked")
		{
		if (result === false) {
			//alert("none Checked")
			return false;
		}
		//alert("Atleast one Checked")
		return true;
		}
		else if (this.condition.toLowerCase() == "notchecked")
		{
	if (result === false) {
			//alert("none Checked")
			return true;
		}
		//alert("Atleast one Checked")
		return false;
		}
		else
		{
			throw "Contition must be 'checked' or 'notchecked'"
		}
	}
};
//***************************   Messengers   *********************************//
var screenMessenger = Class.create();
screenMessenger.prototype =
{
 	initialize: function(where,message)
	{
	this.where = where;
	this.message = message;
	},

	display: function()
	{
	  $(this.where).innerHTML += this.message+"<br/>";
	  $(this.where).style.display = 'block';
	  $(this.where).style.visibility = 'visible';

	},

	clear: function()
	{
	 $(this.where).innerHTML = "";
	 $(this.where).style.display = 'none';
	 $(this.where).style.visibility = 'hidden';
	}
};

var alertMessenger = Class.create();
alertMessenger.prototype =
{
 	initialize: function(message)
	{
	this.message = message;
	},

	display: function()
	{
	  alert(this.message);
	},

	clear: function()
	{
		return
	}
};
//****                Form Validator Objects                              ****//