﻿/// <reference path="~/Scripts/jquery-1.4.4-vsdoc.js"/>

//page ready function
$(function() {
    initializeBehaviors();
});

//function that initializes the client side behaviors for all of the controls on the default page.
function initializeBehaviors() {

    //wire up the zipcode input behaviors
    if ($('#ZipCode').val() == '') {
        $('#ZipCode').val('ex. 21703');
    }
    $('#ZipCode').focus(function () {
        if ($(this).val() == 'ex. 21703')
            $(this).val('');

        $(this).css('backgroundColor', '#ffffff');
    });
    $('#ZipCode').blur(function () {
        if ($(this).val() == '')
            $(this).val('ex. 21703');

        $(this).css('backgroundColor', '#f8f8f8');
    });

    $('#ZipCode').keypress(function () {
        if (event.keyCode == 13) {

            // if we are on one of the locale specific pages, we just want to post
            // which skips the mode page
            var locale = $('#ShowLocaleSpecificPage').val();

            if (locale != undefined && locale == "True") {
                $('form').submit();
            } else {
                performSearch();
            }

            return false;
        }

        return true;
    });
    
    $('#shipmap').colorbox({ href: "/rentals/content/images/deliverymap.jpg", innerHeight: "506px", innerWidth: "645px" });
    
    //wire the search button to the async search functionality
    $('#gobutton').click(function () { performSearch(); return false; });

    //wire up the wait modals
    $(document).ajaxStart(blockUI).ajaxStop($.unblockUI);
}

function blockUI() {
    $.blockUI({ message: '<div style="height: 65px; line-height: 65px;"><h3><img src="/rentals/content/images/loading.gif" style="vertical-align: middle;"/>  Loading, Please Wait...</h3></div>' });
}

//performs an async search for stores based on the entered zipcode
function performSearch() {

    //retrieve the values necessary to perform the search
    var zipValue = $('#ZipCode').val();

    //do the search for the retail/affiliate stores
        var myUrl = "/rentals/Home/Search?ZipCode=" + zipValue;
    $.ajax({
        url: myUrl,
        success: searchCompleted,
        cache: false 
    });

    return true;
}

//callback function for when the school search has completed successfully.
function searchCompleted(data) {

    $('#replaceTarget').replaceWith(data);

    $('#shipmap').colorbox({ href:"/rentals/content/images/deliverymap.jpg", innerHeight:"506px", innerWidth:"645px" });
}




