var req;
var target;
var isIE;

function checkCity(cityName)
{
	if(cityName.length>=3)validateCity(cityName);
}

function initRequest()
{
    if (window.XMLHttpRequest) 
	{
        req = new XMLHttpRequest();
    } 
	else if (window.ActiveXObject) 
	{
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
}


function validateCity(cityName) 
{
	var url = "search_city.php?cityName="+cityName;
    initRequest();
	req.onreadystatechange = processRequest;
    req.open("GET", url, true); 
	req.send(null);
}


function processRequest() 
{
      if( 4 == req.readyState ) {
        if( 200 != req.status ) {
		document.getElementById("divsCity").innerHTML="Fehler " + req.status + ": " + req.statusText;		
        } else {
		if (req.responseText.length>2)
			{
		  	document.getElementById("divsCity").innerHTML=req.responseText;
			if(req.responseText.indexOf("<option value")>1)document.getElementById("submitSearch").disabled=false;
			}
			else
			{
            document.getElementById("divsCity").innerHTML="<b style='color:red;'>Wir konnten leider keinen Ort finden!!!</b>";
			document.getElementById("submitSearch").disabled=true;
			}
        }
      }
}

function checkCityForm()
{
document.getElementById("search_city_form").submit();
}	