// JavaScript Document

function fillCategory(){ 
 // this function is used to fill the category list on load
	addOption(document.reg.room, 0, "Apartment Stambolov");
	//addOption(document.reg.room, 1, "Apartment Smith");
	addOption(document.reg.room, 2, "Apartment Bulgaria");
    addOption(document.reg.room, 3, "Hotel Apartment Gurko");
    addOption(document.reg.room, 4, "General Gurko Guesthouse");
    addOption(document.reg.room, 5, "Apartment City");
    /*addOption(document.reg.room, 5, "Guesthouse on 34 Gurko st.");*/
	addOption(document.reg.flatType, 0, "Whole apartment");
	addOption(document.reg.flatType, 1, "Double room");
	addOption(document.reg.flatType, 2, "Single room");
	addOption(document.reg.flatType, 3, "Triple room");
}
function SelectSubCat(){
// ON selection of category this function will work

	removeAllOptions(document.reg.flatType);
	addOption(document.reg.flatType, "-1", "");
	if(document.reg.room.value == 0) {
		addOption(document.reg.flatType, 0, "Whole apartment");
		addOption(document.reg.flatType, 1, "Double room");
		addOption(document.reg.flatType, 2, "Single room");
		addOption(document.reg.flatType, 3, "Triple room");
	}
	if(document.reg.room.value == 2) {
		addOption(document.reg.flatType, 0, "Whole apartment");
		addOption(document.reg.flatType, 1, "Double room with bedroom suite");
		addOption(document.reg.flatType, 2, "Single room");
		addOption(document.reg.flatType, 3, "Double room");
	}
    if(document.reg.room.value == 3) {
		addOption(document.reg.flatType, 0, "Whole apartment");
		addOption(document.reg.flatType, 1, "Bedroom");
        addOption(document.reg.flatType, 2, "Double room");
		addOption(document.reg.flatType, 3, "3 guests in the apartment");
		addOption(document.reg.flatType, 4, "4 guests in the apartment");
	}
    if(document.reg.room.value == 4) {
		addOption(document.reg.flatType, 0, "Whole house");
		addOption(document.reg.flatType, 1, "Bedroom");
		addOption(document.reg.flatType, 2, "3 guests in the house");
		addOption(document.reg.flatType, 3, "4 guests in the house");
	}
    if(document.reg.room.value == 5) {
		addOption(document.reg.flatType, 0, "Whole apartment");
		addOption(document.reg.flatType, 1, "Bedroom with bathroom and kitchenette");
		addOption(document.reg.flatType, 2, "Bedroom with extending sofa");
		addOption(document.reg.flatType, 3, "Double room");
	}
	showPrice();
}
////////////////// 

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}

function showPrice() {
    var prices = new Array(
						   new Array(150,40,25,50),
						   new Array(40,35,30),
						   new Array(160,50,50,40),
                           new Array(100,60,60,80,100),
                           new Array(110,60,80,110),
                           new Array(110,55,60,50)
						   );
	targetRoom = document.getElementById("room").value;
	targetFlat = document.getElementById("flatType").value;
	
	if (targetRoom == 1) {
			var priceNight;
			var nights = document.getElementById("nights").value;
			if (nights <= 5) {
				priceNight = 0;
			}
			if (nights >= 6) {
				priceNight = 1;
			}
			if (nights >= 30) {
				priceNight = 2;
			}
			document.getElementById("price").value = prices[1][priceNight];		
	} else {
		if (targetFlat == -1) {
			document.getElementById("price").value = 0;
		} else {
			document.getElementById("price").value = prices[targetRoom][targetFlat];
		}
	}
}
