/* %Z%%P%	%I% */

var currentHit = 0;
var hitCount = 0;
var HitPrefix = "hit";

function hits() {
	//count the hits. draw anchor into hit.
	//if any display the navigation buttons.
	//get the url of the next hit
	//on final hit, if a next hit
	var hc=1;
	var hit;
	var c=0; // prevent while loop excesses.
	var nav;

	while(true) {
		c++;
		if(c >1000) break;
                var id = HitPrefix+hc;
		hit = document.getElementById(id);
		if(hit != null) {
			hc++;
			try {
				hit.innerHTML += '<a name="'+id+'" />';
			} catch(err) {
				// sometimes the hit is inside a hyperlink
				// IE6 will fall over with 'unknown runtime
				// error' if you try to add an <a> inside
				// another <a>; we suppress it, thought that
				// will lead to oddities in the navigation
			}
			hitCount++;
		}
	}
	//alert(hitCount);
	//Counted
	if(hitCount == 0) return 0;

	nav = document.getElementById("hit_navigation");

	if(nav != null) {
		nav.style.display = "block";
		nav.style.visibility = "visible";
	}

	if(window.location.hash == "#"+HitPrefix+"1") {
		//initialise
		document.getElementById(HitPrefix + "1").className = "hit_current";
		currentHit = 1;
	}
	return true;
}

function hit_fprev() {
	var url = "";
	if(currentHit > 1) {
		currentHit--;
		window.location.hash = HitPrefix + currentHit;
		try {
			document.getElementById(HitPrefix + (currentHit+1)).className = "";
			document.getElementById(HitPrefix + currentHit).className = "hit_current";
		}catch(de) {}
	} else {
		//attempt previous record
		url = document.getElementById("full_nav_previous");
		if(url != null &&  url.href != "") document.location = url.href + "#"+HitPrefix+"1";
	}
	return true;
}

function hit_fnext() {
	var url = "";
	if(currentHit < hitCount) {
		currentHit++;
		window.location.hash = HitPrefix + currentHit;
		try {
			document.getElementById(HitPrefix + currentHit).className = "hit_current";
			document.getElementById(HitPrefix + (currentHit-1)).className = "";
		} catch(de) {}
	} else {
		//attempt next record
		url = document.getElementById("full_nav_next");
		if(url != null &&  url.href != "") document.location = url.href + "#"+HitPrefix+"1";
	}
	return true;
}

function fclear() {
	var ins = document.getElementsByTagName("input");
	for(var i=0;i<ins.length;i++){
	  if(ins[i].type == "hidden") {
	      continue;
	  }
	  if(ins[i].checked) {
	      ins[i].checked = false;
	      continue;
	  }
	  if(ins[i].value) ins[i].value = "";

	}
	return false;
}



// JavaScript expanding/contracting box v1.4
// This script takes a list element and subsequently makes
// all children elements hidden on document load. Then when
// the user activates the show/hide link, that should
//  be amended in line with accessibility guidelines,
// the children elements are expanded or contracted.
// Cookies have been added to achieve persistance. If cookies are
// disabled then no persistance, if JavaScript is
// disabled then the menu does not load.

function divShrinker(elementID){
	// test to see if the element is there and the browser can read/write from the DOM
	if (document.getElementById(elementID) && document.createElement){
		var y = document.getElementById(elementID);

		// set the default load page styling for the child element
    var x=y.childNodes[3];

    if (x==undefined) {
      x=y.childNodes[1];
    }

		// Select the link list
		var origHeight = x.offsetHeight+7;
		// end of default styling

		// IE counts nodes differently to other browsers (perhaps correctly!), to overcome try using the children property which works
    // cross browser, but not in Firefox. This degrades gracefully if support is added later.
    try {
      var a=y.children[0].appendChild(document.createElement('a'));
      } catch (e) {
      var a=y.childNodes[1].appendChild(document.createElement('a'));
    }

		// Add the building blocks of the <a> element
		a.id = elementID+'expander';
		a.href='#'+elementID;
		a.innerHTML = '<img src="styles/images/plus_box.gif" alt="Show menu" class="visible" title="Show menu" /><img src="styles/images/minus_box.gif" alt="Hide menu" class="hidden" title="Hide menu" />';
		// end <a>

		// check to see if a cookie has been set
		if (readCookie("expander"+elementID)) {
			x.style.display = readCookie("expander"+elementID);
			if (readCookie("expander"+elementID)=='block'){
				a.childNodes[1].className='visible';
				a.childNodes[0].className='hidden';
			} else {
				a.childNodes[0].className='visible';
				a.childNodes[1].className='hidden';
			}
		} else {
			x.style.display = 'none';
			createCookie("expander"+elementID,"none");
		}

		// look for an event
		var stopper;
		a.onclick=function(){
			if (stopper==1){
				return;
				} else {
				if (x.offsetHeight<=3){
					x.style.display='block';
					x.style.height='1px';
					x.style.overflow='hidden';
					x.style.display='none';
					createCookie("expander"+elementID,"block");
					setTimeout(function(){expander(x, origHeight, 2, "expand")}, 50);
					//a.innerHTML = '<img src="styles/images/plus_box.gif" alt="Show menu" class="hidden" title="Show menu" /><img src="styles/images/minus_box.gif" alt="Hide menu" class="visible" title="Hide menu" />';
					a.childNodes[1].className='visible';
					a.childNodes[0].className='hidden';
					return false;
				} else {
					x.style.display='block';
					x.style.overflow='hidden';
					//x.style.display='none';
					setTimeout(function(){expander(x, origHeight, 2, "contract")}, 50);
					a.childNodes[0].className='visible';
					a.childNodes[1].className='hidden';
					createCookie("expander"+elementID,"none");
					//a.innerHTML = '<img src="styles/images/plus_box.gif" alt="Show menu" class="visible" title="Show menu" /><img src="styles/images/minus_box.gif" alt="Hide menu" class="hidden" title="Hide menu" />';
					return false;
				}
			}
		}
	}
}

function expander(elementId, origHeight, power, method){
	var expanding;
	var x=elementId; // select the child list

	if (method=="expand"){
		power++;

		if(parseInt(x.offsetHeight)<parseInt(origHeight)){
			if ((parseInt(origHeight)-(x.offsetHeight+(1.1*power)))>1){
				var newHeight=x.offsetHeight+(1.1*power)+'px';
				x.style.display='block';
				x.style.height=newHeight;
				expanding = setTimeout(function(){expander(elementId, origHeight, power, "expand")}, 50);
			} else if ((parseInt(origHeight)-(x.offsetHeight+(1.1*power)))<=1){
				x.style.height=origHeight+"px";
				x.style.display='block';
				power=2;
				clearTimeout(expanding);
			}
		}	else {
		x.style.display='block';
			power=2;
			clearTimeout(expanding);
		}
	} else if (method=="contract"){
		if(parseInt(x.offsetHeight)>1){
			power++;
			if ((x.offsetHeight-(1.1*power))>1){
				var newHeight=x.offsetHeight-(1.1*power)+'px';
				x.style.height=newHeight;
				expanding = setTimeout(function(){expander(elementId, origHeight, power, "contract")}, 50);
			}else if ((x.offsetHeight-(1.1*power))<1){
				x.style.height="1px";
				x.style.display='none';
				power=2;
				clearTimeout(expanding);
			}
		}	else {
			power=2;
			clearTimeout(expanding);
		}
	}
}

// Cookies to add some persistance
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


// the function list for onload event
window.onload=function(){
	divShrinker('refineVolIAndII');
	divShrinker('refineVolIII');
	divShrinker('refineVolIV');
	divShrinker('refineBPVet');
	hits();
}

