﻿/* Create a namespace */
var NPBY = {};


//try to eliminate IE 6 flicker
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch (err) { }


/* Check to see if a particular querystring parameter exists */
function getAnchor() {
    var regexS = "#[A-Za-z0-9]+"; //"[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results;
};


/* Initialize when page is ready */
$(document).ready(function() {
    NPBY.enableWinPop();
    NPBY.clearInputDefaultText();
    NPBY.enableModalPop();
    NPBY.enablePrint();
});

/* jQuery unobtrusive window pop */
NPBY.enableWinPop = function() {
    $("a.poptrigger").click(function() {
        var destination = $(this).attr("href");
        var winheight;
        var winwidth;
        if ($(this).hasClass("productlocator")) {
            winheight = 598;
            winwidth = 502;
        }
        var newwindow = window.open(destination, "popup", "width=" + winwidth + ",height=" + winheight + ",resizable=true,scrollbars=yes");
        if (window.focus) { newwindow.focus() };
        return false;
    });
}; 

/* Set/clear default input value */
NPBY.clearInputDefaultText = function() {
    $('.clear-text').each(function() {
        var default_value = this.value;
        $(this).focus(function() {
            if (this.value == default_value) {
                this.value = '';
            }
        });
        $(this).blur(function() {
            if (this.value == '') {
                this.value = default_value;
            }
        });
    });
}; 

/* Modal windows */
NPBY.enableModalPop = function() {
    $(document.body).append('<div id="modal-pop" class="jqmWindow"><div class="jqmContent"><div class="jqmContentInner"><div id="modal-pop-top"></div><div id="modal-pop-bot"></div><div id="jqmAjaxTarget"></div></div></div>');
    $('#modal-pop').jqm({
        modal: true,
        ajax: '@href',
        trigger: 'a.open-modal',
        target: 'div#jqmAjaxTarget',
        toTop: true
    });
};

NPBY.enablePrint = function() {
    $('a.print').click(function() {
        if (window.print) {
            window.print();
        } else {
            alert('Your browser (or its current settings) does not support this print button. You may need to manually print this page.');
        }
        return false;
    });
};

