
// 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 enddate = 0;
var cTicks = 0;
var timersize = 0;

function addhtmlintodivs() {

if(cTicks >= 86400)
  timersize = 12;
else if(cTicks >= 3600)
  timersize = 8;
else if(cTicks >= 60)
  timersize = 5;
else
  timersize = 2;

var alldivs = document.getElementsByTagName('div');

for(i = 0; i < alldivs.length; i++) {
var adiv = alldivs[i];
if (adiv.className  == "counterdiv")
    adiv.innerHTML = '<center><form name="theClock"><input type=text name="theTime" size='+timersize+' 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><div  name= "toppar" id="toppar">'+ startTopText+ '</div><br><a id="ahref" name="ahref" href="'+startAhref+'"><img src="'+startImageURL+'" name="banner" id="banner"></a><br><div  name= "botpar" id="botpar">'+ startBottomText +'</div></form></center>';
}
}

function toggledivs(className, display) {
var alldivs = document.getElementsByTagName('div');

for(i = 0; i < alldivs.length; i++) {
var adiv = alldivs[i];
if (adiv.className  == className)
    adiv.style.display=display;
}
}

function removecounterdivs() {
  toggledivs("counterdiv", "none");
}

function changetextdivs(toptext, bottext) {
var alldivs = document.getElementsByTagName('div');

for(i = 0; i < alldivs.length; i++) {
var adiv = alldivs[i];
if (adiv.id  == "toppar")
    adiv.innerHTML = toptext;
if (adiv.id  == "botpar")
    adiv.innerHTML = bottext;
}
}

function changebanners(imageURL) {
var allimages = document.getElementsByTagName('img');

for(i = 0; i < allimages.length; i++) {
var aimg = allimages[i];
if (aimg.name  == "banner")
    aimg.src = imageURL;
}
}

function changeahrefs(URL) {
var allahrefs = document.getElementsByTagName('a');

for(i = 0; i < allahrefs.length; i++) {
var ahr = allahrefs[i];
if (ahr.name  == "ahref")
    ahr.href = URL;
}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var timeVal = "";
   if(timersize == 12)
     timeVal = Math.floor(this.cTicks/86400/100)+""+Math.floor(this.cTicks/86400/10%10)+""+Math.floor(this.cTicks/86400%10)+":";
   if(timersize >= 8)
     timeVal = timeVal + Math.floor(this.cTicks%86400/3600/10)+""+Math.floor(this.cTicks%86400/3600%10)+":";
   if(timersize >= 5)
     timeVal = timeVal + Math.floor(this.cTicks%86400%3600/60/10)+""+Math.floor(this.cTicks%86400%3600/60%10)+":";

   timeVal = timeVal + Math.floor(this.cTicks%86400%3600%60/10)+""+this.cTicks%86400%3600%60%10;

  for(i = 0; i < document.forms.length; i++) {
    var aform = document.forms[i];
    if (aform.name  == "theClock") {
       aform.theTime.value = timeVal;
       if(cTicks == 0) aform.theTime.style.display = "none";
    }
  }

  if(cTicks == secondtick) {
     changetextdivs(secondTopText, secondBottomText);
     changebanners(secondImageURL);
     changeahrefs(secondAhref);
   }

  if(cTicks == thirdtick) {
     changetextdivs(thirdTopText, thirdBottomText);
     changebanners(thirdImageURL);
     changeahrefs(thirdAhref);
   }

   cTicks--;

   if(cTicks >= 0)
   	 clockID = setTimeout("UpdateClock()", 1000);
   else {
     if(endtype == "hidecoupon")
	   removecounterdivs();
	 else {
       changetextdivs(finalTopText, finalBottomText);
       changebanners(finalImageURL);
       changeahrefs(finalAhref);
	 }
	 toggledivs("counterhidediv", "block");
   }
}
function StartClock() {
   if(started == 0) {
     if(readCookie(cookiename) != null) {
       removecounterdivs();
  	   return;
     }

     createCookie(cookiename,"11",1);

     cTicks = firsttick;
   }
   else {
     var temp = serverdate;

     if(temp == null) {
       removecounterdivs();
       return;
     }

     if(enddate != 0) {
       cTicks = Math.floor((enddate-serverdate) / 1000);

       if(cTicks <= 0) {
         removecounterdivs();
         return;
       }
     }
     else {
       cTicks = Math.floor((serverdate-started) / 1000);

       if(cTicks >= firsttick || cTicks <= 0) {
         removecounterdivs();
         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;
		}
  }

  addhtmlintodivs();
  toggledivs("counterhidediv", "none");


  clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

window.onload = function() { StartClock(); };
window.onunload = function() { KillClock(); };timerbackcolor = "#FFFFFF";
timerforecolor = "#CC0000";
firsttick = 180;
secondtick = 60;
thirdtick = 20;
firstAhref = "index.php?action=order&dc=special";
secondAhref = "index.php?action=order&dc=special";
thirdAhref = "index.php?action=order&dc=special";
finalAhref = "index.php?action=order";
firstImageURL = "/coupon/coupon/couponpix/special.gif";
secondImageURL = "/coupon/coupon/couponpix/special.gif";
thirdImageURL = "/coupon/coupon/couponpix/special.gif";
finalImageURL = "/coupon/coupon/couponpix/horizontal_solution_PP.gif";
firstTopText = "<h3 style=\"text-align: center; color: rgb(255, 0, 0);\"><span style=\"font-weight: bold;\">Click Below <span style=\"text-decoration: underline;\">BEFORE</span> the Timer Expires to Get the Special Price!</span></h3>";
secondTopText = "<h3 style=\"text-align: center; color: rgb(255, 0, 0);\"><span style=\"font-weight: bold;\">60 Seconds Left!<br />Click Below <span style=\"text-decoration: underline;\">BEFORE</span> the Timer Expires to Get the Special Price!</span></h3>";
thirdTopText = "<h3 style=\"text-align: center; color: rgb(255, 0, 0);\"><span style=\"font-weight: bold;\">20 Seconds Left!<br />Click Below <span style=\"text-decoration: underline;\">BEFORE</span> the Timer Expires to Get the Special Price!</span></h3>";
finalTopText = "<h3 style=\"text-align: center; color: rgb(255, 0, 0);\"><span style=\"font-weight: bold;\">Click the Button Below to BUY NOW!</span></h3>";
firstBottomText = "<h3 style=\"text-align: center; color: rgb(0, 0, 255);\"><span style=\"font-weight: bold;\">Click Above <span style=\"text-decoration: underline;\">BEFORE</span> the Timer Expires to Get the Special Price!</span></h3>";
secondBottomText = "<h3 style=\"text-align: center; color: rgb(0, 0, 255);\"><span style=\"font-weight: bold;\">Click Above <span style=\"text-decoration: underline;\">BEFORE</span> the Timer Expires to Get the Special Price!</span></h3>";
thirdBottomText = "<h3 style=\"text-align: center; color: rgb(0, 0, 255);\"><span style=\"font-weight: bold;\">Click Above <span style=\"text-decoration: underline;\">BEFORE</span> the Timer Expires to Get the Special Price!</span></h3>";
finalBottomText = "<br />";
endtype = "showfinalstate";
cookiename="special.js16032008022118"+window.location;
