<!--
var state = 'none';
function showhide(layer_ref) {

if (state == 'block') {
state = 'none';
}
else {
state = 'block';
}
if (document.getElementById) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}
}

	
function showOptions(){
 var wf = document.forms["calculator"].elements["wasteType"];
 var i, v
for(i=0;i<wf.length;i++){
  if(wf[i].checked){
   v = wf[i].value;
   /*alert(v);*/
  }
 }
 for(i=1;i<=3;i++){
  if(i==v){
   document.getElementById("Q" + i).style.display = "block";
  } 
  else{
   document.getElementById("Q" + i).style.display = "none";
  }
 }
 return true
}

function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
	  e.style.display = 'none';
   else
	  e.style.display = 'block';
}

function showhideCost(id)
{
	// Test for NS6 IE5--&gt;
	if (document.getElementById)
	{
		for(i=1; i <=6; i++){

			obj = document.getElementById("c"+i);
			obj2 = document.getElementById("active"+i);
			
			if (("c"+i) == id){
				obj.style.display = "";
				obj2.className = "active";
			}

			else{
					obj.style.display = "none";
					obj2.className = "";
			}

		}
	}
}

function showhideKnow(id)
{
	// Test for NS6 IE5--&gt;
	if (document.getElementById)
	{
		for(i=1; i <=3; i++){

			obj = document.getElementById("k"+i);
			obj2 = document.getElementById("active"+i);

			if (("k"+i) == id){
				obj.style.display = "";
				obj2.className = "active";
			}

			else{
					obj.style.display = "none";
					obj2.className = "";
			}

		}
	}
}
/*-----------------------------------*/
/*-----------------------------------*/
/*-----------------------------------*/
//Count commas
String.prototype.replaceAll=function(s1, s2) { 
	return this.replace(new RegExp(s1,"g"), s2);
}
/* image popup */
function showImgOver(name,imgSrc,imgDesc){
	var id = document.getElementById(name+"PopUp");
	if(id.style.display == "none"){
		id.style.display = "block";
		
		//var htmlheight = document.body.parentNode.scrollHeight; 
		//var windowheight = window.innerHeight; 
		//if ( htmlheight < windowheight ) { alert(windowheight + "px - window height"); } 
		//else { alert(htmlheight + "px - html height"); }

		document.body.style.background = "url('/images/transBkg.png') repeat 0 0 #4fa833";
		document.getElementById("fadeBkg").style.backgroundColor = "#4fa833";
		document.getElementById("popTitle").innerHTML = imgDesc;
		document.getElementById("popImage").innerHTML = '<img src="'+imgSrc+'" alt="" />';
	}else{
		id.style.display = "none";
		document.body.style.background = "transparent";
		document.body.style.backgroundColor = "#4fa833";
		//document.getElementById("test").style.background = "transparent";
	}
}
/*- Global ajax popup size - default of 234px x 500px -*/
ajaxWidth = 234;
ajaxHeight = 450;
function getCompCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
				return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return ""
}
function setCompCookie(c_name,value,expiredays){
	var writeCookie = 1
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	var openId = getCompCookie('stone');
	var display = document.getElementById('stone'+value);
	//use split and join to use an array
	if(openId!=null && openId!=""){
		var endValue = openId.split(",");
		var alreadyThere = -1;
		for (var i=0; i < endValue.length; i++){
		if (value == endValue[i]){
			var alreadyThere = i ;
			break ;
		}
	}

	if(alreadyThere == -1){
		//check number in cookie
		var k = checkNumberCompared();
		//alert(k);
		if(k == 3){
			alert("You can only compare 3 aggregates")
			writeCookie = 0
		}else{
			display.innerHTML = "Remove Compare";
			endValue.splice(endValue.length,0,value);
		}
	}else{
		display.innerHTML = "Compare Me";
		endValue.splice(alreadyThere,1);
	}
	endValue = endValue.join(",");
	}else{
		if(value!=null && value!=""){
			display.innerHTML = "Remove Compare";
		}
		endValue = value;
	}
	if(writeCookie == 1){
		document.cookie=c_name+ "=" +escape(endValue)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+"; path=/");
	}
	//alert("End Value "+endValue);
	//count number of commas to determine ajax width
	var compareButton = document.getElementById("compareAgg");
	var fakeButton = document.getElementById("noClick");
	var clearButton = document.getElementById("clearCookie");
	if(endValue.length > 0){
		var j = checkNumberCompared();
		if(j==1){
			ajaxWidth = 234;
			compareButton.href = "compare.asp?height="+ajaxHeight+"&width="+ajaxWidth;
		}else{
			ajaxWidth = 234 + (200*(j-1));
			compareButton.href = "compare.asp?height="+ajaxHeight+"&width="+ajaxWidth;
		}
		if(j < 3){
			var linkTxt = "You can compare upto "+(3-(j))+" other aggregate";
			if(j<=1){
				compareButton.style.display = "none";
				fakeButton.style.display = "inline";
				linkTxt =  linkTxt + "s";
				fakeButton.innerHTML = linkTxt;
				if(j=1){clearButton.style.display = "inline";}
			}else{
				fakeButton.style.display = "none";
				compareButton.style.display = "inline";
				clearButton.style.display = "inline";
				compareButton.innerHTML = linkTxt;
				}
		}else{
			fakeButton.style.display = "none";
			compareButton.style.display = "inline";
			clearButton.style.display = "inline";
			compareButton.innerHTML = "Compare your 3 chosen aggregates.";
		}
	}else{
		compareButton.style.display = "none";
		clearButton.style.display = "none";
		fakeButton.style.display = "inline";
		fakeButton.innerHTML = "Click &ldquo;Compare Me&rdquo; to compare upto 3 aggregates side by side.";
	}
	//alert(ajaxWidth);
	
}
function checkCompCookie(){
	var openId = getCompCookie('stone');
	var compareButton = document.getElementById("compareAgg");
	var fakeButton = document.getElementById("noClick");
	var clearButton = document.getElementById("clearCookie");
	var j = checkNumberCompared();
//	alert(openId);
	if(openId!=null && openId!=""){
		openId = unescape(openId);
		openId = openId.split(",");
		for(i in openId){
			if(document.getElementById('stone'+openId[i])){
				document.getElementById('stone'+openId[i]).innerHTML = "Remove Compare";
			}
			ajaxWidth = 234;
			if(j>1){ajaxWidth = ajaxWidth + (200*(j-1));}
			compareButton.href = "compare.asp?height="+ajaxHeight+"&width="+ajaxWidth;
		}
		if(j < 3){
			var linkTxt = "You can compare upto "+(3-(j))+" other aggregate";
			if(j<=1){
				compareButton.style.display = "none";
				fakeButton.style.display = "inline";
				linkTxt =  linkTxt + "s";
				fakeButton.innerHTML = linkTxt;
				if(j=1){clearButton.style.display = "inline";}
			}else{
				fakeButton.style.display = "none";
				compareButton.style.display = "inline";
				clearButton.style.display = "inline";
				compareButton.innerHTML = linkTxt;
			}
		}else{
			fakeButton.style.display = "none";
			compareButton.style.display = "inline";
			clearButton.style.display = "inline";
			compareButton.innerHTML = "Compare your 3 chosen aggregates.";
		}
	}else{
		setCompCookie('stone','',365);
		clearButton.style.display = "none";
	}
}
function checkNumberCompared(){
	var opened = getCompCookie('stone');
	var j = 0;
	if(opened!=null && opened!=""){
		opened = unescape(opened);
		opened = opened.split(",");
		for(i in opened){
			j++;
		}
	}
	return j
}
function clearCookie(){
	var openId = getCompCookie('stone');
	if(openId!=null && openId!=""){
		var expiredays = 365;
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie="stone"+ "=" +''+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+"; path=/");
	}
}
/*function displayCompCookie(){
	var openId = getCompCookie('stone')
	if(openId!=null && openId!=""){
		openId = unescape(openId);
		//openId = openId.split(",");
		return openId;
	}else{
		return 0;
	}
}*/


/*------------------------------------------------------------------------*/

function calc(){
	var width = checknumber(document.getElementById('width').value, 1); //alert(width);
	var length = checknumber(document.getElementById('length').value, 1); //alert(length);
	var depth = checknumber(document.getElementById('depth').value, 50); //alert(depth);
	var density = checknumber(getSizeDensity(), 1); //alert(density);
	//alert("density "+density);
	var area = length * width;
	var volume  = area *(depth/1000);
	var kgs = 1000*(volume*density);
	var ton = kgs/1000
	var bags = Math.floor(kgs/25);
	if ((kgs % 25) > 0) {
		bags = bags + 1;
	}
	var tons, extBag
	extBag = ''
	if (kgs  <= 850){
		tons = 1;
	} else {
		tons = Math.floor(kgs/850);
		if ((kgs % 850) > 0) {
			//alert(kgs % 850);
			if ((kgs % 850) > 500){
				tons++;
			} else {
				var e = (kgs % 850);
				var eb = e/25;
				if ((e % 25) > 0){ eb++; }				
				extBag = "+ " + eb.toFixed(0) + " x 25kg bags";
			}
		}
	}

	document.getElementById('volval').innerHTML = volume.toFixed(2)+"m&sup3;";
	document.getElementById('kgval').innerHTML = ton.toFixed(2)+" tons";
	document.getElementById('bagval').innerHTML = bags.toFixed(0)+" x 25kg bags <span style='font-weight:100;font-size:11px;'>or:</span> ";
	document.getElementById('tonval').innerHTML = tons.toFixed(0)+" x bulk bags";
	document.getElementById('extval').innerHTML = extBag;
}

function checknumber(value, deflt){
	var x=value
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if(anum.test(x)){
		testresult=value
	}else{
		testresult=deflt
	}
	return(testresult)
}

function getSizeDensity(){
	//alert("get size density");
	return document.getElementById("density").value;
	
}

function createDensity(id){
	var val = document.getElementById("size_"+id).value;
	document.getElementById("density").value = val;
	//alert("create density "+val);
	calc();
}

function getSizes(){
	prod = document.getElementById("product");
	//firstly hide all size boxes
	//go from 1 to eliminate first row ( -Please select a product- )
	for(i=1;i<prod.length;i++){ 
		//alert("debug - got array item "+i);
		inx = prod[i].value;
		if(inx!='dispOnly'){
			document.getElementById("size_"+inx).style.display = "none";
		}
	}
	var showOpt = document.getElementById("showOptions");
	showOpt.style.display = "none";
	var showSze = document.getElementById("showSize");
	showSze.style.display = "none";
	
	var ind = document.calcAgg.product.selectedIndex;
	var val = document.calcAgg.product[ind].value;
	
	if(document.getElementById("size_"+val)){
	
		var sze = document.getElementById("size_"+val);
		if(sze.style.display == "none"){
			sze.style.display = "inline";
		}else{
			sze.style.display = "none";
		}
		showOpt.style.display = "block";
		showSze.style.display = "inline";
	createDensity(val);
	}
}
-->