var detail_suche_aus = true;
var selectbox_aus = true;
var al_counter=-1;

if (document.images)
{
	var img_suche_auf = new Image(13,20);
	img_suche_auf.src="/images/detailsuche_auf.gif";

	var img_suche_zu = new Image(13,20);
	img_suche_zu.src="/images/detailsuche_zu.gif";

}

function detail_suche_ein_aus()
{
	if (x$("detail_suche_obj"))
	{
		if (detail_suche_aus)
		{
			x$("detail_suche_obj").style.display=""; 
			x$("detail_suche_ein_aus").style.top="112px"; 
			x$("div_umkreis").style.display=""; 
			detail_suche_aus = false;
			cookie.set("yo_suche","ein");
			window.setTimeout("button_suche_aus()", 10);
		}
		else
		{
			x$("detail_suche_obj").style.display="none"; 	
			x$("detail_suche_ein_aus").style.top="80px";
			x$("div_umkreis").style.display="none"; 
			detail_suche_aus = true;
			cookie.set("yo_suche","aus");
			window.setTimeout("button_suche_ein()", 10);
			x$("box_options").style.visibility="hidden"; 
			selectbox_aus = true;
		}
		x$("detail_suche_ein_aus").style.display=""; 
	}
}
function selectbox_ein_aus()
{
	if (selectbox_aus)
	{
		x$("box_options").style.visibility="visible"; 
		selectbox_aus = false;
	}
	else
	{
		x$("box_options").style.visibility="hidden"; 
		selectbox_aus = true;
	}
}

function set_box_value(new_box_value)
{
	if (new_box_value != "")
		x$("box_value").innerHTML = new_box_value + " km";
	else
		x$("box_value").innerHTML = "";
	x$("ds_umkreis").value = new_box_value;
	x$("box_value").style.visibility="visible"; 
	x$("box_options").style.visibility="hidden"; 
	selectbox_aus = true;
}

function button_suche_aus()
{
	if (document.images.img_suche)
		document.images.img_suche.src = img_suche_zu.src;

	if (x$("txt_suche"))
		x$("txt_suche").innerHTML = "Detailsuche ausblenden";


}

function button_suche_ein()
{
	if (document.images.img_suche)
		document.images.img_suche.src = img_suche_auf.src;

	if (x$("txt_suche"))
		x$("txt_suche").innerHTML = "Detailsuche einblenden";
}


function check_status_suche()
{
	if (cookie.get("yo_suche")=="ein")
		detail_suche_aus = true;
	else
		detail_suche_aus = false;
	detail_suche_ein_aus();
}




var ajax_feld = "";

function ajax_suche_head(feld)
{
 al_counter=-1;

 ajax_feld = feld;

 SBObj = eval("document.form2."+ajax_feld);
 if (SBObj)
 	SB = SBObj.value;

 SB = SB.replace(/%/gi, "");
 SB = SB.replace(/'/gi, "");

 mode = "suche";
 
 iniXMLHttpRequest("/ajax_suche.php?af="+ajax_feld+"&SB="+escape(SB), "GET");
 XMLHTTP.send(null);

 return false;

}


function iSB(SB,brancheID)
{
	if (ajax_feld == "ds_firmen")
		document.form2.ds_firmen.value = SB;

	if (ajax_feld == "ds_ort")
		document.form2.ds_ort.value = SB;

	document.form2.ds_brancheID.value = brancheID;

	x$('ajax_results').style.display="none";
	x$('ajax_results_bg').style.display="none";
	x$('ajax_results').innerHTML = "";
	al_counter=-1;
}

function checkKeycode(e)
{
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else
		if (e)
			keycode = e.which;

	if (keycode == 40) // down
	{
		clearAjaxSelection()
		al_counter++;
		if (x$("al"+al_counter))
		{
			x$("al"+al_counter).className = "ajaxselect";
			x$("al"+al_counter).focus();
		}

	}

	if (keycode == 38) // up
	{
		clearAjaxSelection()
		al_counter--;
		if (x$("al"+al_counter))
		{
			x$("al"+al_counter).className = "ajaxselect";
			x$("al"+al_counter).focus();
		}

	}

	if (al_counter<0)
		al_counter=0;
	else
		if (!x$("al"+al_counter))
			al_counter--;

	if (al_counter==-1)
		if (keycode == 13)
		{
			var sb_firma   = trim(document.form2.ds_firmen.value);
			var sb_stadt   = trim(document.form2.ds_ort.value);
			var sb_strasse = trim(document.form2.ds_strasse.value);

			if (   ((sb_firma.length <= 2)   || (sb_firma == "Firma, Branche, Produkt"))
				&& ((sb_stadt.length <= 1)   || (sb_stadt == "PLZ oder Stadt"))
				&& ((sb_strasse.length <= 2) || (sb_strasse == "Straßenname"))
			)
			{

			}
			else
				document.form2.submit();
		}


	if ((keycode == 40)||(keycode == 38))
		return false;

}

function clearAjaxSelection()
{
	if (x$("al"+al_counter))
	{
		x$("al"+al_counter).className = "fillSB";
		x$("al"+al_counter).blur();
	}
}

function hideAllSelectBoxes()
{
	
	if (x$("ds_umkreis"))
	    x$("ds_umkreis").style.visibility="hidden";
	if (x$("ds_firmen_auswahl"))
	    x$("ds_firmen_auswahl").style.visibility="hidden";
	if (x$("ds_bundesland"))
	    x$("ds_bundesland").style.visibility="hidden";
}

function showAllSelectBoxes()
{
	if (x$("ds_umkreis"))
	    x$("ds_umkreis").style.visibility="visible";
	if (x$("ds_firmen_auswahl"))
	    x$("ds_firmen_auswahl").style.visibility="visible";
	if (x$("ds_bundesland"))
	    x$("ds_bundesland").style.visibility="visible";

}


function watch_for_ajax_results(ff)
{
	if (x$("ajax_results"))
	    if (x$("ajax_results").style.display=="none")
	  	 showAllSelectBoxes();
}

function closeAJ()
{
	x$('ajax_results').style.display="none"; 
	x$('ajax_results_bg').style.display="none"; 
	showAllSelectBoxes();
	x$('ajax_results').innerHTML = "";
}

var watch_ajax_results = window.setInterval("watch_for_ajax_results(1)", 300);

document.onkeydown = checkKeycode;



