//
//  This file is broken out into two section.  A code section followed by a data 
//  section.  Please scroll to the bottom of this file.
//
//  This javascript file controls the data in the podcast page.
//  Each line below is shown in the grid on the padcast page.  
//  There are three parameters on the file.  The first one is the message, 
//  the second one is the scripture and the last one is the date.  There is a 
//  pipe '|' separating the lines.  
//
//  At noon on the date of the last parameter, the podcast will show as a link. 
//  Before that time, the screen will show the date without the link.
//
//  To add a new date, copy a line and change the three fields.  The order of the 
//  lines below will be shown in the page
//   
//  Please note:  Date must be in this format MM-DD-YYYY (with dashes).
//		  Month and date must be two characters (IE '04' NOT '4')
//
//  Sample row:  
//          addRow('Message 1|Test Scripture1|06-15-2008'); 
//

// ********************************
// *********** Code Section *******
// ********************************


function addRow( addTableRow )
{
  var agt=navigator.userAgent.toLowerCase();
   

  var currentDate = new Date();     // creates a new Date representing today
  var dateOnly    = new Date(currentDate.getYear(), currentDate.getMonth(), currentDate.getDate());

  var temp        = addTableRow.split("|");
  var Message     = temp[0];
  var Scripture   = temp[1];
  var serDate     = temp[2];
  var setAnchor   = 0      ; // when 1 then show message as anchor.

  datePart       = serDate.split("-");
  var sermonDate = new Date( datePart[2], datePart[0], datePart[1] ); 
 
  curYear = currentDate.getYear();

  if (curYear < 2000 ) {
    curYear = curYear + 1900;
  }

  yearDiff  = (curYear                    - datePart[2]) * 365 ;
  monthDiff = (currentDate.getMonth() + 1 - datePart[0]) *  28 ;
  dateDiff  = (currentDate.getDate()      - datePart[1]) *   1 ;

  totalDiff = yearDiff  + monthDiff + dateDiff  ;



  if (totalDiff == 0 ){
     if ( currentDate.getHours() > 9 ) {
	setAnchor = 1;
     }
  }

  if (totalDiff > 0 ) { 
	setAnchor = 1; 
  }


  var tbl = document.getElementById('Podlist');
  var lastRow = tbl.rows.length;

  var iteration = lastRow;
  var row       = tbl.insertRow(lastRow);

  var cellRightSel  = row.insertCell(0);
  var cellMiddleSel = row.insertCell(0);
  var cellLeftSel   = row.insertCell(0);
  
  if (setAnchor==1){
	destination = 'http://dewittredeemer.org/podcast/'+ datePart[2]+ datePart[0]+datePart[1]+'.mp3';

	var newanchor  = document.createElement('a');
	newanchor.href = destination ;
	cellLeftSel.appendChild(newanchor);

	newanchor.setAttribute('href',destination);
	newanchor.setAttribute('title','Sermon');
	newanchor.setAttribute('rel','sidebar');
	
	text1 = document.createTextNode(Message) 
	newanchor.appendChild(text1);
        cellLeftSel.appendChild(newanchor);
  } else {
	  text1 = document.createTextNode(Message) 
	  cellLeftSel.appendChild(text1);
  }

  text2 = document.createTextNode(Scripture) 
  cellMiddleSel.appendChild(text2);

  text3 = document.createTextNode(serDate) 
  cellRightSel.appendChild(text3);

return; 
}

// ********************************
// *********** Data Section *******
// ********************************
//  To add a new date, copy a line and change the three fields.  The order of the 
//  lines below will be shown in the page
//   
//  Please note:  Date must be in this format MM-DD-YYYY (with dashes).
//		  Month and date must be two characters (IE '04' NOT '4')
//
//  Sample row:  
//          addRow('Message 1|Test Scripture1|06-15-2008'); 
addRow('Invited to the Big House|Luke 14:15-24|08-01-2010');
addRow('Living Gods Dream|Joshua 3|07-25-2010');
addRow('Living The Dream|Genesis 15|07-18-2010');
addRow('Long term relationships: Guest Speaker, Ron Bekkering|Zephaniah 3:17|07-11-2010');
addRow('I Pledge Allegiance||07-04-2010');
addRow('Storytellers: Guest Speaker, Ron Bekkering||06-27-2010');
addRow('A Father Who Leads|Ephesians 6:4|06-20-2010');
addRow('Burkett:Missionaries to Ukraine||06-13-2010');
addRow('Life After Graduation|Hebrews 11:8|06-06-2010');
addRow('Created for Community|Acts 2:42-47|05-30-2010');
addRow('The Spirit and the Power|Acts 2:2-4|05-23-2010');
addRow('God Has Gone Up|Acts 1:6-14|05-16-2010');
addRow('Impossible Mission|Acts 1:8|05-09-2010');
addRow('Elijah:Leaving a Legacy||05-02-2010');


