
<!-- Paste this code into an external JavaScript file  -->

function calc(form)
{
var trainingCosts=0;
var occupants=0;
var trainees=0;
var cabinCosts=0;
var gratuityAmount=0;
var canResident=0;
var total=0;

	if( form.training[0].checked == true ) //1 for training
	{
		
		trainingCosts = 575;
		trainees = 1;
		

	}
	else //2 for training
	{
		
		trainingCosts = 1150;
		trainees = 2;
		
	}

if (form.occupants[0].checked == true) //1 occupant
	{
		occupants=1;
	}
	else	//2 occupants
	{
		occupants=2;
	}

if( form.cabin[0].checked == true ) //inside cabin
{
	cabinCosts = (459 * 2) + (55.53 * occupants);
}
else if ( form.cabin[1].checked == true )  //outside cabin
{
	cabinCosts = (579 * 2) + (55.53 * occupants);
}
else //balcony cabin
{
	cabinCosts = (749 * 2) + (55.53 * occupants);
}

if (form.gratuity.checked == true)
{
gratuityAmount = 70 * occupants;	
}


total = trainingCosts + cabinCosts + gratuityAmount;


return(formatCurrency(total));
}



// Format a value as currency.
function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
     num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
      cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + '$' + num + '.' + cents);
}

// This function initialzes all the form elements to default values.
function InitForm(form) 
{
 form.total.value = "$1"; 
}




