﻿DOMAssistant.DOMReady(eddaOnLoad);

function eddaOnLoad() {
	//Hide locations on load
	$("#qsForm ul.hasc").each(function () {
		hideBlock(this);
	});
	
	$("#qsForm li").each(function () {
		hideBlock(this);
	});
	
	$("#qsForm li.c" + $$("county").options[$$("county").selectedIndex].value).each(function () {
		showBlock(this);
	});
	
	clearAllChecks();
	//checkIfRoom();
	
	//Add event that shows nested list
	$("#qsForm input.hasc").addEvent("click", showSelChildren);

	$$("county").addEvent("change", function (){
		clearAllChecks();
	
		$("#qsForm ul.hasc").each(function (){
			hideBlock(this);
		});
		
		$("#qsForm li").each(function (){
			hideBlock(this);
		});
		
		$("#qsForm li.c" + $$("county").options[$$("county").selectedIndex].value).each(function () {
			showBlock(this);
		});
	});
	
	//Fix so that room hides when switch is selected
//		$$("switch").addEvent("click", function () {
//			if ($$(this).checked){
//				hideInline("roomSpan");
//				$$("rty4e8113b6-648c-421f-8746-22084737f40c").checked = false;
//			}
//		});
//		$$("rent").addEvent("click", function () {
//			if ($$(this).checked)
//				showInline("roomSpan");
//		});
//		
//		if ($$("switch").checked)
//			hideInline("roomSpan");
	
//		$$("rtyApartment").addEvent("click", checkIfRoom);
//		$$("rtyVilla").addEvent("click", checkIfRoom);
//		$$("rtyRoom").addEvent("click", checkIfRoom);
}

function showSelChildren(){
	$("#qsForm ul.hasc").each(function (){
		hideBlock(this);
	});
	
	if ($$(this).checked){
		showBlock("lc" + $$(this).value);
		$("#lc" + $$(this).value + " li").each(function (){
			showBlock(this);
		});
	} else {
		hideBlock("lc" + $$(this).value);
		$("#lc" + $$(this).value + " li").each(function (){
			hideBlock(this);
		});
		$("#lc" + $$(this).value + " input").each(function (){
			$$(this).checked = false;
		});
	}
}

function clearAllChecks(){
	$("#locationCblDiv input").each(function (){
		$$(this).checked = false;
	});
}

function checkIfRoom(){
	if ($$("rtyRoom").checked == true & $$("rtyApartment").checked == false & $$("rtyVilla").checked == false){
		$(".notForRoom select").each(function (){
			$$(this).disabled = true;
		});
	} else {
		$(".notForRoom select").each(function (){
			$$(this).disabled = false;
		});
	}
}