
function mgp_calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (mgp_LeadingZero && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function mgp_CountBack(secs) {
  if (secs < 0) {
    document.getElementById("mgp_cntdwn").innerHTML = FinishMessage;
    return;
  }

DisplayStr = mgp_DisplayFormatDays.replace(/%%D%%/g, mgp_calcage(secs,86400,100000));
document.getElementById("mgp_d1").innerHTML = DisplayStr;
document.getElementById("mgp_d2").innerHTML = "D ";

DisplayStr = mgp_DisplayFormatHours.replace(/%%H%%/g, mgp_calcage(secs,3600,24));
document.getElementById("mgp_h1").innerHTML = DisplayStr;
document.getElementById("mgp_h2").innerHTML = "H ";

DisplayStr = mgp_DisplayFormatMinutes.replace(/%%M%%/g, mgp_calcage(secs,60,60));
document.getElementById("mgp_m1").innerHTML = DisplayStr;
document.getElementById("mgp_m2").innerHTML = "M ";

DisplayStr = mgp_DisplayFormatSeconds.replace(/%%S%%/g, mgp_calcage(secs,1,60));
document.getElementById("mgp_s1").innerHTML = DisplayStr;
document.getElementById("mgp_s2").innerHTML = "S";

  if (mgp_CountActive)
    setTimeout("mgp_CountBack(" + (secs+mgp_CountStepper) + ")", mgp_SetTimeOutPeriod);
}

function mgp_putspan(backcolor, forecolor) {
 document.write("<span id='mgp_d1' style='font-family: HelviticaBlack-T&M; font-size: 18px;  font-weight: bold;  font-style: italic;height: 20px'></span>");
 document.write("<span id='mgp_d2' style='font-family: HelviticaBlack-T&M; font-size: 8px;  font-weight: regular;  font-style: normal; '></span>");
 document.write("<span id='mgp_h1' style='font-family: HelviticaBlack-T&M; font-size: 18px;  font-weight: bold;  font-style: italic; height: 20px'></span>");
 document.write("<span id='mgp_h2' style='font-family: HelviticaBlack-T&M; font-size: 8px;  font-weight: regular;  font-style: normal;'></span>");
 document.write("<span id='mgp_m1' style='font-family: HelviticaBlack-T&M; font-size: 18px;  font-weight: bold;  font-style: italic; height: 20px'></span>");
 document.write("<span id='mgp_m2' style='font-family: HelviticaBlack-T&M; font-size: 8px;  font-weight: regular;  font-style: normal;'></span>");
 document.write("<span id='mgp_s1' style='font-family: HelviticaBlack-T&M; font-size: 18px;  font-weight: bold;  font-style: italic; height: 20px'></span>");
 document.write("<span id='mgp_s2' style='font-family: HelviticaBlack-T&M; font-size: 8px;  font-weight: regular;  font-style: normal;'> </span>");
}



if (typeof(mgp_BackColor)=="undefined")
  mgp_BackColor = "white";
if (typeof(mgp_ForeColor)=="undefined")
  mgp_ForeColor= "black";
if (typeof(mgp_TargetDate)=="undefined")
  mgp_TargetDate = "12/31/2009 5:00 AM";
if (typeof(mgp_DisplayFormat)=="undefined")
  mgp_DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(mgp_CountActive)=="undefined")
  mgp_CountActive = true;
if (typeof(mgp_FinishMessage)=="undefined")
  mgp_FinishMessage = "";
if (typeof(mgp_CountStepper)!="number")
  mgp_CountStepper = -1;
if (typeof(mgp_LeadingZero)=="undefined")
  mgp_LeadingZero = true;
if (typeof(mgp_DisplayFormatDays)=="undefined")
  mgp_DisplayFormatDays = "%%D%%";
if (typeof(mgp_DisplayFormatHours)=="undefined")
  mgp_DisplayFormatHours = "%%H%%";
if (typeof(mgp_DisplayFormatMinutes)=="undefined")
  mgp_DisplayFormatMinutes = "%%M%%";
if (typeof(mgp_DisplayFormatSeconds)=="undefined")
  mgp_DisplayFormatSeconds = "%%S%%";






mgp_CountStepper = Math.ceil(mgp_CountStepper);
if (mgp_CountStepper == 0)
  mgp_CountActive = false;
var mgp_SetTimeOutPeriod = (Math.abs(mgp_CountStepper)-1)*1000 + 990;
mgp_putspan(mgp_BackColor, mgp_ForeColor);
var dthen = new Date(mgp_TargetDate);
var dnow = new Date();
if(mgp_CountStepper>0)
  ddiff = new Date(dnow-dthen);
else
  ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
mgp_CountBack(gsecs);
