function cityFilter() {
   var url = "/content/data/airportGrpService.xml";
   url = url + "?dummy=" + new Date().getTime();
   request2.open("GET", url, true);
   request2.onreadystatechange = function() { 
            requestCities(); 
        };
   request2.send(null);
}

var xmlDoc;
var noCookie;

function requestCities() {
   if (request2.readyState == 4) {
      if (request2.status == 200) {       
         var xmlDoc = request2.responseXML;         
         rePop("toList");  
      } else {       
         applyDropdownCookies();
      }
   }
}

function rePop(to) {
   self.onerror = function() { return true; }
   toIdx = toList.selectedIndex;
   var sel_text;
   var destArray = new Array(); 
   /* Get selected departure information */
   var fromIdx   = fromList.selectedIndex;  
   var fromValue = fromList.options[fromIdx].value; 
   var fromClass = fromList.options[fromIdx].getAttribute('class');
   var fromCode  = fromValue.substring((fromValue.length - 3), fromValue.length);

   if ( toIdx != -1 ) { sel_text = toList.options[toIdx].text; }  
  
   /* If a departure city is selected, get list of destination cities */
   if ((fromValue != "") && (fromClass != "cityarea"))  {          
      destArray = getDestinationCities(fromCode);      
   } else { return; }
   /* Clear destination city select box  */
   while (toList.options.length > 1) { toList.options[1] = null;  } 
   
   /* Loop thru departure list and look for matching destinations.
   /* If destination is found, copy departure options to destination list */
   newelement = 1;   
   for (i=1; i < fromList.length; i++) {
      
      fromText  = fromList.options[i].text;
      fromValue = fromList.options[i].value;
      fromClass = fromList.options[i].getAttribute('class');
      fromCode  = "";         
      
      /*  If selected option class is a city area - fromCode is fromValue 
      /*  else from code is city code  */     
      if (fromList.options[i].getAttribute("class") == "cityarea")  { 
         fromCode = fromValue;
      } else { 
         fromCode = fromValue.substring((fromValue.length - 3), fromValue.length);          
      }
    
      /* check for match between fromCode in  */
     for (j=0; j <  destArray.length; j++) {    
         /* if match found copy option from departure select box to destination Select Box */
         if (destArray[j] == fromCode) {                    
            cityText  = fromText;            
            cityValue = fromValue;            
            /*  for Opera browsers - check for a space, then add indention */
            if (cityText.charAt(0) == ' ')  {  
               cityText = (String.fromCharCode(160, 160, 160, 160, 160) + cityText);           
            }   
            if (cityText == sel_text) { 
              var option = new Option (cityText, cityValue, 0, 1); 
            } else { 
              var option = new Option (cityText, cityValue); 
            }               
            toList.options[newelement]=option; 
            if (fromClass == "cityarea") { option.setAttribute('class', fromClass); }                                 
            newelement++; 
         } 
      }         
   }       
   if (noCookie != 'yes') { applyDropdownCookies("out_arr_airport"); }
}

function checkSel() {  
   var toIdx = fromList.selectedIndex;   
   if (toIdx != null) { 
       toIdx = 0;  
   }
   noCookie = 'yes';
   return;
}

function getDestinationCities(code) {  
   self.onerror   = function() { return true; }
   var destArray  = new Array();
   var srvcIdx = null;
   var xmlDoc = request2.responseXML; 

   var origCityLst = xmlDoc.getElementsByTagName("o");
   var srvcLst = xmlDoc.getElementsByTagName("s");    
   
   var newelement = 0;   
   /* Find Selected City node in xml doc */
   for (i = 0; i < origCityLst.length; i++) {     
      origCity = origCityLst[i].firstChild.nodeValue;  
      if (origCity == code) {
         srvcIdx = i;
         var codeFound = true;  break;
      }  
   }      
   if (codeFound != true) { return; }      
   /* Find corresponding destination cities and add to  */
   var destCityLst = srvcLst[srvcIdx].getElementsByTagName("d");  
   for (j = 0; j < destCityLst.length; j++) {   
      destCity = (destCityLst[j].firstChild.nodeValue);      
      destArray[newelement]  = destCity;	  newelement++;
   }        
   /* Find corresponding city areas and add to  */   
   var destAreaLst = srvcLst[srvcIdx].getElementsByTagName("a");   
   for (k = 0; k < destAreaLst.length; k++) {   
       destArea = (destAreaLst[k].firstChild.nodeValue);    
       destArray[newelement]  = destArea;	  newelement++;
   }      
   return destArray;   
}      
