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_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_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_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];}
}

function popup(url, name, width, height)
{
settings=
"toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,width="+width+",height="+height;MyNewWindow=window.open(url,name,settings);
}

function flipText(newTEXT) {
		document.getElementById('description').innerHTML=newTEXT;
}

function isBlank(varString) {
	var boolStringIsBlank = true
	var intI

	if(varString) {
		for(intI=0; intI < varString.length; intI++) {
			if(varString.charAt(intI) != " ") {
				boolStringIsBlank = false
				break
			}
		}
	}

	return boolStringIsBlank
}

function doCalc() {
	var boolPerform = true
	var strMsg
	var intDepth
	var intArea
	var intLength
	var intWidth
	var sngResult

	if(isBlank(document.MulchCalc.thickness.value)) {
		boolPerform = false
		strMsg = "Thickness is required."
		document.MulchCalc.thickness.focus()
	}

	if(boolPerform)
		if((isBlank(document.MulchCalc.length.value)) && (isBlank(document.MulchCalc.area.value)) && (isBlank(document.MulchCalc.width.value))) {
			boolPerform = false
			strMsg = "Please Enter Length and Width or Area"
			document.MulchCalc.length.focus()
		}

	if(boolPerform)
		if((isBlank(document.MulchCalc.width.value)) && (isBlank(document.MulchCalc.area.value)) && !(isBlank(document.MulchCalc.length.value))) {
			boolPerform = false
			strMsg = "Total Width is required."
			document.MulchCalc.width.focus()
		}

	if(boolPerform)
		if((isBlank(document.MulchCalc.length.value)) && (isBlank(document.MulchCalc.area.value)) && !(isBlank(document.MulchCalc.width.value))) {
			boolPerform = false
			strMsg = "Total Length is required."
			document.MulchCalc.length.focus()
		}

	if(boolPerform) {
		intDepth = document.MulchCalc.thickness.value

		if(!(isBlank(document.MulchCalc.width.value)) && !(isBlank(document.MulchCalc.length.value))) {
		intArea = document.MulchCalc.length.value * document.MulchCalc.width.value
		} else { intArea = document.MulchCalc.area.value }
		// The following comments relate to the calculation that follows them:
		// Multiply area by 144 to convert to square inches.
		// Assume 46656 cubic inches to the cubic yard...
		//	27 cubic feet per cubic yard
		//	x 1728 cubic inches per cubic foot
		//	= 46656 cubic inches per cubic yard
		// Before rounding, multiply by 100 (144 becomes 14400) to preserve 2 decimal positions.
		// After rounding, divide by 100 to restore the 2 decimal positions.
		sngResult = Math.round((intDepth * intArea * 14400) / 46656) / 100
		sngResult = Math.ceil(sngResult)
		document.MulchCalc.Total.value = sngResult
		if(isBlank(document.MulchCalc.area.value)) { document.MulchCalc.area.value = intArea }
	}
	else
		alert(strMsg)
}
