// General - links
function link(name) {
	loadPage(name);
	actual_page = name;
	document.getElementById('link_' + name).blur();
}
function loadPage(page) {
	url = defs_url + "/" + page + ".inc.php";
	loadFile(url, showPage);
}

// Search - results, engines
function seek(type) {
	if (type == "ferien" || type == "dauer" || type == "kauf") {
		loadSearch(type);
		actual_page = "search_" + type;
	} else {
		loadSpecialSearch(type);
	}
	document.getElementById('link_search_' + type).blur();
}
function loadSearch(type) {
	search_type = type;
	if (type != "ferien") {
		hideSearchPanel("search_ferien");
	}
	if (type != "dauer") {
		hideSearchPanel("search_dauer");
	}
	if (type != "kauf") {
		hideSearchPanel("search_kauf");
	}
	deleteEmphasys("search_" + type);
	showSearchSearching(type);
	query_string = parseSearchForm(type);
	url = defs_url + "search_results.inc.php?search=" + type + "&" + query_string;
	if (type == "nummer" && query_string != "") {
		loadFile(url, showPage);
	} else if (type != "nummer") {
		loadFile(url, showSearchResults);
	}
}

function loadSearchNT(insId) {
	hideSearchPanel("search_ferien");
	hideSearchPanel("search_dauer");
	hideSearchPanel("search_kauf");
	url = defs_url + "search_results.inc.php?search=nummer&insid="+insId;
	loadFile(url, showPage);
}

function loadSpecialSearch(type) {
	search_type = type;
	url = defs_url + "search_results.inc.php?search=" + type;
	loadFile(url, showPage);
}
function parseSearchForm(type) {
	form = document.getElementById("form_" + type);
	if (type == "nummer") {
		if (form.insid.value != "") {
			query_string = "insid=" + form.insid.value;
		} else {
			query_string = "";
		}
	} else {
		query_string = "luogo=" + form.luogo.value + "&prezzo=" + form.prezzo.value;
	}
	switch (type) {
		case "ferien":
		query_string = query_string + "&letti=" + form.letti.value + "&kw=" + form.kw.value;
		break;
		case "dauer":
		case "kauf":
		query_string = query_string + "&locali=" + form.locali.value;
		break;
	}
	return query_string;
}
function showSearchResults() {
	div = document.getElementById("search_results");
	div.innerHTML = this.request.responseText;
	hideSearchSearching();
	hidePrefButtonIfEmpty();
}
function loadResultsPage(page) {
	url = defs_url + "templer/search_results.inc.php?page=" + page;
	loadFile(url, showSearchResultsPage);
	showSearchSearching(search_type);
	a = document.getElementById("page" + page + "a");
	if (a != null) {
		a.style.color = '#000000';
	}
	b = document.getElementById("page" + page + "b");
	if (b != null) {
		b.style.color = '#000000';
	}
	i = 1;
	while (document.getElementById("page" + i + "a") != null) {
		if (i != page) {
			a = document.getElementById("page" + i + "a");
			if (a != null) {
				a.style.color = '#009966';
			}
			b = document.getElementById("page" + i + "b");
			if (b != null) {
				b.style.color = '#009966';
			}
		}
		i++;
	}
}
function showSearchResultsPage() {
	div = document.getElementById("search_results_content");
	div.innerHTML = this.request.responseText;
	hideSearchSearching();
	hidePrefButtonIfEmpty();
}

// Insertions - show
function loadIns(id) {
	showSearchSearching(search_type);
	url = defs_url + "show_ins.inc.php?insid=" + id;
	loadFile(url, showSearchResultsPage);
	document.body.style.cursor = "default";
}
function loadInsDetails(id) {
	//showSearchSearching(search_type);
	url = defs_url + "templer/show_ins_details.inc.php?insid=" + id;
	loadFile(url, showInsPage);
	div = document.getElementById("show_ins_details_button");
	if (div != null) {
		div.style.visibility = "hidden";
	}
	div = document.getElementById("show_ins_photos_button");
	if (div != null) {
		div.style.visibility = "visible";
	}
}
function loadInsPhotos(id) {
	//showSearchSearching(search_type);
	url = defs_url + "templer/show_ins_photos.inc.php?insid=" + id;
	loadFile(url, showInsPage);
	div = document.getElementById("show_ins_photos_button");
	if (div != null) {
		div.style.visibility = "hidden";
	}
	div = document.getElementById("show_ins_details_button");
	if (div != null) {
		div.style.visibility = "visible";
	}
}
function showInsPage() {
	div = document.getElementById("show_ins_content");
	div.innerHTML = this.request.responseText;
	hideSearchSearching();
	hidePrefButtonIfEmpty();
}

// Polls
function votePoll(id, vote) {
	url = defs_url + "parts/umfrage.inc.php?poll=" + id + "&vote=" + vote;
	loadFile(url, showPoll);
}
function loadPoll(id) {
	url = defs_url + "parts/umfrage.inc.php?poll=" + id;
	loadFile(url, showPoll);
}
function showPoll() {
	div = document.getElementById("umfrage_content");
	div.innerHTML = this.request.responseText;
}

// Links
function loadLinks() {
	form = document.getElementById("form_links");
	if (form != null) {
		qs_luogo = form.luogo.options[form.luogo.selectedIndex].value;
		qs_categoria = form.categoria.options[form.categoria.selectedIndex].value;
	}
	url = defs_url + "templer/links.inc.php?luogo=" + qs_luogo + "&categoria=" + qs_categoria;
	loadFile(url, showLinks);
}
function showLinks() {
	div = document.getElementById("links_content");
	div.innerHTML = this.request.responseText;
}

// Automates
function loadAutomate(automate) {
	if (automate == "kontakt") {
		query_string = "";
		form = document.getElementById("form_" + automate);
		if (form != null) {
			s = new String(form.testo.value);
			s = s.replace(/\n/g, "%0D%0A");
			query_string = query_string + "cognome=" + form.cognome.value;
			query_string = query_string + "&email=" + form.email.value;
			query_string = query_string + "&telefono=" + form.telefono.value;
			query_string = query_string + "&insid=" + form.insid.value;
			query_string = query_string + "&testo=" + s;
		}
	} else if (automate == "empfehlung") {
		query_string = "";
		form = document.getElementById("form_" + automate);
		if (form != null) {
			s = new String(form.testo.value);
			s = s.replace(/\n/g, "%0D%0A");
			query_string = query_string + "email=" + form.email.value;
			query_string = query_string + "&email2=" + form.email2.value;
			query_string = query_string + "&testo=" + s;
		}
	}
	url = defs_url + "../automate/" + automate + ".inc.php?" + query_string;
	loadFile(url, showAutomate);
}
function showAutomate() {
	div = document.getElementById("messagePanel");
	if (div != null) {
		div.innerHTML = this.request.responseText;
	}
}

// General - file loader
function loadFile(url, handler) {
	load_file = new net.ContentLoader(url, handler);
}
// General - display handler
function showPage() {
	div = document.getElementById("eh_site_content");
	div.innerHTML = this.request.responseText;
	hidePrefButtonIfEmpty();
}
