window.onload = initPage;
var numPictures = 0;
var contentPane;
var request;
var pictureCounter = 1;
var pictureArray;
var bookArray;
var speakerArray;
var sermonArray;
var seriesArray;
var sermon = new latestSermonObj(null, "", "", "");
var divOverlay;
var sermonSQL = "SELECT a.date, b.first, b.last, c.description,"
+ " a.chapter, a.file, a.title, a.comments, a.slidefile \n"
+ " from audio_files a, \n"
+ " speaker b,\n"
+ " book c\n"
+ " where b.speaker = a.speaker\n"
+ " and c.book = a.book";
var sermonOrder = "\n order by date desc";

var msBrowser=(navigator.appName).substr(0, 9).toLowerCase()=="microsoft";

function parseDBDate(d) {
  if (d!=null) {
    var yr = d.substr(0, 4);
    var mm = d.substr(5, 2);
    var dd = d.substr(8, 2);
    var offset = (new Date()).getTimezoneOffset()/60;
    var rtn=new Date(Date.UTC(yr, mm-1, dd, offset));
    return rtn;
  } else
    return null;
}

function latestSermonObj(d, s, t, f) {
  this.sermonDate=parseDBDate(d);
  this.speaker=s;
  this.title=t;
  this.filename=f;
//alert("d = "+d+this.sermonDate);
}

var warnings = {
  "fullNameTB" : {
    "required": "Please enter your full name.",
    "err"     : 0
  },
  "commentTA" : {
    "required": "Please include a comment.",
    "err"     : 0
  },
  "emailTB" : {
    "required": "Please enter in your e-mail address.",
    "format" : "Please enter your e-mail in the form 'name@domain.com'.",
    "err"     : 0
  }
}

$(document).ready(function () {
  $('#nav-one ul.children').hide();
  $('#nav-two ul.children').hide();
  $('#nav-three ul.children').hide();
  $('#nav-one').hover(
    function () {
      //change the background of parent menu
      $('#nav-one li a.nav').addClass('hover');
      //display the submenu
      $('#nav-one ul.children').show();
    },
    function () {
      //change the background of parent menu
      $('#nav-one li a.nav').removeClass('hover');
      //display the submenu
      $('#nav-one ul.children').hide();
    });
  $('#nav-two').hover(
    function() {
      //change the background of parent menu
      $('#nav-two li a.nav').addClass('hover');
      //display the submenu
      $('#nav-two ul.children').show();
    }, function() {
      //change the background of parent menu
      $('#nav-two li a.nav').removeClass('hover');
      //display the submenu
      $('#nav-two ul.children').hide();
    });
  $('#nav-three').hover(
    function() {
      //change the background of parent menu
      $('#nav-three li a.nav').addClass('hover');
      //display the submenu
      $('#nav-three ul.children').show();
    }, function() {
      //change the background of parent menu
      $('#nav-three li a.nav').removeClass('hover');
      //display the submenu
      $('#nav-three ul.children').hide();
    });
});

function initPage() {
  autoScroll('scroller_container','scrollcontent',10,true);
  //  loadNewsScroller();
  hideDevelopmentContent();
  defaultState();
  if (numPictures==0)
    initialLoad();
  t=setInterval(changePicture, 10000);
}

function initialLoad() {
  request = createRequest();
  if (request==null)
    alert('Unable to create Ajax request');
  var url = 'initialDBCall.php';
  request.open('GET', url, true);
  request.onreadystatechange = function() {
    if ((request.readyState==4) && (request.status==200)) {
      var results = eval('(' + request.responseText + ')');
      pictureArray = results[0];
      numPictures = pictureArray.length;
      sermonArray = results[1];
      sermon = new latestSermonObj(sermonArray[0][0],
        sermonArray[0][1]+" "+sermonArray[0][2],
        sermonArray[0][6],
        sermonArray[0][5]);
      bookArray =results[2];
      speakerArray = results[3];
      seriesArray = results[4];
      divOverlay = document.createElement("div");
      divOverlay.setAttribute("id", "bannerPicText");
      var h2 = document.createElement("h2");
      h2.appendChild(document.createTextNode("This Week's Message:"));
      divOverlay.appendChild(h2);
      divOverlay.appendChild(document.createElement("br"));
      var p = document.createElement("p");
      p.appendChild(document.createTextNode(sermon.title));
      divOverlay.appendChild(p);
      divOverlay.appendChild(document.createElement("br"));
      var p2 = document.createElement("p");
      p2.setAttribute("class", "citation");
      p2.setAttribute("className", "citation");
      p2.appendChild(document.createTextNode("By: " + sermon.speaker +
        " - Recorded on: " + (sermon.sermonDate).toDateString()));
      divOverlay.appendChild(p2);
    }
  };
  request.send(null);
}

function hideDevelopmentContent() {
  var hiddenContent = document.getElementsByTagName("li");
  var parent;
  for (var i=0; i<hiddenContent.length; i++) {
    if ((hiddenContent[i].getAttribute("className")=="hide") ||
      (hiddenContent[i].getAttribute("class")=="hide")) {
      parent = hiddenContent[i].parentNode;
      clearChildren(hiddenContent[i]);
      parent.removeChild(hiddenContent[i]);
    }
  }
}

function loadNewsScroller() {
  reqNews = createRequest();
  if (reqNews==null)
    alert("unable to create ajax request");
  var url = "readHTML.php?page=html/announcements.html";
  reqNews.open("GET", url, false);
  reqNews.send(null);
  var rightPane = document.getElementById("scrollerPane");
  clearChildren(rightPane);
  rightPane.innerHTML=reqNews.responseText;
}

function requestContent(htmlData, className) {
  request1 = createRequest();
  if(request1==null)
    alert("unable to create ajax request");
  var url = "readHTML.php?page="+htmlData;
  request1.open("GET", url, false);
  request1.send(null);
  //  request1.onreadystatechange=function() {
  //    if ((request1.readyState == 4) && (request1.status == 200)) {
  contentPane = document.getElementById("homeLeft");
  //remove any content
  clearChildren(contentPane);

  //Add the new content
  var div1 = document.createElement("div");
  div1.setAttribute("id", "DefaultContent");
  div1.setAttribute("class", className);
  div1.setAttribute("className", className);
  contentPane.appendChild(div1);
  //BetterInnerHTML(document.getElementById("DefaultContent"), url2, true);
  div1.innerHTML=request1.responseText;
//    }
//  };
}

function sendMail() {
  mailReq = createRequest();
  if(mailReq==null)
    alert("Unable to create AJAX request");
  else {
    var url = "sendMail.php";
    var reqData = "fullName="+
    escape(document.getElementById("fullNameTB").value)+"&eMail="+
    escape(document.getElementById("emailTB").value)+"&phone="+
    escape(document.getElementById("phoneTB").value)+"&comment="+
    escape(document.getElementById("commentTA").value);
    mailReq.onreadystatechange = function() {
      if ((mailReq.readyState==4) && (mailReq.status==200)) {
        var div=document.getElementById("DefaultContent");
        var p=document.createElement("p");
        p.className="center";
        p.appendChild(document.createTextNode(mailReq.responseText));
        div.appendChild(p);
      }
    };
    mailReq.open("POST",url,true);
    mailReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mailReq.send(reqData);
  }
}

function selectSermons() {
  sermonReq = createRequest();
  if(sermonReq==null)
    alert("Unable to create AJAX request");
  else {
    var url = "readDB.php";
    var speaker=document.getElementById("speakerSel").value;
    var book=document.getElementById("bookSel").value;
    var series=document.getElementById("seriesSel").value;
    var sql=sermonSQL;
    if (speaker!=" ")
      sql+="\n    and b.speaker='"+speaker+"'";
    if (book!=" ")
      sql+="\n    and c.book='"+book+"'";
    if (series!=" ")
      sql+="\n    and a.series='"+series+"'";
    sql+=sermonOrder;
    var sermonData = "sql="+sql;
    sermonReq.onreadystatechange = function() {
      if ((sermonReq.readyState==4) && (sermonReq.status==200)) {
        var results = eval('(' + sermonReq.responseText + ')');
        sermonArray = results;
        buildAudioTable();
      }
    };
    sermonReq.open("POST", url, true);
    sermonReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    sermonReq.send(sermonData);
  }
}

function downloadFile(f) {
  req2 = createRequest();
  if (req2==null)
    alert("unable to create Ajax Request");
  //updateDownloadCount(sermonArray[row][0]);
  var url="download.php?file="+f;
  alert("Calling: "+url);
  req2.open("GET", url, false);
  req2.send(null);
}

function updateDownloadCount(date) {
  alert("date = "+date);
  sqlDateReq = createRequest();
  if (sqlDateReq==null)
    alert("Unable to create Ajax Request");
  else {
    var url = "writeDB.php";
    var sql = "sql=update audio_files set download_cnt = download_cnt + 1 where date = '"+date+"'";
    alert("SQL = "+sql);
    sqlDateReq.onreadystatechange = function() {
      if ((sqlDateReq.readyState==4) && (sqlDateReq.status==200)) {
        alert("SQL RAN");
      }
    };
    sqlDateReq.open("POST", url, true);
    sqlDateReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    sqlDateReq.send(sql);
  }
}

function defaultState() {
  contentPane = document.getElementById("homeLeft");
  //Remove any content
  clearChildren(contentPane);

  //Add the default DIV
  var div1 = document.createElement("div");
  div1.setAttribute("id", "DefaultContent");
  var div2 = document.createElement("div");
  div2.setAttribute("id", "");
  div2.setAttribute("class", "welcome");
  div2.setAttribute("className", "welcome");
  var div3 = document.createElement("div");
  div3.setAttribute("id", "");
  div3.setAttribute("class", "welcomeText");
  div3.setAttribute("className", "welcomeText");
  var welcomeText1 = document.createTextNode("We hope you enjoy this site and "+
    "find all the information about EBC that you could need. We are so excited to "+
    "be a part of the Ennis community and to reaching out to Ellis county with " +
    "the life changing gospel of Jesus Christ. There is plenty to share about our " +
    "church and it's ministries. If you are new, make sure you check out " +
    "our ");
  var welcomeText2 = document.createElement("a");
  welcomeText2.appendChild(document.createTextNode("\"Newcomer's\""));
  // The following code is required for getting around the IE limitation of
  // not being able to set attribute on onclick()
  welcomeText2.onclick = function() {
    requestContent('html/newComers.html', "textPane");
  };
  var welcomeText3 = document.createTextNode(" page as a place to start.");
  var div4 = document.createElement("div");
  div4.setAttribute("className", "bottompicts");

  var img1 = document.createElement("img");
  img1.setAttribute("src", "images/newcomer.jpg");
  img1.setAttribute("alt", "Newcommers Welcome!");
  img1.setAttribute("width", "220px");
  img1.setAttribute("height", "155px");
  img1.className = "bottompicts";
  img1.onclick=function () {
    requestContent('html/newComers.html', "textPane");
  };

  var img2 = document.createElement("img");
  img2.setAttribute("src", "images/events.jpg");
  img2.setAttribute("alt", "Events Calendar");
  img2.setAttribute("width", "220px");
  img2.setAttribute("height", "155px");
  img2.className = "bottompicts";
  img2.onclick=function() {
    displayCalendar();
  };

  var img3 = document.createElement("img");
  img3.setAttribute("src", "images/connect.jpg");
  img3.setAttribute("alt", "Connect");
  img3.setAttribute("width", "220px");
  img3.setAttribute("height", "155px");
  img3.className = "bottompicts";
  img3.onclick=function() {
    requestContent('html/lifegroup.html', "textPane");
  };

  div4.appendChild(img1);
  div4.appendChild(img2);
  div4.appendChild(img3);

  div3.appendChild(welcomeText1);
  div3.appendChild(welcomeText2);
  div3.appendChild(welcomeText3);
  div2.appendChild(div3);
  div1.appendChild(div2);
  div1.appendChild(div4);
  contentPane.appendChild(div1);
}

function clearChildren(elem) {
  for (var i = elem.childNodes.length; i>0; i--)
    elem.removeChild(elem.childNodes[i-1]);
}

function changePicture() {
  if (numPictures!=0) {
    var idx = (pictureCounter++) % numPictures;
    var url = "images/bannerPictures/" + pictureArray[idx][1];
    var alt = pictureArray[idx][2];
    var link = pictureArray[idx][3];
    var newTab = (pictureArray[idx][4]=="1");
    var overlay = (pictureArray[idx][5]=="1");
    var bannerPic = document.getElementById("bannerPic");

    if (bannerPic.hasChildNodes()) {
      // Remove current children
      for (var i=bannerPic.childNodes.length; i>0; i--)
        bannerPic.removeChild(bannerPic.childNodes[i-1]);

      // Add new Image Child
      if (!overlay) {
        var img = document.createElement("img");
        img.setAttribute("src", url);
        img.setAttribute("alt", alt);
        if (link!="") {
          var imgLink = document.createElement("a");
          imgLink.setAttribute("href", link);
          if (newTab)
            imgLink.setAttribute("target", "_blank");
          imgLink.appendChild(img);
          bannerPic.appendChild(imgLink);
        }else {
          bannerPic.appendChild(img);
        }
      } else {
        var style="url(" + url + ")";
        divOverlay.style.backgroundImage = style;
        if (link!="") {
          var divLink = document.createElement("a");
          divLink.setAttribute("href", link);
          if (newTab)
            divLink.setAttribute("target", "_blank");
          divOverlay.appendChild(divLink);
        }
        bannerPic.appendChild(divOverlay);
      }
    }
  }
}

function create_contact_form() {
  contentPane = document.getElementById("homeLeft");
  //Remove any content
  clearChildren(contentPane);

  var div1 = document.createElement("div");
  div1.setAttribute("id", "DefaultContent");
  div1.setAttribute("class", "textPane");
  div1.setAttribute("className", "textPane");

  var h2 = document.createElement('h2');
  h2.setAttribute("class", "center");
  h2.setAttribute("className", "center");
  h2.appendChild(document.createTextNode("CONTACT US"));
  div1.appendChild(h2);

  var p1 = document.createElement("p");
  p1.setAttribute("class", "center");
  p1.setAttribute("className", "center");
  p1.appendChild(document.createTextNode("If you have any questions about " +
    "Ennis Bible Church, its ministries, or just have questions about " +
    "Christianity in general, we would love to hear from you."));
  div1.appendChild(p1);
  div1.appendChild(document.createElement("br"));

  var formDiv = document.createElement("div");
  formDiv.setAttribute("class", "eMailForm");
  formDiv.setAttribute("className", "eMailForm");

  var pname = document.createElement("fieldset");
  var lname = document.createElement("label");
  lname.setAttribute("for", "fullNameTB");
  lname.appendChild(document.createTextNode("Full Name*:"));
  lname.appendChild(document.createElement("br"));
  pname.appendChild(lname);
  var iname = document.createElement("input");
  iname.setAttribute("class", "textbox1");
  iname.setAttribute("className", "textbox1");
  iname.setAttribute("name", "fullNameTB");
  iname.setAttribute("id", "fullNameTB");
  iname.setAttribute("type", "text");
  pname.appendChild(iname);
  formDiv.appendChild(pname);

  var pEmail = document.createElement("fieldset");
  var lEmail = document.createElement("label");
  lEmail.setAttribute("for", "emailTB");
  lEmail.appendChild(document.createTextNode("eMail Addres*:"));
  lEmail.appendChild(document.createElement("br"));
  pEmail.appendChild(lEmail);
  var iemail = document.createElement("input");
  iemail.setAttribute("class", "textbox1");
  iemail.setAttribute("className", "textbox1");
  iemail.setAttribute("name", "emailTB");
  iemail.setAttribute("id", "emailTB");
  iemail.setAttribute("type", "text");
  pEmail.appendChild(iemail);
  formDiv.appendChild(pEmail);

  var pPhone = document.createElement("fieldset");
  var lPhone = document.createElement("label");
  lPhone.setAttribute("for", "phoneTB");
  lPhone.appendChild(document.createTextNode("Phone Number:"));
  lPhone.appendChild(document.createElement("br"));
  pPhone.appendChild(lPhone);
  var iphone = document.createElement("input");
  iphone.setAttribute("class", "textbox1");
  iphone.setAttribute("className", "textbox1");
  iphone.setAttribute("name", "phoneTB");
  iphone.setAttribute("id", "phoneTB");
  iphone.setAttribute("type", "text");
  pPhone.appendChild(iphone);
  formDiv.appendChild(pPhone);
  
  var pComments = document.createElement("fieldset");
  var lComments = document.createElement("label");
  lComments.setAttribute("for", "commentTA");
  lComments.appendChild(document.createTextNode("Comments or Questions*:"));
  lComments.appendChild(document.createElement("br"));
  pComments.appendChild(lComments);
  var taComment = document.createElement("textarea");
  taComment.setAttribute("class", "textarea1");
  taComment.setAttribute("className", "textarea1");
  taComment.setAttribute("name", "commentTA");
  taComment.setAttribute("id", "commentTA");
  taComment.setAttribute("rows", "2");
  taComment.setAttribute("cols", "20");
  pComments.appendChild(taComment);
  formDiv.appendChild(pComments);

  formDiv.appendChild(document.createElement("p").
    appendChild(document.createTextNode("* Required Fields")));

  formDiv.appendChild(document.createElement("br"));

  var iSubmit = document.createElement("input");
  iSubmit.setAttribute("type", "submit");
  iSubmit.setAttribute("name", "submitBtn");
  iSubmit.setAttribute("id", "submitBtn");
  iSubmit.setAttribute("value", "submit");
  iSubmit.setAttribute("disabled", "true");
  formDiv.appendChild(iSubmit);

  formDiv.appendChild(document.createElement("br"));
  
  div1.appendChild(formDiv);
  contentPane.appendChild(div1);
  
  addEventHandler(document.getElementById("fullNameTB"), "blur", fieldIsFilled);
  addEventHandler(document.getElementById("emailTB"), "blur", fieldIsFilled);
  addEventHandler(document.getElementById("emailTB"), "blur", eMailIsProper);
  addEventHandler(document.getElementById("commentTA"), "blur", fieldIsFilled);
  addEventHandler(document.getElementById("submitBtn"), "click", sendMail);
}

function buildListenPane() {
  requestContent('html/listen.html', "listenPane");
  var sel = document.getElementById("speakerSel");
  var options;
  var itm;
  var i;
  for (i=0;i < speakerArray.length; i++)  {
    options = document.createElement("option");
    options.setAttribute("value", speakerArray[i][0]);
    options.appendChild(document.createTextNode(speakerArray[i][3]));
    sel.appendChild(options);
  }
  sel = document.getElementById("bookSel");
  for (i=0; i<bookArray.length; i++) {
    options = document.createElement("option");
    options.setAttribute("value", bookArray[i][0]);
    options.appendChild(document.createTextNode(bookArray[i][1]));
    sel.appendChild(options);
  }
  sel = document.getElementById("seriesSel");
  for (i=0; i<seriesArray.length; i++) {
    options = document.createElement("option");
    options.setAttribute("value", seriesArray[i][0]);
    options.appendChild(document.createTextNode(seriesArray[i][1]));
    sel.appendChild(options);
  }
  addEventHandler(document.getElementById("search"), "click", selectSermons);

  //var plyr=document.getElementById("embedderPlayer");
  var media=sermon.filename;
  setAudioFile2(media, sermon.title, sermon.speaker, (sermon.sermonDate));

  turnOffAutoStart()

  buildAudioTable();
}

function buildAudioTable() {
  var sermonTbl=document.getElementById("sermons");
  clearChildren(sermonTbl);

  var tb=document.createElement("tbody");

  var row=document.createElement("tr");
  row.className="tHeader";
  row.appendChild(addTD2("Listen", "tHeader"));
  //  row.appendChild(addTD2("Download", "tHeader"));
  row.appendChild(addTD2("Date", "tHeader"));
  row.appendChild(addTD2("Speaker", "tHeader"));
  row.appendChild(addTD2("Title (Click to Download)", "tHeader"));
  row.appendChild(addTD2("Notes", "tHeader"));
  tb.appendChild(row);

  var speaker;
  var filename;
  var sermondate;
  var slidefile;
  var title;

  for (i=0; i<sermonArray.length; i++) {
    sermondate=parseDBDate(sermonArray[i][0]);
    speaker=sermonArray[i][1]+" "+sermonArray[i][2];
    filename=sermonArray[i][5];
    title=sermonArray[i][6];
    if (sermonArray[i][8]=="")
      slidefile="";
    else
      slidefile="docs/"+sermonArray[i][8];
    row=document.createElement("tr");
    row.appendChild(addTD4(" ", "tListen", "images/headphones-small.png", i));
    row.appendChild(addTD2(sermondate.toDateString()));
    row.appendChild(addTD1(speaker));
    row.appendChild(addTDa(title, i));
    if (slidefile=="")
      row.appendChild(addTD1(" "));
    else
      row.appendChild(addTD4(slidefile, "tSupport", "images/download.png"))
    tb.appendChild(row);
  }
  sermonTbl.appendChild(tb);
}

function addTD4(txt, cls, img, row) {
  var cell=document.createElement("img");
  cell.setAttribute("src", img);
  cell.setAttribute("alt", cls+txt);
  cell.className=cls;
  cell.setAttribute("border", "0 0 0 0")
  var col=document.createElement("td");
  if (cls=="tListen") {
    cell.onclick=function() {
      setAudioFile(row);
    };
    col.appendChild(cell);
  } else if (cls=="tSupport") {
    var slideLink = document.createElement("a");
    slideLink.setAttribute("href", txt);
    slideLink.setAttribute("target", "_blank");
    slideLink.appendChild(cell);
    col.appendChild(slideLink);
    //var cmd1="download.php?file="+txt;
    //cell.onclick=downloadFile(txt);
    //cell.setAttribute("href", cmd1);
    //cell.onclick=function() {
    //  req2 = createRequest();
    //  if (req2==null)
    //    alert("unable to create Ajax Request");
    //  //updateDownloadCount(sermonArray[row][0]);
    //  var url="download.php?file="+txt;
    //  req2.open("GET", url, false);
    //  req2.send(null);
    //};
  }
  return col;
}

function addTD1(txt) {
  var col=document.createElement("td");
  col.appendChild(document.createTextNode(txt));
  return col;
}

function addTD2(txt, cls) {
  var col=document.createElement("td");
  if (cls!=null)
    col.className=cls;
  col.appendChild(document.createTextNode(txt));
  return col;
}

function addTDa(txt, row) {
  var col=document.createElement("td");

//  var a = document.createElement("a");
//  // The following code is required for getting around the IE limitation of
//  // not being able to set attribute on onclick()
//  a.onclick = function() {
//    downloadFile(row);
//  };
//  a.appendChild(document.createTextNode(txt));

  var a=document.createElement("a");
  a.setAttribute("href", "download.php?file="+sermonArray[row][5]+
    "&date="+sermonArray[row][0]);
  a.appendChild(document.createTextNode(txt));
  col.appendChild(a);
  return col;
}

function setAudioFile(row) {
  setAudioFile2(sermonArray[row][5],
    sermonArray[row][6],
    sermonArray[row][1]+" "+sermonArray[row][2],
    parseDBDate(sermonArray[row][0]));
}

function setAudioFile2(media, title, speaker, date) {
  var mp;
  media="audio/" + media;
  if (msBrowser) {
    mp=document.getElementById("MediaPlayer1");
    mp.fileName = media;
    //    mp.src = media;
    //    mp.autoplay = "true";
    mp.autoStart = "true";
  } else {
    mp=document.getElementById("embeddedPlayer");
    mp.src=media;
    //    mp.setAttribute("src", media);
    //    mp.setAttribute("autoplay", "true");
    mp.setAttribute("autoStart", "true");
  }
  var itm=document.getElementById("sermonTitle");
  clearChildren(itm);
  itm.appendChild(document.createTextNode(title));
  itm=document.getElementById("speakerAndDate");
  clearChildren(itm);
  var spk=speaker+' - '+date.toDateString();
  itm.appendChild(document.createTextNode(spk));
}

function turnOffAutoStart() {
  var mp;
  if (msBrowser) {
    mp=document.getElementById("MediaPlayer1");
    //    mp.autoplay = "false";
    mp.autoStart = "false";
  } else {
    mp=document.getElementById("embeddedPlayer");
    //    mp.setAttribute("autoplay", "false");
    mp.setAttribute("autoStart", "false");
  }

}

function displayCalendar() {
  contentPane = document.getElementById("homeLeft");
  // Remove any content
  clearChildren(contentPane);
  requestContent('html/calendar.html', "calPane");

//  var div1 = document.createElement("div");
//  div1.setAttribute("id", "calendar");
//  var iframe = document.createElement("iframe");
//  iframe.className = "calendar";
//  iframe.src="https://www.google.com/calendar/embed?showTitle=0&amp;showPrint=0&amp;showCalendars=0&amp;height=600&amp;wkst=1&amp;hl=en&amp;bgcolor=%23FFFFFF&amp;src=ennisbiblechurch%40gmail.com&amp;color=%232952A3&amp;ctz=America%2FChicago";
//  div1.appendChild(iframe);
//  contentPane.appendChild(div1);
}

function getGoogleMap() {
  contentPane = document.getElementById("homeLeft");
  //Remove any content
  clearChildren(contentPane);

  var div1 = document.createElement("div");
  div1.setAttribute("id", "map");
  contentPane.appendChild(div1);
 
  var startLatLon = new google.maps.LatLng(32.334366,-96.615808);
  var churchLatLon = new google.maps.LatLng(32.3315736226227,
    -96.61707937717438);
  //var churchImage = 'images/flag.png';
  var churchImage = 'images/round_push_1.gif';
  var myMapOptions = {
    zoom: 16,
    center: startLatLon,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: true,
    mapTypeControlOptions: {
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    },
    navigationControl: true,
    navigationControlOptions: {
      style: google.maps.NavigationControlStyle.SMALL
    }
  };
  var map = new google.maps.Map(document.getElementById("map"), myMapOptions);
  var churchMarker = new google.maps.Marker({
    position: churchLatLon,
    map: map,
    icon: churchImage
  });
  var churchInfo = new google.maps.InfoWindow({
    position: churchLatLon,
    content: "<div class=\"mapInfo\">" +
  "<img src=images/ebc2-thumb.jpg alt=logo /><br>" +
  "<b>Ennis Bible Church</b>"+
  "<p>110 S. Mulberry</p>"+
  "<p>Ennis, TX 75119</p>" +
  "<p>(972) 825-7185</p>&nbsp;" +
  "<p><a href=http://www.ennisbiblechurch.org>\n\
http://www.ennisbiblechurch.org</a></p>" +
  "</div>"
  });
  churchInfo.open(map);
}

