
var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight = parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers


// useful pop function
function Popup(myUrl,popType) {
	var winName='macleans';
	var winTop=50;
	var winLeft=150;
	var d = new Date();
	var winTime = d.getUTCHours()+'_'+d.getUTCMinutes()+'_'+d.getUTCSeconds();

	switch (popType) {
		case 0:   // new window (blogs)
	  	pop = window.open(myUrl,winName+winTime,'width=700,height=520,top=' + winTop + ',left=' + winLeft + ',toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,directories=no,status=yes,copyhistory=no');
		break
	}

	pop.focus();

}

// turns a zoneTitle to yellow....was disabled because
// it was deemed too buggy for Firefox...reason unknown
function zoneOn(idName) {
	var theClass = "";
	if (idName=="top5") {
		theClass = "substoryZoneTitleHover";
	} else {
		theClass = "zoneTitleHover";
	}
	if (document.getElementById(idName+"Zone")) {
//		document.getElementById(idName+"Zone").className=theClass;
	}
}

// turns a zoneTitle to yellow....was disabled because
// it was deemed too buggy for Firefox...reason unknown
function zoneOff(idName) {
	var theClass = "";
	if (idName=="top5") {
		theClass = "substoryZoneTitle";
	} else {
		theClass = "zoneTitle";
	}
	if (document.getElementById(idName+"Zone")) {
//		document.getElementById(idName+"Zone").className=theClass;
	}
}

function showMe(idName) {
	if (document.getElementById(idName)) {
		document.getElementById(idName).style.display='inline';
	}
}

function hideMe(idName) {
	if (document.getElementById(idName)) {
		document.getElementById(idName).style.display='none';
	}
}

var articlePath = "";
function goHere(url) {
	window.location.href=url;
}

function iFrameHeight(idName) {
	if(document.getElementById(idName)) {
		if (idName=="commentsFrame") {
			if (document.getElementById(idName).contentDocument) {
				h = document.getElementById(idName).contentDocument.getElementById("mac50template").offsetHeight+FFextraHeight;
			} else {
				h = document.frames(idName).document.getElementById("mac50template").scrollHeight;
			}
		} else {
			if (document.getElementById(idName).contentDocument) {
				h = document.getElementById(idName).contentDocument.body.offsetHeight+FFextraHeight;
			} else {
				h = document.frames(idName).document.body.scrollHeight;
			}
		}
		document.getElementById(idName).style.height = h;
	}
}

// Handles e-mail window
function emailArticle(content) 
{
	pop = window.open('/shared/email.jsp?content=' + content, 'cbEmailWindow','width=620, height=500, status=1, scrollbars=no');
	//window.open('/iw-web/shared/email.jsp?content=' + content);
}
			
function launchone(fname, w, h) { x=window.open(fname,"WindowName","width=" + w + ",height=" + h +",top=100,left=100, resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no") }

// classy function to make the articles turn on and off when hover
// this means you can change the function in here instead of generated archive file
function archiveOn(o,c) {
	o.className="articleHover "+c;
}

function archiveOff(o,c) {
	o.className=c;
}

// opens the radio player
function openPlayer(stationId) {
  var url = theHost+"/radio/player.jsp";
  if (stationId && stationId > 0) {
    url += "?station=" + stationId
  }

  var w = null;
  w = window.open(url, "PLAYER", "scrollbars=0,width=733,height=375");

  if (w){
    w.focus();
  } else {
    alert('player window failed to open.  perhaps your popup blocker blocked it?');
  }
}

// returns the showzone for admins
// double click and press 's'....you know you love it!
function goShowZone() {
	var loc = window.location+"";
	var newUrl = "";
	if (loc.indexOf("?") >=0) {
		newUrl = loc+"&showzone=";
	} else {
		newUrl = loc+"?showzone=";
	}
	if (window.event.keyCode == 115) {
		window.location.href=newUrl;
	}
}


// for converting time and army time etc...
// some cool stuff here
function noArmy(t) {
	if (t > 12) {
		t = t - 12;
	}
	return t;
}

function convertTime(timestamp,timeDiff) {	
	var d = new Date()
	var finalTime = "";
	var theTime = "";	
	var splitDate = new Array;
	var minutes = "";
	var hours = "";
	var theTime = timestamp;
	var newHours = "";
	var finalHours = "";
	var tempHours = "";
	var ampm = "";
	if (theTime.indexOf(":") >=0) {
		splitDate = theTime.split(":");
		hours = splitDate[0]; // gets the hour
		minutes = splitDate[1]; // gets the minutes
		newHours = parseInt(hours);
		tempHours = newHours - timeDiff; // to see if it's am or pm
		newHours = noArmy(newHours - timeDiff); // new hour with no army time
		if (tempHours == 0) {
			finalHours = "12";
			ampm = "am";
		} else if (tempHours < 0) {
			finalHours = noArmy(tempHours + 24);
			ampm = "pm";
		} else {
			finalHours = newHours;
			if (tempHours >=12) {
				ampm = "pm";
			} else {
				ampm = "am";
			}
		}
		finalTime = finalHours+":"+minutes+" "+ampm+" EST";
	}
	return finalTime;		
}

// converting article date, etc..
function getArticleDate(d) {
	var	monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var idValue = document.getElementById(d);
	var theDate = idValue.innerHTML;
	var theYear = "";
	var theMonth = "";
	var theDay = "";
	var finalDate = "";
	if ((theDate != "") && (theDate.length == 8)) {
		theYear = theDate.substr(0,4);
		theMonth = Math.floor(theDate.substr(4,2));
		theDay = Math.floor(theDate.substr(6,2));
		finalDate = monthArray[theMonth-1].substr(0,3)+" "+theDay+", "+theYear;
		idValue.innerHTML=finalDate+" | ";
	} else {
		idValue.innerHTML = "";
	}
}

// opens a pdf for the advertise page....
function goPDF(f) {
  	pop = window.open(f,"pdf","width=700,height=520,top=5,left=5,toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,directories=no,status=yes,copyhistory=no");
}

function findBlog(blogID) {
	for (i = 0; i < iArray.length; i++) {
		if (iArray[i] == blogID) {
			return i;
			break;
		}
	}
}

function subPanel() {
	var panelCheck = document.getElementById("panelCheck").value;
	if (panelCheck == "off") { // time to open
		document.getElementById("subPanelFlyout").style.display="block";
		document.getElementById("panelCheck").value = "on";
		document.getElementById("expand").style.display="none";
		document.getElementById("expandOn").style.display="block";
	} else {
		document.getElementById("subPanelFlyout").style.display="none";
		document.getElementById("panelCheck").value = "off";
		document.getElementById("expand").style.display="block";
		document.getElementById("expandOn").style.display="none";
	}
}

// Returns the current DateTimeStamp - added by Michelle from CBO
function curDateStamp() {
	var monthArray = new Array("January","February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var daysOfTheWeek = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var myDate = new Date();
	var myYear = myDate.getYear();
	if (myYear < 1900) {
		myYear = myYear + 1900;
	}
	var myMonth = myDate.getMonth();
	var myDayDate = myDate.getDate();
	var myDay = myDate.getDay();
	var myHour = myDate.getHours();
	var myMeridian = '';
	
//determine am or pm
    if(myHour >= 12){
	myMeridian = "p.m.";
	} else {
	myMeridian = "a.m.";
	}
	//fake 12hr time
	if (myHour > 12) {
		myHour = myHour - 12;
	}
	//fake 12am
	if (myHour == 0) {
	   myHour = 12;
	}
	//end fake
	
	var myMins = myDate.getMinutes();
	var myMinsString = myMins + "";
	if (myMins < 10) {
		myMinsString = "0" + myMinsString;
	}
	//Old output, used day of the week function
	//var myFormattedDate = daysOfTheWeek[dayOfWeek(myDay,myMonth,myYear)] + ", " + monthArray[myMonth] + " " + myDay + ", " + myYear + " " + myHour + ":" + myMins + " " + myMeridian;

	//New output - uses myDate.getDay()
	//var myFormattedDate = daysOfTheWeek[myDay] + ", " + monthArray[myMonth] + " " + myDayDate + ", " + myYear + " " + myHour + ":" + myMinsString + " " + myMeridian;
	var myFormattedDate = daysOfTheWeek[myDay] + ", " + monthArray[myMonth] + " " + myDayDate + ", " + myYear;

	return myFormattedDate;
}

