//popup functionality - taken directly from the RAID utility.js
window.onerror = null;
var win = null;
function PopWindow(mypage, myname) {
    //closePopWin();
    winprops = 'height=500,width=820,top=30,left=0,scrollbars=1,resizable=1,status=1';
    win = window.open(mypage, myname, winprops);
}
function SizedPopWindow(mypage, myname, w, h) {
    //closePopWin();
    winprops = 'height=' + h + ',width=' + w + ',top=30,left=0,scrollbars=1,resizable=1,status=1';
    win = window.open(mypage, myname, winprops);
}
function closePopWin() {
    if (win != null) {
        if (!win.closed) {
            win.close();
            win = null;
        } else {
            win = null;
        }
    }
}

//faq toggle
function toggle(obj) {
    var el = document.getElementById(obj);
    var ar = document.getElementById(obj + 'ar');
    if (el.style.display != 'none') {
        el.style.display = 'none';
        ar.innerHTML = '<img src="/Style Library/Images/arrow_right.gif" style="width:5px;height:9px;" alt="" title="" />';
    }
    else {
        el.style.display = 'block';
        ar.innerHTML = '<img src="/Style Library/Images/arrow_down.gif" style="width:9px;height:5px;" alt="" title="" />';
    }

}

//navigation rollovers
function load(defImg) {
    if (document.getElementById(defImg) != null && document.getElementById(defImg) != 'undefined')
        document.getElementById(defImg).src = ("/en-US/PublishingImages/i/left/nav_" + defImg + "_on.gif");
}

sfHover = function () {
    var sfEls = document.getElementById("leftNav").getElementsByTagName("a");
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onmouseover = function () {
            this.className += " sfhover";
        }
        sfEls[i].onmouseout = function () {
            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}

if (window.attachEvent && document.getElementById("leftNav") != null) window.attachEvent("onload", sfHover);

// function: clear form field
function clearDefault(el) {
    if (el.defaultValue == el.value) el.value = "";
    el.setAttribute('maxLength', '9');
}



//Added by AG Moved from Omniture_methods.js

function getQueryString(parameter) {
    var queryString = window.location.search.substring(1);
    var sections = queryString.split("&");
    var store = new Array();
    for (var i = 0; i < sections.length; i++) {
        var pieces = sections[i].split("=");
        if (pieces.length > 1) {
            store[pieces[0]] = pieces[1];
        } else {
            store[pieces[0]] = null;
        }
    }
    if (parameter == null) {
        return store;
    }
    if (typeof store[parameter] != undefined) {
        return store[parameter];
    }
    return null;
}


/*solution finder Menu Tabs*/
var categoryValue;
$(document).click(function () {
    $('div#learnwhy').fadeOut(500);
});
$(document).ready(function () {

    $(".hideTab").hide();
    $('.Learn').click(function (e) {

        e.stopPropagation();
    });
    $('#learnwhy').click(function (e) {

        e.stopPropagation();
    });

    if (window.location.hash) {

        categoryValue = window.location.hash;
        getCurrentCategory(categoryValue.replace(/%20/g, '').replace(/ /g, ''));
        hashValue = categoryValue.replace('#', '');
        $('.' + hashValue).show();
        window.location.hash = hashValue;
        $(".tmenu").each(function () {

            if ($(this).find('img').attr("alt") == hashValue) {
                $(this).addClass("activeMenu");
            }
        });

    }

    else {

        $(".Bathroom").show();
        $(".tmenu").each(function () {
            if ($(this).find('img').attr("alt") == "Bathroom") {
                $(this).addClass("activeMenu");
            }
        });
    }

    $('.tmenu').click(function () {
        $('.tmenu').removeClass("activeMenu");
        var currentTab = $(this).find('img').attr("alt");
        $(".hideTab").hide();
        $("." + currentTab).show();
        $(this).addClass("activeMenu");
        window.location.hash = currentTab;
        var omni = s_gi(s_account);
        omni.channel = "SOLUTION FINDER";
        omni.prop1 = currentTab.toUpperCase();
        omni.prop2 = "";
        omni.prop3 = "";
        linkName = "SOLUTION_" + currentTab.toUpperCase();
        omni.tl(this, 'o', linkName);

    });

    $('.solution_finder_list li a').click(function () {
        window.location.replace($(this).attr('href'));
        $(".hideTab").hide();
        $('.tmenu').removeClass("activeMenu");
        hashValue = location.hash.replace('#', '');
        $("." + hashValue).show();
        $(".tmenu").each(function () {

            if ($(this).find('img').attr("alt") == hashValue) {
                $(this).addClass("activeMenu");
            }
        });


    });

    //Learn why
    $('div#learnwhy').hide();

    $('a.Learn').click(function () {
        $('div#learnwhy').fadeIn(500);
        var omni = s_gi(s_account);
        omni.channel = "SOLUTION FINDER";
        var currentProduct = $(this).parent().find('img').attr('id');
        var currentDrainCategory = $(this).attr('rel');
        omni.prop1 = currentDrainCategory.toUpperCase();
        omni.prop2 = currentProduct.toUpperCase();
        omni.prop3 = currentDrainCategory.toUpperCase() + "_" + currentProduct.toUpperCase() + "_LEARNWHY";
        omni.pageName = "SOLUTION_" + omni.prop3;
        linkName = "SOLUTION_" + omni.prop3
        omni.tl(this, 'o', linkName);

    });

    $('a.closeBtn').click(function () {
        $('div#learnwhy').fadeOut(500);
    });

    var close_anim_wrapper;

    $(".dranoimg").mouseenter(function (e) {
        $('.toolTip').hide();
        var currentWidth = $(this).find('img').attr('width');

        clearInterval(close_anim_wrapper);
        var currentLeftPosition = $(this).position().left;
        var currentTopPosition = $(this).position().top;
        currentLeftPosition = currentLeftPosition + currentWidth;
        if (currentTopPosition >= 324) {
            currentTopPosition = 320;
        }
        else {
            currentTopPosition = 70;
        }
        $(this).parent().find('.toolTip').css({ "left": currentLeftPosition + "px", "top": currentTopPosition + "px" });
        $(this).parent().find('.toolTip').show();
        var omni = s_gi(s_account);
        omni.channel = "SOLUTION FINDER";
        var currentProduct = $(this).find('img').attr('id');
        var currentDrainCategory = $(this).attr('rel')
        omni.prop1 = currentDrainCategory.toUpperCase();
        omni.prop2 = currentProduct.toUpperCase();
        omni.prop3 = currentDrainCategory.toUpperCase() + "_" + currentProduct.toUpperCase() + "_ROLL"
        omni.pageName = "SOLUTION_" + omni.prop3;
        var s_code = s.t();



    });

    $(".dranoimg").click(function () {

        var currentWidth = $(this).find('img').attr('width');
        var currentLeftPosition = $(this).position().left;
        var currentTopPosition = $(this).position().top;
        currentLeftPosition = currentLeftPosition + currentWidth;
        if (currentTopPosition >= 324) {
            currentTopPosition = 320;
        }
        else {
            currentTopPosition = 70;
        }
        $(this).parent().find('.toolTip').css({ "left": currentLeftPosition + "px", "top": currentTopPosition + "px" });
        $(this).parent().find('.toolTip').show();
        var omni = s_gi(s_account);
        omni.channel = "SOLUTION FINDER";
        var currentProduct = $(this).find('img').attr('id');
        var currentDrainCategory = $(this).attr('rel');
        omni.prop1 = currentDrainCategory.toUpperCase();
        omni.prop2 = currentProduct.toUpperCase();
        omni.prop3 = currentDrainCategory.toUpperCase() + "_" + currentProduct.toUpperCase() + "_CLICK"
        omni.pageName = "SOLUTION_" + omni.prop3;
        linkName = "SOLUTION_" + omni.prop3
        omni.tl(this, 'o', linkName);

    });
    //for learn more click
    $('.learnMore').click(function () {
        var currentdiv = $(this).getParent(4);
        var omni = s_gi(s_account);
        omni.channel = "SOLUTION FINDER";
        var currentProduct = currentdiv.find('img').attr('id');
        var currentDrainCategory = currentdiv.find('.dranoimg').attr('rel');
        omni.prop1 = currentDrainCategory.toUpperCase();
        omni.prop2 = currentProduct.toUpperCase();
        omni.prop3 = currentDrainCategory.toUpperCase() + "_" + currentProduct.toUpperCase() + "_CLICK"
        omni.pageName = "SOLUTION_" + omni.prop3;
        linkName = "SOLUTION_" + omni.prop3
        omni.tl(this, 'o', linkName);

    });


    var close_anim_wrapper;
    $(".dranoimg").mouseleave(function () {
        var currentImg = $(this);
        close_anim_wrapper = setTimeout(function () {
            $('.toolTip').hide();
        }, 500);

    });
    $('.toolTip').mouseenter(function () {

        if (close_anim_wrapper != null) {
            clearInterval(close_anim_wrapper);
        }
    });
    $('.toolTip').mouseleave(function () {
        $('.toolTip').hide();

    });


});


//Tooltip

$.urlParam = function (name) {
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (!results) {
        return 0;
    }
    return results[1] || 0;
}
function getCurrentCategory(obj) {

    switch (obj) {
        case '#BathroomSink,TuborShower':
            categoryValue = "Bathroom";
            break;
        case '#KitchenSinks':
            categoryValue = "Kitchen"
            break;
        case '#Toilets':
            categoryValue = "Toilet";
            break;

        case '#OtherSinks&Drains':
            categoryValue = "Other";
            break;

    }

}

//Function to get the nth parent
jQuery.fn.getParent = function (num) {
    var last = this[0];
    for (var i = 0; i < num; i++) {
        last = last.parentNode;
    }
    return jQuery(last);
};




