N.C. Division of Pollution Prevention and Environmental Assistance
Banned Materials


Landfill Ban Countdown Code

To add a counter to your Web site (like the one here), you will need some knowledge of HTML. The countdown uses javascript, but you will only need to copy and paste the code, so it is okay if you do not know javascript. Follow the three steps below.
Step 1: Copy and paste the code below between your <head></head> tags in your Web page's HTML code.

<script language="JavaScript">
<!--

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>


Step 2: Download the background image and save to your Web site's image folder. Right click the image and "save as." Make sure the image is named "countdown.png" and is saved in a folder named "images" in the site root.
ban countdown image

Step 3: Figure out where in your page you would like the countdown. Then copy and paste the code below between your <body></body> tags in the appropriate place in your Web page's HTML code.

<div title="more disposal ban info" style="background-image:url('images/countdown.png'); background-repeat:no-repeat; height:62px; width:250px; padding-top:47px; text-align:center; font:31px Arial Black; color:#ffffff; cursor:pointer; " onClick="window.location='http://p2pays.org/BannedMaterials/index.asp';""><script type="text/javascript">
<!-- //start

dateFuture = new Date(2009,9,1,0,0,0);

// TESTING: comment out the line below to print out the "dateFuture" for testing purposes
//document.write(dateFuture +"<br />");

//###################################
//nothing beyond this point

function padZeros(theNumber, max) {
var numStr = String(theNumber);

while ( numStr.length < max) {
numStr = '0' + numStr;
}

return numStr;
}

function GetCount(){

dateNow = new Date(); //grab current date
amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;

// time is already past
if(amount < 0){
document.getElementById('countbox').innerHTML="Now!";
}
// date is still good
else{
days=0;hours=0;mins=0;secs=0;out="";

amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

days=Math.floor(amount/86400);//days
amount=amount%86400;

hours=Math.floor(amount/3600);//hours
amount=amount%3600;

mins=Math.floor(amount/60);//minutes
amount=amount%60;

secs=Math.floor(amount);//seconds

if(days != 0){out += padZeros(days, 2) +":";}
if(days != 0 || hours != 0){out += padZeros(hours, 2) +":";}
if(days != 0 || hours != 0 || mins != 0){out += padZeros(mins, 2) +":";}
out += padZeros(secs, 2);
document.getElementById('countbox').innerHTML=out;

setTimeout("GetCount()", 1000);
}
}

window.onload=GetCount;//call when everything has loaded

//-->
</script>
<div id="countbox"></div></div>

The countdown should now appear on your Web page.
NCDENR Homepage