﻿function AddressFind()
{
	var self = this;
	var parcelSearchUseTypeID="parcelSearchUseType";
	var streetNameBoxID = "parcelSearchStreet";
	var addressNumBoxID = "parcelSearchStreetNo";
	var loadingAddressMessage = "Loading...";
	var selectAddressMessage = "Select Street";
	var selectUseTypesMessage = "Select Use Type";
	var selectStNoMessage = "Number";
	var loadingAddressList = false;
	var loadingStreetNumList = false;
	var XmlReqAddressList = null;
	var XmlReqStNumList = null;
	var XmlReqUseTypesList = null;
	var XmlReqCounties = null;
	var XmlReqConservationLandTypes = null;
	var XmlReqWatershedCodes = null;
	var XmlReqRivers = null;
	var streets;
	var top;
	var bottom;
	var streetList = new Array();
	var length = 0;
	var divfocus = 0;
	var boxfocus = 0;
	var shownStreets = 0;
	var index = -1;
	
	this.init = init;
	this.addressfind = addressfind;
	this.populateCountyDDs = populateCountyDDs;
	this.processCounties = processCounties;
	this.processReponse = processResponse;
	this.processConservationLandTypes = processConservationLandTypes;
	this.populateConservationLandTypeDD = populateConservationLandTypeDD;
	this.populateWatershedCodeDD = populateWatershedCodeDD;
	/*this.processRivers = processRivers;
	this.populateRiversDD = populateRiversDD;
	
	function populateRiversDD()
	{
	    url = server + "FindService.asmx/GetRiverStatuses";
	    if( null == self.XmlReqRivers)
	    {
	        self.XmlReqRivers = new TXmlHttp();
	    }
	    if( null != self.XmlReqRivers )
	    {
	        self.XmlReqRivers.onreadystatechange = processRivers;
	        self.XmlReqRivers.open("GET", url, true);
	        self.XmlReqRivers.send(null);
	    }
	}
	function processRivers()
	{
	    processResponse("selectRiverStatus", "STATUS", "name", self.XmlReqRivers);
	}*/
	function populateCountyDDs()
	{
	    url = server + "FindService.asmx/GetCounties";
		if(null == self.XmlReqCounties){
			self.XmlReqCounties = new TXmlHttp();
		}
		if(null != self.XmlReqCounties)
		{
			self.XmlReqCounties.onreadystatechange = processCounties;
			self.XmlReqCounties.open("GET", url, true); //async call
			self.XmlReqCounties.send(null);
		}
	}
	function processCounties()
	{
	    processResponse("selectCountyFindCounty", "COUNTY", "name", self.XmlReqCounties);
	    processResponse("VCLNACounties", "COUNTY", "name", self.XmlReqCounties);
	}
	function processResponse(id, tag, attribute, request)
	{
	    if( request.readyState == 4 )
		{
			if( request.status == 200 )
			{
			    var dd = document.getElementById(id);
			    
			    while (dd.length > 1)
			        dd.remove(1);
			    var response = request.responseXML.documentElement;
			    var counties = response.getElementsByTagName(tag);
			    var x = dd.length;
			    if( null != counties && counties.length > 0)
			    {
			        for(var i = 0;i < counties.length; i++){
						county = counties[i].attributes.getNamedItem(attribute).value;
						
						if( !browser.isInternetExplorer() )
						{
						    if( county != null && county.length > 0)
    							dd.add( new Option(county,county,false,false),null );
						
						}
						else
						{
							if( county != null && county.length > 0)
							    dd.options[i+x] = new Option(county,county, false, false);
							
						}
					}
			    }
			    dd.selectedIndex = 0;
			}
		}
	}
	
	function populateConservationLandTypeDD()
	{
	    url = server + "FindService.asmx/GetConservationLandTypes";
		if(null == self.XmlReqConservationLandTypes){
			self.XmlReqConservationLandTypes = new TXmlHttp();
		}
		if(null != self.XmlReqConservationLandTypes)
		{
			self.XmlReqConservationLandTypes.onreadystatechange = processConservationLandTypes;
			self.XmlReqConservationLandTypes.open("GET", url, true); //async call
			self.XmlReqConservationLandTypes.send(null);
		}
	}
	function processConservationLandTypes()
	{
	    processResponse("selectTypeFindCounty", "TYPE", "name", self.XmlReqConservationLandTypes);
	    processResponse("selectTypeFindWatershed", "TYPE", "name", self.XmlReqConservationLandTypes);
	}
	function populateWatershedCodeDD()
	{
	    url = server + "FindService.asmx/GetWatershedCodes";
		if(null == self.XmlReqWatershedCodes){
			self.XmlReqWatershedCodes = new TXmlHttp();
		}
		if(null != self.XmlReqConservationLandTypes)
		{
			self.XmlReqWatershedCodes.onreadystatechange = processWatershedCodes;
			self.XmlReqWatershedCodes.open("GET", url, true); //async call
			self.XmlReqWatershedCodes.send(null);
		}
	}
	function processWatershedCodes()
	{
	    processResponse("selectWatershedCodeFindWatershed", "CODE", "code", self.XmlReqWatershedCodes);
	}
	function init(){
	    self.populateCountyDDs();	
	    self.populateConservationLandTypeDD();
	    self.populateWatershedCodeDD();
	    //self.populateRiversDD();
	}
}
