﻿function escapeName(name)
{
    var str = name;
    return str.replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_").replace(" ","_");
}
		
		
function getNeighbourhoodCitiesByProvince(province, lang)
{
if(lang=="EN")
  RLPInternet.AjaxNeighbourhood.getNeighbourhoodCitiesByProvince(province, lang, getNeighbourhoodCitiesByProvince_callback);  // asynchronous call
else
  RLPInternet.AjaxNeighbourhood.getNeighbourhoodCitiesByProvince(province, lang, getNeighbourhoodCitiesByProvince_callback_fr);  // asynchronous call

}

// This method will be called after the method has been executed
// and the result has been sent to the client.

function getNeighbourhoodCitiesByProvince_callback(response)
{
     if (response.error != null)
     {
      return;
     }

     var cities = response.value;  
     //if the response wasn't what we expected  
     if (cities == null || typeof(cities) != "object")
     {
      return;
     }
     //Get the states drop down
     var cmbCities = document.getElementById("cmbCity");
     cmbCities.options.length = 0; //reset the states dropdown

      cmbCities.options[cmbCities.options.length] = 
             new Option('Show All', 'showall');

     var cmbNeighbourhood = document.getElementById("cmbNeighbourhood");
     cmbNeighbourhood.options.length = 0; //reset the states dropdown

      cmbNeighbourhood.options[cmbNeighbourhood.options.length] = 
             new Option('Show All', 'showall');

     //Remember, its length not Length in JavaScript
         for (var iii = 0; iii < cities.length; ++iii)
         {
          //the columns of our rows are exposed like named properties
          cmbCities.options[cmbCities.options.length] = 
                 new Option(cities[iii][1], cities[iii][0]);
         }
}

function getNeighbourhoodCitiesByProvince_callback_fr(response)
{
     if (response.error != null)
     {
      return;
     }

     var cities = response.value;  
     //if the response wasn't what we expected  
     if (cities == null || typeof(cities) != "object")
     {
      return;
     }
     //Get the states drop down
     var cmbCities = document.getElementById("cmbCity");
     cmbCities.options.length = 0; //reset the states dropdown

      cmbCities.options[cmbCities.options.length] = 
             new Option('Toutes les villes', 'showall');

     var cmbNeighbourhood = document.getElementById("cmbNeighbourhood");
     cmbNeighbourhood.options.length = 0; //reset the states dropdown

      cmbNeighbourhood.options[cmbNeighbourhood.options.length] = 
             new Option('Tous les voisinages', 'showall');


     //Remember, its length not Length in JavaScript
     for (var iii = 0; iii < cities.length; ++iii)
     {
      //the columns of our rows are exposed like named properties
      cmbCities.options[cmbCities.options.length] = 
             new Option(cities[iii][1], cities[iii][0]);
     }
}

function getNeighbourhoodsByCity(neighbourhood,language)
{
    var province = document.getElementById("cmbProvince").value;
   if(language=="EN") 
      RLPInternet.AjaxNeighbourhood.getNeigbourhoodsByCity(neighbourhood,province,language, getNeighbourhoodsByCity_callback);  // asynchronous call
    else
      RLPInternet.AjaxNeighbourhood.getNeigbourhoodsByCity(neighbourhood,province,language, getNeighbourhoodsByCity_callback_fr);  // asynchronous call
}

// This method will be called after the method has been executed
// and the result has been sent to the client.

function getNeighbourhoodsByCity_callback(response)
{
     if (response.error != null)
     {
      //we should probably do better than this
      alert(response.error); 
      return;
     }

     var neighbourhood = response.value;  
     //if the response wasn't what we expected  
     if (neighbourhood == null || typeof(neighbourhood) != "object")
     {
      return;
     }
     //Get the states drop down
     var cmbNeighbourhood = document.getElementById("cmbNeighbourhood");
     cmbNeighbourhood.options.length = 0; //reset the states dropdown

      cmbNeighbourhood.options[cmbNeighbourhood.options.length] = 
             new Option('Show All', 'showall');

     if(neighbourhood.length > 0)
     {
        cmbNeighbourhood.disabled = false;
         //Remember, its length not Length in JavaScript
         for (var iii = 0; iii < neighbourhood.length; ++iii)
         {
          //the columns of our rows are exposed like named properties
          cmbNeighbourhood.options[cmbNeighbourhood.options.length] = 
                 new Option(neighbourhood[iii][1], neighbourhood[iii][0]);
         }
     }
     else
     {
        cmbNeighbourhood.disabled = true;
     }
}

function getNeighbourhoodsByCity_callback_fr(response)
{
     if (response.error != null)
     {
      //we should probably do better than this
      alert(response.error); 
      return;
     }

     var neighbourhood = response.value;  
     //if the response wasn't what we expected  
     if (neighbourhood == null || typeof(neighbourhood) != "object")
     {
      return;
     }
     //Get the states drop down
     var cmbNeighbourhood = document.getElementById("cmbNeighbourhood");
     cmbNeighbourhood.options.length = 0; //reset the states dropdown

      cmbNeighbourhood.options[cmbNeighbourhood.options.length] = 
             new Option('Tous les voisinages', 'showall');
     if(neighbourhood.length > 0)
     {
            cmbNeighbourhood.disabled = false;
         //Remember, its length not Length in JavaScript
         for (var iii = 0; iii < neighbourhood.length; ++iii)
         {
          //the columns of our rows are exposed like named properties
          cmbNeighbourhood.options[cmbNeighbourhood.options.length] = 
                 new Option(neighbourhood[iii][1], neighbourhood[iii][0]);
         }
     }
     else
     {
        cmbNeighbourhood.disabled = true;
     }

}