//var ajaxUrl = 'plz.php?ctry=' + document.getElementById(mobile_locations_country_0);
var ajaxUrl = 'plz.php?ctry=germany';
// dieses ctry=germany innerhalb von connectInputFields übergeben - wie geht das???

/*
function connectInputFields(sourceId, targetId, minLength, paramName) {
    var source = document.getElementById(sourceId);
    var target = document.getElementById(targetId);
    var ajax = new Ajax.Dropdown(
        ajaxUrl,
        paramName,
        {method: 'post'},
        source,
        target
    );
    source.onkeyup = function() { ajax.run(); }
}
*/

function connectInputFields(config) {
    var zipElem     = document.getElementById(config['zip']);
    var cityElem    = document.getElementById(config['city']);
    var countryElem = document.getElementById(config['country']);
//    var countryElem = config['country'] ? document.getElementById(config['country']) : null;
    var resultElem  = document.getElementById(config['result']);
    var ajaxZip  = new Ajax.Dropdown(ajaxUrl, 'zip',  {method: 'post'}, zipElem,     resultElem);
    var ajaxCity = new Ajax.Dropdown(ajaxUrl, 'city', {method: 'post'}, cityElem,    resultElem);
//    var ajaxCtry = new Ajax.Dropdown(ajaxUrl, 'ctry', {method: 'post'}, countryElem, resultElem);
    ajaxZip.setZipCity(zipElem, cityElem, countryElem);
    ajaxCity.setZipCity(zipElem, cityElem, countryElem);
    zipElem.ajax  = ajaxZip;
    cityElem.ajax = ajaxCity;
    zipElem.onkeyup  = ajaxZip.run.bind(ajaxZip);
    cityElem.onkeyup = ajaxCity.run.bind(ajaxCity);
    zipElem.onfocus  = ajaxZip.run.bind(ajaxZip);
    cityElem.onfocus = ajaxCity.run.bind(ajaxCity);
    countryElem.onchange = ajaxZip.run.bind(ajaxZip);
    //zipElem.onblur   = ajaxZip.close.bind(ajaxZip);
    //cityElem.onblur  = ajaxCity.close.bind(ajaxCity);

}

