/************************************


created         : Thursday 21st May 2009 
copyright       : Darren George Web Development
author          : darren george
version         : NA
************************************/

function getModels(manufacturerId)
  {
  url = "/find/search_groups_get_models_by_manufacturer_" + manufacturerId;
  
  MakeServerRequest(url);   
  }

  
function getYears(manufacturerId, modelId)
  {
  url = "/find/search_groups_get_years_by_manufacturer_" + manufacturerId + "_and_model_" + modelId;
  
  MakeServerRequest(url);   
  }  


function getEditions(manufacturerId, modelId, yearId)
  {  
  url = "/find/search_groups_get_editions_by_manufacturer_" + manufacturerId + "_and_model_" + modelId  + "_and_year_" + yearId;
    
  MakeServerRequest(url);   
  }
  

function DisplayServerResponse(serverResponse)
  {    
  //root element of the xml document being parsed i.e. <selectQuery></selectQuery> in this case
  var xmlDoc = serverResponse.documentElement;


  switch(xmlDoc.firstChild.nodeName)
    {
    case 'modelList':
      
      var modelList = document.getElementById("modelID");             
      var returnedList = xmlDoc.firstChild;
      
      if(returnedList.childNodes.length > 0)
        {
        //there is at least one set of <choice></choice> tag sets
        if(modelList.disabled == false)
          {
          //clear the existing options from the model list
          modelList.options.length = 0;         
          }
        else
          {          
          //enable the model list
          modelList.disabled = false;              
          }  
        
        
        //now populate the model list with the new options        
        if(search == true)
          {
          modelList.options[0] = new Option("All", "-1");
          }
        else
          {
          modelList.options[0] = new Option("Please Select", "-1");
          }  
          
              
        for(i=0; i<returnedList.childNodes.length; i++)
          {
          //for each <choice></choice> tag set
          choice = returnedList.childNodes[i];
            
          choiceId = choice.firstChild;
          choiceText = choice.lastChild;  
            
          modelList.options[i+1] = new Option(choiceText.firstChild.nodeValue, choiceId.firstChild.nodeValue); 
          }                                         
        }
      else
        {
        //there are no <choice></choice> tag sets
        if(modelList.disabled == false)
          {
          //so clear the model list and disable it
          modelList.options.length = 0;
          modelList.disabled = true;
          }
        }
      
      
      
      var yearList = document.getElementById("yearID"); 
      if(yearList != null)
        {
        if(yearList.disabled == false)
          {
          //so clear the year list and disable it
          yearList.options.length = 0;
          yearList.disabled = true;
          }
        }
        

      var editionList = document.getElementById("editionID");
      if(editionList != null)
        { 
        if(editionList.disabled == false)
          {
          //so clear the edition list and disable it
          editionList.options.length = 0;
          editionList.disabled = true;
          }
        }        
      break;

    case 'yearList':

      var yearList = document.getElementById("yearID");             
      var returnedList = xmlDoc.firstChild;
      
      if(returnedList.childNodes.length > 0)
        {
        //there is at least one set of <choice></choice> tag sets
        if(yearList.disabled == false)
          {
          //clear the existing options from the year list
          yearList.options.length = 0;         
          }
        else
          {          
          //enable the year list
          yearList.disabled = false;              
          }  
        
        
        //now populate the year list with the new options
        if(search == true)
          {
          yearList.options[0] = new Option("All", "-1");
          }
        else
          {
          yearList.options[0] = new Option("Please Select", "-1");
          }          
        

              
        for(i=0; i<returnedList.childNodes.length; i++)
          {
          //for each <choice></choice> tag set
          choice = returnedList.childNodes[i];
            
          choiceId = choice.firstChild;
          choiceText = choice.lastChild;  
            
          yearList.options[i+1] = new Option(choiceText.firstChild.nodeValue, choiceId.firstChild.nodeValue); 
          }                                         
        }
      else
        {
        //there are no <choice></choice> tag sets
        if(yearList.disabled == false)
          {
          //so clear the year list and disable it
          yearList.options.length = 0;
          yearList.disabled = true;
          }
        }
      
      
      var editionList = document.getElementById("editionID"); 
      if(editionList.disabled == false)
        {
        //so clear the edition list and disable it
        editionList.options.length = 0;
        editionList.disabled = true;
        }
      
      break;        
      
    case 'editionList':

      var editionList = document.getElementById("editionID");             
      var returnedList = xmlDoc.firstChild;
      
      if(returnedList.childNodes.length > 0)
        {
        //there is at least one set of <choice></choice> tag sets
        if(editionList.disabled == false)
          {
          //clear the existing options from the edition list
          editionList.options.length = 0;         
          }
        else
          {          
          //enable the edition list
          editionList.disabled = false;              
          }  
        
        
        //now populate the edition list with the new options
        if(search == true)
          {
          editionList.options[0] = new Option("All", "-1");
          }
        else
          {
          editionList.options[0] = new Option("Please Select", "-1");
          }  


              
        for(i=0; i<returnedList.childNodes.length; i++)
          {
          //for each <choice></choice> tag set
          choice = returnedList.childNodes[i];
            
          choiceId = choice.firstChild;
          choiceText = choice.lastChild;  
            
          editionList.options[i+1] = new Option(choiceText.firstChild.nodeValue, choiceId.firstChild.nodeValue); 
          }                                         
        }
      else
        {
        //there are no <choice></choice> tag sets
        if(editionList.disabled == false)
          {
          //so clear the edition list and disable it
          editionList.options.length = 0;
          editionList.disabled = true;
          }
        }
      
      break;    
    }
  }  
  

