function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function calculateShipmentWeight(rooms_id,people_id,desity_level_id,moving_level,result_id)
{
	var NumberOfRooms = $(rooms_id).value;
	var NumberOfPeople = $(people_id).value;
	var DensityLevel = $(desity_level_id).value;
	var MovingLevel = $(moving_level).value;
	
	var PeoplePerRoom = NumberOfPeople / NumberOfRooms;
	
	if (PeoplePerRoom<0.5)
	{
		PeoplePerRoom = 0.5;
	}
	if (PeoplePerRoom>4)
	{
		PeoplePerRoom = 4;
	}
	
	var LbsPerRoom = 500 + ( (PeoplePerRoom * 500) * ( (DensityLevel / 2) + 1) )
	var EstimatedWeight = 1000 + Math.round((NumberOfRooms * LbsPerRoom) * (MovingLevel / 4));
	
	var el = $(result_id);
	el.style.display = 'inline';
	el.innerHTML = "Your approx shipment weight is <strong>" + EstimatedWeight + "</strong> Lbs.";
	setWeightValues(EstimatedWeight);
}

   
function weight_to_volume(weight_id, score_id)
{
	if (!IsNumeric($(weight_id).value))
	{
		alert("Please enter a weight in numbers.");
		return;
	}
	var el = $(score_id);
	el.style.display = 'inline';
	el.innerHTML = "Your estimated shipment volume in cubic feet is : <strong>" + Math.round($(weight_id).value / 7) + "</strong>";
}

function calc_storage(weight_id,result_id) {
	
	// check values
	if ($(weight_id).value=="") { alert("Enter Estimated Shipment Weight!"); $(weight_id).focus(); return; }
	
	var result = $(weight_id).value / 7;

	if(result < 140)
		result = "Your estimated storage size requirement is a <strong>5x5 Sq.Ft. unit.</strong>";
	else if(result < 280)
		result = "Your estimated storage size requirement is a <strong>5x10 Sq.Ft. unit.</strong>";
	else if(result < 560)
		result = "Your estimated storage size requirement is a <strong>10x10 Sq.Ft. unit.</strong>";
	else if(result < 840)
		result = "Your estimated storage size requirement is a <strong>10x15 Sq.Ft. unit.";
	else if(result < 1120)
		result = "Your estimated storage size requirement is a <strong>10x20 Sq.Ft. unit.</strong>";
	else if(result < 1260)
		result = "Your estimated storage size requirement is a <strong>15x15 Sq.Ft. unit.</strong>";
	else if(result < 1680)
		result = "Your estimated storage size requirement is a <strong>15x20</strong> or <strong>10x30</strong> Sq.Ft. unit.";
	else  
	{
		result = Math.round(result / 1680 + 1);
		result = "Your estimated storage requirement is <strong>" + result + "</strong> units of <strong>15x20</strong> or <strong>10x30</strong> Sq.Ft. each.";
	}
	
	var el = $(result_id);
	el.style.display = 'inline';
	el.innerHTML = result;
	
}

function calc_packing(weight_id,result_id) {
	W = $(weight_id).value;
	if (W=="") { alert("Enter Estimated Shipment Weight!"); $(weight_id).focus(); return; }
	
	var oUL;
	var oParagraph = document.createElement("p");
	
	var smallBoxes =3;
	var meduimBoxes = 5;
	var largeBoxes = 5;
	var pictureBoxes = 1;
	var wardrobeBoxes = 1;
	var tapes = 5;
	var whitePaperLBS = 5;
	var incFactor = Math.round(W / 1000)-1;
	
	if (incFactor>0)
	{
		smallBoxes += incFactor;
		meduimBoxes += Math.round(incFactor*1.5);
		largeBoxes += Math.round(incFactor*1.5);
		pictureBoxes += incFactor;
		wardrobeBoxes += Math.round(incFactor*0.5);
		tapes += incFactor;
		whitePaperLBS += Math.round(incFactor*2.5);
	}
	oParagraph.innerHTML = "To pack " + W + " Lbs. of household goods you'll need approximatly:";
	oUL = genPackingList(smallBoxes,meduimBoxes,largeBoxes,pictureBoxes,wardrobeBoxes,tapes,whitePaperLBS);

	var el = $(result_id);
	el.style.display = 'inline';
	el.innerHTML = "";
	el.appendChild(oParagraph);
	el.appendChild(oUL);
}

function genPackingList(smallBoxes,meduimBoxes,largeBoxes,pictureBoxes,wardrobeBoxes,tapes,whitePaperLBS)
{
	var oUL = document.createElement("ul");
	
	if (smallBoxes>0)
	{
		var oLI = document.createElement("li");
		oLI.innerHTML = "<strong>" + smallBoxes + "</strong> small sized boxes";
		oUL.appendChild(oLI);
	}

	if (meduimBoxes>0)
	{
		var oLI = document.createElement("li");
		oLI.innerHTML = "<strong>" + meduimBoxes + "</strong> medium sized boxes";
		oUL.appendChild(oLI);
	}

	if (largeBoxes>0)
	{
		var oLI = document.createElement("li");
		oLI.innerHTML = "<strong>" + largeBoxes + "</strong> medium-large sized boxes";
		oUL.appendChild(oLI);
	}
	
	if (pictureBoxes>0)
	{
		var oLI = document.createElement("li");
		oLI.innerHTML = "<strong>" + pictureBoxes + "</strong> picture boxes";
		oUL.appendChild(oLI);
	}

	if (wardrobeBoxes>0)
	{
		var oLI = document.createElement("li");
		oLI.innerHTML = "<strong>" + wardrobeBoxes + "</strong> wardrobe boxes";
		oUL.appendChild(oLI);
	}
	
	if (tapes>0)
	{
		var oLI = document.createElement("li");
		oLI.innerHTML = "<strong>" + tapes + "</strong> rolls of tape";
		oUL.appendChild(oLI);
	}

	if (whitePaperLBS>0)
	{
		var oLI = document.createElement("li");
		oLI.innerHTML = "<strong>" + whitePaperLBS + "</strong> Lbs. of white paper";
		oUL.appendChild(oLI);
	}
	return oUL;
}	

function setWeightValues(weight)
{
	$('weight_for_volume').value = weight;
	$('weight_for_storage').value = weight;
	$('weight_for_packing').value = weight;
}

