<!-- Clock in Java Script .. Cameron Gregory http://www.bloke.com/
// http://www.bloke.com/javascript/Clock/
speed=1000;
//len=28;
len=25;
tid = 0;
num=0;
clockA = new Array();
offsetA = new Array();
dd = new Date();


function doDate(x)
{
  for (i = 0; i < num; i++) 
  {
    dt = new Date();
  
    var MonthF = clockA[i].MonthF.value - 1;
    var WeekF  = clockA[i].WeekF.value;
    var DayF   = clockA[i].DayF.value;
    var TimeF  = parseInt(clockA[i].TimeF.value) + 1;  // convert from daylight time to real time

    var MonthB = clockA[i].MonthB.value - 1;
    var WeekB  = clockA[i].WeekB.value;
    var DayB   = clockA[i].DayB.value;
    var TimeB  = parseInt(clockA[i].TimeB.value) - 1;  // convert from daylight time to real time

    var Hours  = clockA[i].Hours.value;

    var summTime = false;

    var curMonth =  dt.getMonth();  // from 0 to 11
    var curYear  =  dt.getYear();

    // Days in Month
    var prevDate = new Date(curYear, curMonth + 1, 0); //???! 
    var numMonthDays = prevDate.getDate();

   
  if (Hours != 0) 
  {
   
   if (curMonth == MonthF)  
   {
     var WeekCounter = 0;
     var TmpDay

     if (WeekF > 0)
     {
       // week start not from monday
       var TmpDate = new Date(curYear, curMonth, 1);
       TmpDay = TmpDate.getDay();

       if  (TmpDay != 0) WeekCounter++;

       for (j = 1; j <= numMonthDays; j++)
       {
        var TmpDate = new Date(curYear, curMonth, j); 
        TmpDay = TmpDate.getDay();

        if  (TmpDay == 0) WeekCounter++;

        if ((WeekCounter >= WeekF) & (TmpDay == DayF))  
        {
          var  curDate = j;
          break;
        }

       }
     }
     else
     {
      // week end not from Saturday
      var TmpDate = new Date(curYear, curMonth, 1); 
     
      TmpDay = TmpDate.getDay();

      if  (TmpDay != 6) WeekCounter++;

      for (j = numMonthDays; j >= 1; j--)
      {

       var TmpDate = new Date(curYear, curMonth, j); 
       TmpDay = TmpDate.getDay();

       if  (TmpDay == 6) WeekCounter++;

       if ((-WeekCounter >= WeekF) & (TmpDay == DayF))  var  curDate = j;

      }
     }

     var findedDate = new Date();

     findedDate.setYear (curYear);
     findedDate.setMonth(MonthF);
     findedDate.setDate(curDate); 

     findedDate.setHours(parseInt(TimeF), 0, 0); 


     if (findedDate <= dt)  summTime = true;

   }
   else 
   {

     if (curMonth == MonthB)
     {
       var WeekCounter = 0;
       var TmpDay
  
     if (WeekB > 0)
     {
       // week start not from monday
       var TmpDate = new Date(curYear, curMonth, 1); 

       TmpDay = TmpDate.getDay();
       if  (TmpDay != 0) WeekCounter++;

       for (j = 1; j <= numMonthDays; j++)
       {
        var TmpDate = new Date(curYear, curMonth, j); 
        TmpDay = TmpDate.getDay();

        if  (TmpDay == 0) WeekCounter++;


        if ((WeekCounter == WeekB) & (TmpDay == DayB))
           var  curDate = j;
       }
     }
     else
     {
      // week end not from Saturday
       var TmpDate = new Date(curYear, curMonth, 1); 

       TmpDay = TmpDate.getDay();
       if  (TmpDay != 6) WeekCounter++;

       for (j = numMonthDays; j >= 1; j--)
       {
         var TmpDate = new Date(curYear, curMonth, j); 
         TmpDay = TmpDate.getDay();

         if  (TmpDay == 6) WeekCounter++;

         if ((-WeekCounter == WeekB) & (TmpDay == DayB)) var  curDate = j;
       }
     }

     var findedDate = new Date();
     findedDate.setYear (curYear);
     findedDate.setMonth(MonthB);
     findedDate.setDate( curDate);
     findedDate.setHours(TimeB, 0, 0);

    

     if (findedDate >= dt)  summTime = true;

     } 
     else 
     {

       if (MonthF < MonthB) 
       {
         if ((curMonth > MonthF ) & (curMonth < MonthB))  summTime = true;
       }
     
       if (MonthF > MonthB)
       {
         if ((curMonth > MonthF ) || (curMonth < MonthB))  summTime = true;
       }
     }
   }


    if (summTime == true)
    {
       gt = dt.getTime();
       gt = gt + Hours*60*60*1000;
       dt.setTime(gt);
    }


   }

    if (offsetA[i] != 0) {
      gt = dt.getTime();
      gt = gt + offsetA[i];
      dt.setTime(gt);
      }

   clockA[i].date.value = dt.toGMTString();
  }

  tid=window.setTimeout("doDate()",speed);

}

function startLong(diff) {

  clockA[num] = document.forms["form"+num];

  offsetA[num] = (diff)*60*1000;

  if (num == 0)  
    tid=window.setTimeout("doDate()",speed);
  num++;
}


//day of week 0..6 0-Sanday


//<!--  ServerClock( GMT_offset, MonthF, WeekF, DayF, TimeF, MonthB, WeekB, DayB, TimeB, Hours) -->

function ServerClock(diff, MonthF, WeekF, DayF, TimeF,  MonthB, WeekB, DayB, TimeB, Hours)

{
  document.write('<FORM name=form'+num+'><input name=date style="BORDER-TOP-STYLE: none; BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px;');
  document.write('BORDER-BOTTOM: 0px; FONT-SIZE: 12px;" size=');
  // we chop the end, because it would be the wrong timezone
  document.write(30);
  //document.write(19)
  document.write(' readOnly   value="Date/Time">');

  document.write('<input type="hidden" name="MonthF"   value='+MonthF+'>');
  document.write('<input type="hidden" name="WeekF"    value='+WeekF+'>');
  document.write('<input type="hidden" name="DayF"     value='+DayF+'>');
  document.write('<input type="hidden" name="TimeF"    value='+TimeF+'>');

  document.write('<input type="hidden" name="MonthB"   value='+MonthB+'>');
  document.write('<input type="hidden" name="WeekB"    value='+WeekB+'>');
  document.write('<input type="hidden" name="DayB"     value='+DayB+'>');
  document.write('<input type="hidden" name="TimeB"    value='+TimeB+'>');

  document.write('<input type="hidden" name="Hours" value='+Hours+'>');

  document.write('</FORM>');
  startLong(diff);
}




var win = null;
function openWindow(wnd, _width, _height){
        posx = (screen.width) ? (screen.width-_width)/2 : 0;
        posy = (screen.height) ? (screen.height-_height)/2 : 0;
        settings = 'height='+_height+',width='+_width+',top='+posy+',left='+posx+',scrollbars=no'
        win = window.open(wnd,'popwindow',settings)
        if(win.window.focus){win.window.focus();}
}


