﻿// preload ajax loading image for buttons
$(document).ready(function(){
    $('<img />').attr('src', '/Content/Images/button_busy.gif');
});

(function($){
    $.fn.DeactivateAjaxButton = function(){
        return this.each(function(){
            if($(this).is(':visible')){
                var clone = $('<a href="" />').attr('id', '_' + $(this).attr('id')).click(function(){ return false; });
                clone.addClass('button').addClass('_deactivatedAjaxButton').css({
                    position: 'absolute',
                    height: $(this).height() + 'px',
                    width: $(this).width() + 'px',
                    top: $(this).offset().top + 'px',
                    left: $(this).offset().left + 'px',
                    backgroundImage: 'url(/Content/Images/button_busy.gif)',
                    backgroundRepeat: 'no-repeat',
                    backgroundPosition: 'center center'
                }).appendTo(document.body);
            }
        });
    };
    
    $.fn.ReactivateAjaxButton = function(){
        return this.each(function(){
            $('#_' + $(this).attr('id')).remove();
        });
    };
    
    $.ReactivateAllAjaxButtons = function(){
        $('._deactivatedAjaxButton').remove();
    };
})(jQuery);

// alert box
function alertBox(title, message, allowClose){
    var abox = $('<div id="AlertBox" />').addClass('jqmWindow').jqm({
        modal: !allowClose,
        closeClass: 'jqmClose',
        onHide: function(hash){
            hash.o.remove();
            hash.w.remove();
        }
    });
    abox.append($('<h2 />').html(title)).append($('<p />').html(message));
    if(allowClose){
        abox.append(
            $('<div />').addClass('buttons').append(
                $('<a href="" onclick="return false;" />').addClass('button').html('Close').addClass('jqmClose')));
    }
    abox.appendTo(document.body).jqmShow();
}

function popupListing(id, mls){
    var day = new Date();
    var winid = day.getTime();
    if(!mls)
        var url = '/Listings/Details?id=' + id;
    else
        var url = '/Listings/MLSDetails?id=' + id;
    eval('page' + winid + '=window.open(url,\'' + id + '\',\'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=900,height=600\');');
};
