var SearchForm = new CSearchForm();
var ZipTown;
var Street;
var Zip;
var Town;
var Catchword;
var PhoneNumber;

function CSearchForm()
{
	this._Settings = {};
}

CSearchForm.prototype.Init = function(Settings)
{
	this._Settings = Settings;

	Catchword = (typeof(SearchForm.GetParam("Catchword")) == "undefined") ? "" : SearchForm.GetParam("Catchword");
	PhoneNumber = (typeof(SearchForm.GetParam("PhoneNumber")) == "undefined") ? "" : SearchForm.GetParam("PhoneNumber");
	ZipTown = (typeof(SearchForm.GetParam("ZipTown")) == "undefined") ? "" : SearchForm.GetParam("ZipTown");
	Street = (typeof(SearchForm.GetParam("Street")) == "undefined") ? "" : SearchForm.GetParam("Street");
	Zip = (typeof(SearchForm.GetParam("Zip")) == "undefined") ? "" : SearchForm.GetParam("Zip");
	Town = (typeof(SearchForm.GetParam("Town")) == "undefined") ? "" : SearchForm.GetParam("Town");
	Town2 = (typeof(SearchForm.GetParam("Town2")) == "undefined") ? "" : SearchForm.GetParam("Town2");
	SessionGuid = (typeof(SearchForm.GetParam("SessionGuid")) == "undefined") ? "" : SearchForm.GetParam("SessionGuid");
	PageID = (typeof(SearchForm.GetParam("PageID")) == "undefined") ? "" : SearchForm.GetParam("PageID");
	
	// Welches Suchformular soll eingeblendet werden	
	switch(SearchForm.GetParam("QT"))
	{
		case "3":
			GetFormular('BranchSearch');
			break;
		case "17": // einfache Suche ohne Ort
		case "18": // einfache Suche mit Ortsangaben
			GetFormular('WhitePageSearch');
			break;
		case "19": // Umkreissuche
			GetFormular('WhitePageSearchCircumCircle');
			break;
		case "20": // Rückwärtssuche
			GetFormular('WhitePageSearchReversSearch');
			break;
		case "21": // Vorwahlsuche
			// Noch nicht implementiert
			break;
		case "22": // erweitere Suche
			GetFormular('WhitePageSearchExtended');
			break;
		default:
			GetFormular('BranchSearch');
			break;
	}
};

/* Hilfsfunktion: Gibt einen Parameter zurück */
CSearchForm.prototype.GetParam = function(Name, DefaultVal) 
{
	var Value = (typeof(this._Settings[Name]) == "undefined") ? DefaultVal : this._Settings[Name];

	// Fix bool values
	if (Value == "true" || Value == "false")
		return (Value == "true");

	return Value;
};

// Auf das entsprechende Formular umschalten
function ChangeFrmOptionalFields(NodeId)
{
	CloseFrm();
	
	switch (NodeId)
	{
		case "WhitePageSearch":
			GetFormular('WhitePageSearch');
			break;
		case "WhitePageSearchReversSearch":
			GetFormular('WhitePageSearchReversSearch');
			break;
		case "WhitePageSearchCircumCircle":
			GetFormular('WhitePageSearchCircumCircle');
			break;
		case "WhitePageSearchExtended":
			GetFormular('WhitePageSearchExtended');
			break;
		case "BranchSearchCircumCircle":
			GetFormular('BranchSearchCircumCircle');
			break;
		case "BranchSearch":
			GetFormular('BranchSearch');
			break;
	}
}

// Alle Formulare schliessen
function CloseFrm()
{
	if (document.getElementById('WhitePageSearch') != null)
		document.getElementById('WhitePageSearch').style.display = 'none';
	if (document.getElementById('WhitePageSearchReversSearch') != null)
		document.getElementById('WhitePageSearchReversSearch').style.display = 'none';
	if (document.getElementById('WhitePageSearchCircumCircle') != null)
		document.getElementById('WhitePageSearchCircumCircle').style.display = 'none';
	if (document.getElementById('WhitePageSearchExtended') != null)
		document.getElementById('WhitePageSearchExtended').style.display = 'none';
}

var Formular = "";

function GetFormular(ElementID)
{
	if (document.getElementById('ZipTown') != null)
	{
		ZipTown = document.getElementById('ZipTown').value;
	}
	if (document.getElementById('Catchword') != null)
	{
		Catchword = document.getElementById('Catchword').value;
	}
	if (document.getElementById('Street') != null)
	{
		Street = document.getElementById('Street').value;
	}
	if (document.getElementById('Zip') != null)
	{
		Zip = document.getElementById('Zip').value;
	}
	if (document.getElementById('Town') != null)
	{
		Town = document.getElementById('Town').value;
	}
	if (document.getElementById('Town2') != null)
	{
		Town2 = document.getElementById('Town2').value;
	}
	if (document.getElementById('PhoneNumber') != null)
	{
		PhoneNumber = document.getElementById('PhoneNumber').value;
	}
	
	var Location = Zip + " " + Town + " " + Town2;
	Location = Location.Trim();

	switch(ElementID)
	{
		case "BranchSearch":
			Formular = "<div id=\"BranchSearchForm\">" + 
				"<form action=\"../../Partners/DresdnerBranchen/Search.aspx\" method=\"post\" name=\"SearchForm\">" + 
				"<input type=\"hidden\" name=\"Search\" value=\"true\"/>" + 
				"<input type=\"hidden\" name=\"QT\" value=\"3\"/>" + 
				"<input type=\"hidden\" name=\"SessionGuid\" value=\"" + SessionGuid + "\"/>" + 
				"<input type=\"hidden\" name=\"PageID\" value=\"" + PageID + "\"/>" + 
				"<input type=\"hidden\" name=\"ClearGroups\" value=\"SearchItem,GeoAddress,GeoMap,Paging\"/>" + 
				"<input type=\"hidden\" name=\"ClearParas\" value=\"PhoneNumber,Error,TextMessage\"/>" + 
				"<div id=\"HomeSearchTitle\"><a href=\"../../YM/MyYellowMap/MyYellowMap.aspx?SessionGuid=" + SessionGuid + "\">Login</a> | <a href=\"#\">Hilfe</a></div>" + 
				"<div id=\"CircumCircleExtension\">" + 
				"	<span id=\"CircumCircleExtensionButton\"><a href=\"#\" onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('BranchSearchCircumCircle');\">Umkreissuche ein</a></span>" + 
				"</div>" + 
				"<div id=\"HomeSearchWhat\">" + 
				"<span id=\"HomeSearchWhatLabel\"><strong>Was/Wen</strong><br/>suchen Sie?</span>" + 
				"<span id=\"HomeSearchWhatInput\"><input id=\"Catchword\" type=\"text\" name=\"Catchword\" size=\"20\" value=\"" + Catchword + "\" accesskey=\"s\" title=\"Branche, Firmenname oder Stichwort (Accesskey s)\"/></span>" + 
				"<span id=\"HomeSearchWhereLabel\"><strong>Wo</strong><br/>suchen Sie?</span>" + 
				"<span id=\"HomeSearchWhereInput\"><span id=\"HomeSearchWhereInputLabel\">Ort, PLZ oder KFZ-Kennzeichen</span><input id=\"ZipTown\" type=\"text\" name=\"ZipTown\" value=\"" + Location + "\" size=\"40\" onmouseover=\"document.getElementById('HomeSearchWhereInputLabel').style.visibility = 'visible'\" onmouseout=\"document.getElementById('HomeSearchWhereInputLabel').style.visibility = 'hidden'\"/></span>" + 
				"<!--<span id=\"HomeSearchSubmit\"><button type=\"submit\"><img src=\"../../Partners/DresdnerBranchen/Layout/Images/Custom/SearchSubmit.gif\"/></button></span>-->" + 
				"<span id=\"HomeSearchSubmit\"><button type=\"submit\">Suchen</button></span>" + 
				"</div>" + 
				"</form>" + 
				"</div>";
				document.getElementById("Formular").innerHTML = Formular;
				document.SearchForm.Catchword.focus();
			break;
		case "BranchSearchCircumCircle":
			Formular = "<div id=\"BranchSearchCircumCircleForm\">" + 
				"<form action=\"../../Partners/DresdnerBranchen/Search.aspx\" method=\"post\" name=\"SearchForm\">" + 
				"<input type=\"hidden\" name=\"Search\" value=\"true\"/>" + 
				"<input type=\"hidden\" name=\"QT\" value=\"3\"/>" + 
				"<input type=\"hidden\" name=\"SessionGuid\" value=\"" + SessionGuid + "\"/>" + 
				"<input type=\"hidden\" name=\"PageID\" value=\"" + PageID + "\"/>" + 
				"<input type=\"hidden\" name=\"ClearGroups\" value=\"SearchItem,GeoAddress,GeoMap,Paging\"/>" + 
				"<input type=\"hidden\" name=\"ClearParas\" value=\"PhoneNumber,Error,TextMessage\"/>" + 
				"<div id=\"HomeSearchTitle\"><a href=\"../../YM/MyYellowMap/MyYellowMap.aspx?SessionGuid=" + SessionGuid + "\">Login</a> | <a href=\"#\">Hilfe</a></div>" + 
				"<div id=\"CircumCircleExtension\">" + 
				"	<span id=\"CircumCircleExtensionButton\"><a href=\"#\" onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('BranchSearch');\">Umkreissuche aus</a></span>" + 
				"</div>" + 
				"<div id=\"HomeSearchWhat\">" + 
				"	<span id=\"HomeSearchWhatLabel\"><strong>Was/Wen</strong><br/>suchen Sie?</span>" + 
				"	<span id=\"HomeSearchWhatInput\"><input id=\"Catchword\" type=\"text\" name=\"Catchword\" size=\"20\" value=\"" + Catchword + "\" accesskey=\"s\" title=\"Branche, Firmenname oder Stichwort (Accesskey s)\"/></span>" + 
				"	<span id=\"HomeSearchWhereLabel\"><strong>Wo</strong><br/>suchen Sie?</span>" + 
				"	<span id=\"HomeSearchWhereInput\"><span id=\"HomeSearchWhereInputLabel\">Ort, PLZ oder KFZ-Kennzeichen</span><input id=\"ZipTown\" type=\"text\" name=\"ZipTown\" value=\"" + Location + "\" size=\"40\" onmouseover=\"document.getElementById('HomeSearchWhereInputLabel').style.visibility = 'visible'\" onmouseout=\"document.getElementById('HomeSearchWhereInputLabel').style.visibility = 'hidden'\"/></span>" + 
				"</div>" + 
				"<div id=\"HomeSearchStreet\">" + 
				"	<span id=\"HomeSearchStreetLabel\"><strong>Stra&szlig;e</strong></span>" + 
				"	<span id=\"HomeSearchStreetInput\"><input id=\"Street\" type=\"text\" name=\"Street\" value=\"" + Street + "\" size=\"40\"/></span>" + 
				"	<span id=\"HomeSearchRadiusLabel\"><strong>Radius</strong></span>" + 
				"	<span id=\"HomeSearchRadiusInput\">" + 
				"		<select name=\"Radius\">" + 
				"			<option value=\"1000\">1 Km</option><option value=\"5000\">5 Km</option>" + 
				"			<option value=\"10000\">10 Km</option><option value=\"20000\" selected=\"selected\">20 Km" + 
				"			</option><option value=\"50000\">50 Km</option><option value=\"-1\">unbegrenzt</option>" + 
				"		</select>" +
				"	</span>" + 
				"	<!--<span id=\"HomeSearchSubmit\"><button type=\"submit\"><img src=\"../../Partners/DresdnerBranchen/Layout/Images/Custom/SearchSubmit.gif\"/></button></span>-->" + 
				"	<span id=\"HomeSearchSubmit\"><button type=\"submit\">Suchen</button></span>" + 
				"</div>" + 
				"</form>" + 
				"</div>";
				document.getElementById("Formular").innerHTML = Formular;
				document.SearchForm.Catchword.focus();
			break;
		case "WhitePageSearch":
			Formular = "<div id=\"WhitePageSearch\">" + 
				"<form action=\"../../Partners/DresdnerBranchen/Search.aspx\" method=\"post\" name=\"SearchForm\">" + 
				"<input type=\"hidden\" name=\"Search\" value=\"true\"/>" + 
				"<input type=\"hidden\" name=\"View\" value=\"8\"/>" + 
				"<input type=\"hidden\" name=\"QT\" value=\"17\"/>" + 
				"<div id=\"HomeSearchTitle\"><a href=\"../../YM/MyYellowMap/MyYellowMap.aspx?SessionGuid=" + SessionGuid + "\">Login</a> | <a href=\"#\">Hilfe</a></div>" + 
				"<div id=\"CircumCircleExtension\">" + 
				"	<span id=\"CircumCircleExtensionButton\"><a href=\"#\" onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('WhitePageSearchCircumCircle');\">Umkreissuche ein</a>&nbsp;|&nbsp;" + 
				"	<a href=\"#\" onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('WhitePageSearchReversSearch');\">Rückwärtssuche ein</a></span>" + 
				"<!--<fieldset>" + 
				"		<legend></legend>" + 
				"		<div>" + 
				"			<label for=\"CircumCircleExtension\">Optional: Suche in Ihrem Umkreis:</label>" + 
				"			<input onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('WhitePageSearchCircumCircle');\" id=\"CircumCircleExtensionButton\" type=\"image\" src=\"../../Partners/DresdnerBranchen/Layout/Images/Generic/DropDownButton.gif\" value=\"\"/>" + 
				"		</div>" + 
				"	</fieldset>-->" + 
				"</div>" + 
				"<div id=\"HomeSearchWhat\">" + 
				"	<span id=\"HomeSearchWhatLabel\"><strong>Wen</strong><br/>suchen Sie?</span>" + 
				"	<span id=\"HomeSearchWhatInput\"><input id=\"Catchword\" type=\"text\" name=\"Catchword\" size=\"20\" value=\"" + Catchword + "\" accesskey=\"s\" title=\"Name oder Stichwort (Accesskey s)\"/></span>" + 
				"	<span id=\"HomeSearchWhereLabel\"><strong>Wo</strong><br/>suchen Sie?</span>" + 
				"	<span id=\"HomeSearchWhereInput\"><span id=\"HomeSearchWhereInputLabel\">Ort, PLZ oder KFZ-Kennzeichen</span><input id=\"ZipTown\" type=\"text\" name=\"ZipTown\" value=\"" + Location + "\" size=\"40\"  onmouseover=\"document.getElementById('HomeSearchWhereInputLabel').style.visibility = 'visible'\" onmouseout=\"document.getElementById('HomeSearchWhereInputLabel').style.visibility = 'hidden'\"/></span>" + 
				"	<!--<span id=\"HomeSearchSubmit\"><button type=\"submit\"><img src=\"../../Partners/DresdnerBranchen/Layout/Images/Custom/SearchSubmit.gif\"/></button></span>-->" + 
				"	<span id=\"HomeSearchSubmit\"><button type=\"submit\">Suchen</button></span>" + 
				"</div>" + 
				"</form>" + 
				"</div>";
				document.getElementById("Formular").innerHTML = Formular;
				document.SearchForm.Catchword.focus();
			break;
		case "WhitePageSearchCircumCircle":
			Formular = "<div id=\"WhitePageSearchCircumCircle\">" + 
				"<form action=\"../../Partners/DresdnerBranchen/Search.aspx\" method=\"post\" name=\"SearchForm\">" + 
				"<input type=\"hidden\" name=\"Search\" value=\"true\"/>" + 
				"<input type=\"hidden\" name=\"View\" value=\"8\"/>" + 
				"<input type=\"hidden\" name=\"QT\" value=\"19\"/>" +
				"<input type=\"hidden\" name=\"ClearParas\" value=\"PhoneNumber\"/>" + 
				"<div id=\"HomeSearchTitle\"><a href=\"../../YM/MyYellowMap/MyYellowMap.aspx?SessionGuid=" + SessionGuid + "\">Login</a> | <a href=\"#\">Hilfe</a></div>" + 
				"<div id=\"CircumCircleExtension\">" + 
				"	<span id=\"CircumCircleExtensionButton\"><a href=\"#\" onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('WhitePageSearch');\">Umkreissuche aus</a>&nbsp;|&nbsp;" + 
				"	<a href=\"#\" onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('WhitePageSearchReversSearch');\">Rückwärtssuche ein</a></span>" + 
				"	<!--<fieldset>" + 
				"		<legend></legend>" + 
				"		<div>" + 
				"			<label for=\"CircumCircleExtension\">Optional: Suche in Ihrem Umkreis:</label>" + 
				"			<input onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('WhitePageSearch');\" id=\"CircumCircleExtensionButton\" type=\"image\" src=\"../../Partners/DresdnerBranchen/Layout/Images/Generic/DropDownButtonUp.gif\" value=\"\"/>" + 
				"		</div>" + 
				"	</fieldset>-->" + 
				"</div>" + 
				"<div id=\"HomeSearchWhat\">" + 
				"	<span id=\"HomeSearchWhatLabel\"><strong>Wen</strong><br/>suchen Sie?</span>" + 
				"	<span id=\"HomeSearchWhatInput\"><input id=\"Catchword\" type=\"text\" name=\"Catchword\" size=\"20\" value=\"" + Catchword + "\" accesskey=\"s\" title=\"Name oder Stichwort (Accesskey s)\"/></span>" + 
				"	<span id=\"HomeSearchWhereLabel\"><strong>Wo</strong><br/>suchen Sie?</span>" + 
				"	<span id=\"HomeSearchWhereInput\"><span id=\"HomeSearchWhereInputLabel\">Ort, PLZ oder KFZ-Kennzeichen</span><input id=\"ZipTown\" type=\"text\" name=\"ZipTown\" value=\"" + Location + "\" size=\"40\"  onmouseover=\"document.getElementById('HomeSearchWhereInputLabel').style.visibility = 'visible'\" onmouseout=\"document.getElementById('HomeSearchWhereInputLabel').style.visibility = 'hidden'\"/></span>" + 
				"</div>" + 
				"<div id=\"HomeSearchStreet\">" + 
				"	<span id=\"HomeSearchStreetLabel\"><strong>Stra&szlig;e</strong></span>" + 
				"	<span id=\"HomeSearchStreetInput\"><input id=\"Street\" type=\"text\" name=\"Street\" value=\"" + Street + "\" size=\"40\"/></span>" + 
				"	<span id=\"HomeSearchRadiusLabel\"><strong>Radius</strong></span>" + 
				"	<span id=\"HomeSearchRadiusInput\">" + 
				"		<select name=\"Radius\">" + 
				"			<option value=\"1000\">1 Km</option><option value=\"5000\">5 Km</option>" + 
				"			<option value=\"10000\">10 Km</option><option value=\"20000\" selected=\"selected\">20 Km" + 
				"			</option><option value=\"50000\">50 Km</option><option value=\"-1\">unbegrenzt</option>" + 
				"		</select>" +
				"	</span>" + 
				"	<!--<span id=\"HomeSearchSubmit\"><button type=\"submit\"><img src=\"../../Partners/DresdnerBranchen/Layout/Images/Custom/SearchSubmit.gif\"/></button></span>-->" + 
				"	<span id=\"HomeSearchSubmit\"><button type=\"submit\">Suchen</button></span>" + 
				"</div>" + 
				"</form>" + 
				"</div>";
				document.getElementById("Formular").innerHTML = Formular;
				document.SearchForm.Catchword.focus();
			break;
		case "WhitePageSearchReversSearch":
			Formular = 
				"<div id=\"WhitePageSearchReversSearch\">" + 
				"<form action=\"../../Partners/DresdnerBranchen/Search.aspx\" method=\"post\" name=\"SearchForm\">" + 
				"<input type=\"hidden\" name=\"Search\" value=\"true\"/>" + 
				"<input type=\"hidden\" name=\"View\" value=\"8\"/>" + 
				"<input type=\"hidden\" name=\"QT\" value=\"20\"/>" + 
				"<input type=\"hidden\" name=\"ClearParas\" value=\"Catchword\"/>" + 
				"<input type=\"hidden\" name=\"SessionGuid\" value=\"" + SessionGuid + "\"/>" + 
				"<div id=\"HomeSearchTitle\"><a href=\"../../YM/MyYellowMap/MyYellowMap.aspx?SessionGuid=" + SessionGuid + "\">Login</a> | <a href=\"#\">Hilfe</a></div>" + 
				"<div id=\"CircumCircleExtension\">" + 
				"	<span id=\"CircumCircleExtensionButton\"><a href=\"#\" onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('WhitePageSearchCircumCircle');\">Umkreissuche ein</a>&nbsp;|&nbsp;" + 
				"	<a href=\"#\" onclick=\"return false;\" onmousedown=\"ChangeFrmOptionalFields('WhitePageSearch');\">Rückwärtssuche aus</a></span>" + 
				"</div>" + 
				"<div id=\"ReversSearchWhat\">" + 
				"	<span id=\"ReversSearchWhatLabel\"><strong>Telefonnummer</strong></span>" + 
				"	<span id=\"ReversSearchWhatInput\"><input id=\"PhoneNumber\" type=\"text\" name=\"PhoneNumber\" size=\"20\" value=\"" + PhoneNumber + "\" accesskey=\"s\" title=\"Telefonnummer (Accesskey s)\"/></span>" + 
				"	<!--<span id=\"HomeSearchSubmit\"><button type=\"submit\"><img src=\"../../Partners/DresdnerBranchen/Layout/Images/Custom/SearchSubmit.gif\"/></button></span>-->" + 
				"	<span id=\"HomeSearchSubmit\"><button type=\"submit\">Suchen</button></span>" + 
				"</div>" + 
				"</form>" + 
				"</div>";
				document.getElementById("Formular").innerHTML = Formular;
				document.SearchForm.PhoneNumber.focus();
			break;
		case "WhitePageSearchExtended":
			break;
		default:
			break;
	}
}

// Trim Funktion da es anscheinend keine in JavaScript existiert.
String.prototype.Trim = function(dir)
{
	switch(dir)
	{
		case 'r':
			return this.replace(/\s+$/g,'');
			break;
		case 'l':
			return this.replace(/^\s+/g,'');
			break;
		default:
			return this.replace(/(^\s+|\s+$)/g,'');
	}
}
