// /www/funcs.js
var Today = new Date();
var Weekdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var Months = new Array("January", "February", "March", "April", "May", "June", 
			"July", "August", "September", "October", "November", "December");
var MonthsAbbrev = new Array("Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec.");			

var OmnitureBlocksPresent = 0;		// JLF 20070523 - This variable is used for determining whether we can execute Omniture code on any page.
var OverrideNewsholeAd = false;		// JLF 20070613 - This variable can be set to true so that newshole ads will not appear.
var adAlign = "right";

function TodaySpot() {
	var thisWeekday = Weekdays[Today.getDay()];
	var thisMonth = Months[Today.getMonth()];
	var thisDay = Today.getDate();	
	var thisYear = Today.getFullYear();
	var Temp = "<b>Pittsburgh, PA</b><br>" + thisWeekday + "<br>";
	Temp += thisMonth + " " + thisDay + ", " + thisYear;
	
	return "<!-- js:TodaySpot -->" + Temp;
}

function TodaySpotWide() {
	var thisWeekday = Weekdays[Today.getDay()];
	//var thisMonth = Months[Today.getMonth()];
	var thisMonth = MonthsAbbrev[Today.getMonth()];
	var thisDay = Today.getDate();	
	var thisYear = Today.getFullYear();				

	var Temp = "<a href=\"http://www.post-gazette.com\"><img src=\"http://www.post-gazette.com/includes/images/topthingroot.gif\"";
	Temp += " alt=\"post-gazette.com\" border=0></a><br>";
	Temp += "<span style=\"font: 12px Arial\">&nbsp;<b>Pittsburgh, Pa.</b> " + thisWeekday + ", ";
	Temp += thisMonth + " " + thisDay + ", " + thisYear + "</span>";
	
	return "<!-- js:TodaySpotWide -->" + Temp;
}

function getRssButton() {
	var obj = document.getElementsByTagName("link");
	var i = 0;
	var rssButton = "";
	var href = "";	
	var title = "";
	
	while(obj[i] && rssButton == "") {
		if(obj[i].getAttribute("type").indexOf("rss") != -1) {
			href = obj[i].href;
			title = "RSS - " + obj[i].title;
			rssButton = "<a href='" + href + "'>" + 
					"<img src='/events/images/rssbutton.gif' " + 
					"border='0' alt='" + title + "' /></a>";			
		}
		i++;
	}
	
	return "<!-- js:getRssButton -->" + rssButton;
}

function TodaySpotWider() {
	// JLF 20061212 - switch to this instead.
	var thisWeekday = Weekdays[Today.getDay()];
	//var thisMonth = Months[Today.getMonth()];
	var thisMonth = MonthsAbbrev[Today.getMonth()];
	var thisDay = Today.getDate();	
	var thisYear = Today.getFullYear();				

	var Temp = "<div style=\"height: 50px; font-family: Arial, sans-serif; font-size: 10pt; vertical-align: middle;\">";
	Temp += "<b>Pittsburgh, Pa.</b><br />";
	Temp += thisWeekday + ", " + thisMonth + " " + thisDay + ", " + thisYear;
	Temp += "<br />" + getRssButton() + "</div>";
	
	return "<!-- js:TodaySpotWider -->" + Temp;
}

function MakePFLink() {
	var thisPage = escape(document.URL);	

	var output = "<font face='Arial' size='2'>";
	output += "<a href='http://www.post-gazette.com/storymailer2.asp?story=" + thisPage + "'>E-mail this story&nbsp;";
	output += "<img src='http://www.post-gazette.com/includes/images/25x19email.gif' alt='E-mail this story' border='0' align='absmiddle' />";
	output += "</a>&nbsp;";
	output += "<a href='http://www.post-gazette.com/printer.asp?story=" + thisPage + "'>Print this story&nbsp;";
	output += "<img src='http://www.post-gazette.com/includes/images/25x19printer.gif' alt='Printer-friendly page' border='0' ";
	output += "align='absmiddle' /></a>";
	
	output += "<div style='padding: 3px;'>Get home delivery of the Post-Gazette - ";
	output += "<a href='http://www.post-gazette.com/pgdelivery/currentSpecialOffer.asp'>";
	output += "click here for a special offer</a>.</div></font><br /><br />";
	
	return "<!-- js:MakePFLink -->" + output;
}

function MakeOnlyPFLink() {
	var thisPage = escape(document.URL);
	
	var output = "<font face=\"Arial\" size=2>";
	output += "<a href=\"/printer.asp?story=" + thisPage + "\">Print this story&nbsp;";
	output += "<img src=\"/includes/images/25x19printer.gif\" alt=\"Printer-friendly page\" border=0 ";
	output += "align=\"absmiddle\"></a></font><br><br>";
	
	return "<!-- js:MakeOnlyPFLink -->" + output;
}

function MakeSharingBox() {
	var escapedURL = encodeURIComponent(document.URL);
	var escapedTitle = encodeURIComponent(document.title).replace("'", "%27");
	
	var output = "<div class=\"hideForPrint\" style=\"border: 1px solid silver; background: white; width: 100%; font-family: Arial, sans-serif;\">\n";
	output += "<div style=\"background: url(http://www.post-gazette.com/includes/images/tableheader.gif); font-size: 10pt; font-weight: bold; padding: 3px;\">Saving & Sharing</div>\n";
	output += "<div style=\"padding: 5px; margin-bottom: 5px;\">\n";
	output += "<div style=\"float: left; width: 50%; margin-right: 5px; font-size: 9pt;\">\n";
	output += "<div style=\"height: 25px;\"><a href=\"http://www.post-gazette.com/printer.asp?story=" + escapedURL + "\"><img src=\"/icons/print.gif\" alt=\"Print this article\" title=\"Print this article\" border=\"0\" align=\"absmiddle\" />&nbsp;Print this article</a></div>\n";
	output += "<div style=\"height: 25px;\"><a href=\"http://digg.com/submit?phase=2&url=" + escapedURL + "&title=" + escapedTitle + "\"><img src=\"/icons/digg.gif\" alt=\"Digg\" title=\"Digg\" border=\"0\" align=\"absmiddle\" />&nbsp;Digg</a></div>\n";
	output += "<div style=\"height: 25px;\"><a href=\"http://www.google.com/bookmarks/mark?op=add&title=" + escapedTitle + "&labels=&annotation=&bkmk=" + document.URL + "\"><img src=\"/icons/google.gif\" alt=\"Google\" title=\"Google\" border=\"0\" align=\"absmiddle\" />&nbsp;Google</a></div>\n";
	output += "</div>\n";
	
	output += "<div style=\"float: left; width: 40%; font-size: 9pt;\">\n";
	output += "<div style=\"height: 25px;\"><a href=\"http://www.post-gazette.com/storymailer2.asp?story=" + escapedURL + "\"><img src=\"/icons/mail.gif\" alt=\"E-mail link to a friend\" title=\"E-mail link to a friend\" border=\"0\" align=\"absmiddle\" />&nbsp;E-mail link to a friend</a></div>\n";
	output += "<div style=\"height: 25px;\"><a href=\"http://del.icio.us/post\" onclick=\"window.open('http://del.icio.us/post?v=4&partner=pitt&noui&jump=close&url=" + encodeURIComponent(location.href) + "&title=" + escapedTitle + "','delicious','toolbar=no,width=700,height=400'); return false;\">";
	output += "<img src=\"/icons/delicious.gif\" alt=\"Del.icio.us\" title=\"Del.icio.us\" border=\"0\" align=\"absmiddle\" />&nbsp;Del.icio.us</a></div>\n";
	output += "<div style=\"height: 25px;\"><a href=\"http://myweb2.search.yahoo.com/myresults/bookmarklet?u=" + escapedURL + "&title=" + escapedTitle + "&popup=true\"><img src=\"/icons/yahoo.gif\" alt=\"Yahoo!\" title=\"Yahoo!\" border=\"0\" align=\"absmiddle\" />&nbsp;Yahoo!</a></div>\n";
	output += "</div>\n";
	output += "</div>\n";
	output += "<div style=\"content: '.'; display: block; height: 0; font-size: 0; clear: both; visibility: hidden;\"></div>\n";
	output += "</div>\n";

	return "<!-- js:MakeSharingBox -->" + output;
}

function NoDFPAdTag() {
	// rotates non-DFP ads.
	var Imgs = new Array(	"120x240businessnews.gif", 
							"120x240health.gif", 
							"120x240weather.gif",
							"120x240hssports.gif");
							
	var URLs = new Array(	"http://www.post-gazette.com/businessnews", 
							"http://www.post-gazette.com/healthscience", 
							"http://www.post-gazette.com/weather", 
							"http://www.post-gazette.com/highschoolsports");
							
	var ImgDir = "http://www.post-gazette.com/includes/images/";
	
	var adCount = Imgs.length;
	var i = Math.floor(Math.random() * adCount);

	return "<!-- js:NoDFPAdTag --><a href=" + URLs[i] + "><img border=0 vspace=1 src=" + ImgDir + Imgs[i] + "></a>";
}

function getDirectory(someURL) {
	// Returns only the directory name from within a URL.
	// It also handles directories that are nested, like sports/golf.
	var temp = someURL.split("/");		// split the URL on the slashes.
	var num = temp.length;
	var retVal = "";
	
	// If the array contains less than four elements, the URL is pointing
	// to a file that is sitting directly on the root of the site.  Thus, 
	// we return nothing.
	// http://www.post-gazette.com/sports/golf/default.asp
	// ------ -------------------- -----  ---- -----------
	//   0  1         2              3      4     5
	if(num > 3) {
		for(var i = 3; i < num - 1; i++) {
			retVal += temp[i];
			if(i < num - 2)
				retVal += "/";
		}					
	}								
	
	return retVal;
}

function getFilename(someURL) {
	// Returns only the file name from within a URL.
	var temp = someURL.split("/");		// split the URL on the slashes.
	var num = temp.length;
	var retval = "";
	
	// Get the last item in the array.  It will be the file name.
	if(num > 2)
		retVal = temp[num - 1];				
	
	// Test for the existence of a query string, and remove it.
	if(retVal.indexOf("?") != -1)
		retVal = retVal.substring(0, retVal.indexOf("?"));
	
	return retVal;
}

function CreateDRB()
{
	var d = document.getElementById("endrb");
	var obj = "http://a201.g.akamai.net/7/201/32539/v001/dmc.download.akamai.com/32539/pittsburgh/employment/160x600.swf";
	
	d.innerHTML = "<!-- js:CreateDRB --><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' "
					+ "codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' "
					+ "width='160' "
					+ "height='300' "
					+ "id='endrb1' "
					+ "align='middle'> "
						+ "<param name='allowScriptAccess' value='always' /> "
						+ "<param name='movie' value='" + obj + "' /> "
						+ "<param name='quality' value='high' /> "
						+ "<param name='menu' value='false' /> "
						+ "<!--<param name='bgcolor' value='#000000' />--> "
						+ "<embed src='" + obj + "' "
							+ "quality='high' "
							+ "width='160' "
							+ "height='300' "
							+ "name='endrb1' "
							+ "align='middle' "
							+ "menu='false' "
							+ "allowScriptAccess='always' "
							+ "type='application/x-shockwave-flash' "
							+ "pluginspage='http://www.macromedia.com/go/getflashplayer'> "
						+ "</embed> "
					+ "</object>";
}

function putAdInNewshole(OASsitepage, OASposition, alignment, adWidth, adHeight, verticalPosition) {
	// Places an ad within the news content of the site.	
	// Example call: putAdInNewshole(OAS_sitepage, "x50", "right", 300, 250, 3);
	if(!OverrideNewsholeAd) {
		var adBuffer = "10px";
		var div = document.createElement("p");
		div.id = "newsHoleAd";
		div.style.textAlign = "center";	
		
		// Create the "advertisement" text node.
		var adBnr = document.createTextNode("Advertisement");	
		var adBnrDiv = document.createElement("div");
		adBnrDiv.style.fontFamily = "Arial";
		adBnrDiv.style.fontSize = "9pt";
		adBnrDiv.style.color = "#999999";
		adBnrDiv.style.textAlign = "center";
		adBnrDiv.appendChild(adBnr);
		
		// Create an image - replace with actual OAS code (x50).
		var ad = document.createElement("iframe");
		ad.name = "nhAd";
		ad.width = adWidth;
		ad.height = adHeight;
		ad.marginWidth = 0;
		ad.marginHeight = 0;
		ad.frameBorder = 0;
		ad.scrolling = "no";
		ad.borderColor = "#ffffff";
		ad.hSpace = 0;
		ad.vSpace = 0;
		ad.src = "http://oascentral.post-gazette.com/RealMedia/ads/adstream_sx.ads/" + OASsitepage + "@" + OASposition;
		
		// Add the image to the div.
		div.appendChild(adBnrDiv);
		div.appendChild(ad);
		
		// Create the fragment.
		var frag = document.createDocumentFragment();
		frag.appendChild(div);
		
		// Find the news hole and look for the target placement node.
		var nh = document.getElementById("contentArea");
		var ps = 0;
		var targetNode = null;
		var i = 0;
		
		while(i < nh.childNodes.length && ps <= verticalPosition) {
			if(nh.childNodes[i].tagName == "P") {
				ps++;
				targetNode = nh.childNodes[i];				
			}								
			i++;		
		}			

		if(targetNode) {
			nh.insertBefore(frag, targetNode);
		}			
	}
}

function DisplayOASAd(position, width, height) {
	var RN = new String(Math.random());
	var RNS = RN.substring(2, 11);
	var oas = "http://oascentral.post-gazette.com/RealMedia/ads/";
	var oaspage = sitepage + "/1" + RNS + "@" + position;

	if(_version < 11) {
		document.write("<a href='" + oas + "click_nx.ads/" + oaspage + "' target='_top'>");
		document.write("<img src='" + oas + "adstream_nx.ads/" + oaspage + "' border='0' width='" + width + "' height='" + height + "'></a>");
	} else {
		document.write("<scr" + "ipt type='text/javascript' src='" + oas + "adstream_jx.ads/" + oaspage + "'></scr" + "ipt>");
	}
}