// JavaScript Document

function searchNews(){
	if($("#searchterm").val().trim() == ""){
		alert("Please enter the term(s) you would like to search by");
	}else{
		$("#newsSearchForm").submit();
	}
}

/*-------------------------------------------------*/
/*	Used by News Search view for jQuery-powered
/*	pagination (show/hide DIVs)
/*-------------------------------------------------*/
function prevPage(){
	var current = $("#news_items").attr("current_page") || 1;
	if(current > 1){
		var previous = current - 1;
		$("#news_group"+current).hide();
		$("#news_group"+previous).show();
		$("#news_items").attr("current_page", previous);
		$(".paging .next").show();
		if(previous == 1) $(".paging .prev").hide();
	}else{
		$(".paging .prev").hide();
	}
}

/*-------------------------------------------------*/
/*	Used by News Search view for jQuery-powered
/*	pagination (show/hide DIVs)
/*-------------------------------------------------*/
function nextPage(){
	var current = $("#news_items").attr("current_page") || 1;
	var totalPages = $(".news_group").length;
	if(current < totalPages){
		var next = current + 1;
		$("#news_group"+current).hide();
		$("#news_group"+next).show();
		$("#news_items").attr("current_page", next);
		$(".paging .prev").show();
		if(next == 1) $(".paging .next").hide();
	}else{
		$(".paging .next").hide();
	}
}

/*-------------------------------------------------*/
/*	Used by News & News Archive view for filtering
/*	by Category (Construction, Sales, etc.)
/*-------------------------------------------------*/
function getNews(ctg,type){
	$("#news_loader").fadeIn();
	$("#dd_ctg .selection").html(ctg);
	if(ctg == "") $("#dd_ctg .selection").html("All News");
	$("#dd_ctg ul").hide();
	$("#news_items").load("/includes/ajax/ajax_news.php", {view:type, category:ctg}, function(){
		$("#news_loader").fadeOut();
	});
}

/*-------------------------------------------------*/
/*	Used by News Archive view for AJAX-powered
/*	pagination (refresh HTML)
/*-------------------------------------------------*/
function viewPage(num){
	$("#news_loader").fadeIn();
	var ctg = $("#dd_ctg .selection").html();
	$("#news_items").load("/includes/ajax/ajax_news.php", {view:"archive", page:num, category:ctg}, function(){
		$("#news_loader").fadeOut();
	});
}