function getCookie(mdp_partner)
{
    var prefix = mdp_partner + "=";
    var cookieStartIndex = document.cookie.indexOf(prefix);
    if (cookieStartIndex == -1)
            return null;
    var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
            cookieEndIndex = document.cookie.length;
    return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}
    
function authUser()
{
    var remodelingLoginUrl = "https://secure.remodelingcenter.com/common/profile/login1.jsp?regSource=8672&returnURL=";
    var kitchenLoginUrl = "https://secure.kitchenbathideas.com/common/profile/login1.jsp?regSource=8621&returnURL=";
    var loginUrl = "";
    
    if ( document.location.host.toLowerCase().indexOf( "remodelingcenter.com" ) >= 0 )
        loginUrl = remodelingLoginUrl;
    else if ( document.location.host.toLowerCase().indexOf( "kitchenbathideas.com" ) >= 0 )
        loginUrl = kitchenLoginUrl;
    else if ( document.location.host.toLowerCase().indexOf( "localhost" ) >= 0 )
        return;
            
    var  currentLocation = parent.location.href;
    if ( getCookie("mdp_partner") == null )
    {
        parent.location.href = loginUrl + parent.location.href;
        return false;
    }
    var sCookie = getCookie("mdp_partner");
    var aCookie = sCookie.split("|");
    if ( aCookie != null && aCookie.length >= 3 && aCookie[3] != null && aCookie[3] != 'Y' )
    {
        document.location.href = loginUrl + parent.location.href;
        return false;
    }
}

function getDesignName()
{
    var locationParts = document.location.pathname.split("/");
    if ( locationParts.length > 0 )
        return locationParts[locationParts.length-1];
    return "";
}

function callCategoryChanged( categoryId, subCategoryId )
{   
    if ( categoryId == 1 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab1'); // Appliances and Electronics
    else if ( categoryId == 2 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab2'); // Architectural Elements
    else if ( categoryId == 3 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab3'); // Cabinets and Storage
    else if ( categoryId == 4 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab4'); // Decor and Accessories
    else if ( categoryId == 5 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab5'); // Floors, Walls and Countertops
    else if ( categoryId == 6 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab6'); // Furniture
    else if ( categoryId == 8 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab7'); // Landscape and Outdoors
    else if ( categoryId == 7 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab8'); // Lighting, Fans and Electrical
    else if ( categoryId == 9 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab9'); // Plumbing Fixtures
    else if ( categoryId == 10 )
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab10'); // Windows and Doors
    else
        sendPageEvent ('','MyDesignIn_' + getDesignName() + '_Tab11'); // Other
}

// call autoUser when script loads
authUser();

//Note: The follwing is Fix for undefined RCMenu class from Omniture.
function CMenu(){}
CMenu.prototype.showMenu = function(x) {}

if ( typeof RCMenu == "undefined" )
{
    var RCMenu = new CMenu();
}

            
/*Script goes here that redirects back to 
https://secure.kitchenbathideas.com/common/profile/login1.jsp?regSource=8621 if cookie is 
not found, or if 'Y' is NOT found as the character after three '|' characters. The Reg 
Source for this is being requested so that after login in redirects back to the URL it came 
from instead of exclusive offers */

/*Script goes here that allows MyDesignIn page to continue loading if a 'Y' is found at the character 
after three '|' characters*/