﻿// used for channels pages
function disImage(){
	var sImage = document.getElementById("ctl00_ctl10_g_1986fcb4_1481_4086_bf83_c1af520b08b6");
	if(sImage == null){return false;}
	else {
		var sImage2 = sImage.getElementsByTagName("iframe")[0],
		sImage3 = sImage.getElementsByTagName("image")[0];
		if(sImage3 == null && sImage == null){
			sImage.style.display = "none";
			return false;
		}
		else if(sImage2 != null && sImage3 == null){
			document.getElementById("sponsoredBy").style.display = "block";
		}
		else if(sImage2 == null && sImage3 != null){
			document.getElementById("sponsoredBy").style.display = "block";
		}		
	}
}

// used for articles pages
function hideAdBodyDiv(){
	var adDiv = document.getElementById("bodyAd");
	if(adDiv == null || adDiv2 == null){return false;}
	else {
		var adDiv2 = adDiv.getElementsByTagName("img")[0];
		if(adDiv2.height > 1){
			adDiv.style.display = "block";
		}
	}
}

//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'
	});
}

//Override the AutoFocus function
function WebForm_AutoFocus(focusId) {} 

// dropdown nav
function montre(id) {
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
	if (d) {d.style.display='block';}
}
			
$(function(){
	var fieldHint = {
		'#SearchTerms' : 'Begin Search',
		'#email' : 'Enter Your Email Address'
	}, h1 = $("h1:first"), trimh1 = h1.html(),
	dt = new Date(), year = dt.getFullYear();
	
	//pagination enhancement
	$('.articleNewPaging').clone().insertBefore('#pageHolder');
	
	/* trims leading nbsp if inserted */
	if (trimh1) {
		trimh1 = trimh1.replace(/^(&nbsp;)/, "");
		h1.html(trimh1);
	}
	
	/* call fxns */
	fieldTip(fieldHint);
	smallScreen($('#topAd object'));
	
	/* date fxns */
	$('#year').text(year + ' ');
	
	/* 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","#ColumnTwo","#ArticleComments","#MagazineSearch","#MagazineFooter","#RelatedArticles","#MPNav","#SecondaryNav",".ArticlePagingPageCount","#Pagination #Pagination",".ArticlePagingCurrentPage","#EmailColleague",".printButton",".largeTextButton",".smallTextButton","#ColumnThreeArticle"];	
	
	//hide the items	
	$(".printButton").css("cursor","pointer").click(function(){
		$.grep(arr, function(x){$(x).hide();
			$("#Pagination").css("font-size","12pt");
			$(".print-article").show();
		});
		//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, ".print-article").hide();
		});
		print();
	});
});