window.onload = updateSections;

var arrTypes = new Array();
arrTypes[0] = new classType("", "ANY", 1);
arrTypes[1] = new classType("1", "1 Star",1);
arrTypes[2] = new classType("2-3", "2 and 3 Star",1);
arrTypes[3] = new classType("4-5", "4 and 5 Star",1);

arrTypes[4] = new classType("", "ANY",2);
arrTypes[5] = new classType("1-2", "1 and 2 Star",2);
arrTypes[6] = new classType("3", "3 Star",2);
arrTypes[7] = new classType("4-5", "4 and 5 Star",2);

arrTypes[8] = new classType("", "ANY",3);
arrTypes[9] = new classType("1-2", "1 and 2 Key",3);
arrTypes[10] = new classType("3", "3 Key",3);
arrTypes[11] = new classType("4-5", "4 and 5 Key",3);

arrTypes[12] = new classType("", "ANY",5);
arrTypes[13] = new classType("1-2", "1 and 2 Star ",5);
arrTypes[14] = new classType("3", "3 Star",5);
arrTypes[15] = new classType("4-5", "4 and 5 Star",5);

arrTypes[16] = new classType("", "Not Applicable",4);

// new horrid things...
arrTypes[17] = new classType("", "ANY",6);
arrTypes[18] = new classType("1-2", "1 and 2 Star ",6);
arrTypes[19] = new classType("3", "3 Star",6);
arrTypes[20] = new classType("4-5", "4 and 5 Star",6);

arrTypes[21] = new classType("", "ANY",7);
arrTypes[22] = new classType("1-2", "1 and 2 Star ",7);
arrTypes[23] = new classType("3", "3 Star",7);
arrTypes[24] = new classType("4-5", "4 and 5 Star",7);

arrTypes[25] = new classType("", "ANY",8);
arrTypes[26] = new classType("1-2", "1 and 2 Star ",8);
arrTypes[27] = new classType("3", "3 Star",8);
arrTypes[28] = new classType("4-5", "4 and 5 Star",8);

arrTypes[29] = new classType("", "ANY",9);
arrTypes[30] = new classType("1-2", "1 and 2 Star ",9);
arrTypes[31] = new classType("3", "3 Star",9);
arrTypes[32] = new classType("4-5", "4 and 5 Star",9);

arrTypes[33] = new classType("", "ANY",10);
arrTypes[34] = new classType("1-2", "1 and 2 Star ",10);
arrTypes[35] = new classType("3", "3 Star",10);
arrTypes[36] = new classType("4-5", "4 and 5 Star",10);

arrTypes[37] = new classType("", "ANY",11);
arrTypes[38] = new classType("1-2", "1 and 2 Star ",11);
arrTypes[39] = new classType("3", "3 Star",11);
arrTypes[40] = new classType("4-5", "4 and 5 Star",11);

arrTypes[41] = new classType("", "ANY",12);
arrTypes[42] = new classType("1-2", "1 and 2 Star ",12);
arrTypes[43] = new classType("3", "3 Star",12);
arrTypes[44] = new classType("4-5", "4 and 5 Star",12);

arrTypes[45] = new classType("", "ANY",13);
arrTypes[46] = new classType("1-2", "1 and 2 Star ",13);
arrTypes[47] = new classType("3", "3 Star",13);
arrTypes[48] = new classType("4-5", "4 and 5 Star",13);

arrTypes[49] = new classType("", "ANY",14);
arrTypes[50] = new classType("1-2", "1 and 2 Star ",14);
arrTypes[51] = new classType("3", "3 Star",14);
arrTypes[52] = new classType("4-5", "4 and 5 Star",14);

arrTypes[53] = new classType("", "ANY",15);
arrTypes[54] = new classType("1-2", "1 and 2 Star ",15);
arrTypes[55] = new classType("3", "3 Star",15);
arrTypes[56] = new classType("4-5", "4 and 5 Star",15);

arrTypes[57] = new classType("", "ANY",16);
arrTypes[58] = new classType("1-2", "1 and 2 Star ",16);
arrTypes[59] = new classType("3", "3 Star",16);
arrTypes[60] = new classType("4-5", "4 and 5 Star",16);

arrTypes[61] = new classType("", "Not Applicable",17);
// arrTypes[62] = new classType("1-2", "1 and 2 Star ",17);
// arrTypes[63] = new classType("3", "3 Star",17);
// arrTypes[64] = new classType("4-5", "4 and 5 Star",17);

arrTypes[62] = new classType("", "ANY",18);
arrTypes[63] = new classType("1-2", "1 and 2 Star ",18);
arrTypes[64] = new classType("3", "3 Star",18);
arrTypes[65] = new classType("4-5", "4 and 5 Star",18);

arrTypes[66] = new classType("", "ANY",19);
arrTypes[67] = new classType("1-2", "1 and 2 Key",19);
arrTypes[68] = new classType("3", "3 Key",19);
arrTypes[69] = new classType("4-5", "4 and 5 Key",19);

arrTypes[70] = new classType("", "ANY",20);
arrTypes[71] = new classType("1-2", "1 and 2 Star ",20);
arrTypes[72] = new classType("3", "3 Star",20);
arrTypes[73] = new classType("4-5", "4 and 5 Star",20);
// 

var sections = new Array();
sections[0] = "facilities";
sections[1] = "guests";
sections[2] = "rooms";

var accomTypes = new Array();

accomTypes[1] = new Array("facilities", "rooms"); // hotel [13]
accomTypes[2] = new Array("facilities", "rooms"); // guest + B&B
accomTypes[3] = new Array(); 			 // campsites
accomTypes[4] = new Array("guests", "facilities"); // hostel
accomTypes[5] = new Array("guests", "facilities");  // self catering

// MAK 2008-01-22 - i really don't know why i'm adding to this list
// it makes me feel wrong, so wrong
accomTypes[6] = new Array("facilities", "rooms"); // country house hotel [13]
accomTypes[7] = new Array("facilities", "rooms"); // small hotel [13]
accomTypes[8] = new Array("facilities", "rooms"); // town house hotel [13]
accomTypes[9] = new Array("facilities", "rooms"); // metro hotel
accomTypes[10] = new Array("facilities", "rooms"); // guest house
accomTypes[11] = new Array("facilities", "rooms"); // inn
accomTypes[12] = new Array("facilities", "rooms"); // restaurant with rooms
accomTypes[14] = new Array("guests", "facilities"); // Serviced Apartments
accomTypes[15] = new Array("facilities", "rooms"); // B&Bs
accomTypes[16] = new Array("facilities", "rooms"); // Farmhouses
// groups [ types that are parents of other types ]
accomTypes[13] = new Array("facilities", "rooms"); // hotels [any hotel type]
accomTypes[17] = new Array("guests", "facilities"); // hostels [any hostels type]
accomTypes[18] = new Array("guests", "facilities"); // self catering [you get the idea]
accomTypes[19] = new Array(); // campsites
accomTypes[20] = new Array("facilities", "rooms"); // Guest

function classType(id, caption, search_type_ID) {
	this.caption = caption;
	this.id = id;
	this.search_type_ID = search_type_ID;
	return this;
}

function popUpProperties(inobj) {
	op = window.open();
	op.document.open('text/plain');
	for (objprop in inobj) {
	op.document.write(objprop + ' => ' + inobj[objprop] + '\n');
	}
	op.document.close();
}

function updateSections() {

	var objCategories = document.frmSearch["type"];
// alert(strID);
// popUpProperties(objCategories);		
	var index = getselectedindex(objCategories);
	var strID = (index < 0 ? "" : objCategories[index].value);
// alert(strID);
 	if (strID != "") {
		var objTypes = document.frmSearch["class"];
		
		var typeindex = getselectedindex(objTypes);
		var typeval = (typeindex < 0 ? "" : objTypes[typeindex].value);

		clearcombobox(objTypes);
		
		for (var a = 0; a < arrTypes.length; a++) {					
			if (arrTypes[a].search_type_ID == strID) {
				addtexttocombo(objTypes, arrTypes[a].caption, arrTypes[a].id);
			}
		}
		if (typeval != "") {
			for (var a = 0; a < objTypes.options.length; a++) {
				if (objTypes.options[a].value == typeval) {
					objTypes.options[a].selected = true;
				}
			}
		}
		
		// switch all sections off by default		
		for (var i=0;i < sections.length;i++)
		{
			updateTableRows(false, sections[i]);
		}
	
		// update display based on the accom type
		for (var j=0;j<accomTypes[strID].length;j++)
		{
			if (accomTypes[strID][j] != null)
				updateTableRows(true, accomTypes[strID][j]);		
		}
	}
}

function updateTableRows(display, classname)
{
	var trs = document.getElementsByTagName("tr");
			
	for (var i=0; i < trs.length;i++)
	{
		if (trs[i].className == classname)
		{
			if (display)
			{
				trs[i].style.display = "";
			}	
			else
			{
				trs[i].style.display = "none";
			}
		}	
	}
}

function checkAccomType() {
	if(document.frmSearch["type"].value == "") {
		alert("Please select an accommodation type before choosing the rating");
	}		
}




