/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function mudaDistrito(distrito,concelho)
{
  jQuery.ajax({
        type: "POST",
        url: "/agenda/?id=42",
        data: ({
            Distrito : distrito.value
            }),
        dataType: "xml",
        success: function(xml){

            //This simple XPath XML function looks through the returned XML data
            //All tags can now be accessed within the loop
            var _numeroConcelho = "";
            var _concelho= "";

            var elSel = concelho;
            var i;
            for (i = elSel.length - 1; i>=0; i--) {
                elSel.remove(i);
            }
            //Add option Todos
            var elOptNew = document.createElement('option');
            elOptNew.text = "Todos";
            elOptNew.value = "";

            try {
                elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
            }
            catch(ex) {
                elSel.add(elOptNew); // IE only
            }

            //This function will loop for each match on addresses/address
            var cinema = $(xml).find('Concelhos');
            jQuery(cinema).find('Row').each(function(){

                _numeroConcelho = $("Numero", this).text();
                _concelho = $("Concelho", this).text();

                var elOptNew = document.createElement('option');
                elOptNew.text = _concelho;
                elOptNew.value = _numeroConcelho;
                var elSel = concelho;

                try {
                    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
                }
                catch(ex) {
                    elSel.add(elOptNew); // IE only
                }

            })
        }
    })
                jQuery.ajax({ type: "POST", url: "/agenda/?id=121", data: ({Distrito : distrito.value, Concelho : "", Genero : "", Classificacao : "", DiasProgramacao : ""}), dataType: "xml", success: function(xml){

                    //This simple XPath XML function looks through the returned XML data
                    //All tags can now be accessed within the loop
                    var _numeroCinema = "";
                    var _cinema= "";

                    var elSel = document.getElementById('Cinemas');
                    var i;
                    for (i = elSel.length - 1; i>=0; i--) {
                      elSel.remove(i);
                    }
                    //Add option Todos
                    var elOptNew = document.createElement('option');
                    elOptNew.text = "Todos";
                    elOptNew.value = "";

                    try {
                      elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
                    }
                    catch(ex) {
                      elSel.add(elOptNew); // IE only
                    }

                    //This function will loop for each match on addresses/address
                    var cinema = $(xml).find('Cinema');
                    jQuery(cinema).find('Row').each(function(){

                    _numeroCinema = $("NumeroCinema", this).text();
                    _cinema = $("Cinema", this).text();

                    var elOptNew = document.createElement('option');
                    elOptNew.text = _cinema;
                    elOptNew.value = _numeroCinema;
                    var elSel = document.getElementById('Cinemas');

                    try {
                      elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
                    }
                    catch(ex) {
                      elSel.add(elOptNew); // IE only
                    }

                    })
                }
                })

                jQuery.ajax({ type: "POST", url: "/agenda/?id=141", data: ({Distrito : distrito.value, Concelho : "", Genero : "", Classificacao : "", DiasProgramacao : ""}), dataType: "xml", success: function(xml){

                    //This simple XPath XML function looks through the returned XML data
                    //All tags can now be accessed within the loop
                    var _numeroFilme = "";
                    var _filme= "";

                    var elSel = document.getElementById('Filmes');
                    var i;
                    for (i = elSel.length - 1; i>=0; i--) {
                      elSel.remove(i);
                    }
                    //Add option Todos
                    var elOptNew = document.createElement('option');
                    elOptNew.text = "Todos";
                    elOptNew.value = "";

                    try {
                      elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
                    }
                    catch(ex) {
                      elSel.add(elOptNew); // IE only
                    }

                    //This function will loop for each match on addresses/address
                    var cinema = $(xml).find('Cinema');
                    jQuery(cinema).find('Row').each(function(){

                    _numeroFilme = $("NumeroFilme", this).text();
                    _filme = $("Filme", this).text();

                    var elOptNew = document.createElement('option');
                    elOptNew.text = _filme;
                    elOptNew.value = _numeroFilme;
                    var elSel = document.getElementById('Filmes');

                    try {
                      elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
                    }
                    catch(ex) {
                      elSel.add(elOptNew); // IE only
                    }

                    })
                }
                })

            }


