// Countdown and Count up


var CountDownDate=new Date(), BeforeCountDown=true;
var DaysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

//Date to count down to
CountDownDate = new Date(2000,5,18,12,30,00);

//Date in UTC (Year, month-1, day)
//CountDownDate = new Date(2000,5,17,15,40,00);
CountDownDate.setUTCFullYear(2000,5,18);
CountDownDate.setUTCHours(11,30,00);


// --></script><script language="JavaScript"><!--
//var CountDownDate=new Date(), BeforeCountDown=true;
//CountDownDate = new Date(2000,5,18,11,30,00);
//CountDownDate = new Date(2000,5,17,15,40,00);

//alert(CountDownDate);
BeforeCountDown = (CountDownDate > new Date());

function CountDown(form) {
var now = new Date(), toCountDown, CountDownText, y,m,d, before, days, hh,mm,ss, hhbefore;

//Test (Year, month-1, day)
//now.setUTCFullYear(2001,1,18);
//now.setUTCHours(11,30,00);

 before = (CountDownDate > now);
//alert(''+(BeforeCountDown != before)+'\n'+before+' '+BeforeCountDown);

// if (BeforeCountDown != before) {document.URL=document.URL;};

 BeforeCountDown = before;
 if (BeforeCountDown) {
  toCountDown=CountDownDate - now;
  y = CountDownDate.getUTCFullYear() - now.getUTCFullYear();
  m = CountDownDate.getUTCMonth() - now.getUTCMonth();
//  d = CountDownDate.getUTCDate() - now.getUTCDate();
  d = CountDownDate.getUTCDate() - now.getUTCDate() - 1;
 }
 else {
  toCountDown= now - CountDownDate;
  y = now.getUTCFullYear() - CountDownDate.getUTCFullYear();
  m = now.getUTCMonth() - CountDownDate.getUTCMonth();
//  d = now.getUTCDate() - CountDownDate.getUTCDate();
  d = now.getUTCDate() - CountDownDate.getUTCDate() - 1;
 };
// days=Math.ceil(toCountDown/1000/3600/24);
 days=Math.ceil(toCountDown/1000/3600/24*100)/100;
 toCountDown=new Date(toCountDown);
// days=toCountDown.days();
// form.CountDown.value=toCountDown;

// y=toCountDown.getUTCFullYear()-1970;
// m=toCountDown.getUTCMonth();
// d=toCountDown.getUTCDate()-1;

// hhmmss = now.getUTCTime() - CountDownDate.getUTCTime();
 hhbefore = (now.getTime() < CountDownDate.getTime());
 hh=toCountDown.getUTCHours();
 mm=toCountDown.getUTCMinutes();
 ss=toCountDown.getUTCSeconds();

 y2=y
 m2=m;
 d2=d;

 if (hhbefore > 0) {
   d = d - 1;
   };

 if (d < 0) { 
//   d = d + 30;
   d = d + DaysInMonth[now.getUTCMonth()-1]; 
   m = m - 1;
//m2 = m + 0.5;
   };
 if (m < 0) { 
   m = m + 12;
//   m = m + 11;
   y = y - 1;
   };

  


//alert(CountDownDate+'\n'+now+'\n'+toCountDown+'\n'+m+'/'+d+'/'+y);

 CountDownText='';
 if (y > 0) CountDownText=y+' years ';
 if (m > 0) CountDownText=CountDownText+m+' months ';
 if (d > 0) CountDownText=CountDownText+d+' days ';
//alert(toCountDown.getHours());
// CountDownText=CountDownText+(toCountDown.getUTCHours()-1)+':';
 CountDownText=CountDownText+hh+':';
 CountDownText=CountDownText+mm+':';
 CountDownText=CountDownText+ss+'';
 CountDownText=CountDownText+' ('+days+')';

//Debug
// CountDownText=CountDownText+' ['+y+' '+m+' '+d+' '+']';
// CountDownText=CountDownText+' ['+y2+' '+m2+' '+d2+' '+DaysInMonth[now.getUTCMonth()-1]+']';
// CountDownText=CountDownText+' ['+hh+' '+mm+' '+ss+' '+']';
// CountDownText=CountDownText+' ['+y2+' '+m2+' '+d2+' '+DaysInMonth[now.getUTCMonth()-1]+']';
// CountDownText=CountDownText+' ['+now.getUTCFullYear()+' '+now.getUTCMonth()+' '+now.getUTCDate()+' '+']';


 form.CountDown.value=CountDownText;

//alert(form.name);

 setTimeout('CountDown(document.Wedding)',1000);

};

//CountDown(document.Wedding);
//alert(document.URL);
