
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var serverdate;
var clockID = 0;
var started = 0;
var cTicks = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   document.theClock.theTime.value = Math.floor(this.cTicks/3600/10)+""+Math.floor(this.cTicks/3600%10)+":"+Math.floor(this.cTicks%3600/60/10)+""+Math.floor(this.cTicks%3600/60%10)+":"+Math.floor(this.cTicks%3600%60/10)+""+this.cTicks%3600%60%10;
      
   if(cTicks == secondtick) {
   	document.banner.src = secondImageURL;
   	var topp = document.getElementById("toppar");
	topp.innerHTML = secondTopText; 
   	var botp = document.getElementById("botpar");
	botp.innerHTML = secondBottomText; 
   	var ahref = document.getElementById("ahref");
	ahref.href = secondAhref;
}
   
   if(cTicks == thirdtick) {
   	document.banner.src = thirdImageURL;
   	var topp = document.getElementById("toppar");
	topp.innerHTML = thirdTopText; 
   	var botp = document.getElementById("botpar");
	botp.innerHTML = thirdBottomText; 
   	var ahref = document.getElementById("ahref");
	ahref.href = thirdAhref;
}

   cTicks--;
     
   if(cTicks >= 0)
   	clockID = setTimeout("UpdateClock()", 1000);
   else {
   	var dv2 = document.getElementById("counterdiv");
	dv2.style.visibility="hidden";
	}
     
}
function StartClock() {      
   var temp = serverdate;
   
   if(temp == null)
	 return;     
     
   if(started) {
   	   
   cTicks = Math.floor((serverdate-started) / 1000);
        
   if(cTicks >= firsttick || cTicks <= 0)
     return;
     
   cTicks = firsttick - cTicks;
   
   if(cTicks < thirdtick) {
     startAhref = thirdAhref;
     startImageURL = thirdImageURL;
     startTopText = thirdTopText;
     startBottomText = thirdBottomText;
   }
   else {
		if(cTicks < secondtick) {
	     startAhref = secondAhref;
	     startImageURL = secondImageURL;
	     startTopText = secondTopText;
	     startBottomText = thirdBottomText;		
		}
		else {
	     startAhref = firstAhref;
	     startImageURL = firstImageURL;
	     startTopText = firstTopText;
	     startBottomText = firstBottomText;					
		}
}
	

	var dv = document.getElementById("counterdiv");
   	dv.innerHTML = '<center><form name="theClock"><input type=text name="theTime" size=8 style="text-align: center;   background: '+ timerbackcolor+ ';   color: '+ timerforecolor + ';   font-size: 30pt;   font-family: Verdana; font-weight: bold;   border: 2px outset;   border-left: 2px outset darkgray;   border-top: 2px outset darkgray;"><br><p  name= "toppar" id="toppar">'+ startTopText+ '</p><br><a id="ahref" href="'+startAhref+'"><img src="'+startImageURL+'" name="banner" id="banner"></a><br><p  name= "botpar" id="botpar">'+ startBottomText +'</p></form></center>';
   	
   	clockID = setTimeout("UpdateClock()", 500);
  }
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

window.onload = function() { StartClock(); };
window.onunload = function() { KillClock(); };
timerbackcolor = "#FFFF99";
timerforecolor = "#009900";
firsttick = 300;
secondtick = 290;
thirdtick = 280;
firstAhref = "1111";
secondAhref = "2222";
thirdAhref = "3333";
firstImageURL = "coupon/couponpix/image1.jpg";
secondImageURL = "coupon/couponpix/mavi.JPG";
thirdImageURL = "coupon/couponpix/image3.jpg";
firstTopText = "1111";
secondTopText = "2222";
thirdTopText = "3333";
firstBottomText = "1111";
secondBottomText = "2222";
thirdBottomText = "3333";
started = new Date(2007,9,8,19,30,35);;

