var intTotal
var pre_pack
var prePackTotal
var bulkBagTotal
var  bulk_bag

	function calculate()
	{
	
		strType      = document.formDecoPakCalculator.areaType.value;
		strDepthType = document.formDecoPakCalculator.depthType.value;
		intA         = new Number(document.formDecoPakCalculator.intA.value);
		intB         = new Number(document.formDecoPakCalculator.intB.value);
		intDepth     = new Number(document.formDecoPakCalculator.intDepth.value);
		
		if( isNaN( intA ) ||  isNaN( intB ) ||  isNaN( intDepth ) || intA == '' || intB == '' || intDepth == '' )
		{
			alert ('Please enter valid values for Length, Width and Depth fields.');
			dojo.byId('result').innerHTML = 'Invalid value(s) in Length, Width or Depth field(s)';
			
		}
		else
		{
		
		
			if(strType == "2"){
				intA = intA * 0.3048;
				intB = intB * 0.3048;
			}
			if(strType == "3"){
				intA = intA * 0.9144;
				intB = intB * 0.9144;
			}
			
			if (strDepthType == "3"){
				intDepth = (intDepth * 25)  / 1000;
			}
			if (strDepthType == "2"){
				intDepth = (intDepth * 10) / 1000;
			}
			if (strDepthType == "1"){
				intDepth = (intDepth) / 1000;
			}
			
			intTotal = intA * intB;
			intTotal = intTotal * intDepth;
			prePackTotal = intTotal * 60;
			bulkBagTotal = prePackTotal / 40;		
					
			
			prePackTotal = prePackTotal.toString();
			bulkBagTotal = bulkBagTotal.toString();
			
			if( prePackTotal.indexOf('.') != -1 )
			{
				prePackTotal = new Number(prePackTotal);
				prePackTotal = prePackTotal + 0.5;
				prePackTotal = Math.round(prePackTotal);
			}
			
			if( bulkBagTotal.indexOf('.') != -1  )
			{
				bulkBagTotal = new Number(bulkBagTotal);
				bulkBagTotal = bulkBagTotal + 0.5;
				bulkBagTotal = Math.round(bulkBagTotal);
			}
			
			//document.formDecoPakCalculator.total.value = intTotal;
			//$('result').hide();
			if( prePackTotal == 1 )
			{
			 pre_pack = 'Pre-pack bag'
			}
			else
			{
			  pre_pack = 'Pre-pack bags'
			}
		
			if( bulkBagTotal == 1 )
			{
			 bulk_bag = 'bulk bag'
			}
			else
			{
			  bulk_bag = 'Bulk bags'
			}
	
			//if( prePackTotal.test( /[0-9]+\.[0-9]*/ ) )
			//{
				dojo.byId('result').innerHTML = 'Approximately ' + prePackTotal + ' ' + pre_pack + ' ' + 'or ' + bulkBagTotal + ' ' + bulk_bag + ' will be required.\n\n<br>'+'<lable style="color:#FF0000;">N.B.: A Bulk bag equals to 40 Pre-pack bags.</lable>';
			//}
			
			dojo.style('result', 'display', 'block');
			//$('result').highlight();
		}

	}
