

var pattern_url = "http://nuernberg.lokaltipps.de/result.aspx?iid=%iid%&did=%did%&keyword=%kw%&sn=%sn%&sa=%sa%&sp=%sp%&bg=%bg%&pa=%pa%&cl=%cl%&mode=%mode%";
var keywordId = "ctl00_formcontent_searchbar_searchValue";
var searchInNameId = "ctl00_formcontent_searchbar_searchInName";
var searchInAddressId = "ctl00_formcontent_searchbar_searchInAddress";
var searchInPortraitId = "ctl00_formcontent_searchbar_searchInInterview";
var hasBeergardenId = "ctl00_formcontent_searchbar_searchHasBeergarden";
var hasParkareaId = "ctl00_formcontent_searchbar_searchHasParkarea";
var hasCashlessId = "ctl00_formcontent_searchbar_searchHasCashless";
var treeIndustryId = "ctl00_formcontent_searchbar_TreeIndustries_selected";
var treeMunichId = "ctl00_formcontent_searchbar_TreeMunich_selected";
var treeMunichOtherId = "ctl00_formcontent_searchbar_TreeMunichOther_selected";
var keywordFromBoxId = "stichwortsuche";

function GetResultURL(KW,SIN,SIA,SIP,HBG,HPA,HCL,TI,TM,MO) {
	var splittedDids = TM.split(";");
	var newDids = new Array();
	var found = 0;

	for (var i = 0; i < splittedDids.length; i++)
	{
		found = 0;
		for (var j = 0; j < newDids.length; j++)
		{
			if (splittedDids[i] == newDids[j])
				found = 1;
		}
		if (found == 0)
			newDids.push(splittedDids[i]);
	}
	var url = pattern_url;
	url = url.replace("%iid%",TI);
	url = url.replace("%did%",TM);
	url = url.replace("%kw%",KW);
	url = url.replace("%sn%",SIN);
	url = url.replace("%sa%",SIA);
	url = url.replace("%sp%",SIP);
	url = url.replace("%bg%",HBG);
	url = url.replace("%pa%",HPA);
	url = url.replace("%cl%",HCL);
	url = url.replace("%mode%",MO);
	return url;
}

function ExecuteNormalSearch() {
	var industries = document.getElementById(treeIndustryId);
	if (industries == null){
		alert("No IndustriesTree?");
		return;
	}
	
	var munich = document.getElementById(treeMunichId);
	if (munich == null){
		alert("No MunichTree?");
		return;
	}
	
	window.location.href = GetResultURL("", false, false, false, 2, 2, 2, encodeURI(industries.value), encodeURI(munich.value), "fast");
	return;
}

function ExecuteExtendedSearch() {
	var industries = document.getElementById(treeIndustryId);
	if (industries == null){
		alert("No IndustriesTree?");
		return;
	}
		
	var munich = document.getElementById(treeMunichId);
	if (munich == null){
		alert("No MunichTree?");
		return;
	}
	
	var munichother = document.getElementById(treeMunichOtherId);
	if (munichother == null){
		alert("No MunichOtherTree?");
		return;
	}
		
	var keyword = document.getElementById(keywordId);
	if (keyword == null){
		alert("No Keyword?");
		return;
	}
	
	var searchInName = document.getElementById(searchInNameId);
	if (searchInName == null){
		alert("No searchInName?");
		return;
	}
		
	var searchInAddress = document.getElementById(searchInAddressId);
	if (searchInAddress == null){
		alert("No searchInAddress?");
		return;
	}
		
	var searchInPortrait = document.getElementById(searchInPortraitId);
	if (searchInPortrait == null){
		alert("No searchInPortrait?");
		return;
	}
	
	var hasBeergarden = document.getElementById(hasBeergardenId);
	if (hasBeergarden == null){
		alert("No hasBeergarden?");
		return;
	}

	var hasParkarea = document.getElementById(hasParkareaId);
	if (hasParkarea == null){
		alert("No hasParkarea?");
		return;
	}
	
	var hasCashless = document.getElementById(hasCashlessId);
	if (hasCashless == null){
		alert("No hasCashless?");
		return;
	}
		
	window.location.href = GetResultURL(encodeURI(keyword.value),encodeURI(searchInName.checked),encodeURI(searchInAddress.checked),encodeURI(searchInPortrait.checked), encodeURI(hasBeergarden.options[hasBeergarden.selectedIndex].value), encodeURI(hasParkarea.options[hasParkarea.selectedIndex].value), encodeURI(hasCashless.options[hasCashless.selectedIndex].value), encodeURI(industries.value), encodeURI(munich.value), encodeURI(munichother.value), "ext");
}

function ExecuteKeywordSearch()
{
	var keyword = document.getElementById(keywordFromBoxId);
	if (keyword == null){
		alert("No keywordbox?");
		return;
	}

	window.location.href = GetResultURL(encodeURI(keyword.value),true,true,true,2,2,2,"","","","keyword");
}

function ExecuteKeywordSearchOnEnter(myfield,e)
{
	var keycode;
	
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	{
		ExecuteKeywordSearch()
		return false;
	}
	else
		return true;
}
