﻿//  Ajax Form search function
ApplicationUtility.prototype.formSearch = function(searchObject) {
    if (searchObject !== undefined || searchObject != null) {
        this.last_search_object = searchObject;
        this.last_parcel_search = searchObject;
    }

    jQuery.ajax({
        cache: true,
        data: this.last_search_object,
        url: 'ajax/FormSearch.aspx',
        beforeSend: function() {
            jQuery('#search-results').html('').addClass('ajax-working');
            jQuery('.tabs li').eq(1).click();
        },
        success: function(data, textStatus, XMLHttpRequest) {
            jQuery('#search-results').html(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            jQuery('#search-results').html('<p>An error occurred while searching.</p>');
        },
        complete: function(XMLHttpRequest, textStatus) {
            jQuery('#search-results').removeClass('ajax-working');
            jQuery('#search-result-table tbody tr:odd').addClass('alt-row');
        }
    });
}

//  Single parcel(page) search
ApplicationUtility.prototype.parcelSearch = function(page) {
    this.last_parcel_search.page = page;

    jQuery.ajax({
        cache: true,
        data: this.last_parcel_search,
        url: 'ajax/ParcelSearch.aspx',
        beforeSend: function() {
            jQuery('#parcel-result').html('').addClass('ajax-working');
            jQuery('.tabs li').eq(2).click();
        },
        success: function(data, textStatus, XMLHttpRequest) {
            jQuery('#parcel-result').html(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            jQuery('#parcel-result').html('<p>An error occurred while searching.</p>');
        },
        complete: function(XMLHttpRequest, textStatus) {
            jQuery('#parcel-result').removeClass('ajax-working');
            jQuery('table.parcel-result-table tbody tr:odd').addClass('alt-row');
            jQuery('#agsImage, #content .parcel-item a.propPhoto').lightBox();
        }
    });
}

//  Single parcel search
ApplicationUtility.prototype.singleParcelSearch = function(searchObject){
    if(searchObject === undefined || searchObject == null){ return false; }
    
    jQuery.ajax({
        cache: true,
        data: searchObject,
        url: 'ajax/ParcelSearch.aspx',
        beforeSend: function(){
            jQuery('#parcel-result').html('').addClass('ajax-working');
            jQuery('.tabs li').eq(2).click();
        },
        success: function(data, textStatus, XMLHttpRequest){
            jQuery('#parcel-result').html(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            jQuery('#parcel-result').html('ERROR');
        },
        complete: function(XMLHttpRequest, textStatus){
            jQuery('#parcel-result').removeClass('ajax-working');
            jQuery('table.parcel-result-table tbody tr:odd').addClass('alt-row');
            jQuery('#agsImage, #content .parcel-item a.propPhoto').lightBox();
        }
    });
}

ApplicationUtility.prototype.identifyMapSearch = function(parcel){
    this.formSearch({'parcel': parcel});
}

ApplicationUtility.prototype.selectionMapSearch = function(parcelList){
    this.formSearch({'parcel': parcelList});
}
