﻿
// Global Variables.    
var ucAdvancedSearch = null;

(function($) {

    window["load_AutoOwners_AgencyLocator_ucAdvancedSearch"] = function(obj) {
    
    
        // Variables.
        ucAdvancedSearch = {};
        
        
        // Attach Watermarks.
        $.Artemis.InputMask.Watermark($("input[id$='txtZipCodeOnly']"), { 
            initialValue: "enter a zip code",
            setInitialValue: false
        });
        
        $.Artemis.InputMask.Watermark($("input[id$='txtAddress']"), { 
            initialValue: "enter an address",
            setInitialValue: false
        });
        
        $.Artemis.InputMask.Watermark($("input[id$='txtCity']"), { 
            initialValue: "enter a city",
            setInitialValue: false
        });
        
        $.Artemis.InputMask.Watermark($("input[id$='txtZipCode']"), { 
            initialValue: "enter a zip code",
            setInitialValue: false
        });
        
        
        // Attach Event Handlers.
        $("input[id$='txtZipCodeOnly']").keydown(function(event) {
            if (event.which == 13) 
            {
                event.preventDefault();
                event.stopPropagation();
                
                $("input[id$='btnZipSearch']").click();
            }
        });
        
        
        $("input[id$='txtZipCode'],input[id$='txtCity'],input[id$='txtAddress']").keydown(function(event) {
            if (event.which == 13)
            {
                event.preventDefault();
                event.stopPropagation();
                
                $("input[id$='btnAddressSearch']").click();
            }
        });
        
        
        $("a.more_options").click(function(event) {
            event.preventDefault();
            
            var self = $(this);
            
            if (self.hasClass("arrow_right"))
            {                
                ucAdvancedSearch.showSearchOptions();
            }
            else if (self.hasClass("arrow_down"))
            {
                ucAdvancedSearch.hideSearchOptions();
            }
        });
        
        
        $("a.cancel").click(function(event) {
            event.preventDefault();
            ucAdvancedSearch.hideSearchOptions();
        });
        
        
        
        // Functions.
        ucAdvancedSearch.showSearchOptions = function() {
            $(".search_options").slideDown("medium");
            $("a.more_options").removeClass("arrow_right").addClass("arrow_down");
            
            ucAdvancedSearch.disableZipCodeSearchValidators();
            ucAdvancedSearch.enableAddressSearchValidators();
        };
        
        
        ucAdvancedSearch.hideSearchOptions = function() {
             $(".search_options").slideUp("medium", function() {
                ucAdvancedSearch.disableAddressSearchValidators();
                ucAdvancedSearch.enableZipCodeSearchValidators();
            });
            
            $("a.more_options").removeClass("arrow_down").addClass("arrow_right");
        };
        
        
        ucAdvancedSearch.clearZipSearchFields = function() {
            $("input[id$='txtZipCodeOnly']").val("").blur();
        };
        
        
        ucAdvancedSearch.clearAddressSearchFields = function() {
            $("input[id$='txtZipCode'],input[id$='txtCity'],input[id$='txtAddress']").val("").blur();
            $("select[id$='ddlState']").val("-1");
        };
        
        
        ucAdvancedSearch.enableAddressSearchValidators = function() {
            if (typeof ValidatorUpdateDisplay === "function") 
            {
                $(".search_options .validator").each(function(i) {                    
                    this.isvalid = true;
                    ValidatorUpdateDisplay(this);
                });
            }
        };
        
        
        ucAdvancedSearch.disableAddressSearchValidators = function() {
            if (typeof ValidatorUpdateDisplay === "function") 
            {
                $(".search_options .validator").each(function(i) {                    
                    this.isvalid = true;
                    ValidatorUpdateDisplay(this);
                });
            }
        };
        
        
        ucAdvancedSearch.enableZipCodeSearchValidators = function() {
            if (typeof ValidatorUpdateDisplay === "function") 
            {
                $("#quick_search .validator").each(function(i) {                    
                    this.isvalid = true;
                    ValidatorUpdateDisplay(this);
                });
            }
        };
        
        
        ucAdvancedSearch.disableZipCodeSearchValidators = function() {
            if (typeof ValidatorUpdateDisplay === "function") 
            {
                $("#quick_search .validator").each(function(i) {
                    this.isvalid = true;
                    ValidatorUpdateDisplay(this);
                });
            }
        };
    };
    
})(jQuery.noConflict());