﻿function addBookmark(i)
{
    if (typeof (_gat) == 'object')
    {
        var pageTracker = _gat._getTracker("UA-2263513-3");
        pageTracker._trackPageview('/Bookmark/Store');
    }
    if (document.all)
    {
        window.external.AddFavorite(document.getElementById("f_storB" + i).value, document.getElementById("f_storN" + i).value + " - Do The Bright Thing");
    } else if (window.sidebar)
    { // Firefox
        window.sidebar.addPanel(document.getElementById("f_storN" + i).value + " - Do The Bright Thing", document.getElementById("f_storB" + i).value, '');
    } else if (window.opera && window.print)
    {
        window.external.AddFavorite(document.getElementById("f_storB" + i).value, document.getElementById("f_storN" + i).value + " - Do The Bright Thing");
    }
    if (vIsLogged == 1)
    {
        sendBookmarkAjax(i);
    } else
    {
        ShowLoginRegisterDiv("bookmarkStore", i);
        return;
    }
}

function sendBookmarkAjax(i)
{
    $.ajax({
        url: vPageAddr + '/pages/BookmarkAjax.aspx',
        type: 'POST',
        async: false,
        data: "storeId=" + document.getElementById("f_storId" + i).value,
        beforeSend: function () {
        },
        success: function (data) {
            if (checkBrows()) {
                document.getElementById("bookmarkBtn_" + i).setAttribute("style", "cursor:default;");
                document.getElementById("bookmarkBtn_" + i).setAttribute("class", "buttonSmallCheckedFlat storeButtonA");
                document.getElementById("bookmarkBtn_" + i).removeAttribute("href");
            } else {
                document.getElementById("bookmarkBtn_" + i).setAttribute("class", "buttonSmallChecked storeButtonA");
            }
        },
        complete: function () {
        }
    });
}

function addBookmarkLogin(i)
{
    if (vIsLogged == 1)
    {
        sendBookmarkAjax(i);
    }
}

function scaleMerchant(i)
{
    if (typeof i.style === "undefined")
    {
        //alert("something is undefined");
    }
    else
    {
        var ow = i.width;
        var oh = i.height;
        if (i.width > 190)
        {
            i.width = 190;
            i.height = 190 / (ow / oh);
        }
        if (i.height > 75)
        {
            i.height = 75;
            i.width = 75 / (oh / ow);
        }
        i.style.marginTop = "" + ((80 - i.height) / 2) + "px";
        i.style.visibility = "visible";
    }
}

function displButtonsMerchant(i) {
    document.getElementById("fa_st_" + i).style.display = "none";
    document.getElementById("fa_st2_" + i).style.display = "block";
}

function hideButtonsMerchant(i) {
    document.getElementById("fa_st2_" + i).style.display = "none";
    document.getElementById("fa_st_" + i).style.display = "block";
}

function removeFavMerchant(i) {
    document.getElementById("s_storeId").value = document.getElementById("f_storId" + i).value;
    document.getElementById("sendFormRemoveFav").submit();
}

function goToMerchant(i) {
    document.getElementById("s_storName").value = document.getElementById("f_storA" + i).value;
    document.getElementById("s_storAff").value = document.getElementById("f_storAff" + i).value;
    document.getElementById("sendFormGoToMerchant").submit();
}

function checkBrows() {
    if (document.all || window.sidebar || (window.opera && window.print)) {
        return false;
    } else {
        return true;
    }
}

function changeFavBtn(i) {
}
