﻿$(function () {
	if($("#mainContent")) {
		if($("#mainContent").height() < $("#sidebar").height()) {
			$("#mainContent").height($("#sidebar").height());
		}
	}
});

jQuery(document).ready(function(){
	jQuery(".MoreLink").click(function(){
		var text = (jQuery(this).text() == "Hide...") ? "More..." : "Hide...";
		jQuery(this).text(text);
		jQuery(this).parent().find(".MoreList").slideToggle();
		return false;
	});
	
	//for the global advanced search		
	addFormSubmit(".txtSearch", AdvancedSearch);
	
	//search results page
	if(jQuery("td.SubmitField input")) {
		jQuery("td.SubmitField input").live("click", function() {
			jQuery("div.PagerTitle").html('Your search results for "' + jQuery("td.FormField input").val() + '"');
		});
		jQuery("td.FormField input").live("keyup", function(e) {
			if(e.keyCode==13) {
				jQuery("div.PagerTitle").html('Your search results for "' + jQuery("td.FormField input").val() + '"');
			}
		});
	}
});

function AdvancedSearch() {
	window.location = "/Admin/SearchResults.aspx" + BuildQString("", "q", jQuery(".txtSearch").attr("value"));		
}

function addFormSubmit(inputID, func){
  	
	jQuery(inputID).keyup(function(event){
		if(event.keyCode == 13){
			func();
		}
	});
	
	jQuery(inputID).keydown(function(event){
		if(event.keyCode == 13){
			func();
		}
	});
}

function BuildQString(qs, field, value){
	qs += (qs.length > 0 && value.length > 0) ? "&" : "";
	qs += (qs.length == 0 && value.length > 0) ? "?" : "";
	qs += (value.length > 0) ? field + "=" + value : "";
	return qs;
}