//localStorage.clear();
var preload={"currentid":2,"song":[{"id":0,"firstline":"I will praise You, oh Lord, among the nations","words":"v1:\n       Em     D       C               Em\nI will praise You, oh Lord, among the nations\n       C           D         Em\nI will sing of You among the people\nEm                D     C               Em\nFor great is Your love, reaching to the heavens\n     C            D              Em\nYour faithfulness reaches to the skies\n\nchorus:\n     G   D       Em             C\nBe exal  ted, oh God, above the heavens\n         G        D        Em    C\nLet your glory be over the Earth\n     G   D       Em             C\nBe exal  ted, oh God, above the heavens\n         G        D        Em\nLet your glory be over the Earth\nC        D   Em\nOver all the Earth\n\nv2:\n       Em     D       C          Em\nI will praise You, oh God of all creation\n       C               D              Em\nI will give to You the honor due your name\nEm             D         C             Em\nFor You are my hope, and You are my salvation\nC             D            Em\nYou alone are worthy of my praise\n\ncopy:\nMusic by Helen Green, Lyrics by Helen Green and John Green - Copyright © 1997"},{"id":1,"firstline":"The heavens declare,    the glory of God","words":"capo:\n1\n\nv1:\nA             E    Bm7        D\nthe heavens declare,    the glory of God\nA        E              Bm7   D\ncreation shows his handiwork\nA         E    Bm7          D\nday after day, night after night\nA         E                    Bm7   D\na message goes out to all the earth\n\nchorus:\nA              E\nthe heavens declare your glory\nBm7            D\nthe heavens declare your glory\nA              E\nthe heavens declare your glory\nBm7  D                        A\noh  God      (repeat) so will i.....\n\nv2:\nA                E   Bm7                      D\nwe're called to shine,   as lights in the dark\nA       E               Bm7    D\nburning brightly with his love\nA           E     Bm7               D\ntellin' the world,    of all he has done\nA           E                Bm7   D\ntakin' the message to all the earth\n\ncopy: John Green - Recent Rainfall Music 2002\nrecentrainfall.com"}]};
songstore=localStorage.songstore?JSON.decode(localStorage.songstore):preload;
//alert(localStorage.length);

function readSongs()
{
  var out=new Array();
  var i=0;
  songstore.song.each(function(song,i)
  {
    out[i]={};
    out[i].id=song.id;
    out[i].firstline=song.firstline;
    i++;
  });
  return out;
}

function deleteSong(id)
{
  songstore.song.splice(getSongIndex(id),1);
  localStorage.songstore=JSON.encode(songstore);
}

function getSongIndex(id)
{
  var out=0;
  songstore.song.each(function(song,i)
  {
    if(parseInt(song.id)==id)
    {
      out=i;
    }
  });
  return out;
}

function readSong(id)
{
  return songstore.song[getSongIndex(id)];
}

function addSong(words,firstline)
{
//  console.log('add: '+firstline);
  song={id:songstore.currentid++,firstline:firstline,words:words};
  songstore.song.push(song);
 // alert('store: '+JSON.encode(songstore));
  localStorage.songstore=JSON.encode(songstore);
  return songstore.currentid-1;
}

function updateSong(id,words,firstline)
{
//  console.log('update: '+firstline);
  song={id:id,firstline:firstline,words:words};
  songstore.song.splice(getSongIndex(id),1,song);
  localStorage.songstore=JSON.encode(songstore);
}

