////////////////////////////////////////////////////////////////////////////
//Author: Robert Adkison
//Date: 12/9/2008
//
//Description:
//  
//Notes:
//
/////////////////////////////////////////////////////////////////////////////
var arAircraftMakeModel = new Array();

arAircraftMakeModel[0]=new Array("bombardier","CANADAIR REGIONAL JET","CRJ");
arAircraftMakeModel[1]=new Array("bombardier","CHALLENGER 300","C300");
arAircraftMakeModel[2]=new Array("bombardier","CHALLENGER 600","CAN");
arAircraftMakeModel[3]=new Array("bombardier","CHALLENGER 601","C601");
arAircraftMakeModel[4]=new Array("bombardier","CHALLENGER 604","C604");
arAircraftMakeModel[5]=new Array("bombardier","GLOBAL EXPRESS","GLOBAL");
arAircraftMakeModel[6]=new Array("bombardier","LEARJET","LEARJET");
arAircraftMakeModel[7]=new Array("bombardier","LEARJET 24, 25 SERIES","L24");
arAircraftMakeModel[8]=new Array("bombardier","LEARJET 31 SERIES","L31");
arAircraftMakeModel[9]=new Array("bombardier","LEARJET 35, 36 SERIES","L35");
arAircraftMakeModel[10]=new Array("bombardier","LEARJET 45 SERIES","L45");
arAircraftMakeModel[11]=new Array("bombardier","LEARJET 55 SERIES","L55");
arAircraftMakeModel[12]=new Array("bombardier","LEARJET 60","L60");
arAircraftMakeModel[13]=new Array("cessna","CESSNA","CES");
arAircraftMakeModel[14]=new Array("cessna","CESSNA CARAVAN","C208");
arAircraftMakeModel[15]=new Array("cessna","CITATION 560XL","CXL");
arAircraftMakeModel[16]=new Array("cessna","CITATION BRAVO","BRAVO");
arAircraftMakeModel[17]=new Array("cessna","CITATION CJ1, 2, 3","CJ");
arAircraftMakeModel[18]=new Array("cessna","CITATION EXCEL 560","EXCEL");
arAircraftMakeModel[19]=new Array("cessna","CITATION I, II, SP","CIT");
arAircraftMakeModel[20]=new Array("cessna","CITATION III, 650","CIT 3");
arAircraftMakeModel[21]=new Array("cessna","CITATION SOVERIGN","C680");
arAircraftMakeModel[22]=new Array("cessna","CITATION X, 750","CIT 10");
arAircraftMakeModel[23]=new Array("embraer","EMBRAER","EMBRAER");
arAircraftMakeModel[24]=new Array("embraer","EMBRAER BRASILIA","120");
arAircraftMakeModel[25]=new Array("embraer","EMBRAER LEGACY","LEGACY");
arAircraftMakeModel[26]=new Array("embraer","EMBRAER REGIONAL JET","ERJ");
arAircraftMakeModel[27]=new Array("falcon","DASSAULT FALCON","FALCON");
arAircraftMakeModel[28]=new Array("falcon","FALCON 10, 50","FAL");
arAircraftMakeModel[29]=new Array("falcon","FALCON 50","FAL 50");
arAircraftMakeModel[30]=new Array("falcon","FALCON 900","FAL 900");
arAircraftMakeModel[31]=new Array("falcon","FOKKER","FOKKER");
arAircraftMakeModel[32]=new Array("falcon","FOKKER 50","F50");
arAircraftMakeModel[33]=new Array("falcon","FOKKER F28","F28");
arAircraftMakeModel[34]=new Array("gulfstream","GULFSTREA II","G II");
arAircraftMakeModel[35]=new Array("gulfstream","GULFSTREAM","GULFSTREAM");
arAircraftMakeModel[36]=new Array("gulfstream","GULFSTREAM ASTRA G100","ASTRA");
arAircraftMakeModel[37]=new Array("gulfstream","GULFSTREAM G200 GALAXY","GALAXY");
arAircraftMakeModel[38]=new Array("gulfstream","GULFSTREAM III","G III");
arAircraftMakeModel[39]=new Array("gulfstream","GULFSTREAM IV, IVSP","G IV");
arAircraftMakeModel[40]=new Array("hawker","BEECHCRAFT","BCH");
arAircraftMakeModel[41]=new Array("hawker","BEECHCRAFT KINGAIR 100 SERIES","B100");
arAircraftMakeModel[42]=new Array("hawker","BEECHCRAFT KINGAIR 200 SERIES","B200");
arAircraftMakeModel[43]=new Array("hawker","BEECHCRAFT KINGAIR 300/350 SERIES","B350");
arAircraftMakeModel[44]=new Array("hawker","BEECHCRAFT KINGAIR F90","F90");
arAircraftMakeModel[45]=new Array("hawker","BEECHCRAFT,1900","B1900");
arAircraftMakeModel[46]=new Array("hawker","BEECHJET 400/400A","BCHJET");
arAircraftMakeModel[47]=new Array("hawker","MITSUBISHI DIAMOND 1, 1A","DIAMOND");
arAircraftMakeModel[48]=new Array("hawker","PREMIER","PREMIER");
arAircraftMakeModel[49]=new Array("hawker","RAYTHEON HAWKER 125 THRU -700","HAWKER");
arAircraftMakeModel[50]=new Array("hawker","RAYTHEON HAWKER 800, 800XP","H 800");
arAircraftMakeModel[51]=new Array("paiggio","PIAGGIO","PG");
arAircraftMakeModel[52]=new Array("platus","PILATUS","PC12");
arAircraftMakeModel[53]=new Array("westwind","1121, 1123, 1124","WESTWIND");
arAircraftMakeModel[54]=new Array("westwind","ISRAEL INDUSTRIES","IA");
arAircraftMakeModel[55]=new Array("other","HONEYWELL","HONEY");


//Function called when a make is selected from the Aircraft Make listbox.
//When a make is selected, then the contents of the Model listbox are remove
//(except for the default value), and all of the models related to the 
//selected maked are added to the model listbox.
function MakeSelected(SelectedMake)
{
   var SelectedMake = document.getElementById("aircraftmake").value;
   var ModelBox = document.getElementById("modelbox");
   
   
   //determine if a pointer was returened from the listbox
   if (SelectedMake != null)
   {
    //make sure that the default was not selected, if so then disable the Model listbox
     if (SelectedMake != "allmake")
     {
       //make sure a pointer was returned from the Model listbox 
       //if so then enable the listbox so that the user can now select a model.
       if (ModelBox != null)
       {
         //Clear the model listbox of all models except for the default
         //model
         if ( ClearModelListBox() )
         { 
            //fill the model listbox with all of the model related to
            //the selected Make in the Make listbox.
            FillModelListBox(SelectedMake);
            //Enable the Aircraft Model listbox
            document.mainsearch.aircraftmodel.disabled = false;         
         }
         
       };
     }
     else
     {
       if (ModelBox != null)
       {
         document.mainsearch.aircraftmodel.disabled = true;
         ClearModelListBox();
       };          
     }
   };

   
};

//Called when the page is first opened.
//Function makes sure that the model listbox is disabled.
function SetInitial()
{
   var SelectedMake = document.getElementById("aircraftmake").value;
   var ModelBox = document.getElementById("modelbox");
   
   
   if (SelectedMake != null)
   {

     if (SelectedMake == "allmake")
     {
       
       if (ModelBox != null)
       {
         //ModelBox.disabled = true;
         document.mainsearch.aircraftmodel.disabled = true;
       };
     }
   };

   
};

//Function deletes all the items from the model listbox before new items 
//are added.  This is called after the user has selected a make from the
//Aircraft Make listbox.
function ClearModelListBox()
{    
    
    if (document.mainsearch.aircraftmodel != null)
    {
      //Iterate through the model listbox deleting the last elemement until only the first
      //elemenet (the default value) remains.
      while (document.mainsearch.aircraftmodel.length > 1)
      {
        document.mainsearch.aircraftmodel.remove(document.mainsearch.aircraftmodel.length - 1);
      };
    }
    else
    {return false;};
    
    return true;
    
};

//Function fills the Aircraft Model listbox based on the passed Aircraft Make.
//The function iterates through the arAircraftMakeModel array checking if the passed
//make matches the first element - if so then the Model and Model code are copied 
//from the array, a new option element created, option element's value and text set
//with the array data, and the new option element added to the model listbox.
function FillModelListBox(sMake)
{
    //var arAircraftMakeModel = new Array();
    //arAircraftMakeModel[0]=new Array("bombardier","CANADAIR REGIONAL JET","CRJ");
    
    //Iterate through the arAircraftMakeModel array trying to match the passed
    //Make to the first element of each array within the arAircraftMakeModel array.
    for (var i = 0; i < arAircraftMakeModel.length; i++)
    {
        //If the makes match then create a options element,
        //set the text and value from the array elements,
        //and add the option element to the model list box
        if (arAircraftMakeModel[i][0] == sMake)
        {
          //Create new options listbox item
          var elOptNew = document.createElement('option');
          //set value and text to the array data.
          elOptNew.text = arAircraftMakeModel[i][1];
          elOptNew.value = arAircraftMakeModel[i][2];
          
          //Add the options elements to the model listbox.
          try {
                document.mainsearch.aircraftmodel.add(elOptNew, null); // standards compliant; doesn't work in IE
              }
          catch(ex) {document.mainsearch.aircraftmodel.add(elOptNew);} // IE only

          
        };
    };
};

function fnTrapKD(btn, event){

 if (document.all){

  if (event.keyCode == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();

  }

 }

 else if (document.getElementById){

  if (event.which == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();

  }

 }

 else if(document.layers){

  if(event.which == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();

  }

 }

};

