// JavaScript Document

//addDOMLoadEvent(addSearchHint);
//addDOMLoadEvent(makeuOttawadotcaLinksRelative);

/* Obsolete */
function makeuOttawadotcaLinksRelative () {
	if (!document.getElementById) { return; }
	
	var links;
	if (!(links = document.getElementsByTagName('a'))) { return; }
	
	for (var i=0; i< links.length; i++){
		if (links[i].href.match(/http:\/\/www.uottawa.ca/)) {
			links[i].href = links[i].href.replace(/http:\/\/www.uottawa.ca/,'');
		}
	}	
}

/* Search box */

function addSearchHint () {
	if (!document.getElementById) { return; }
	
	var label, searchBox;
	if (!(label = document.getElementById('global-site-search-label'))) { return; }
	if (!(searchBox = document.getElementById('global-site-search-words'))) { return; }
	
	// hide the label
	cssjs('add',label,'hidden');
	
	// the hint is the searchbox's label
	searchBox.hint = (label.innerText != undefined)? label.innerText : label.textContent;
	
	// if field is empty, add hint
	if (searchBox.value == "") {
		searchBox.value = searchBox.hint;
	}

	// onfocus: remove hint
	addEvent(searchBox,'focus',function() {
		if (searchBox.value == searchBox.hint) {
			searchBox.value = "";
		}
	});
	// onblur: add hint again if empty
	addEvent(searchBox,'blur',function() {
		if (searchBox.value == "") {
			searchBox.value = searchBox.hint;
		}
	});
}