﻿var interval_id, zipcode;

var GB_ROOT_DIR = "/App_Themes/PetSafe/javascripts/greybox/";

CheckGreyBox();

function CheckGreyBox() {
    interval_id = setInterval("isGreyBoxLoaded()", 500);
}

function addEvent (el, evStr, handler)
{
    if (el.addEventListener)
        el.addEventListener(evStr, handler, false);
    else
    {
        el.attachEvent("on" + evStr, handler);
    }
}

function ToggleValueFocus ()
{
    if (zipcode.value == defaultValue)
        zipcode.value = "";
}

function ToggleValueBlur ()
{
    if (zipcode.value == "")
        zipcode.value = defaultValue;
}

function ValidateZip (AlertErrBool)
{
    if (zipcode == null || !zipRegExp.test(GetZip()))
    {
        if (AlertErrBool)
            alert(invalidZipMsg);
        return false;
    } else return true;
}

function GetZip ()
{
    return Trim(zipcode.value).toUpperCase();
}

function Trim (str)
{
    return str.replace(/^\s*(.+)/, "$1").replace(/\s*$/, "");
}

function getLocalDealerURL() {
    var zipcode = document.getElementById("zipcode").value;
    return "http://wwww.petsafe.net/dealer_locator/4dub_view_dealers_" + (isIntl ? "canada" : "remote") + ".php?zipcode=" + zipcode + "&product=" + (ddl ? ddl.value : selectedSKU);
}

function showLocalDealerGB() {
    document.body.focus();
    if (ValidateZip(false))
    { return GB_showCenter('Dealer Locator', getLocalDealerURL(), 453, 715); }
}

function enter_pressed(e) {
    if (e != null && e.keyCode == 13) {
        if (ValidateZip(true))
            showLocalDealerGB();
        return true;
    } else return false;
}