function ImageOf(strID)

{
if (document.all)
   return document.all[strID];
else
   return document.images[strID];
}

function SetDigits(strTagID,strPiece,intValue)

{
var B1=ImageOf(strTagID+strPiece+"1");
var B2=ImageOf(strTagID+strPiece+"2");
var Tens=Math.floor(intValue/10);
var Ones=intValue-(Tens*10);
B1.src="http://www.mdrocketry.org/images/timer/c"+Tens+".gif";
B2.src="http://www.mdrocketry.org/images/timer/c"+Ones+".gif";
}

function SetDigits3(strTagID,strPiece,intValue)

{
var B0=ImageOf(strTagID+strPiece+"0");
var B1=ImageOf(strTagID+strPiece+"1");
var B2=ImageOf(strTagID+strPiece+"2");
var Huns=Math.floor(intValue/100);
var Tens=Math.floor((intValue - (Huns*100))/10);
var Ones=intValue-(Tens*10)-(Huns*100);
B0.src="http://www.mdrocketry.org/images/timer/c"+Huns+".gif";
B1.src="http://www.mdrocketry.org/images/timer/c"+Tens+".gif";
B2.src="http://www.mdrocketry.org/images/timer/c"+Ones+".gif";
}

function TimerTick(strTagID, intEventDate)

{
var strDate=new Date();
var intMs=intEventDate-new Date(strDate).valueOf();
if(intMs<=0)
  {
  intMs=intMs*-1;
  TimerIdle(strTagID);
  return;
  };

var intDays=Math.floor(intMs/864E5);
intMs=intMs-(intDays*864E5);
SetDigits3(strTagID,'_Days',intDays);

var intHours=Math.floor(intMs/36E5);
intMs=intMs-(intHours*36E5);
SetDigits(strTagID,'_Hours',intHours);

var intMinutes=Math.floor(intMs/6E4);
intMs=intMs-(intMinutes*6E4);
SetDigits(strTagID,'_Mins',intMinutes);

var intSeconds=Math.floor(intMs/1000);
SetDigits(strTagID,'_Secs',intSeconds);

ArmTrigger(strTagID,intEventDate);
}

function ArmTrigger(strTagID,intEventDate)

{
var objDateNow=new Date();
var intMsDelay=1000-objDateNow.getMilliseconds();
setTimeout('TimerTick("'+strTagID+'",'+intEventDate+');',intMsDelay);
}

function CountdownTimer(strTagID,strEventDate)

{
document.write('<table bgcolor=black cellpadding=0><tr>');
document.write('<td colspan=8><img src="http://www.mdrocketry.org/images/timer/cDot.gif" width=1 height=4></td></tr><tr>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/cT.gif"><img src="http://www.mdrocketry.org/images/timer/cMinus.gif"></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Days0" width=16 height=21><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Days1" width=16 height=21><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Days2" width=16 height=21></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/cSpace.gif"></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Hours1" width=16 height=21><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Hours2" width=16 height=21></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/cSpace.gif"></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Mins1" width=16 height=21><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Mins2" width=16 height=21></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/cSpace.gif"></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Secs1" width=16 height=21><img src="http://www.mdrocketry.org/images/timer/cOff.gif" name="'+strTagID+'_Secs2" width=16 height=21></td>');
document.write('</tr><tr><td><img src="http://www.mdrocketry.org/images/timer/iDot.gif" width=1 height=4></td>');
document.write('<td align=center><img src="http://www.mdrocketry.org/images/timer/cDays.gif" width=28 height=15></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/iDot.gif" width=1 height=4></td>');
document.write('<td align=center><img src="http://www.mdrocketry.org/images/timer/cHours.gif" width=28 height=15></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/iDot.gif" width=1 height=4></td>');
document.write('<td align=center><img src="http://www.mdrocketry.org/images/timer/cMins.gif" width=28 height=15></td>');
document.write('<td><img src="http://www.mdrocketry.org/images/timer/iDot.gif" width=1 height=4></td>');
document.write('<td align=center><img src="http://www.mdrocketry.org/images/timer/cSecs.gif" width=28 height=15></td>');
document.write('</tr></table>');


if (strEventDate=="OFF")
  {
  TimerIdle(strTagID);
  }
else
  {
  var intEventDate=new Date(strEventDate).valueOf();
  ArmTrigger(strTagID,intEventDate);
  }
}


function DoDashes(strTagID,Char)

{
ImageOf(strTagID+"_Days1").src = Char;
ImageOf(strTagID+"_Days2").src = Char;
ImageOf(strTagID+"_Hours1").src = Char;
ImageOf(strTagID+"_Hours2").src = Char;
ImageOf(strTagID+"_Mins1").src = Char;
ImageOf(strTagID+"_Mins2").src = Char;
ImageOf(strTagID+"_Secs1").src = Char;
ImageOf(strTagID+"_Secs2").src = Char;
}

function DashesOn(strTagID)

{
DoDashes(strTagID,"http://www.mdrocketry.org/images/timer/cOff.gif");
setTimeout("DashesOff('"+strTagID+"');",1500);
}


function DashesOff(strTagID)

{
DoDashes(strTagID,"http://www.mdrocketry.org/images/timer/cMinus.gif");
setTimeout("DashesOn('"+strTagID+"');",1500);
}

function TimerIdle(strTagID)

{
DashesOn(strTagID);
}
