/**
 * @author Maceo Marquez
 * special thanks to Crane, Pascarello, & James
 * www.maceomarquez.com	
 */

      function FillArea(oElem,oTarget){
	  	preloader();                           
        var strValue = oElem.options[oElem.selectedIndex].value;                       
        var url = 'ajax.php';                                         
        var strParams = oElem.name+'='+strValue;                   
        var loader1 = new net.ContentLoader(url,FillDropDown,null,"POST",strParams);    
	  }
      function FillDropDown(){
	  	//use to debug issue
	  	//alert(this.req.responseText);
		var xmlDoc = this.req.responseXML.documentElement;              

        var xSel = xmlDoc.getElementsByTagName('selectElement')[0];                   
		// Changed from above - do not use firstchild in areas where there may be whitespace-- this is a MOZ issue.                         
        var strFName = xSel.getElementsByTagName('formName')[0].firstChild.nodeValue;
		var strEName = xSel.getElementsByTagName('formElem')[0].firstChild.nodeValue; 
		    
        var objDDL = document.forms[strFName].elements[strEName];                                         
        objDDL.options.length = 0;                                     
            
        var xRows = xmlDoc.getElementsByTagName('entry');  
		
        for(i=0;i<xRows.length;i++){
		                          
          var theText  = xRows[i].getElementsByTagName('optionText')[0].firstChild.nodeValue; 
		  var theValue = xRows[i].getElementsByTagName('optionValue')[0]
		  if (theValue.hasChildNodes()) {
		  	theValue = theValue.firstChild.nodeValue;
		  }
		  else {
		  	theValue = "";  //use empty string so we dont have to modify ASP logic.
		  }
          var option   = new Option(theText,theValue);                           
          objDDL.options.add(option, objDDL.options.length);                      
        }                                                              
      }  
	  
	  /* Thisis somewhat hardcoded in that it knows about the IslandID form.
	   * This must be loaded before FillDropDown, which should overwrite it. 
	   * */
	  function preloader() {
	  	
		var islDDL  = document.forms['searchProperties'].elements['IslandID'];
		//alert(islDDL);
		var areaDDL = document.forms['searchProperties'].elements['areaID'];
		 
		if (islDDL.options.selectedIndex.value=="" ) {
		  	areaDDL.options.length = 0;  
			areaDDL.options[0]     = new Option('All Areas', ''); 			
		}
		else {
		  	areaDDL.options.length = 0;  
			areaDDL.options[0]     = new Option('Loading Areas...', '0'); 			
		}

	  }
