// JavaScript Document
function RefreshMenus() {
	var menu_list = document.getElementsByTagName('select'); 
	var i; 
	for (i=0; i<menu_list.length; i++){
		menu_list[i].selectedIndex=0;
	}
}

function RollOver(){
	if(document.getElementById && document.createTextNode){
		var tables=document.getElementsByTagName('table');
		window.orgPicture = document.getElementById('org_pic'); // make this global
			for(var i=0; i<tables.length; i++){
				if(tables[i].className=='info_table'){
					for(var j=1; j<tables[i].rows.length; j++){ // first row is a header, start with the row 1
					var row = tables[i].rows[j];
					var cells = row.cells;
					var lastCell = cells[cells.length - 1];
					if(lastCell.className == "thumb"){
					var images = lastCell.getElementsByTagName("img");
						if(images && images.length > 0){
						row.image = images[0]; // take first image	
						row.onmouseover = function(){
						// row is passed as this
						if(this.image)
							setOrgPicture(this.image.src, this.image.alt);
						else
						setEmptyImage("No picture is available");
						return false;
						}
						row.onmouseout = function(){
						setEmptyPicture();
						return false;
						}
					}
					} //className == thumb
				}//end for
			}//end if info_table
		}//end for tables
	}//end DOM check
}//end function


function setOrgPicture(src, alt){
	orgPicture.src = src;
	orgPicture.alt = arguments.length > 1? arguments[1] : "";
}

function setEmptyPicture(alt){
	orgPicture.src = "thumbs/empty.png";
	orgPicture.alt = arguments.length > 0? arguments[0] : "";
}

//

//function to display or hide a given element

//got rid of this- modified inline styles- switched to modifying class names to make XHTML compliant

var hide;
function showHideItems_old(myTable, myButton){
	//this is the ID of the hidden item
	var myTable = document.getElementById(myTable);
	//this is the ID of the plus/minus image
	var myButton = document.getElementById(myButton);
	var len=myTable.rows.length;
	var vStyle = (hide)? "none" : "";
	for(i=6; i<len; i++){
		myTable.rows[i].style.display=vStyle;
		}
	if(hide){
		myButton.innerHTML = "Show all (+)";
	}
	else{
		myButton.innerHTML = "Hide all (-)";
	}
	hide=!hide;
}


//new function to change class rather than inline display
var hide;
function showHideItems(myTable, myButton){
	//this is the ID of the table 
	var myTable = document.getElementById(myTable);
	//this is the ID of teh pluc/minus image
	var myButton = document.getElementById(myButton);
	var len=myTable.rows.length;
	for(var i=6; i<len;i++){
		var row=myTable.rows[i];
		if(row.className=="show_rows" || row.className =="show_rows odd"){
			cssjs('swap', row, 'show_rows', 'hide_rows');
			//row.className="hide_rows";
			myButton.src="img/plus.png";
		}
		else{
			cssjs('swap', row, 'hide_rows', 'show_rows');
			//row.className="show_rows";
			myButton.src="img/minus.png";
		}

	}//end for loop
	//if(hide){
	//	myButton.src = "img/plus.png";
	//}
	//else{
	//	myButton.src = "img/minus.png";
	//}
	//hide=!hide;
}

//function for hiding/showing list- probably should combine this and previous function

var hide;

function showHideList(myList, myText){
	//this is the ID of the table 
	var myList = document.getElementById(myList);
	//this is the ID of teh pluc/minus image
	var myText = document.getElementById(myText);
	if(myList.className == 'hide_list'){
		myList.className = 'show_list';
		myText.innerHTML = '(hide)';
	}
	else{
		myList.className = 'hide_list';
		myText.innerHTML = '(details...)';
	}

}

//function for hiding/showing div- really do need to deal with a general class here...

var hide1;

function showHideDiv(myDiv, myImg){
	//id of div
	var myDiv = document.getElementById(myDiv);
	//id of image
	var myImg = document.getElementById(myImg);
	if(hide1){
		cssjs('swap', myDiv, 'show_alignment', 'hide_alignment');
		myImg.src="../../img/down-h.png";

	}
	else{
		cssjs('swap', myDiv, 'hide_alignment', 'show_alignment');
		myImg.src="../../img/right-h.png";
	}
	hide1=!hide1;
}

/*

 * cssjs

 * written by Christian Heilmann (http://icant.co.uk)

 * eases the dynamic application of CSS classes via DOM

 * parameters: action a, object o and class names c1 and c2 (c2 optional)

 * actions: swap exchanges c1 and c2 in object o

 *			add adds class c1 to object o

 *			remove removes class c1 from object o

 *			check tests if class c1 is applied to object o

 * example:	cssjs('swap',document.getElementById('foo'),'bar','baz');

 */



function cssjs(a,o,c1,c2)

{

	switch (a){

		case 'swap':

			o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);

		break;

		case 'add':

			if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}

		break;

		case 'remove':

			var rep=o.className.match(' '+c1)?' '+c1:c1;

			o.className=o.className.replace(rep,'');

		break;

		case 'check':

			return new RegExp('\\b'+c1+'\\b').test(o.className)

		break;

	}

}



//Function to refresh page- useful until we switch to AJAX



function refreshpage()

	{

		window.location.reload();	

	}

