function setFocus() {
	if ( document.forms.length == 0 )
		return;
	var form = document.forms[0];
	var element, id, isPageNumbers;
	for ( i = 0; i < form.length; i++ ) {
		element = form.elements[i];
		if ( element.type != "hidden" && element.className != 'username' ) {
			try {
				element.focus();
			}
			catch(err) {
				// don't do anything if there is an error, probably a field hidden with css
			}			
			return;
		}
	}
}
window.onload=setFocus;

function $(id) {
	return document.getElementById(id);	
}

function checkEnterKey(field, e) {
	var keycode;
	if ( window.event )
		keycode = window.event.keyCode;
	else if (e)
		keycode = e.which;
	else
		return true;
		
	if ( keycode == 13 ) {
		// field.form.submit();
		document.forms[0].submit();
		return false;
	}
	return true;
}

function reveal(icon) {
	icon.style.display = 'none';
	icon.nextSibling.style.display = 'inline';
}

function confirmAction(message, url) {
	if ( confirm(message) )
		document.location = url;
}

function findObj(theObj, theDoc)
{
	var p, i, foundObj;
		
	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
	{
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
		
	return foundObj;
}

function endsWith(s, suffix) {
    var startPos = s.length - suffix.length;
    if (startPos < 0) {
      return false;
    }
    return (s.lastIndexOf(suffix, startPos) == startPos);
}

function selectedValue(select) {
	return select.options[select.selectedIndex].value;
}