function write_re_text(s) {
 	    var retext = document.getElementById('re_text');
 	    var option = s.options[s.selectedIndex];
 	    retext.value = option.text;
	}


function loadXMLDocTowns(method,reid){
	var url = "../ajax/towns.php?reid=" + reid;
	var newtown = document.getElementById('newtown');
    newtown.style.display = 'none';
	newtown.value = '';


    if(window.XMLHttpRequest){
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangeTowns;
        req.open(method, url, true);
        req.send(null);
    }else if(window.ActiveXObject){
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if(req){
            req.onreadystatechange = processReqChangeTowns;
            req.open(method, url, true);
            req.send(null);
        }
    }
}

function processReqChangeTowns(){
    if(req.readyState == 4){
        if(req.status == 200){
			getTowns(req.responseXML.documentElement);
        }else{
            alert(req.status + "There was a problem retrieving the XML data:\\n" + req.statusText);
        }
    }
}


function getTowns(xml){	var towns = xml.getElementsByTagName("town");
	var container = document.getElementById("alltowns");
	container.innerHTML = '';

	option = document.createElement("option");
	option.value = '0';
	option.innerHTML = '- Выберите или введите ниже -';
	container.appendChild(option);

	option = document.createElement("option");
	option.value = '0';
	option.innerHTML = '----------------------------------';
	container.appendChild(option);

	option = document.createElement("option");
	option.value = '';
	option.innerHTML = '&nbsp;&nbsp;Добавить другой город';
	container.appendChild(option);

	option = document.createElement("option");
	option.value = '0';
	option.innerHTML = '---------------------------------';
	container.appendChild(option);

	for(i=0;i<towns.length;i++){
				option = document.createElement("option");
				option.value = towns[i].firstChild.data;
				option.innerHTML = towns[i].firstChild.data;
				container.appendChild(option);
	 		}


}