//                       order of array is most recent sermon first. Zero for the recording means the recording is unavailable.
//
//                       date,short description,long description,recording available(1 or 0) 
function serieslist () {
   var g_SeriesArray = new Array(
              "14","The Four Corners of Foursquare","uploads/Foursquare/4Cornersof4squareSm.jpg",
              "13","July 4th","uploads/holidays/DependenceDaySm.jpg",
              "10","The Beautiful Attitudes","uploads/Beattitude/beattitude.jpg",
              "12","Father's Day","uploads/holidays/fathersday.jpg",
              "11","Mother's Day","uploads/holidays/mothersday.jpg",
              "8","God's Orchard","uploads/GodsOrchard/Orchardtitle.jpg",
              "9","Easter","uploads/Easter/Easter.jpg",
              "7","Refine", "uploads/refine/Refine.jpg",
              "6","The Art of Living", "uploads/art of  living/Art of Living Background.jpg",
              "5","Take It On Faith", "uploads/take_it_on_faith/Faith Graphic.jpg",
              "4","Fearless Love", "uploads/fearless_love/Fearless Love.jpg",
              "3","Pure Desire", "uploads/pure-desire/Pure Desire.jpg",
              "2","Be Yourself", "uploads/be_yourself/Be Yourself.gif",
              "1","Nurture", "uploads/nurture/Nurture.gif"
			);
   return g_SeriesArray;
}

function sermonlist () {
   var g_SermonArray = new Array(
              "14","08/22/2010","We Are Foursquare", " ", "1",
              "14","08/15/2010","The King is Coming", "Are You Ready", "1",
              "14","08/08/2010","The Healing Corner", "Exploring the Healing Touch of Jesus", "1",
              "14","08/01/2010","Power and Purpose", "Why we need the Baptism of the Holy Spirit", "1",
              "14","07/25/2010","Savior", " ", "1",
              "14","07/18/2010","How Godly Government Guides Foursquare", " ", "1",
              "14","07/11/2010","Connecting Our Hearts to a Movement of God", " ", "1",
              "13","07/04/2010","The Dependence of Independence", "Real liberty depends upon God", "1",
              "10","06/27/2010","Jailhouse Jubilee", "Knowing the blessing that comes from persecution", "1",
              "12","06/20/2010","The Jealous Father", " ", "1",
              "10","06/13/2010","Peace Plan", "Pursing the peace that shows we are God’s children", "1",
              "10","06/06/2010","Heart Vision", "Eliminating the junk that blocks our view of God", "1",
              "10","05/30/2010","Mercy Me", "Mercy is its own reward", "1",
              "10","05/23/2010","Heaven’s Diner", "Developing a hunger and thirst for righteousness", "1",
              "10","05/16/2010","Greetings Earthling!", " ", "1",
              "11","05/09/2010","A Mother’s Discipline", " ", "1",
              "10","05/02/2010","Are You A Mourning Person?", "Loving our enemies by seeing them through the eyes of Christ", "1",
              "10","04/25/2010","Only a spiritual beggar becomes rich in Christ", " ", "1",
              "10","04/18/2010","The Beautiful Attitudes", "What’s It Like to Be Jesus", "1",
              "8","04/11/2010","Guardrails of Self-Control", "Staying firmly on the Narrow Path", "1",
              "9","04/04/2010","Knockin' On Heaven's Door", "Our heart is the doorway to Heaven", "1",
              "8","03/28/2010","Corralling Gentleness", "Taming the Disciple's Heart", "1",
              "8","03/21/2010","The Key of Faithfulness", "Unlocking the Door to Abundant Life", "1",
              "8","03/14/2010","Good to Go", "Discovering the source of true goodness", "1",
              "8","03/07/2010","Cultivating Kindness", "Kindness is Love in Action", "0",
              "8","02/28/2010","Patience and the Promised Land", "Lessons on patience from the life of Moses", "1",
              "8","02/21/2010","Refined Peace", "Discovering the fruit of peace in all circumstances", "1",
              "8","02/14/2010","Joyful, Joyful", "Growing the Fruit of Joy", "1",
              "8","02/07/2010","Concrete Love", "Examining the Fruit of Love", "1",
              "8","01/31/2010","God's Orchard", "Examining the Fruit of the Holy Spirit", "1",
              "7","01/24/2010","Refine", " ", "1",
              "6","01/17/2010","God and Country", "How disciplined Christianity can restore our land", "1",
              "6","01/10/2010","Banking on God", " ", "1",
              "6","01/03/2010","Reflection", "Reflect back on 2009 to see how god has moved in your life. Pray about what he will do for you in 2010", "0",
              "6","12/27/2009","God Hugs 2", "Embracing God through the spiritual disciplines of engagement", "0",
              "6","12/20/2009","God Hugs 1", "Embracing God through the spiritual disciplines of engagement", "1",
              "6","12/13/2009","Living In Denial 2", "Denying the flesh to build the spirit", "1",
              "6","12/06/2009","Living In Denial", "Denying the flesh to build the spirit", "1",
              "6","11/29/2009","Christianity Is Fun", "Exploding the myth that Christianity is boring", "1",
              "6","11/22/2009","Controlled Burn", "Burning away spiritual impurities with Holy Spirit fire!", "1",
              "6","11/15/2009","In God's Workshop", "Experiencing the loving discipline of our Heavenly Father", "1",
              "6","11/08/2009","Cross Purposes", "Accepting the easy yoke and the light burden of Jesus", "1",
              "5","11/01/2009","Multipied Faith", "Faith in the One Who Feeds the Multitudes", "1",
              "5","10/25/2009","Armored Faith", " ", "1",
              "5","10/18/2009","Timing of Faith", " ", "1",
              "5","10/11/2009","Faith That Works", " ", "1",
              "5","10/04/2009","Stormy Faith", " ", "1",
              "5","09/27/2009","Avoiding Shipwrecked Faith", " ", "1",
              "5","09/20/2009","Groundless Faith", " ", "1",
              "5","09/13/2009","Without A Doubt", " ", "1",
              "5","09/06/2009","Seeing Is Not Believing", " ", "1",
              "4","08/30/2009","Fearless Love", " ", "1",
              "3","08/23/2009","Tools of Desire", " ", "1",
              "3","08/16/2009","Filled with Desire", " ", "1",
              "3","08/09/2009","The Prayer of Desire", " ", "0",
              "3","08/02/2009","Burning Desire", " ", "0",
              "3","07/26/2009","The Pain of Desire", "How suffering refines the desire within.", "0",
              "2","07/19/2009","Within Myself", "The new creation.", "1",
              "2","07/12/2009","Guest Speaker Robin Smyth", "Tent Makers of Rwanda", "1",
              "2","07/05/2009","Just Myself", "What is God calling me to be? 2 Corinthians 10:12.", "1",
              "2","06/28/2009","Beside Myself", "Coveting) not wishing to be someone else.", "1",
              "2","06/21/2009","Fathers Day", "A King and His Castle. Deuteronomy 17:14-20, Isa 39:8", "1",
              "2","06/14/2009","Below myself", "not allowing false humility to hold us back from God's calling.", "1",
              "2","06/07/2009","Above Myself", "Job 29 not defining our self Image with things, jobs or perks.", "1",
              "1","1/1/2009","", "", "5",
              "1","12/31/2009","Crosspoint Spiritual Vision:", "Nurture", "5"
			);
   return g_SermonArray;
}

function htmlencode (str) 
{

   return str.replace(/&/g,'&amp;').replace(/"/i,'&quot;').replace(/</i,'&lt;').replace(/>/i,'&gt;').replace(/`/i,'&apos;').replace(/'/i,'&apos;').replace(/’/i,'&apos;');
}
function urlencode (str) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: This reflects PHP 5.3/6.0+ behavior
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
 
    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };
 
    var ret = '',
            unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();
 
    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            // Reserved assumed to be in UTF-8, as in PHP
            if (code === 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) { // 3 bytes
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}	
function format2digit(i)
{
  if (i<10)
  {
    j="0" + i;
  }
  else
  {
    j="" + i;
  }
return j;
}

function BuildSermonList(listType)
{
  var d=new Date();
  var SeriesArray = [];
  var SermonArray = [];
  SeriesArray = serieslist();
  SermonArray = sermonlist();
  var retBuf;
  var seriesStart="";
  var seriesEnd="";
  //alert( " we are here2" );
  var i_SeriesItems=0;
  var i_Increment=3; // series increment
  var seriesID="";
  var sermonBuf=" ";
  var tmpArray = new Array();
  var i_Items=0;
  var songtitle=" ";
  var mp3name=" ";
  var outlinename=" ";
  if( listType == 1 ) // current series, zero means all
  {
	 i_Increment = 999; // used to stop after one
  }
  else
  {
     if( listType == 2 ) // everything but current series
     {
        i_SeriesItems=3;
     }
	 else
	 {
	    if( listType == 3 )
		{
			i_Increment = 999; // used to stop after one
           tmpArray = SermonArray[0+1].split('/');
//           alert( tmpArray[0] );
//           alert( tmpArray[1] );
//           alert( tmpArray[2] );
           d.setFullYear(tmpArray[2]*1,(tmpArray[0]*1)-1,tmpArray[1]*1); //latest sunday month is one digit lower than on the calendar
		    retBuf="<a href=\"sermons/" + d.getFullYear() + format2digit(d.getMonth()+1) + format2digit(d.getDate()) + ".pdf\" target=\"_blank\">View Current Message Outline</a>";
			return retBuf;
		}
	 }
  }

  retBuf = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";
  do
  {
     seriesID = SeriesArray[i_SeriesItems];
	 // #############################################################################
     i_Items=0;
     songtitle=" ";
     mp3name=" ";
	 sermonBuf = " ";
     seriesStart="";
     seriesEnd="";
     do
     {
//	 alert( SermonArray[i_Items] );
//	 alert( SeriesArray[i_SeriesItems] );
	    if( SermonArray[i_Items] == SeriesArray[i_SeriesItems] )
		{
		   if( sermonBuf.length < 2 )
		   {
               sermonBuf="<td><ul>";
		   }
		   if( seriesStart.length < 2 )
		   {
		       seriesStart = SermonArray[i_Items+1];
		       seriesEnd = SermonArray[i_Items+1]; // in case it is only one week
		   }
		   else
		   {
		       seriesEnd = SermonArray[i_Items+1];
		   }
           tmpArray = SermonArray[i_Items+1].split('/');
//           alert( tmpArray[0] );
//           alert( tmpArray[1] );
//           alert( tmpArray[2] );
           d.setFullYear(tmpArray[2]*1,(tmpArray[0]*1)-1,tmpArray[1]*1); //latest sunday month is one digit lower than on the calendar
           songtitle=urlencode(SermonArray[i_Items+2]);
	       mp3name="sermons/" + d.getFullYear() + format2digit(d.getMonth()+1) + format2digit(d.getDate()) + ".mp3";
	       outlinename="sermons/" + d.getFullYear() + format2digit(d.getMonth()+1) + format2digit(d.getDate()) + ".pdf";

		   if( SermonArray[i_Items+4] == "5")
		   {
	          if( SermonArray[i_Items+2].length > 2 )
	          {
                 sermonBuf += "<li height=15><strong>";
		         sermonBuf += SermonArray[i_Items+2] + " " + SermonArray[i_Items+3];
				 sermonBuf += "</strong></li>";
			  }
		   }
		   else
		   {
              sermonBuf += "<li>";
			  sermonBuf += "<a href=\"" + outlinename + "\" target=\"_blank\">";
		      sermonBuf += format2digit(d.getMonth()+1) +"/"+ format2digit(d.getDate()) + "/" + d.getFullYear() + " " + htmlencode(SermonArray[i_Items+2]);
	          if( SermonArray[i_Items+3].length > 2 )
	          {
	             sermonBuf += " - " + htmlencode(SermonArray[i_Items+3]);
	          }
	          sermonBuf += "<br />";
	          if( SermonArray[i_Items+4] != "1")
	          {
                 songtitle=urlencode("Not Available");
	             mp3name="sermons/notavail.mp3";
	          }  
              sermonBuf += "</a><object type=\"application/x-shockwave-flash\" width=\"400\" height=\"15\" data=\"sermons/xspf_player_slim.swf?player_title="+songtitle+"&song_title="+songtitle+"&song_url=" + mp3name + "\"><param name=\"movie\" value=\"xspf_player_slim.swf?song_title="+songtitle+"&song_url=" + mp3name + "\" /></object> ";
			  sermonBuf += "</li>";
		   }
		}
//	 alert( sermonBuf );
        i_Items += 5;
     }
     while (i_Items < SermonArray.length);
     if( sermonBuf.length > 2 )
     {
         sermonBuf+="</ul></td></tr>";
     }
//	 alert( sermonBuf );
	 // #############################################################################
     retBuf += "<tr><td valign=\"top\"><img src=\"" + SeriesArray[i_SeriesItems+2] + "\" alt=\"" + SeriesArray[i_SeriesItems+1] + "\" width=\"134\" height=\"101\" /><br /><strong>";
     if( SeriesArray[i_SeriesItems+1].length > 2 )
     {
	    retBuf += SeriesArray[i_SeriesItems+1];
	 }
	 retBuf +="</strong><br />";
     if( seriesStart.length > 2 )
     {
        // start date
        tmpArray = seriesStart.split('/');
        d.setFullYear(tmpArray[2]*1,(tmpArray[0]*1)-1,tmpArray[1]*1); //latest sunday month is one digit lower than on the calendar
	    retBuf += (d.getMonth()+1) +"/"+ d.getDate() + "/" + (d.getFullYear()).toString().slice(2);
        // end date
        tmpArray = seriesEnd.split('/');
        d.setFullYear(tmpArray[2]*1,(tmpArray[0]*1)-1,tmpArray[1]*1); //latest sunday month is one digit lower than on the calendar
	    retBuf += " - " + (d.getMonth()+1) +"/"+ d.getDate() + "/" + (d.getFullYear()).toString().slice(2) + "</td>";
	    retBuf += sermonBuf;
	 }
     i_SeriesItems += i_Increment;
  }
  while (i_SeriesItems < SeriesArray.length); 

  retBuf += "</table>";
return retBuf;
}

