﻿//check to see if pfd base oject is not null
if (typeof (pfd) == 'undefined') {
    pfd = function() { };
}
pfd.display = function() { };
pfd.display.showSuccessDiv = function(successDiv) {
    $(successDiv).removeClass("popup");
    $(successDiv).addClass("popupSuccess");
    $("#submitSection").html("");
}


pfd.display.hideEmailAndSubmit = function() {
    var obj = document.getElementById("emailAddress");
    obj.style.visibility = "hidden";
    var obj = document.getElementById("couponSubmit");
    obj.style.visibility = "hidden";
}

pfd.display.showEmailAndSubmit = function() {
    var obj = document.getElementById("emailAddress");
    obj.style.visibility = "visible";
    var obj = document.getElementById("couponSubmit");
    obj.style.visibility = "visible";
}
pfd.display.testShowMoreButton = function() {

    var contentLength = $("#shortDescription").text().length;
    if (contentLength > 300) {
        $("#moreDescriptionLink").removeClass("MoreButtonHidden");
        $("#moreDescriptionLink").addClass("MoreButton");
    }
};
pfd.display.showMoreContent = function() {
    $("#prodDesc").removeClass("ProductDisplay");
    $("#prodDesc").addClass("ProductDisplayLong");
    $("#moreButton").removeClass("MoreButton");
    $("#moreButtton").addClass("MoreButtonHidden");
}
pfd.display.changeTitleOnCategory = function() {
    var str;
    var title;
    var title2;
    var thisUrl = location.href.toString();
    if (thisUrl.toUpperCase().indexOf('DOG-FOOD') != -1 && thisUrl.toUpperCase().indexOf('/BRAND/') != -1) {
        str = thisUrl.split(/Brand/);
        title = str[1].replace("/", " ") + " Dog Food | NationalPetPharmacy.com";
        title2 = title.replace("-", " ");
        title = title2.replace("-", " ");
        title2 = title.replace("/", " ");
        title = title2.replace("/", " ");
        document.title = title.replace("-", " ");
    } else if (thisUrl.toUpperCase().indexOf('CAT-FOOD') != -1 && thisUrl.toUpperCase().indexOf('/BRAND/') != -1) {
        str = thisUrl.split(/Brand/);
        title = str[1].replace("/", " ") + " Cat Food | NationalPetPharmacy.com";
        title2 = title.replace("-", " ");
        title = title2.replace("-", " ");
        title2 = title.replace("/", " ");
        title = title2.replace("/", " ");
        document.title = title2.replace("-", " ");
    }
}

pfd.display.ShowPopup = function (cartDivId) {
    var obj = document.getElementById(cartDivId);
    obj.style.visibility = "visible";
    obj.style.display = "block";
    pfd.display.centerPopupInClient(cartDivId);
    $("#bkgPopup").fadeIn("fast");
}

pfd.display.HidePopup = function (cartDivId) {
    var obj = document.getElementById(cartDivId);
    obj.style.visibility = "hidden";
    obj.style.display = "none";
    $("#bkgPopup").fadeOut("fast");

}
pfd.display.centerPopupInClient = function(clientId) {
    var heightFudge = 2.0;
    var element = $("#" + clientId);
    var jWin = $(window);

    var x = jWin.width() / 2 - element.outerWidth() / 2;
    var y = jWin.height() / heightFudge - element.outerHeight() / 2;

    element.css("left", x + jWin.scrollLeft());
    element.css("top", y + jWin.scrollTop());
}
pfd.display.showNppCommercialPopup = function (URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=1,statusbar=0,menubar=0,resizable=0,width=500,height=250,left = 262,top = 259');");
}

pfd.display.showInstantCoupon = function () {
    //$("#popupGround").show();
    pfd.display.ShowPopup('popup');
    
    if ($.cookie("coupon") == "true") {
        pfd.display.showSuccessDiv("#popup");
    }

    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1)
    }

    if (ieversion < 7) {
        pfd.display.showSuccessDiv("#popup");
    }

}
pfd.display.slideToggleVisibility = function (id) {
    $('#' + id).slideToggle("slow");

}
pfd.display.show = function (id) {
    $('#' + id).show("slow");
}
pfd.display.hide = function (id) {
    $('#' + id).hide("slow");
}
