
		function roundNumber(num) {
			var rnum = num;
			var rlength = 2; // The number of decimal places to round to
			if (rnum > 8191 && rnum < 10485) {
				rnum = rnum-5000;
				var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
				//newnumber = newnumber+5000;
			} else {
				var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
			}
			return newnumber;
		}		  




	  	//global
		
		urlArr = new Array("","","","","");
		urlArrM = new Array("","","","","");
	  
	  
	    //calculate the stuff
	    function calc()
		{
		  //get the data from the table
		  var width = (document.calcform.wf.value * 12) + (document.calcform.wi.value * 1);
		  var length = (document.calcform.lf.value * 12) + (document.calcform.li.value * 1);
		  var depth = (document.calcform.df.value * 12) + (document.calcform.di.value * 1);
		  var overlap = (document.calcform.of.value * 12) + (document.calcform.oi.value * 1);
		  var mwidth = (document.calcform.wc.value * 1) + (document.calcform.wm.value * 100);
		  var mlength = (document.calcform.lc.value * 1) + (document.calcform.lm.value * 100);
		  var mdepth = (document.calcform.dc.value * 1) + (document.calcform.dm.value * 100);
		  var moverlap = (document.calcform.oc.value * 1) + (document.calcform.om.value * 100);
		  
		  //check for the validity of the inputs
		  if (isNaN(width)) { alert("Imperial width is not numeric!!"); return; }
		  if (isNaN(length)) { alert("Imperial length is not numeric!!"); return; }
		  if (isNaN(depth)) { alert("Imperial depth is not numeric!!"); return; }
		  if (isNaN(overlap)) { alert("Imperial overlap is not numeric!!"); return; }
		  if (isNaN(mwidth)) { alert("Metric width is not numeric!!"); return; }
		  if (isNaN(mlength)) { alert("Metric length is not numeric!!"); return; }
		  if (isNaN(mdepth)) { alert("Metric depth is not numeric!!"); return; }
		  if (isNaN(moverlap)) { alert("Metric overlap is not numeric!!"); return; }
		  
		  //work out the width and length in inches
		  var pwidth = width + (depth * 2) + (overlap * 2);
		  var plength = length  + (depth * 2) + (overlap * 2);
		  //work out the width and length in CM
		  var cwidth = mwidth + (mdepth * 2) + (moverlap * 2);
		  var clength = mlength  + (mdepth * 2) + (moverlap * 2);
		  
		  //the actual liner length and width after rounding up
		  var liner_width = roundUp(pwidth);
		  var liner_length =  roundUp(plength);
		  var liner_widthm = roundUpM(cwidth);
		  var liner_lengthm =  roundUpM(clength);
		  //alert("W"+ liner_widthm +" L" +liner_lengthm);


          //set the width and height in the document
		  document.getElementById("lwidth").innerHTML = "" + toFeet(liner_width);
		  document.getElementById("llength").innerHTML = "" + toFeet(liner_length);
		  document.getElementById("lwidthm").innerHTML = "" + toMetres(liner_widthm);
		  document.getElementById("llengthm").innerHTML = "" + toMetres(liner_lengthm);
		  
		  //work out the square feet area
		  var sq_size = liner_width * liner_length;
		  var sq_sizem = liner_widthm * liner_lengthm;
		  
		  //set the square feet in the document
		  document.getElementById("sqft").innerHTML = "" + toSqFeet(sq_size);
		  document.getElementById("sqmt").innerHTML = "" +  ((Math.round((sq_size * 0.0006452)*100))/100 );
		  document.getElementById("sqmtr").innerHTML = "" + toSqM(sq_sizem)
		   
		}//end of function
		
		//round up to the nearest 6 inches
		function roundUp(number)
		{
		  var mod = number % 6;
		  if (mod == 0) return number;
		  else return number + (6 - mod);
		}
		
		function roundUpM(number)
		{
		  var mod = number % 50;
		  if (mod == 0) return number;
		  else return number + (50 - mod);
		}
		
		//format to feet and inches
		function toFeet(inches)
		{
		  var foot = Math.floor(inches / 12);
		  var inch = inches % 12;
		  return foot + "ft " + inch + "&quot;";
		}
		function toMetres(cms)
		{
		  var m = Math.floor(cms / 100);
		  var cm = cms % 100;
		  if (cm < 10)
			  return m + ".0" +  cm + "m";
		  else
			  return m + "." +  cm + "m";
		}
		
		
		//format to square feet and inches
		function toSqFeet(inches)
		{
		  var foot = Math.floor(inches / 144);
		  var inch = inches % 12;
		  return foot + "ft " + inch + "&quot;";
		}
		function toSqM(cm)
		{	
		  var m = cm / 10000;
		  return m.toFixed(2)+ "m";
		}


