
   
var ajax = new Array();

function getCityList(sel)
{
    var countryCode = sel.options[sel.selectedIndex].value;
    document.getElementById('edit-concelho').options.length = 0;    // Empty city select box
    document.getElementById('edit-freguesia').options.length = 0; 
    if(countryCode.length>0){
        var index = ajax.length;
        ajax[index] = new sack();

        ajax[index].requestFile = 'sites/all/themes/Sado2000temp/getGeo.php?distritoCode='+countryCode; // Specifying which file to get
        ajax[index].onCompletion = function(){ createCities(index) };   // Specify function that will be executed after file has been found
        ajax[index].runAJAX();      // Execute AJAX function
    }
}

function createCities(index)
{
    var obj = document.getElementById('edit-concelho');
    eval(ajax[index].response); // Executing the response from Ajax as Javascript code  
}


function getFreguesiaList(sel)
{
    var concelhoCode = sel.options[sel.selectedIndex].value;
    document.getElementById('edit-freguesia').options.length = 0;    // Empty freguesia select box
    //var distritoCode = document.getElementById('edit-distrito').value;
   
    if(concelhoCode.length>0){
     
        var index2 = ajax.length;
        ajax[index2] = new sack();
        ajax[index2].requestFile = 'sites/all/themes/Sado2000temp/getGeo.php?concelhoCode='+concelhoCode +'&distritoCode=15'; // Specifying which file to get
        ajax[index2].onCompletion = function(){ createFreguesia(index2) };   // Specify function that will be executed after file has been found
        ajax[index2].runAJAX();      // Execute AJAX function
    }
}

function createFreguesia(index)
{
    var obj = document.getElementById('edit-freguesia');
    eval(ajax[index].response); // Executing the response from Ajax as Javascript code  
}

function getTipologiaList(sel)
{
    var naturezaCode = sel.options[sel.selectedIndex].value;
    document.getElementById('edit-tipologia').options.length = 0;    // Empty freguesia select box
       
    if(naturezaCode.length>0){
     
        var index3 = ajax.length;
        ajax[index3] = new sack();
        ajax[index3].requestFile = 'sites/all/themes/Sado2000temp/getGeo.php?naturezaCode='+naturezaCode; // Specifying which file to get
        ajax[index3].onCompletion = function(){ createTipologia(index3) };   // Specify function that will be executed after file has been found
        ajax[index3].runAJAX();      // Execute AJAX function
    }
}

function createTipologia(index)
{
    var obj = document.getElementById('edit-tipologia');
    eval(ajax[index].response); // Executing the response from Ajax as Javascript code  
}

function setAdvancedFormulario(naturezaCode,distritoCode,concelhoCode,tipologiaCode,freguesiaCode)
{
/*   
   if(naturezaCode.length > 0){
        document.getElementById('edit-tipologia').options.length = 0;    // Empty freguesia select box
        var index3 = ajax.length;
        ajax[index3] = new sack();
        ajax[index3].requestFile = 'sites/all/themes/Sado2000temp/getGeo.php?naturezaCode='+naturezaCode+'&tipologiaCode='+tipologiaCode; // Specifying which file to get
        ajax[index3].onCompletion = function(){ createTipologia(index3) };   // Specify function that will be executed after file has been found
        ajax[index3].runAJAX();  
   }
/*   
    if(distritoCode.length>0){
        document.getElementById('edit-concelho').options.length = 0;    // Empty city select box
        var index = ajax.length;
        ajax[index] = new sack();

        ajax[index].requestFile = 'sites/all/themes/Sado2000temp/getGeo.php?distritoCode='+distritoCode+'&code='+concelhoCode; // Specifying which file to get
        ajax[index].onCompletion = function(){ createCities(index) };   // Specify function that will be executed after file has been found
        ajax[index].runAJAX();      // Execute AJAX function
    }
  
    if(concelhoCode.length>0){
        document.getElementById('edit-freguesia').options.length = 0;    // Empty freguesia select box
        var index2 = ajax.length;
        ajax[index2] = new sack();
        ajax[index2].requestFile = 'sites/all/themes/Sado2000temp/getGeo.php?concelhoCode='+concelhoCode+'&distritoCode='+distritoCode+'&freguesiaCode='+freguesiaCode; // Specifying which file to get
        ajax[index2].onCompletion = function(){ createFreguesia(index2) };   // Specify function that will be executed after file has been found
        ajax[index2].runAJAX();      // Execute AJAX function
    }
*/
}
