/*
Date/time script
By Vera Cranor Sep 24, 2007
vcranor@twlakes.net
*/
tz_times=new Array();
last_sec=0;
function run_time() {
  for(i=0; i<tz_times.length; i+=3) {
    tz=tz_times[i+1]; // time zone hrs to GMT
    idnam=tz_times[i];
    tmpform=tz_times[i+2]+'&nbsp;';
    moa=new Array('January', 'February', 'March', 'April', 'May', 'June', 
      'July', 'August', 'September', 'October', 'November', 'December');
    wda=new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 
      'Thursday', 'Friday', 'Saturday');
    today=new Date();
    dval=today.getTime();
    zmin=today.getTimezoneOffset();
    today.setTime(dval+(zmin.valueOf()*60-tz*3600)*1000);
    sec=today.getSeconds();
    if(sec==last_sec) {
      setTimeout('run_time()', 500);
      return;
    }
    if(sec<10) sec="0"+sec;
    min=today.getMinutes();
    if(min<10) min="0"+min;
    hr=today.getHours();
    hr24=hr;
    if(hr24<10) hr24='0'+hr24;
    if(hr>=12) tmpform=tmpform.replace(/#a(p)/i, "$1");
    else tmpform=tmpform.replace(/#(a)p/i, "$1");
    if(hr>12) hr-=12;
    if(hr==0) hr=12;
    wd=wda[today.getDay()];
    mon=today.getMonth()+1;
    mo=moa[today.getMonth()];
    dt=today.getDate();
    yr=today.getFullYear();
    tmpform=tmpform.replace(/#wday/, wd);
    tmpform=tmpform.replace(/#moname/, mo);
    tmpform=tmpform.replace(/#monum/, mon);
    tmpform=tmpform.replace(/#date/, dt);
    tmpform=tmpform.replace(/#yyyy/, yr);
    tmpform=tmpform.replace(/#yy/, yr.toString().substr(2));
    tmpform=tmpform.replace(/#time12s/, hr+':'+min+':'+sec);
    tmpform=tmpform.replace(/#time12/, hr+':'+min);
    tmpform=tmpform.replace(/#time24s/, hr24+':'+min+':'+sec);
    tmpform=tmpform.replace(/#time24/, hr24+':'+min);
    document.getElementById(idnam).innerHTML=tmpform;
  }
  last_sec=sec;
  setTimeout('run_time()', 500);
}
function datetimes(d) {
  d=d.replace(/\^$/, '');
  tz_times=d.split('^');
  run_time();
}
//End



/*

Example:

<script type="text/javascript" src="datetimes.js"></script>
<script type="text/javascript">
var setupinfo=
'span1_ID_name^hrs_to_GMT^format^'+
'span2_ID_name^hrs_to_GMT^format^'+
'span3_ID_name^hrs_to_GMT^format^';
</script>

<body onload="datetimes(setupinfo)">

<span id="span_1_ID_name">date/time is placed here</span>                                    

format: '#wday #moname #date #yyyy  #time12s  #ap
               #monum        #yy    #time12   #AP
                                    #time24s
                                    #time24


*/
