/* author: David Faulder */
/* Creation date: 16/12/2007 */

/* functions to manage show/hide of "More detail" blocks */
var prev = "";

if (document.layers) 
    var doc = 'document.', vis = '.visibility';
if (document.all) 
   var doc = 'document.all.', vis = '.style.visibility';
if(document.getElementById)
   var doc = 'document.getElementById("', vis = '").style.visibility';
   
function show(object) {
	if (object == prev) {hide(prev) ; return;}
    if (document.layers || document.all || document.getElementById)
		if (prev != "") {hide(prev) ;}
        eval(doc + object + vis + ' = "visible"');
		prev = object ;
}

function hide(object) {
    if (document.layers || document.all || document.getElementById)
        eval(doc + object + vis + ' = "hidden"');
		prev = "" ;
}

/* functions to manage the revealing of stories according to selector boxes */
function hideall() {
	// hide all stories initially
	changedis("li","stories","none");
	// look for specific &snip=ww in search string and display snippet of that class
	var teststring = window.location.search
	if (teststring.len != 0 && teststring.indexOf("snip=") != -1) { // only if search string is relevent
		re = /(snip=[\w\s]+)/i;								// search for snip=[any alphanumeric/space] (&# do not match)
		testitem = teststring.match(re);
		testitem = testitem[0].replace("snip=","").toLowerCase()	// extract the value
		changedis("li",testitem,"list-item")				// display items with class of this value
		if(document.getElementById)							// Set the List title
   			document.getElementById("listtitle").innerHTML = "Selected Record(s)" ;	
		document.location = "#datatop" ; 					// scroll to first story
	}
}

function changedis(testtag,test,state) {					// Change the way a tag of class test is displayed
	if (!document.getElementsByTagName) return; 			// only for modern compliant browsers
 		var tags = document.getElementsByTagName(testtag); 	// create array of tags
 		for (var i=0; i < tags.length; i++) {				// go through each tag
   			var tag = tags[i];	
   			if (tag.className.indexOf(test) >= 0) {			// picks tags where they include "test"
				tag.style.display = state ;					// eg for list "none" or "list-item"
			}
		}
}

function reveal(selected,singular,plural) {					// what was selected, singular/plural postscript for heading
	if (selected.options[selected.selectedIndex].value == "please-select") return;
	// set title
	var seltext = (selected.options[selected.selectedIndex].text);
	if (seltext == "All") {
		seltext = seltext + " " + plural ;
		} else {
		seltext = seltext + " " + singular ;
		}
	if (document.layers) 
    	document.layers("listtitle").innerHTML = seltext ;
	if (document.all) 
		document.all("listtitle").innerHTML = seltext ;
	if(document.getElementById)
   		document.getElementById("listtitle").innerHTML = seltext ;		 
	// hide previous results
	changedis("li","stories","none");
	// reveal stories with selected text in class
	var selvalue = (selected.options[selected.selectedIndex].value);
	changedis("li",selvalue,"list-item");
	// reset the selection box
	selected.selectedIndex = 0 ;
	document.location = "#datatop" ; 						// scroll to first story
}