﻿//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('');
		});
	});
}

//fix top ad flash for small screen resolution
function smallScreen(el){
	$(this).css({
		'position' : 'relative',
		'z-index' : '0'
	});
}

function hasAds(ads) {
	$.each(ads, function(adIndex, adCont){
		var adSrc = $(adCont),
		adImg = adSrc.find('img').width();
		if(adImg <= 1 || !adImg) {
		    adSrc.find('.channelSponsor').hide();	
		}
	});
}

//Override the AutoFocus function
function WebForm_AutoFocus(focusId) {} 

$(function() {
	var fieldHint = {
		'#SearchTerms' : 'Begin Search'
	}, h1 = $("h1:first"), trimh1 = h1.html(),
	dt = new Date(), curMonth = $("#currentMonth, #currentMonthFooter"),
	month = '', year = dt.getFullYear();
	
	/* trims leading nbsp if inserted */
	if (trimh1) {
		trimh1 = trimh1.replace(/^(&nbsp;)/, "");
		h1.html(trimh1);
	}
	
	/* pagination */
	$('.articleNewPaging').clone().insertBefore('#pageHolder');
	
	/* call fxns */
	fieldTip(fieldHint);
	smallScreen($('#topAd object'));
	hasAds(['#CopyID0EAAA', '#CopyID0EBAA', '#CopyID0ECAA', '#CopyID0EDAA']);	
	
	/* date fxns */
	$('#year').text(year + ' ');
	month = dt.getMonth() + 1;	
	if (month == 1) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=January");
	} else if (month == 2) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=February");
	} else if (month == 3) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=March");
	} else if (month == 4) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=April");
	} else if (month == 5) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=May");
	} else if (month == 6) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=June");
	} else if (month == 7) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=July");
	} else if (month == 8) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=August");
	} else if (month == 9) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=September");
	} else if (month == 10) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=October");
	} else if (month == 11) {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.aspx?key=November");
	} else {
		curMonth.attr("href", "/Pages/Property-Casualty-Magazine-Calendar.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", "#ArticleTools","#ArticleComments","#mainNav","#siteFooter","#topAd","#bottomAd","#relatedContent","#relatedContentSkyscraper","#feedFlare","#subscribeRight","#adColumnSkyscraper",".ArticlePagingCurrentPage","#searchBox","#handleBar","#relatedContentRectangle","#relatedContent",".printButton",".largeTextButton",".smallTextButton","#contentRectangle h2","#channelsNav" ];	
	
	//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();
	});
	
	var news = /\/news\//,
	exclusives = /\/exclusives\//;
	
	if(cssInclude.path.match(news) == null){
		$('#articleDate').show();
	}
	else {
		$('#articleDate, .articleIssueDate, #recentIssues').hide();
		$('.breakingNews, #recentNews').css('display', 'block');
	}
	if(cssInclude.path.match(exclusives) == null){
		$('#articleDate').show();
	}
	else {
		$('.breakingNews, .articleIssueDate').hide();
		$('.webExclusives').css('display', 'block');
	}
});
