// Helper Scripts

// sets a focus to the main search input field
function queryfocus() { 
	// set focus to main search box
	$('#search').find(".dojoComboBox").focus();
}

//switch city layer control icon to active state
function switchSearchIconON() { 
	$("#locationSwitchIco").addClass("locationSwitchIconOn");
	$("#locationSwitchIco").removeClass("locationSwitchIconOff");
}

// switch city layer control icon to inactive state
function switchSearchIconOFF() { 
	$("#locationSwitchIco").addClass("locationSwitchIconOff");
	$("#locationSwitchIco").removeClass("locationSwitchIconOn");
}

// show city layer if not visible
function showAdvancedSearch(container) {
	if ($('#advancedSearch').is(":hidden")) {
		$('#advancedSearch').slideDown("slow");
		if ($('#advancedSearch').is(":visible")) {
			setTimeout('$("#advancedSearch").slideUp("slow");switchSearchIconOFF();', 60000);
		}
		switchSearchIconON();
	}else{
		$('#advancedSearch').slideUp("slow");
		switchSearchIconOFF();
	}	
}

// show city info layer if not visible
function showAdvancedSearchInfo() {
	if ($('#advancedSearchInfo').is(":hidden")) {
		$('#advancedSearchInfo').slideDown("slow");
		if ($('#advancedSearchInfo').is(":visible")) {
			setTimeout('$("#advancedSearchInfo").slideUp("slow");switchSearchIconOFF();', 20000);
		}
		switchSearchIconON();
	}else{
		$('#advancedSearchInfo').slideUp("slow");
		switchSearchIconOFF();
	}	
}

//hide city info layer
function hideAdvancedSearchInfo() {
	$('#advancedSearchInfo').slideUp("slow");
	return false;
}

// show detail image
function showDetailImage(location) {
	img = document.getElementById('detailImage');
	img.src = location;
}

// set city in input field, submit form, hide advancedSearch
function setCity(city) { 
	// set City Name to Frontend
	$('#cityLabel').text(city);
	
	// set City Name to InputField
	
	if(document.forms[0].elements["selectedCity"] != null){
		document.forms[0].elements["selectedCity"].value = city;	
	}else{
		$("input[name$='selectedCity']").val(city);
	}
	//alert(document.forms[0].elements["selectedCity"].value = city);
	//document.forms[0].elements["selectedCity"].value = city;
	// submit the city form
	$('#inputFormCityId').submit();
	
	// hide advancedSearch
	showAdvancedSearch('advancedSearch');
	return false;
}

function setCityDetail(city) { 
	// set City Name to Frontend
	$('#cityLabelDetail').text(city);
	
	// set City Name to InputField
	if(document.forms[0].elements["selectedCity"] != null){
		document.forms[0].elements["selectedCity"].value = city;	
	}else{
		$("input[name$='selectedCity']").val(city);
	}

	// submit the city form
	$('#inputFormCityId').submit();
	
	// hide advancedSearch
	showAdvancedSearch('advancedSearch');
	return false;
}

// open close - sidebar window
function sidebarWindowControl(controlElement) {
	if(controlElement.className == 'sidebarHeadControl'){
		controlElement.className = 'sidebarHeadControl_inactive';
		$(controlElement).parents('div:first').next('div').slideToggle('normal');
		return false;
	}else {
		controlElement.className = 'sidebarHeadControl';
		$(controlElement).parents('div:first').next('div').slideToggle('normal');
		return false;
	}
}

//open close - sidebar ditricts
function showMoreDistricts() {
	if(document.getElementById('sidebarDistricts').className == 'sidebarDistrictsIntro'){
		document.getElementById('sidebarDistricts').className = 'sidebarDistrictsContainer';
		$("#showMoreDistricts").slideToggle('normal');
		$("#showLessDistricts").slideToggle('normal');
		cHeight = document.body.scrollHeight;
	}else {
		document.getElementById('sidebarDistricts').className = 'sidebarDistrictsIntro';
		$("#showMoreDistricts").slideToggle('normal');
		$("#showLessDistricts").slideToggle('normal');
	}
}

//open close - sidebar examples
function showMoreExamples() {
	if ($('#moreExamples').is(":hidden")) {
		$('#moreExamplesLink').hide("blind", { direction: "vertical" }, 400);
		setTimeout('$("#moreExamples").slideDown("slow");', 500);
		
	}else{
		$('#moreExamplesLink').show("blind", { direction: "vertical" }, 400);
		setTimeout('$("#moreExamples").slideUp("slow");', 500);
	}	
}