function loadDistricts(townId, districtsElementId, defaulOptionValue, forSearch) {
    //messageTimer = setTimeout("checkMessages()", 60000);
    var districtsElement = document.getElementById(districtsElementId);
    // Semtleri temizle
    while (districtsElement.length > 1) {
        districtsElement.remove(1);
    }
    districtsElement.disabled = true;
    xmlHttp = getXmlHttp();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
                var responseText = xmlHttp.responseText;
                var districtsElement = document.getElementById(districtsElementId);
                if(responseText == 'NONE'){
                    districtsElement.options[0].text = !forSearch ? 'Önce ilçeyi seçin' : defaulOptionValue;//arama ise default' u yaz
                }else{
                    var districts = responseText.split('\n');
                    districtsElement.options[0].text = defaulOptionValue;
                    for (i = 0; i < districts.length - 1; i++) {
                        var district = districts[i].split('\t');
                        var newDistrict = document.createElement('option');
                        newDistrict.text = district[1];
                        newDistrict.value = district[0];
                        try {
                            districtsElement.add(newDistrict, null);
                        } catch(ex) {
                            districtsElement.add(newDistrict);
                        }
                    }
                    districtsElement.disabled = false;
                }
            }
        }
    };

    xmlHttp.open('GET', '/districts?townId=' + townId, true);
    districtsElement.options[0].text = 'Yükleniyor...';
    xmlHttp.send(null);
}

var usernameError = 0;

function closeRumuzResultMessageDiv() {
   var usernameResultDiv = document.getElementById('usernameResultDiv');
   usernameResultDiv.style.visibility = 'hidden';
}

function checkUsername() {
   var username = document.getElementById('username');
   username = username.value;
   var usernameResultDiv = document.getElementById('usernameResultDiv');
   var usernameResultMessageDiv = document.getElementById('usernameResultMessageDiv');

   xmlHttp = getXmlHttp();
   xmlHttp.onreadystatechange = function() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
            if (xmlHttp.responseText == '1') {
               var passwd = document.getElementById('password');
               document.getElementById('usernameResultMessageDiv').innerHTML = '<img src="/images/izmir/rumuz_dolu.gif" width="14" height="14" align="absmiddle" /> Bu rumuz daha önce alınmış. Lütfen yeni bir rumuz deneyin.';

               //               warnDivLeft sayfada tanimlanmistir
                usernameResultDiv.style.marginLeft = warnDivLeft + 'px';
               usernameResultDiv.style.top = (findPosY(passwd) - 8) + 'px';
               usernameResultDiv.style.visibility = 'visible';
               usernameError = 1;
            }
         }
      }
   };

    xmlHttp.open('GET', '/rumuzVarmi?username=' + encodeURIComponent(username)+ '&cache='+Math.floor(Math.random()*100001), true);
   xmlHttp.send(null);
}

function popupHelp(id) {
   mywindow = window.open('acilyardim?id=' + id, 'mywindow', 'width=500px,height=300px,toolbar=0,status=1,menubar=0,resizable=1,scrollbars=1,left=30,top=30,screenX=30,screenY=30');
//   mywindow = window.open('help.php?id=' + id, 'mywindow', 'width=500px,height=300px,toolbar=0,status=1,menubar=0,resizable=1,scrollbars=1,left=30,top=30,screenX=30,screenY=30');
}

function showUserInfo(user, userName, age, townName) {
   var userX = findPosX(user);
   var userY = findPosY(user);

   var info = document.getElementById('userInfoInner');
   info.innerHTML = '<b>' + userName + '</b><br/>Yaş:' + age + ', ' + townName;

   var layer = document.getElementById('userInfoLayer');
   layer.style.top = (userY + 5) + 'px';
   layer.style.left = (userX + 50) + 'px';
   layer.style.visibility = 'visible';
}

function hideUserInfo() {
   document.getElementById('userInfoLayer').style.visibility = 'hidden';
   document.getElementById('userInfoLayer').style.visibility = 'hidden';
}
