function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

addLoadEvent(checkQueryString);

function checkQueryString() {
    if (! document.getElementById) return;
    if (! document.getElementById('site-search')) return;
    var form = document.getElementById('site-search');
    form.onsubmit = function() {
                            if ( document.forms["searchform"].searchterm.value == "" ) {
    	                        alert("Please enter your search term first.");
    	                        document.forms["searchform"].searchterm.value = "";
                          	    document.forms["searchform"].searchterm.focus();
                          	    return false;
	                        } else {
                                return true;
                        	}
                        }
}

function clearPasswordField() {
	if (document.getElementById('newpass1')) {
		window.setTimeout('document.getElementById("newpass1").value = ""', 100);
	}
}

addLoadEvent(clearPasswordField);

/*
To do:

-checking every link on every page for a 'rel' attribute is too inefficient.
-Should use an id on "go back" links so can access via document.getElementById

//addLoadEvent(historyBack);

// set up history.back links
function historyBack() {
    if (! document.getElementsByTagName) return;
    var links = document.getElementsByTagName("a");
    for (var c=0; c<links.length; c++) {
        var anchorlink = links[c];
        if (anchorlink.getAttribute("rel") == "previous") {
            anchorlink.onclick = function() {
                                this.href='javascript:history.back()';
                                //return false;
                             }
        }
    }
}
*/

document.observe('dom:loaded',function(){
	if ($('siteTabs')) {
		var hoverImage = new Image();
		hoverImage.src='/images/House_Hover.gif';
		$$('#siteTabs a').each(function(s){
			if (!s.hasClassName('active')) {
				s.observe('mouseover',function(){
					s.addClassName('hover');
				});
				s.observe('mouseout',function(){
					s.removeClassName('hover');
				});
			}
		});
	}
});

// 2 functions added for searchform by ASB 030908
	function clearText( el ) {
  	if (el.value == "Search") {
    	el.value = '';
    } else {
	    el.focus();
			el.select();
    }
  }

  function resetText( el ) {
  	if (el.value == "") {
    	el.value = 'Search';
    }
  }
  
    function showhide(divid, show) {
        thediv = document.getElementById(divid);
        if (show) {
            if (show == 'yes') {
                thediv.style.display='table-row'
            } else {
                thediv.style.display='none'
            }
        } else {
            if(thediv.style.display== 'none' ){
                thediv.style.display='table-row'
            }else{
                thediv.style.display='none'
            }
        }
    }

