﻿/*
Code specific to the Multihome page. Features persistent return.
*/

var mh$name = "_mhk";

// if cookie pre-exists, go (hard) to corresponding page
function mh$GoCookie() {
    var c = $.cookie(mh$name);
    if (c) {
        // if "init" param passed on the URL, kill the cookie
        if (window.location.href.indexOf("init=1") != -1) {
            mh$ClearCookie();
            return;
        }
        mh$Go(c, true);
    }
}

function mh$SetCookie(key) {
    $.cookie(mh$name, key, { expires: 365, path: '/' });
}

function mh$ClearCookie() {
    $.cookie(mh$name, null, { path: '/' });
}

function mh$ItemClicked(key) {
    // if associated checkbox is checked, set the cookie and go there hard.
    var ch = $('#cbAlways_' + key).attr('checked');
    if (ch) {
        mh$SetCookie(key);
        mh$Go(key, true);
    }

    // otherwise, clear the cookie and go softly to the destination.
    mh$Go(key, false);
}

function mh$Go(strKey, bHard) {
    var dest = mh$data[strKey];
    if (dest && dest.length && dest.length > 0) {
        if (bHard) {
            location.replace(dest);
        } else {
            location = dest;
        }
    }
}   
