
//=========================================================================
city = new Array("Sydney _ _ _ _ _ _ cf.","Tokyo","Shanghai","Guangzhou","Kuala Lumpur","Shingapore","Bangkok","Jakarta","Moscow _ _ _ _ _ _ cf.","Deutschland","Greenwich Main Time","Washington,NewYork","Detroit","Chicago","Los Angeles_ _ _ _ cf.","Honolulu_ _ _ _ _ _ cf.");
zone = new Array( 10, 9, 8, 8, 8, 8, 7, 7, 3, 1, 0, -5, -5, -6, -8, -10);
flag = new Array( 4, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 1, 1, 1, 1, 0);
//=========================================================================

for (i in zone) { if (zone[i] < -12 || zone[i] > 12) { alert("Time Zone Errer\nzone["+i+"] "+zone[i]);} } 
ln = -1; pn = -1;
match = 0;
for (i = 0; i < document.forms.length; i++) { 
    if (document.forms[i].name == "pull") { pn = i; match = 1; } 
}
if (match != 1) { alert("upullv"); }
now = new Date();
year = now.getYear(); if (year < 2000) { year += 1900; }
offset = now.getTimezoneOffset() / 60; 

sun4_1 = calcDst(year,4,1,0);   
sun3_e = calcDst(year,3,5,0);   
sun10_e= calcDst(year,10,5,0);  
sat3_e = calcDst(year,3,5,6);   
sat10_e= calcDst(year,10,5,6);  

updateClock();

//=========================================================================
function calcTime(pctime,tzone,flag) {
   twntime = pctime + (tzone + offset) * 3600000; 
    mark = " "; 
  if (flag == 1) {        
    if ((sun4_1<=twntime) && (sun10_e>twntime)) { twntime+= 3600000; mark="*";}
  } else if (flag == 2) { 
    if ((sun3_e<=twntime) && (sun10_e>twntime)) { twntime+= 3600000; mark="*";}
  } else if (flag == 3) {
    if ((sat3_e<=twntime) && (sat10_e>twntime)) { twntime+= 3600000; mark="*";}
  } else if (flag == 4) { 
    if ((sat10_e<=twntime) || (sat3_e>twntime)) { twntime+= 3600000; mark="*";}
  } else if (flag != 0) {
    alert("Flag Erreri"+flag+"jflag"); return
  }
  
  now.setTime(twntime);
 
  month = new Array("Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez");
  mon = month[now.getMonth() ];
  date = now.getDate(); if (date < 10) { date = " " + date; }
  week = new Array("So","Mo","Di","Mi","Do","Fr","Sa");
  wee = week[now.getDay()];
  hour = now.getHours();  if (hour < 10) { hour = "0" + hour; }
  min  = now.getMinutes(); if (min  < 10) { min = "0" + min; }
  sec  = now.getSeconds(); if (sec  < 10) { sec = "0" + sec; }
  return  wee + ", " + mon+ " "+ date + ", " + hour + ":" + min + ":" + sec + mark  ;
}

//=========================================================================
function updateClock() {
  var now = new Date();
  pctime = now.getTime(); 

  if (pn >= 0) { 
    match = 0;
    for (i in city) { 
      if (document.forms[pn].city.options[document.forms[pn].city.options.selectedIndex].text == city[i]) {
        document.forms[pn].clock.value = calcTime(pctime,zone[i],flag[i]);
        match = 1; break;
      }
    }
    if (match != 1) { alert("City Errer"); return; }
  }
 
  setTimeout("updateClock()", 999);
}

//=========================================================================
function calcDst(year,month,num,wno) {
  if (month < 1 || month > 12) { alert("Month errer"); return; }
 if (wno < 0) { 
  if (num < 1 || num > 31) { alert("Time errer"); return; }
   dstime = new Date(year,month-1,num,2,0,0);
  return dstime.getTime();
 } else { 
  if (num < 1 || num > 5) { alert("Week Errer"); return; }
  if (wno > 6) { alert("week Errer"); return; }

  if (month <= 2) { zyear = year - 1; zmonth = month + 12; }
  else { zyear = year; zmonth = month; } 
  wday = (zyear + Math.floor(zyear/4) - Math.floor(zyear/100)
       + Math.floor(zyear/400) + Math.floor((13*zmonth + 8)/5) + 1) % 7;

  if (num == 5) {
    if (month == 2) {
      if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
                    { leap = 1; } else { leap = 0; } 
      if (leap == 0 || wno != wday) { num -= 1; } 
    } else if (month== 4 || month== 6 || month== 9 || month== 11) { 
      if (wno <= 1) { if( (wno+1) <= wday && wday < (wno+6) ) { num -= 1; } }
               else { if( (wno+1) <= wday || wday < (wno-1) ) { num -= 1; } }
    } else { 
      if (wno <= 2) { if( (wno+1) <= wday && wday < (wno+5) ) { num -= 1; } }
               else { if( (wno+1) <= wday || wday < (wno-2) ) { num -= 1; } }
    }
  }
 
  if (wday <= wno) { dstime = (num-1) * 7 + ((wno+1) - wday); }
              else { dstime = num * 7 - (wday - (wno+1)); }

  
  dstime = new Date(year,month-1,dstime,2,0,0);
  return dstime.getTime();
 }
}

//================================kousakushitsu kara kousaku=============================
