/*
 * Copyright (C) 2010 David A. Deal
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

var showFlash = false;

// The current value of the thermometer
var thermoCurrentValue = 75331;

// The thermometer URL
// var thermoSrc = "http://www.usafundraising.com/php/thermored.php?max=100000&current=" + thermoCurrentValue + "&unit=36";
// var thermoSrc = "img/thermometer.jpeg";

// Source: http://www.jlion.com/Tools/jTherm.aspx
var thermoSrc = "http://www.jlion.com/tools/Thermometer.aspx?MIN=0&MAX=100000&VT=1&T=SRF%20Fundraising&IV=" +
   thermoCurrentValue + "&M=1&SC=0&CS=2&CI=en-US";

/**
 * This function formats numbers by adding commas
 */
function numberFormat(nStr)
{
   nStr += '';
   x = nStr.split('.');
   x1 = x[0];
   x2 = x.length > 1 ? '.' + x[1] : '';
   var rgx = /(\d+)(\d{3})/;
   while (rgx.test(x1))
      x1 = x1.replace(rgx, '$1' + ',' + '$2');
   return x1 + x2;
}

/**
 * Function to print the header pictures
 */
function printHeaderPic()
{
   var headerPicContent = "<img src=\"img/sres_sign_109h.png\" alt=\"School Image\" height=\"109\"/>\n" +
      "<img src=\"img/school_pic_cmp_lab1_109.jpg\" alt=\"School Image\" height=\"109\"/>\n" +
      "<img src=\"img/header_pe1_109.png\" alt=\"School Image\" height=\"109\"/>\n" +
      "<img src=\"img/header_pe2_109.png\" alt=\"School Image\" height=\"109\"/>\n" +
      "<img src=\"img/school_pic_cmp_lab2_109.jpg\" alt=\"School Image\" height=\"109\"/>\n" +
      "<img src=\"img/school_pic2_109.jpg\" alt=\"School Image\" height=\"109\"/>\n";

   /*
    var headerPicContent = "<ul>\n" +
    "<li><img src=\"img/sres_sign_109h.png\" alt=\"School Image\" height=\"109\"/></li>\n" +
    "<li><img src=\"img/school_pic_cmp_lab1_109.jpg\" alt=\"School Image\" height=\"109\"/></li>\n" +
    "<li><img src=\"img/header_pe1_109.png\" alt=\"School Image\" height=\"109\"/></li>\n" +
    "<li><img src=\"img/header_pe2_109.png\" alt=\"School Image\" height=\"109\"/></li>\n" +
    "<li><img src=\"img/school_pic_cmp_lab2_109.jpg\" alt=\"School Image\" height=\"109\"/></li>\n" +
    "<li><img src=\"img/school_pic2_109.jpg\" alt=\"School Image\" height=\"109\"/></li>\n" +
    "</ul>\n";
    */

   document.write(headerPicContent);
}

function showPayPalConfirm()
{
   return window
      .confirm("Please note that a PayPal account is required for the Payment Plan option.\n\nWould you like to continue?");
}


var sponsorData = [
   {
      linkHref : "http://www.northcountycu.org",
      linkTitle : "North County Credit Union",
      imageSrc : "img/corp/nccu.gif",
      imageAlt : "North County Credit Union Image",
      imageTitle : "North County Credit Union"
   }/*,
    {
    linkHref : "http://www.savvyinteriors.com/",
    linkTitle : "Savvy Interiors - Smart Stylish Solutions",
    imageSrc : "img/corp/savvyinteriors.jpg",
    imageAlt : "Savvy Interiors - Smart Stylish Solutions Image",
    imageTitle : "Savvy Interiors - Smart Stylish Solutions"
    }
    */
];

var sponsorIndex = 0;

function sponsorAd()
{
   //alert("sponsorAd");
   setInterval("changeSponsorAd()", 10000);
}

function changeSponsorAd()
{
   //alert("changeSponsorAd");
   if (sponsorIndex + 1 >= sponsorData.length)
   {
      sponsorIndex = 0;
   }
   else
   {
      sponsorIndex++;
   }

   if (document.getElementById("sponsorLink") != null &&
      document.getElementById("sponsorImage") != null)
   {
      document.getElementById("sponsorLink").href = sponsorData[sponsorIndex].linkHref;
      document.getElementById("sponsorLink").title = sponsorData[sponsorIndex].linkTitle;

      document.getElementById("sponsorImage").src = sponsorData[sponsorIndex].imageSrc;
      document.getElementById("sponsorImage").alt = sponsorData[sponsorIndex].imageAlt;
      document.getElementById("sponsorImage").title = sponsorData[sponsorIndex].imageTitle;
   }
}


function setThermoSrc()
{
   if (document.getElementById("imgThermoRed") != null)
   {
      document.getElementById("imgThermoRed").src = thermoSrc;
   }
   else
   {
      // Wait and try again
      setTimeout("setThermoSrc()", 1500);
   }
}

function doPageLoad()
{
   setThermoSrc();
   sponsorAd();
}

function addLoadEvent(func)
{
   var oldonload = window.onload;
   if (typeof window.onload != 'function')
   {
      window.onload = func;
   }
   else
   {
      window.onload = function()
      {
         oldonload();
         func();
      }
   }
}

addLoadEvent(doPageLoad());

