function performMiadidasSearch(response)
{
	bInitApplication = false;
	showOverlay(1);
	isAllMiadidasStores = 1;
	bShowDistance = false;
	oSearchObject.searchType = searchType;
	
	searcher = new MMSearchRequester( showResult );
	search = new MMSearch();

	var logic = new Array('AND');
	var filters = new Array();
		filters.push(new MMSearchFilter('country', 'eq', response.responseText));
		filters.push(new MMSearchFilter('feature7', 'eq', '1') );
		logic.push('AND');		
		
	var aReturnfields = new Array();		
		aReturnfields = sSearchReturnFields.split(',');
	for(var key in oCountryFilters)
	{
		aReturnfields.push(key);
	}
	
	if (aAdditionalReturnFields.length > 0) {
		aReturnfields = aReturnfields.concat(aAdditionalReturnFields);
		search.filters.push( new MMSearchFilter(aAdditionalReturnFields[0], 'not', '') );		
		logic.push('AND');		
	}			
					
	search.count = 9999;		
	search.result_set_size = 9999;
	search.filters = filters;			
	search.return_fields = aReturnfields.join(",");
	search.logic = logic.join(',');
	search.route_mode= new Array('driving','walking');
	search.data_source = getDatasourceForCountry(countryCode);
	search.address = new MMAddress({country_code : countryCode});
	search.distance_units = distance_unit;	
	
	inProgress = true;
	setTimeout("restoreSearchForm()", timeToRestore);
	searcher.search(search);
}


function performSearch()
{	
	var sSearchLinkPos = (searchType == "quicksearch") ? "StoreFinderSimpleSearch" : "StoreFinderAdvancedSearch";
		sSearchLinkPos += (bRefinedSearch) ? "Refined" : "";
	hitboxLink('SFSearchButton', sSearchLinkPos);

	//showSperre(true);
	bInitApplication = false;
	countryCode = $F('countryList');
	showOverlay(1);
	searchLatLon = '';
	bShowDistance = true;
	oSearchObject.searchType = searchType;
	oSearchObject.filters = new Array();
	oSearchObject.address = new Object();
	
	if(countryType == 0) {
		performSingleAddressSearch();
	} else if(typeof isAllMiadidasStores != 'undefined'  && isAllMiadidasStores == 1) {
		callMiadidasByName(countryCode);
	} else {
		var aReturnfields = new Array();		
			aReturnfields = sSearchReturnFields.split(',');
		var logic = new Array();
		var filters = new Array();
	
		searcher = new MMSearchRequester(showResult);
		search = new MMSearch();
		
		// Determine whether searching from address or specified point:
		var selCities = $('select_cities');
		if (selCities && selCities.value.length > 0) {
			var tmp = $F('select_cities').split("|");
			search.point = new MMLocation(new MMLatLon(tmp[0], tmp[1]));
		} else if(searchType == "quicksearch") {
			var qs = new Array();
			qs.push($F("city"));			
			if ($("stateList")) {
				var state = $F("stateList");
				if(state != labels["pleaseSelect"] && state.length > 0) {
					qs.push(state);
				}
			}
			search.address = new MMAddress({ qs : qs.join(", "), country_code : countryCode});
			oSearchObject.address.qs = $F("city");						
		} else {	
			var city = "";
			var street = "";
		  	var zip = "";
			var qs = new Array();
			
			if ($("street")) {
				if($F("street") != labels["street"] && $F("street").length > 0) {
					oSearchObject.address.street = $F("street");
					qs.push($F("street"));
					street = $F("street");
				}
			}			
			if ($("city")) {
				if($F("city") != labels["city"] && $F("city").length > 0) {
					oSearchObject.address.city = $F("city");
					qs.push($F("city"));
					city = $F("city");
				}
			}
			if ($("zip")) {
				if($F("zip") != labels["zip"] && $F("zip").length > 0) {
					oSearchObject.address.postal_code = $F("zip");
					qs.push($F("zip"));
					zip = $F("zip");
				}
			}		
			if ($("stateList")) {
				var state = $F("stateList");
				if(state != labels["pleaseSelect"] && state.length > 0) {
					oSearchObject.address.state = state;
					qs.push(state);
				}
			}			
			//search.address = new MMAddress({country_code: country_code, city: city, street: street, postal_code: zip});
			search.address = new MMAddress({ qs : qs.join(", "), country_code : countryCode});
		}
		
		//oSearchObject.address = search.address;		
		
		search.max_distance = ($("distance")) ? Number($F('distance')) : max_distance;
		search.distance_units = distance_unit;
	
		var checkBoxes = document.getElementsByTagName("input");
		
		for (var a = 0; a < checkBoxes.length; a++) {
			if(checkBoxes[a].type == "checkbox") {
				if(checkBoxes[a].checked && checkBoxes[a].name.indexOf('mm.poi') < 0) {
					logic.push("OR");
					filters.push(new MMSearchFilter(checkBoxes[a].name, 'eq', 1));
					//oSearchObject.filters.push(checkBoxes[a].name);
				}
			}
		}
		
		if (aAdditionalReturnFields.length > 0) {
			logic.push('AND');
			aReturnfields = aReturnfields.concat(aAdditionalReturnFields);
			filters.push( new MMSearchFilter(aAdditionalReturnFields[0], 'not', '') );		
		}
		
		for(var key in oCountryFilters) {
			aReturnfields.push(key);
		}		
		
		if(countryCode.toLowerCase() == "de" || countryCode.toLowerCase() == "us" || countryCode.toLowerCase() == "uk") {
			aReturnfields.push('image_name');
		}
		
		search.count = 9999;		
		search.result_set_size = 9999;
		search.filters = filters;			
		search.return_fields = aReturnfields.join(",");
		search.logic = logic.join(",");
		search.route_mode= new Array('driving','walking');
	  	search.data_source = getDatasourceForCountry(countryCode);
			
		inProgress = true;
	    setTimeout("restoreSearchForm()", timeToRestore);
	    searcher.search(search);
	}
}


function performIdSearch(piId)
{
	var filters = new Array(new MMSearchFilter('client_id', 'eq', piId));
	var aReturnfields = new Array();		
		aReturnfields = sSearchReturnFields.split(',');		
	
	if(bEnableIDSearchTracking)
	{
		hitboxLink('SFParameter', 'DeepLink');
	}
	//showOverlay(1);
	bShowDistance = false;	
	searcher = new MMSearchRequester(processIdSearch);
	search = new MMSearch();
	
	if (aAdditionalReturnFields.length > 0) {
		search.logic = 'AND';
		aReturnfields = aReturnfields.concat(aAdditionalReturnFields);
		filters.push( new MMSearchFilter(aAdditionalReturnFields[0], 'not', '') );		
	}
	
	search.filters = filters;
	search.return_fields = aReturnfields.join(",");
	search.data_source = getDatasourceForCountry(countryCode);
	search.distance_units = distance_unit;
	search.route_mode= new Array('driving','walking');
	//search.address = new MMAddress({country_code : countryCode});
	
	inProgress = true;
	//setTimeout("restoreSearchForm()", timeToRestore);
	searcher.search(search);	
}


function processIdSearch(response)
{
	showOverlay(-1);
	//alert(response.toJSON())
	if(!response.error_code)
	{
		var iCount = response[0].totalRecordCount
		if(iCount > 0)
		{
			TabContent = new Array();
			TabContent[0] = response[0].records[0];
			//alert(response[0].totalRecordCount);		
			getDetails(0);
		}	
	}	
}


function performSingleAddressSearch()
{
	bShowDistance = true;
	var filters = new Array();
	var logic = new Array();

	searcher = new MMSearchRequester(showResult);
	search = new MMSearch();
			
	if (countryEnglishCompleteName.length > 0) {
		filters.push(new MMSearchFilter('country', 'eq', countryEnglishCompleteName));
		logic.push('AND');
	} else {
		search.address = new MMAddress({country_code : countryCode});
	}

	if ($("city")) {
		var city = $F("city");
		if(city != labels["city"] && city.length > 0) {
			filters.push(new MMSearchFilter('town', 'contains', city));
			logic.push('AND');
		}
	}
	if ($("street")) {
		var street = $F("street");
		if(street != labels["street"] && street.length > 0) {
			filters.push(new MMSearchFilter('street', 'contains', street));
			logic.push('AND');
		}
	}
	if ($("zip")) {
		var zip = $F("zip");
		if(zip != labels["zip"] && zip.length > 0) {
			filters.push(new MMSearchFilter('pc', 'contains', zip));
			logic.push('AND');
		}
	}
	if ($("stateList")) {
		var state = $F("stateList");		
		if($F("stateList") != labels["pleaseSelect"] && $F("stateList").length > 0) {
			filters.push(new MMSearchFilter('state', 'contains', state));
			logic.push('AND');
		}
	}
	
	var aReturnfields = new Array();		
		aReturnfields = sSearchReturnFields.split(',');		
	
	for (var key in oCountryFilters) {
		aReturnfields.push(key);
	}	
	
	if(countryCode.toLowerCase() == "de" || countryCode.toLowerCase() == "us" || countryCode.toLowerCase() == "uk") {
		aReturnfields.push('image_name');
	}	

	if (aAdditionalReturnFields.length > 0) {
		logic.push('AND');
		aReturnfields = aReturnfields.concat(aAdditionalReturnFields); // has to be town_
		filters.push( new MMSearchFilter(aAdditionalReturnFields[0], 'not', '') );		
	}

	var checkBoxes = document.getElementsByTagName("input");		
	oSearchObject.filters = new Array();
	
	for (var a = 0; a < checkBoxes.length; a++) {
		if (checkBoxes[a].type == "checkbox") {
			if (checkBoxes[a].checked && checkBoxes[a].name.indexOf('mm.poi') < 0) {
				//filters.push(new MMSearchFilter(checkBoxes[a].name, 'gt', 0));
				oSearchObject.filters.push(checkBoxes[a].name);				
			}
		}
	}
	
	search.return_fields = aReturnfields.join(",");
	search.count = 9999;
	search.result_set_size = 9999; 
	search.logic = logic.join(",");
	search.filters = filters;	
	search.data_source = getDatasourceForCountry(countryCode);
	
	inProgress = true;
	setTimeout("restoreSearchForm()", timeToRestore);
	searcher.search(search);
}


function performCitySearch(response)
{
	var filters = new Array();
	var aReturnfields = new Array('town');
	var order_by_fields = new Array('town');
	showOverlay(1);
	searcher = new MMSearchRequester(handleCityList);
    search = new MMSearch();

    countryEnglishCompleteName = response.responseText;

    if(countryEnglishCompleteName.length > 0) {
    	filters.push(new MMSearchFilter('country', 'eq', countryEnglishCompleteName));
	} else {
    	//Abbruch der Suche, da kein Land gefunden
    	filters.push( new MMSearchFilter('country', 'eq', 'xyz') );
    }
	
	if ($("stateList")) {
		var state = $F("stateList");		
		if($F("stateList") != labels["pleaseSelect"] && $F("stateList").length > 0) {
			filters.push(new MMSearchFilter('state', 'eq', state));
		}
	}	
	
	if (aAdditionalReturnFields.length > 0) {
		search.logic = 'AND';
		order_by_fields = new Array(aAdditionalReturnFields[0]);
		aReturnfields = aReturnfields.concat(aAdditionalReturnFields[0]); // has to be town_
		filters.push( new MMSearchFilter(aAdditionalReturnFields[0], 'not', '') );		
	}

    search.return_fields = aReturnfields.join(",");
	search.count = 9999;
	search.start_index = 1;
	search.filters = filters;
	search.result_set_size = search.count
  	search.order_by_fields = order_by_fields;
	search.order_by_order = new Array('asc');
	search.data_source = getDatasourceForCountry($F("countryList"));

	inProgress = true;
  	setTimeout("restoreSearchForm()", timeToRestore);
    searcher.search(search);
}

function restoreSearchForm()
{
	if(inProgress == true)
	{
		showOverlay(-1);

		if ($('searchButton'))
		{
			$('searchButton').focus();
		}
	}
}