var ajax;



try {

        ajax = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

        try {

                ajax = new ActiveXObject("Microsoft.XMLHTTP");

        } catch (e) {

                if (typeof XMLHttpRequest!='undefined') {

                        ajax = new XMLHttpRequest();

                }

        }

}



function updateDepartements(region) {

        ajax.open('get', 'region2dept.php5?region=' + region);

        ajax.onreadystatechange = handleResponse;

        ajax.send(null);

}



function handleResponse() {



        if(ajax.readyState == 4) {



                var data = ajax.responseXML.getElementsByTagName('departement');



                document.getElementById('departements').innerHTML = '';

                for(var i=0;i<data.length;i++) {



                        var option = document.createElement('option');

                        option.setAttribute('value',data[i].getAttribute("id"));

                        option.appendChild(document.createTextNode(data[i].firstChild.nodeValue));

                        document.getElementById('departements').appendChild(option);

                }

        }

}



function initForm() {

        document.getElementById('regions').selectedIndex = 0;

        updateDepartements(document.getElementById('regions').value);

}



if (window.addEventListener) {

        window.addEventListener("load", initForm, false);

} else if (window.attachEvent){

        window.attachEvent("onload", initForm);

}