// JavaScript Document

function fillCategory(){
 // this function is used to fill the category list on load
	addOption(document.reg.room, 0, "Апартамент Стамболов");
	addOption(document.reg.room, 1, "Апартамент България");
    addOption(document.reg.room, 2, "Апартамент Гурко");
    addOption(document.reg.room, 3, "Къща за гости Гурко");
    addOption(document.reg.room, 4, "Къща за гости Арбанаси");
    addOption(document.reg.room, 5, "Апартамент Сити");
    addOption(document.reg.room, 6, "Хотелско Студио Сити");
	addOption(document.reg.flatType, 0, "Цял апартамент");
	addOption(document.reg.flatType, 1, "Двойна стая");
	addOption(document.reg.flatType, 2, "Единична стая");
	addOption(document.reg.flatType, 3, "Тройна стая");
}
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, "Цял апартамент");
		addOption(document.reg.flatType, 1, "Двойна стая");
		addOption(document.reg.flatType, 2, "Единична стая");
		addOption(document.reg.flatType, 3, "Тройна стая");
	}
	if(document.reg.room.value == 1) {
		addOption(document.reg.flatType, 0, "Цял апартамент");
		addOption(document.reg.flatType, 1, "Двойна стая със спалня");
		addOption(document.reg.flatType, 2, "Тройна стая");
		addOption(document.reg.flatType, 3, "Двойна стая");
	}
    if(document.reg.room.value == 2) {
		addOption(document.reg.flatType, 0, "Цял апартамент");
		addOption(document.reg.flatType, 1, "Двойна стая със спалня");
        addOption(document.reg.flatType, 2, "Двойна стая с две единични легла");
		addOption(document.reg.flatType, 3, "Трима човека в апартамента");
		addOption(document.reg.flatType, 4, "Четири човека в апартамента");
	}
    if(document.reg.room.value == 3) {
		addOption(document.reg.flatType, 0, "Цялата къща");
		addOption(document.reg.flatType, 1, "Двойна стая със спалня");
		addOption(document.reg.flatType, 2, "Трима човека в къщата");
		addOption(document.reg.flatType, 3, "Четири човека в къщата");
	}
    if(document.reg.room.value == 4) {
		addOption(document.reg.flatType, 0, "Цялата къща");
		addOption(document.reg.flatType, 1, "Двойна стая");
	}
    if(document.reg.room.value == 5) {
		addOption(document.reg.flatType, 0, "Цял апартамент");
		addOption(document.reg.flatType, 1, "Двойна стая със спалня");
		addOption(document.reg.flatType, 2, "Тройна стая");
		addOption(document.reg.flatType, 3, "Двойна стая с две единични легла");
	}
    if(document.reg.room.value == 6) {
		addOption(document.reg.flatType, 0, "Студио двама човека");
		addOption(document.reg.flatType, 1, "Студио трима човека");
	}

	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(160,55,55,45),
                           new Array(100,60,60,80,100),
                           new Array(110,60,80,110),
                           new Array(240,60),
                           new Array(110,55,60,50),
                           new Array(55,60)
						   );
	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];
		}
	}
}