﻿$(document).ready(function () {
    $('#faZip').watermark('ZIP Code', { className: 'faWatermark' });

    $('#faBtn').click(function () {
        var zip = $('#faZip').val();

        if (validateZip(zip)) {
            var pType = $('#faPtype').val();

            var redirectUrl = '/insurance/agentsResults.aspx?producttype=' + pType + '&ZipCode=' + zip;
            window.location.href = redirectUrl;
            return false;
        }
        else {
            return false;
        }
    });

    $('#faCloseBtn').click(function () {
        $('#divfindagentbox').fadeOut();
    });

    function validateZip(zipCode) {
        var pat = /^[0-9]{5}$/;

        if (!pat.test(zipCode)) {
            $('#faError').text('Please enter a 5 digit zip code.');
            return false;
        }
        else {
            return true;
        }

    }
});

function showFindAgentBox(elem) {
    if ($("#divfindagentbox").css('display') == 'none') {
        elem = $(elem);
        //get the position of the placeholder element
        var pos = elem.offset();
        var width = elem.width();
        var height = elem.height();
        //show the menu directly over the placeholder
        $("#divfindagentbox").css({ "left": (pos.left + width - 5) + "px", "top": pos.top + "px" });
        $('#divfindagentbox').fadeIn();
    }
    else {
        $('#divfindagentbox').fadeOut();
    }

    return false;
    
}
