/**
 * util.js
 */

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

//
// hasClassName(obj, className)
// Returns whether the object has the specified classname.
// not using this yet. might remove it
//
function hasClassName(obj, className){
	var classNameArray = obj.className.split(' ');

	for(var i = 0; i < classNameArray.length; i++){
		if(classNameArray[i] == className){
			return true;
		}
	}

	return false;
}

function setTitleAttr(obj){
	var altText = obj.getAttribute('alt');
	var titleText = obj.getAttribute('title');

	if(altText != '' && altText != null){
		if(titleText == null){
			obj.setAttribute('title', altText);
		}
	}
}

function addImgTitles(){
	var images = document.getElementById('content').getElementsByTagName('img');

	for(var i=0; i < images.length; i++){
		setTitleAttr(images[i]);
	}
}

function searchSubmit(){
	document.queryForm['searchValue'].value = '*'+document.queryForm['searchValue'].value+'*';
	return true;
}

function checkEnter(){
	if(window.Event){
		window.captureEvents(Event.KEYPRESS)
	}
	document.onkeypress = keyPressed;
	function keyPressed(e){
		var n
		(window.Event) ? n=e.which : n=event.keyCode
		if(n == 13){
			searchSubmit();
		}
	}
}