// JavaScript Document
function reWriteURLs(idElement){
	var el = document.getElementById(idElement);
	var aList = el.getElementsByTagName('a');
	//I read all the a elements inside the passed id element
	for(var i = 0; i < aList.length; i++){
		var addr = aList[i].attributes['href'].nodeValue;		
		var page = addr.split('=');
		page = page[1];
		aList[i].href = '#'+page;
		aList[i].page = page;
		aList[i].onclick = function(){			
			$("#content").load("services/"+this.page+".php");
		}
	}//endfor
};


function  publications(idElement){
	var el = document.getElementById(idElement);
	var aList = el.getElementsByTagName('a');
	//I read all the a elements inside the passed id element
	for(var i = 0; i < aList.length; i++){	
		if(aList[i].rel == 'internal' && aList[i].href != '#'){			
			aList[i].href = "#";
			aList[i].onclick = function(){
				//alert("publications/"+this.id+".php");
				//$("#page_review").load("publications/"+this.id+".php");
				if(document.getElementById('page_'+this.id).style.display == 'none'){
					document.getElementById('page_'+this.id).style.display = 'block';
				} else {
					document.getElementById('page_'+this.id).style.display = 'none';	
				}
			}
		}//endif
	}//endfor	
};

function showcontact(id){
	$("#contact_text").load("contact/contact"+id+".php");
}

// JavaScript Document

var jTabber = {
	selTab: "a",
	selClass: "sel",
	tabs: "",
	tabber: "",
	starterTab: 0,
	objArgs: []
};

jTabber.init = function(){
	//Arguments required
	// 1. id name of the ul that contains the labels
	// 2. selection tag element plus class, eg: "a.sel" 
	// 3. starter tab id, eg: "0" - [OPTIONAL ARGS] !DOESN'T WORK
	this.objArgs = arguments;
	//Overwrite all the li elements
	this.overWriteTabs();
};

jTabber.overWriteTabs = function(){	
	
	this.tabber = document.getElementById(this.objArgs[0]);
	var selElement = this.objArgs[1].split(".");
	this.selTag = selElement[0];//Tag selected
	this.selClass = selElement[1];//Class used for selectino
	this.tabs = this.tabber.getElementsByTagName(this.selTag);
			
	for(i = 0; i < this.tabs.length; i++){
		var currentRef = this.tabs[i].href.split("#");	
		this.tabs[i].rel = currentRef[1];
		this.tabs[i].jsObj = this;
		this.tabs[i].onclick = function(){		
			this.jsObj.selectTab(this);
			return false;
		}
		this.tabs[i].href = "#";
	}//end for
	
	//default starter
	
	if(this.objArgs[2] != "" || this.objArgs[2] == "undefined"){
		this.starterTab	 = this.objArgs[2];
	}
	//init the first element
	//this.selectTab(this.tabs[this.starterTab]);
	this.selectTab(this.tabs[0]);
};

jTabber.selectTab = function(){
	var args = arguments;
	var linkRef = args[0];
	var tabID = linkRef.rel;
	
	$('ul#'+this.objArgs[0]+' '+this.selTag).removeClass(this.selClass);
	$(linkRef).addClass(this.selClass);
	
	for(i = 0; i < this.tabs.length; i++){
		var currentRef = this.tabs[i].rel;			
		if(tabID == currentRef){			
			$("#"+currentRef).show()
		} else {
			$("#"+currentRef).hide()
		}
	}//end for
};

		function errorDisp() {

		alert($msg);
		return false;

		}

		function confirmMe() {
		$msg ="";
		$errors ="no";

		if (!document.emailForm.name.value || document.emailForm.name.value == "") {

		$errors = "yes";
		$msg += "You have not filled in your name.\n"
		}
		
		//Validate Email Address - added by Michael Keegan - 31st March 2006
		var el = document.emailForm.email;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (el.value==0) {
 		$errors = "yes";
       	$msg +="Please enter an Email Address.\n";	}
       	
		else if (!(emailFilter.test(el.value))) { 
       $errors = "yes";
       $msg +="Please enter a valid Email Address.\n";
		}
		//End Validate Email Address - added by Michael Keegan - 31st March 2006
				
		if (!document.emailForm.comments.value || document.emailForm.comments.value == "") {

		$errors = "yes";
		$msg += "Your message is blank.\n"
		}

		if ($errors == "yes") {

		errorDisp();
		return false;

		}

		else { return true; }

		}
