﻿//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 | PetFoodDirect.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 | PetFoodDirect.com";
        title2 = title.replace("-", " ");
        title = title2.replace("-", " ");
        title2 = title.replace("/", " ");
        title = title2.replace("/", " ");
        document.title = title.replace("-", " ");
    }
}

var pfdDisplayShowPopupFunc = function (jObj) {
    // show the object
    $(jObj).css({
        visibility: "visible",
        display: "block",
        position: "absolute",
        "z-index": 1000
    });

    // move the object to the end of the body doc
    $(jObj).prependTo("BODY");

    // if browser is IE, we need to insert the ajax loader into the div
    var isIE = $.browser.msie;
    var version = parseInt($.browser.version, 10);
    if (isNaN(version)) { version = 7; }

    var objId = $(jObj).attr("id");

    if (isIE && version <= 9 && typeof (objId) != "undefined" && objId != null && objId.indexOf("cartProgressBar") > -1) {
        $(jObj).html('<img src="/images/ajax-loader.gif">');
    }

    // modulate the center functionality (so we can call it on resize/scroll)
    var centerIt = function () { pfd.display.centerPopupInClient(jObj); };

    // handle when the user resizes their screen
    $(window).resize(centerIt);

    // handle when the user scrolls the document
    if (isIE) {
        $(window).scroll(centerIt);
    } else {
        $(document).scroll(centerIt);
    }
    // activate the modal to the center of the current screen
    centerIt();

    // fade in the background bg
    $("#bkgPopup").fadeIn("fast");
};

pfd.display.ShowPopup = function (cartDivId) {
    var obj = document.getElementById(cartDivId);
    pfdDisplayShowPopupFunc(obj);
};

pfd.display.ShowPopupBySelector = function (selectorText) {
    pfdDisplayShowPopupFunc(selectorText);
};

var pfdDisplayHidePopupFunc = function (obj, removeBkPopup) {
    var jObj = $(obj);
    if (jObj.length > 0) {
        jObj.css({
            visibility: "hidden",
            display: "none"
        });
    }
    if (removeBkPopup == null || removeBkPopup == true) {
        $("#bkgPopup").fadeOut("fast");
    }
};

pfd.display.HidePopup = function (cartDivId, removeBkPopup) {
    var obj = document.getElementById(cartDivId);
    pfdDisplayHidePopupFunc(obj);
}

pfd.display.HidePopupBySelector = function (selector, removeBkPopup) {
    var jObj = $(selector);
    pfdDisplayHidePopupFunc(jObj, removeBkPopup);
};

pfd.display.centerPopupInClient = function (selector) {
    var heightFudge = 2.0;
    var element = null;
    element = $(selector);
    if (element.length == 0) { element = $("#" + selector); }
    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.slideToggleVisibility = function (id) {
    $('#' + id).slideToggle("slow");

}
pfd.display.show = function (id) {
    $('#' + id).show("slow");
}
pfd.display.hide = function (id) {
    $('#' + id).hide("slow");
}
pfd.display.showPopupforVideo = 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');");
}

