// set the function to clear the field
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

// set the function to restore the field
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}


//TABS!!!
var infoTabLinks = new Array();
var infoContentDivs = new Array();

function initTabs(tabs_id) {
	//alert('initNewsTabs called!');
	// Grab the tab links and content divs from the page
	if (!document.getElementById(tabs_id)){
		return;
	}
	var tabListItems = document.getElementById(tabs_id).childNodes;
	for ( var i = 0; i < tabListItems.length; i++ ) {
		if ( tabListItems[i].nodeName == "LI" ) {
			var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
			var id = getHash( tabLink.getAttribute('href') );
			infoTabLinks[id] = tabLink;
			infoContentDivs[id] = document.getElementById( id );
		}
	}

	// Assign onclick events to the tab links, and
	// highlight the first tab
	var i = 0;

	for ( var id in infoTabLinks ) {
		infoTabLinks[id].onclick = showInfoTab;
		infoTabLinks[id].onfocus = function() { this.blur() };
		if ( i == 0 ) infoTabLinks[id].className = 'selected';
		i++;
	}

	// Hide all content divs except the first
	var i = 0;

	for ( var id in infoContentDivs ) {
		if ( i != 0 ) infoContentDivs[id].className = 'hide';
		i++;
	}
}



function showInfoTab() {
	var selectedId = getHash( this.getAttribute('href') );

	// Highlight the selected tab, and dim all others.
	// Also show the selected content div, and hide all others.
	for ( var id in infoContentDivs ) {
		if ( id == selectedId ) {
			infoTabLinks[id].className = 'selected';
			infoContentDivs[id].className = '';
		} else {
			infoTabLinks[id].className = '';
			infoContentDivs[id].className = 'hide';
		}
	}

	// Stop the browser following the link
	return false;
}

function getFirstChildWithTagName( element, tagName ) {
	for ( var i = 0; i < element.childNodes.length; i++ ) {
		if ( element.childNodes[i].nodeName == tagName ) return element.childNodes[i];
	}
}

function getHash( url ) {
	var hashPos = url.lastIndexOf ( '#' );
	return url.substring( hashPos + 1 );
}

