//short form for getElementById method
function e(id){
	
	return document.getElementById(id);
	
}



// Funcitons to control links and menu visibility
function activeLink(id)
{
	e(id).style.backgroundColor = '#333333';
	e(id).style.color = '#ffffff';
}



// Get all elements based on class provided
function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}


// Create rounded corner divs
function roundedCorners() {
   var divs = document.getElementsByTagName('div');
   var rounded_divs = [];
   /* First locate all divs with 'rounded' in their class attribute */
   for (var i = 0; i < divs.length; i++) {
	   if (/\brounded\b/.exec(divs[i].className)) {
		 rounded_divs[rounded_divs.length] = divs[i];
	   }
   }
   /* Now add additional divs to each of the divs we have found */
   for (var i = 0; i < rounded_divs.length; i++) {
	 var original = rounded_divs[i];
	 /* Make it the inner div of the four */
	 original.className = original.className.replace('rounded', '');
	 /* Now create the outer-most div */
	 var tr = document.createElement('div');
	 tr.className = 'yellow-285';
	 
	 /* Swap out the original (we'll put it back later) */
	 original.parentNode.replaceChild(tr, original);
	 /* Create the two other inner nodes */
	 var tl = document.createElement('div');
	 var br = document.createElement('div');
	 /* Now glue the nodes back in to the document */
	 tr.appendChild(tl);
	 tl.appendChild(br);
	 br.appendChild(original);
   }
}



// Create rounded corner divs
function roundedCornersNew() {
   var divs = document.getElementsByTagName('div');
   var rounded_divs = [];
   /* First locate all divs with 'rounded' in their class attribute */
   for (var i = 0; i < divs.length; i++) {
	   if (/\brounded\b/.exec(divs[i].className)) {
		 rounded_divs[rounded_divs.length] = divs[i];
	   }
   }
   /* Now add additional divs to each of the divs we have found */
   for (var i = 0; i < rounded_divs.length; i++) {
	 var original = rounded_divs[i];
	 /* Copy the contents of the original div and then erase the content */
	 var original_content = original.innerHTML;
	 original.innerHTML = '';

	/* Create the two other inner nodes */
	 var tr = document.createElement('div');
	 var tl = document.createElement('div');
	 var br = document.createElement('div');
	 /* Now glue the nodes back in to the document */
	 original.appendChild(tr);
	 tr.appendChild(tl);
	 tl.appendChild(br);
	 br.innerHTML = original_content;
   }
}



function showHide(id)
{
	var id = document.getElementById(id)
	
	if(id.style.display == "block")
	{
		id.style.display = "none"
	} else {
		id.style.display = "block"
	}
}



function dropDown()
{
	var pane = this.id+'_pane';
	
	if(e(pane))
	{	
	  if(e(pane).style.display == "block")
	  {
		  e(pane).style.display = "none"
	  } else {
		  e(pane).style.display = "block"
	  }
	}
}



//alternates the background colour of each table row
function tableRowColor(){
	
	var tables = getElementsByClass('table1');
	
	for(i=0; i < tables.length; i++){
			
		var rows = tables[i].rows;

		for(j=0; j < rows.length; j++){
			
			if(j % 2){
				rows[j].style.backgroundColor = '#eeeeee';
			}else{
				rows[j].style.backgroundColor = '#dddddd';
			}
			
		}
		
	}
	
}


// Create dropdown menu IDs
function createMenus()
{
	var dropdownTabs = getElementsByClass('dropdown-li');
	//var menus = new Array();	//create array of menu IDs

	for(var i = 0; i < dropdownTabs.length; i++)
	{
		dropdownTabs[i].id = 'tab'+i;
		var dropdownPanes = dropdownTabs[i].getElementsByTagName('ul');
		
		YAHOO.util.Event.addListener('tab'+i, "mouseover", dropDown);
		YAHOO.util.Event.addListener('tab'+i, "mouseout", dropDown);
		
		for(var j = 0; j < dropdownPanes.length; j++)
		{
			dropdownPanes[j].id = 'tab'+i+'_pane';
		}
	}
	
	return menus;
}


/*
addPrintLink function by Roger Johansson, www.456bereastreet.com
*/
var addPrintLink = {
	init:function(sTargetEl,sLinkText) {
		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
		if (!document.getElementById(sTargetEl)) {return;} // Check that the target element actually exists
		if (!window.print) {return;} // Check that the browser supports window.print
		var oTarget = document.getElementById(sTargetEl);
		var oIcon = document.createElement('img');
		oIcon.src = '/images/main/print_icon.gif';
		oIcon.alt = '';
		oIcon.className = 'inline-icon';
		var oLink = document.createElement('a');
		oLink.id = 'print-link'; // Give the link an id to allow styling
		oLink.href = '#'; // Make the link focusable for keyboard users
		oLink.appendChild(oIcon);
		oLink.appendChild(document.createTextNode(sLinkText));
		oLink.onclick = function() {window.print(); return false;} // Return false prevents the browser from following the link and jumping to the top of the page after printing
		//oTarget.appendChild(oIcon);
		oTarget.appendChild(oLink);
	},
/*
addEvent function included here for portability. Replace with your own addEvent function if you use one.
*/
/* addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */
	addEvent:function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};

addPrintLink.addEvent(window, 'load', function(){addPrintLink.init('printlink',' Print this page');});


//YAHOO.util.Event.onDOMReady(tableRowColor);
YAHOO.util.Event.onDOMReady(createMenus);
YAHOO.util.Event.onDOMReady(roundedCornersNew);
