//
//  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('Redemptive Relationships|Ezekiel 16:4-14|02-12-2012');
addRow('How to walk away from the edge of unfaithfulness|2 Samuel 11|02-05-2012');
addRow('Gods Plan for Marriage|Genesis 2:15-24|01-29-2012');
addRow('Letting Go of Super You|Psalm 51:1-12|01-22-2012');
addRow('Healing Is A Process|Isaiah 53:1-5|01-15-2012');
addRow('When Good Is Not Quite Good Enough|Galatians 5:1|01-08-2012');
addRow('Two Inches of Faith|Luke 2:22-40|01-01-2012');
addRow('Christmas Day - Gods Love & Ours||12-25-2011');
addRow('Christmas as Mystery|Luke 1:26-38|12-18-2011');
addRow('Christmas as Comedy|Matthew 1:18-25|12-11-2011');
addRow('Christmas as Tragedy|Genesis 3:13-15|12-04-2011');
addRow('Christmas as Expectation|Luke 1:8-22|11-27-2011');
addRow('From Religion to a Relationship|Acts 9|11-20-2011');
addRow('Moving Outside of our Jerusalem|Acts 7&8|11-13-2011');
addRow('Gifted to Serve|romans 12|11-06-2011');
