// JavaScript Document
window.onload = common_init;

function common_init()
{	
	var search_box = document.getElementById("search_box");
	//var searchForm = document.getElementById("searchForm");
	var searchForm = document.getElementsByTagName("form")[0];
	var archiveForm = document.getElementById("archiveForm");
	var archiveBox = document.getElementById("archiveBox");
	search_box.onfocus = cleanSlate;
	searchForm.onsubmit = validate_search;
	archiveBox.onchange = function(){
		archiveForm.submit();	
	}
}
function cleanSlate(){
		search_box.value = '';
}
function validate_search(){
	if(search_box.value == "Search!" || search_box.value == "" || search_box.value == " ")
	{
		//alert("You must type a search item!");
		var hdnField = document.getElementById("hdnMsg");
		var msg = "<p class='alert'>Please enter a search item</p>";
		//Before inserting the message we have to make sure it doesn't already exist. You would expect the msg would replace the old one
		//without a problem. However it expands it's parent's div everytime for whatever reason!
		if(hdnField.hasChildNodes()){	
			//do nothing
		}else{
		hdnField.innerHTML = msg;
		}
		return false;
	}
	else{
		return true;
	}
}