  var headlines = new Array();
  var index = 0;
  var tday   = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
  var tmonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");


  String.prototype.trim = function (){
    return this.replace(/^[\n\t\s]*/, "").replace(/[\n\t\s]*$/, "");
  }


  function get_headlines()
  {

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open("GET", "/ajax/get_headlines.php", false);
    xmlhttp.send();
    var text = xmlhttp.responseText;

    text = text.trim().split("\n");
    return text;

  }

  function update_headlines()
  {
    headlines = get_headlines( );
    update_headline();
  }


  function update_headline()
  {
    if(index >= headlines.length)
      index = 0;

    document.getElementById('tabs').innerHTML = headlines[index];
    index++;
    var t = setTimeout( "update_headline()", 10000 );
  }

  
  function load_clock()
  {
    update_clock();
  }

  function update_clock()
  {

    var d = new Date();
    nday   = d.getDay();
    nmonth = d.getMonth();
    ndate  = d.getDate();
    nyear = d.getYear();
    nhour  = d.getHours();
    nmin   = d.getMinutes();
    if(nyear<1000)
      nyear=nyear+1900;

    if(nhour ==  0) {ap = " AM";nhour = 12;} 
    else if(nhour <= 11) {ap = " AM";} 
    else if(nhour == 12) {ap = " PM";} 
    else if(nhour >= 13) {ap = " PM";nhour -= 12;}

    if(nmin <= 9) {nmin = "0" +nmin;}


    document.getElementById('clock').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+ndate+", "+nyear+" "+nhour+":"+nmin+ap+"";
    setTimeout("update_clock()", 5000);
  }


  function choose_template()
  {

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    var choice = document.getElementById('template').value;

    xmlhttp.open("GET", "/ajax/choose_template.php?template="+choice, true);
    xmlhttp.send();

    setTimeout("window.location.reload()", 1000);
  }


