﻿//Shows the message div when a channel does not contain articles
function showDivMessage(){
	var showDiv = document.getElementById("WebPartWPQ4"),
	showDiv2 = showDiv.getElementsByTagName("a")[0];
	if (showDiv2 == null){document.getElementById("message").style.display = "block";}
}

// classifieds 
function ShowHideCategory(id) {
	var element = document.getElementById(id);
	element.style.display == 'none' ? element.style.display = 'block' : element.style.display = 'none';
}

// archive dropdown menu
function FP_jumpMenu(el,frm,sel) {//v1.0
 var href=el.options[el.selectedIndex].value; if(sel) el.selectedIndex=0;
 '_new'==frm ? open(href) : eval(frm+".location='"+href+"'");
}

//search and form field hints
function fieldTip(fieldHint) {
	$.each(fieldHint, function(el, text){
		$(el).val(text).focus(function() {
			$(this).val('');
		});
	});
}

//Override the AutoFocus function
function WebForm_AutoFocus(focusId) {} 

$(function(){
	/* var definitions */ 
	var fieldHint = {
		'#SearchTerms' : 'Begin Search'
	}, h1 = $("h1:first"), trimh1 = h1.html(), 
	dt = new Date(), curMonth = $("#currentMonth, #currentMonthFooter"), 
	month = '', year = dt.getFullYear();
	
	/* pagination */
	$('.articleNewPaging').clone().insertBefore('#pageHolder');
	
	/* trims leading nbsp if inserted */
	if(trimh1){
		trimh1 = trimh1.replace(/^(&nbsp;)/, "");
		h1.html(trimh1);  
	}
	
	/* call fxns */
	fieldTip(fieldHint);
		
	/* hide the sponsor div when 0AS send an image that contains "empty" in the name */
	$("a[href*=www.nulh.com/@x]").parent().show();
	
	/* date fxns */
	$('#year').text(year + ' ');
	month = dt.getMonth() + 1;	
	if (month == 1) {
		curMonth.attr("href", "/Pages/Events.aspx?key=January");
	} else if (month == 2) {
		curMonth.attr("href", "/Pages/Events.aspx?key=February");
	} else if (month == 3) {
		curMonth.attr("href", "/Pages/Events.aspx?key=March");
	} else if (month == 4) {
		curMonth.attr("href", "/Pages/Events.aspx?key=April");
	} else if (month == 5) {
		curMonth.attr("href", "/Pages/Events.aspx?key=May");
	} else if (month == 6) {
		curMonth.attr("href", "/Pages/Events.aspx?key=June");
	} else if (month == 7) {
		curMonth.attr("href", "/Pages/Events.aspx?key=July");
	} else if (month == 8) {
		curMonth.attr("href", "/Pages/Events.aspx?key=August");
	} else if (month == 9) {
		curMonth.attr("href", "/Pages/Events.aspx?key=September");
	} else if (month == 10) {
		curMonth.attr("href", "/Pages/Events.aspx?key=October");
	} else if (month == 11) {
		curMonth.attr("href", "/Pages/Events.aspx?key=November");
	} else {
		curMonth.attr("href", "/Pages/Events.aspx?key=December");
	}
	
	/* article controls */
	$(".largeTextButton").css("cursor","pointer").click(function(){
		$("#Pagination").css("font-size","16px");
	});
	$(".smallTextButton").css("cursor","pointer").click(function(){
		$("#Pagination").css("font-size","12px");
	});
	
	//elements to hide					
	var arr = [ ".ms-navframe",".ms-bannerframe",".ms-sbtable",".ms-searchform",".ms-sbtopcorner",".ms-sblbcorner","#SiteActions","#PageStatusConsole","#ArticleTools","#ArticleComments","#mainNav","#siteFooter","#relatedContent","#relatedContentSkyscraper","#feedFlare","#subscribeRight","#adColumnSkyscraper",".ArticlePagingCurrentPage","#searchBox","#handleBar","#relatedContentRectangle","#relatedContent",".printButton",".largeTextButton",".smallTextButton","#contentRectangle h2" ];	
	
	//hide the items	
	$(".printButton").css("cursor","pointer").click(function(){
		$.grep(arr, function(x){$(x).hide();
			$("#Pagination").css("font-size","12pt");
		});
		//shows the print change link and shows the items of the array		
		$(".returnButton").show().css("cursor","pointer").click(function(){
			$.grep(arr, function(x){
				$(x).show();
			});
			$("#Pagination").css("font-size","12px");
			$(this).hide();
		});
		print();
	});
	
	//If the URL contains 'news' hide articleDate
	var news = /\/news\//,
	exclusives = /\/exclusives\//;
	if(cssInclude.path.match(news) == null) {
		$('#articleDate').hide();
	}
	else {
		$('.articleIssueDate, #recentIssues').hide();
		$('.breakingNews, #recentNews').css('display', 'block');
	}
	if(cssInclude.path.match(exclusives) == null){
		$('#articleDate').hide();
	}
	else {
		$('.breakingNews, .articleIssueDate').hide();
		$('.webExclusives').css('display', 'block');
	}
});