function showhide(divid){
	$('#'+divid).toggle();
}

function allocateSidebarHeight() {
	var contentDom = $("#main");
	var sidebarDom = $("#subnav");
	var rightSidebarDom =$("#main_right");

        contentDom.css("width",($(".container").width()-rightSidebarDom.width()-sidebarDom.width()));

        if((contentDom.height()) < sidebarDom.height()) {
		contentDom.css("height",sidebarDom.height()+"px");
	}
	if((contentDom.height()) < rightSidebarDom.height()){
		contentDom.css("height",(rightSidebarDom.height())+"px");
	}
	if(contentDom.children(":first-child") && contentDom.children(":first-child").height() > contentDom.css("height").replace('px','') && contentDom.css("height") != ''){
		contentDom.css("height",contentDom.children(":first-child").height()+"px");
	}
 
}

function checkRequiredTextFields(requiredFields){
   var badfields = "";
   for(field in requiredFields){
       if(requiredFields[field].value==''){
           requiredFields[field].style.backgroundColor = "#FFDDDD";
           if(badfields != "") badfields += ", "+requiredFields[field].title;
           else badfields += requiredFields[field].title;
       }
   }
   if(badfields != ""){
       alert("You need to fill in the following required fields: "+badfields);
       return false;
   }
   return true;
}

function giveFocus(objId){
	var obj = $("#"+objId);
	obj.focus();
}

function ajaxSearch(searchTerm,resultdivid){
        var div = document.getElementById(resultdivid);

	//submits the search term to the page to be added to the database
	var oHttp = zXmlHttp.createRequest();;

	//cancel any active requests
	if(oHttp.readyState != 0){
		oHttp.abort();
	}
	//define the data
	var oData = {
		requesting: "Search",
		text: searchTerm
	};

	//open the connection to the server
	oHttp.open("post","search.php",true);
	
	//no readystate needed
	oHttp.onreadystatechange = function(){
		if(oHttp.readyState == 4){
			//evaluate the returned text Javascript (an Array)
			div.innerHTML = oHttp.responseText;
			allocateSidebarHeight();
			//allocateSidebarHeight();
		}
	};	

	//send the request
	oHttp.send(JSON.stringify(oData));
}