
// SUCHE
function search_address (fieldId, parentId) {

	var searchField = document.getElementById(fieldId);
	var searchterm = searchField.value;

	var countryField = document.getElementById('flaminia_country');
	var country = countryField.value;

	var resultDiv = document.getElementById('search-result');
	var ziplength = 5;

	if (country == 'at' || country == 'ch') {
		var ziplength = 4;
	}

	if (searchterm.length >= ziplength && searchterm != '') {

		http = getHTTPObject();
		var url = 'ajax.contact-persons.php?country=' + country + '&zip=' + searchterm;

		http.open('GET', url, true);

		http.onreadystatechange = function() {
	 		if(http.readyState == 4) {
				resultDiv.style.display = 'block';
				resultDiv.innerHTML = http.responseText;
			}
		}

		http.send(null);

	} else {

		if (resultDiv != null) {
			resultDiv.innerHTML = '';
			resultDiv.style.display = 'none';
		}

	}

}

// LAND AKTIVIEREN
function set_country (parentID, country) {

	var parentUL = document.getElementById(parentID);
	var links = parentUL.getElementsByTagName('a');
	var countryField = document.getElementById('flaminia_country');

	var searchField = document.getElementById('flaminia_searchterm');
	searchField.value = "";
	resetField('flaminia_searchterm');

	for (var i = 0; i < links.length; i++) {

		if (links[i].getAttribute("rel", 0) == country) {
			links[i].className = "active";
			countryField.value = links[i].getAttribute("rel", 0);
		} else {
			links[i].className = "";
		}

	}

}

// Quelle: http://www.harrymaugans.com/2007/03/18/tutorial-ajax-made-easy & http://www.w3schools.com/XML/xml_http.asp
function getHTTPObject(){

	var xmlhttp;

	/*@cc_on

	@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(E) {
			xmlhttp = false;
		}
	}

	@else
	xmlhttp = false;

	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

		try {
			xmlhttp = new XMLHttpRequest();
		} catch(e) {
			xmlhttp = false;
		}

	}

	return xmlhttp;

}
