// JavaScript Document

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ***************************************************
//  	BEGIN ARCHIVE RELATED JAVASCRIPT 
//  	Contact:  Malte Wendlandt for help
// 	Use the following snippet in the page that has the archive:
//		The first Option is the path to the shows archive, relative from cbc.ca/
//		The second Option can be either monthly or weekly, depending on which type of archive is used
//		the third Option is the start year of the archive.
//		the fourth Option is the first month of the start year which has an archive.  Must be entered in Numerical form, ie 5 for may.
//
//			<script type="text/javascript">
//				document.write(makeArchive ('/showname/path_to_archives/', 'weekly', '2005', '5'))
//			</script>
//
// ***************************************************

function y2k(number)    { return (number < 1000) ? number + 1900 : number; }		//  Deal with Javascripts y2k problem

function makeArray0() {
    for (i = 0; i<makeArray0.arguments.length; i++)
        this[i] = makeArray0.arguments[i];
}

function makeArchive (archivePath, archiveType, baseYear, baseMonth) {   

		var archive = '';
		var shortMonths = new makeArray0('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
		var longMonths = new makeArray0('January','February','March','April','May','June','July','August','September','October','November','December');
		var dateObject = new Date();
		var thisYear = y2k(dateObject.getYear());
//		var baseYear = 2004;
		
		if (baseMonth > 0) {
			baseMonth = baseMonth - 1;	
		} else {
			baseMonth = 0;	
		}
		
		for (var i = thisYear; i >= baseYear; i--){

			archive += '<div style="margin-top:5px;"><strong>' + i + '</strong><br>\n<div class="dotsDivider2">&nbsp;</div><ul>';

			if (i == baseYear){
				var startMonth = baseMonth;
			} else {
				var startMonth = 0;
			}

			if (i == thisYear){
				var endMonth = dateObject.getMonth();
			} else {
				var endMonth = 11;
			}
		
			for (j = endMonth; j >= startMonth; j--){

				archive += ('<li><a href=\"' + archivePath + i + '_' + shortMonths[j]);
				
				if (archiveType == 'weekly'){
					archive += ('_w1');
				}

				archive += ('.html\">' + longMonths[j] + ' ' + i + '</a></li>');
			}

			archive += '</ul></div>'

		}
		
		return (archive);
}

//  END ARCHIVE RELATED JAVASCRIPT 


// ***************************************************
//  	BEGIN WEEKEND NEWS RELATED JAVASCRIPT 
//		MHW Time Based Reveal Script v0.4
//  	Contact:  Malte Wendlandt for help
//    For Detailed Information see the wiki at https://wiki.nm.cbc.ca/nm/MHW_Time_Based_Reveal_Script_%28mTBRS%29
// ***************************************************

function revealItem (revealThis, revealStart, revealEnd, currentTime) {   

	var longDays = new Array(
		'sunday',
		'monday',
		'tuesday',
		'wednesday',
		'thursday',
		'friday',
		'saturday'
	);
	
	revealStart 	= revealStart.split(', ');
	revealEnd 		= revealEnd.split(', ');
	currentTime		= currentTime.split(', ');


	
	var thisDayStr = currentTime[0].toLowerCase();
	var thisHour 	= eval(currentTime[1]);

	for ( var counter = 0; counter < longDays.length; counter++ ) {
		if ( longDays[counter] == thisDayStr ) {
			thisDay = counter;	
		}
	}


	if ( thisHour <= 0) {		//  Adjust Day and Time for those instances when the timezone adjustment sets the hour below the valid range of 1 - 24
		thisHour = thisHour + 24;
		thisDay = thisDay - 1;
		if ( thisDay < 0 ) {
			thisDay = 6;	
		}
		thisDayStr = longDays[thisDay];
	}


	if ( thisHour > 24) {		//  Adjust Day and Time for those instances when the timezone adjustment sets the hour above the valid range of 1 - 24
		thisHour = thisHour - 24;
		thisDay = thisDay + 1;
		if ( thisDay > 6 ) {
			thisDay = 0;	
		}
		thisDayStr = longDays[thisDay];
	}

	for ( var counter = 0; counter <= 6; counter++ ){		//	Find the numeric value of the Start and End days

		if ( revealStart[0].toLowerCase() == longDays[counter] ) {
			revealStart[2] = counter;
		} else if ( revealEnd[0].toLowerCase() == longDays[counter] ) {
			revealEnd[2] = counter;
		}	

	}

	if ( thisHour >= revealStart[1] && longDays[thisDay] == revealStart[0].toLowerCase() ) {
		document.getElementById(revealThis).style.display = 'block';
	}


	if ( thisHour < revealEnd[1] && longDays[thisDay] == revealEnd[0].toLowerCase() ) {
		document.getElementById(revealThis).style.display = 'block';
	}

	if ( revealStart[2] < revealEnd[2] ) {			//	The Start Day is before the End Day in the sequence sun - sat

		if ( (thisDay > revealStart[2]) && (thisDay < revealEnd[2]) ) {
				document.getElementById(revealThis).style.display = 'block';
		} 
	
	} else if ( revealStart[2] > revealEnd[2] ) {		//	The End Day is before the Start Day, ie next week.

		if ( thisDay > revealStart[2] && thisDay <= 6 ) {
				document.getElementById(revealThis).style.display = 'block';
		} else if ( thisDay >= 0 && thisDay < revealEnd[2] ) {
				document.getElementById(revealThis).style.display = 'block';
		}
	
	}

}

//  END WEEKEND NEWS RELATED JAVASCRIPT 
