/* JavaScript Document

Name: accomCalculator

it calculates the cost for accommodation, daily - weekly - monthly

*/

//------------------------------------------------------

//----> Accommodation pre-set prices, apply to future changes

var room_bathroom = 45



var regular_room = 32



var weekly_discount = .1	//10%

var monthly_discount = 0.15	//30%



//------------------------------------------------



function calcAccom(){

	var room_type;

	var num_people;

	var aForm = document.form1;

	//----> get the room type

	room_type = getRoomType(aForm);

		

	//----> get number of people

	num_people = aForm.num_people.options[aForm.num_people.selectedIndex].text;

	//aForm.num_people.selectedIndex = aForm.num_people.selectedIndex;

	//alert(room_type);

	//alert(num_people);

	if(num_people > 0 && room_type > 0){

		//alert("ok");

		var room = 0;

		if(room_type == 1){		//room with bathroom

			if(num_people > 1){

				room = (room_bathroom + 5 * (num_people-1));

			}

			else{

				room = room_bathroom;

			}

			aForm.daily.value = room

			aForm.w.value = aForm.daily.value * 7;

			aForm.weekly.value = aForm.w.value * 0.95

						

			aForm.m.value = aForm.daily.value * 30;

			aForm.monthly.value = aForm.m.value * 0.85

		}

		else{	//regular room

			if(num_people > 1){

				room = (regular_room + 5 * (num_people-1));

			}

			else{

				room = regular_room;

			}		

			aForm.daily.value = room;

			aForm.w.value = aForm.daily.value * 7;

			aForm.weekly.value = aForm.w.value * 0.95

			

			aForm.m.value = aForm.daily.value * 30;

			aForm.monthly.value = aForm.m.value * 0.85

		}

		//----> round the weekly and monthly results

		aForm.weekly.value = roundTo(aForm.weekly.value, -1);		

		aForm.monthly.value = roundTo(aForm.monthly.value, -1);

	}

	return false;

}



function roundTo(num,pow){

  num *= Math.pow(10,pow);

  num = (Math.round(num)/Math.pow(10,pow))+ "" ;

  /*if(num.indexOf(".") == -1)

    num += "." ;*/

  while(num.length - num.indexOf(".") - 1 < pow)

    num += "0" ;

  return num ;

}



function getNumPeople(aForm){

	

}



function getRoomType(aForm){

	var room_type = 0;

	if(aForm.radiobutton[0].checked){

		room_type = aForm.radiobutton[0].value;

	}

	else if(aForm.radiobutton[1].checked){

		room_type = aForm.radiobutton[1].value;

	}

	return room_type;

}

