//set search box to nothing on first focus.
var sValue;
function clearSearch(sValue){
	if(!sValue._haschanged){
  	sValue.value=''
	};
	sValue._haschanged=true;
}


//bookmark page
function addToFavorites() {
	var thisTitle = document.title; // get title of the page
	var thisURL = document.URL; // get url of the page
	
	var txt = "Please bookmark this site"; 
	if (window.sidebar) { 
	  // Mozilla Firefox Bookmark		
	  window.sidebar.addPanel(thisTitle, thisURL,"");	
	} 
	else if (window.external) { 
	  	// IE Favorite		
	  	window.external.AddFavorite(thisURL, thisTitle); 
	}	
	
	else if (window.opera && window.print) { 
	  	// Opera Hotlist		
		txt += " using (Ctrl+T)"; 
		window.alert(txt);
	} 
	else
	{ 
		// if its netscape then pop up a alert message for the time being
		txt += " using (Ctrl+D)"; 
		window.alert(txt);
	} 
}

//output centre details show / hide button 
function drawCentreShowHideButton(showLabel, hideLabel){
	document.write('<div class="showHideCourses" id="showCourseLink">');
	document.write("<a href=\"javascript:hideDiv('showCourseLink');showDiv('CentreAvailCourses');showDiv('hideCourseLink');\"><span>" + showLabel + "</span></a>");
	document.write('</div>');
	document.write('<div class="showHideCourses" id="hideCourseLink">');
	document.write("<a href=\"javascript:hideDiv('CentreAvailCourses');hideDiv('hideCourseLink');showDiv('showCourseLink');\"><span>" + hideLabel + "</span></a>");
	document.write('</div>');
  document.write('<script type="text/javascript">');
  document.write("hideDiv('hideCourseLink');");
  document.write('</script>');
}

//open external links in new window
function externalLinks() {
	AddCss("jsactive");
	PrepareAllLinks("contentWrap");
}


function AddCss(fileName){
	var l=CreateEl("link");
	l.setAttribute("type","text/css");
	l.setAttribute("rel","stylesheet");
	l.setAttribute("href","/includes/styles/"+fileName+".css");
	l.setAttribute("media","screen");
	document.getElementsByTagName("head")[0].appendChild(l);
}

function CreateEl(t,c){
	var x=document.createElement(t);
	x.className=c;
	x.style.display="block";
	return(x);
}

function PrepareAllLinks(alink) {
  var links, i;
  if (document.getElementById(alink)) {
    links=document.getElementById(alink).getElementsByTagName("a");
  	for(i=0;i<links.length;i++) Prepare(links[i]);
  }
}

function Prepare(alink){
	var t;
  	t=alink.className;
  	if (t == "extLink" ) {
	  alink.setAttribute("target","_blank");
	}
}

window.onload = externalLinks;

function hideDiv(divID){
  if (document.getElementById(divID)) document.getElementById(divID).style.display = "none";
}

function showDiv(divID){
  if (document.getElementById(divID)) document.getElementById(divID).style.display = "block";
}