function fieldBlur(field_id, default_value) {
    if ($('#' + field_id).attr("value") == '') {
        $('#' + field_id).attr("value", default_value);
    }
}

function fieldFocus(field_id, default_value) {
    if ($('#' + field_id).attr("value") == default_value) {
        $('#' + field_id).attr("value", "");
    }
}

function contentDropdownOn(id) {
    document.getElementById(id).style.display = '';
    //	change_image(img_src, img_id);
    window.contentDropdownMouseIsOver = true;
    if (window.contentDrdopdownId && window.contentDrdopdownId != id) {
        hideDropdown(true);
    }
    window.contentDrdopdownId = id;
}

function contentDropdownOff(id) {
    window.contentDropdownMouseIsOver = false;
    //	window.contentDrdopdownImgId = img_id;
    //	window.contentDrdopdownImgSrc = img_src;
    setTimeout('hideDropdown(false)', 100);
}

function hideDropdown(force) {
    if (!window.contentDropdownMouseIsOver || force) {
        document.getElementById(contentDrdopdownId).style.display = 'none';
    }
}

var tabsStat = 'play';

function startStopSlider() {
    if (window.tabsStat == 'play') {
        $("div.tabs").tabs().stop();
        window.tabsStat = 'stop';
        $("#play-stop-img").attr("src", "/images/butt-stop-active.png");
    } else {
        $("div.tabs").tabs().play();
        window.tabsStat = 'play';
        $("#play-stop-img").attr("src", "/images/butt-stop.png");
    }
}

function setupExternalLinks() {
    var links = document.getElementsByTagName('a');
    var linkcount = 1;
    var setup_link;
    for (var i = links.length; i != 0; i--) {
        setup_link = false;
        var a = links[i - 1];
        if (!a.href) continue;

        // Track external links
        if (a.href.indexOf('http') != -1 &&
			a.href.indexOf(window.location.hostname) == -1 &&
			!excludeUrl(a.href)
			) {
            url = a.href;
            a.onclick = function() {

                // select the overlay element - and "make it an overlay"
                $('#ok-continue').attr('href', this.href);
                $("#facebox").overlay({

                    // custom top position
                    top: 272,

                    // some expose tweaks suitable for facebox-looking dialogs
                    expose: {

                        // you might also consider a "transparent" color for the mask
                        color: '#000',

                        // load mask a little faster
                        loadSpeed: 200,

                        // highly transparent
                        opacity: 0.7
                    },

                    // disable this for modal dialog-type of overlays
                    closeOnClick: false,

                    // we want to use the programming API
                    api: true

                    // load it immediately after the construction
                }).load();

                return false;
            }

            linkcount++;

        }
    }
}

function excludeUrl(url) {
    var excludeUrls = Array(
			  'http://www.multiplemyeloma.org',
			  'http://multiplemyeloma.org'
			  );

    for (var l = 0; l < excludeUrls.length; l++) {
        if (url.indexOf(excludeUrls[l]) == 0) {
            return true;
        }
    }

    return false;
}


function openShare() {
    $("#popup-share").overlay({

        // custom top position
        top: 272,

        // some expose tweaks suitable for facebox-looking dialogs
        expose: {

            // you might also consider a "transparent" color for the mask
            color: '#000',

            // load mask a little faster
            loadSpeed: 200,

            // highly transparent
            opacity: 0.7
        },

        // disable this for modal dialog-type of overlays
        closeOnClick: false,

        // we want to use the programming API
        api: true

        // load it immediately after the construction
    }).load();

    return false;
}

function openStory(id, top) {
    if (!top) {
        top = 100
    }
    $("#" + id).overlay({
        top: top,
        expose: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.7
        },
        closeOnClick: false,
        api: true
    }).load();

    return false;
}

function toggleDef(id) {
    if ($('#' + id).is(":visible")) {
        $('#' + id).hide();
        $('#' + id + '-anchor').attr('innerHTML', 'view <img src="/images/down.jpg" width="6" height="6" alt="" id="bm-img" />');
    } else {
        $('#' + id).show();
        $('#' + id + '-anchor').attr('innerHTML', 'close <img src="/images/up.jpg" width="6" height="6" alt="" id="bm-img" />');
    }
}

function homeTab(id) {
    if (id == 'support-group') {
        $('#home-tab-support-group').attr('src', '/images/tab-support-group-selected.jpg');
        $('#home-tab-blog').attr('src', '/images/tab-blog.jpg');
        $('#home-tab-c-support-group').show();
        $('#home-tab-c-blog').hide();
    } else {
        $('#home-tab-support-group').attr('src', '/images/tab-support-group.jpg');
        $('#home-tab-blog').attr('src', '/images/tab-blog-selected.jpg');
        $('#home-tab-c-support-group').hide();
        $('#home-tab-c-blog').show();
    }
}

function mouseOverTab(id) {
    if (id == 'support-group') {
        if ($('#home-tab-support-group').attr('src') == '/images/tab-support-group.jpg') {
            $('#home-tab-support-group').attr('src', '/images/tab-support-group-on.jpg');
        }
    } else {
        if ($('#home-tab-blog').attr('src') == '/images/tab-blog.jpg') {
            $('#home-tab-blog').attr('src', '/images/tab-blog-on.jpg');
        }
    }
}

function mouseOutTab(id) {
    if (id == 'support-group') {
        if ($('#home-tab-support-group').attr('src') == '/images/tab-support-group-on.jpg') {
            $('#home-tab-support-group').attr('src', '/images/tab-support-group.jpg');
        }
    } else {
        if ($('#home-tab-blog').attr('src') == '/images/tab-blog-on.jpg') {
            $('#home-tab-blog').attr('src', '/images/tab-blog.jpg');
        }
    }
}

function clearRadios(name) {

    $("input[name='" + name + "']").removeAttr('checked');

}

function selectNav() {
    var section = navGetCurrentSection();
    if (section) {
        $('#nav-' + section).attr('src', '/images/nav-' + section + '-on.jpg');
    }

    return true;
}

function expandWebcast(id) {
    if ($('#' + id + 'c').css('display') == 'none') {
        $('#' + id + 'i').attr('src', '/images/btn-close2.jpg');
    } else {
        $('#' + id + 'i').attr('src', '/images/btn-view.jpg');
    }
    $('#' + id + 'c').slideToggle();
}

function navGetCurrentSection() {
    parts = window.location.href.split("/");
    var section = false;
    if (parts[3]) {
        section = parts[3];
        if (section == 'working-with-your-team') {
            section = 'working';
        }
        if (section == 'patient-experience') {
            section = 'patient';
        }
    }
    return section;
}

function navOver(id, src) {
    $('#' + id).attr('src', src);
}

function navOut(id, src) {
    section = navGetCurrentSection();
    if ('nav-' + section == id) {
        return;
    }

    $('#' + id).attr('src', src);
}

function runOnPageFooter() {
    $('.expandable-area-pic-left > span > a').bind('click', function() {
        if ($(this).html() == "view") {
            $(this).parent().children('img').attr('src', '/images/arrow-close.jpg');
            $(this).parent().parent().parent().children('.box-expand').slideDown('fast');
            $(this).html('close');
        } else {
            $(this).parent().children('img').attr('src', '/images/arrow-view.gif');
            $(this).parent().parent().parent().children('.box-expand').slideUp('fast');
            $(this).html('view');
        }
        return false;
    });

    $('.open-expandable-area-pic-left').bind('click', function() {
        if ($('#' + $(this).attr('rel')).html() == "view") {
            $('#' + $(this).attr('rel')).click();
        }
        return false;
    });

    $('.close-expandable-area-pic-left').bind('click', function() {
        $('#' + $(this).attr('rel')).click();
        return false;
    });


}

var glossary_terms = Array(
		'anemia',
		'A low level of red blood cells or hemoglobin; may be characterized by paleness, weakness, or shortness of breath with activity',
		'angiogenesis',
		'Refers to the growth of new blood vessels needed enable tumors to grow<sup><b>39</b></sup>',
		'antibody',
		'Proteins (known as immunoglobulins) that circulate in the blood to protect against infections by recognizing and binding to foreign substances such as germs. This signals to other parts of the immune system to destroy germs or other targets',
		'apoptosis',
		'Programmed cell death<sup><b>40</b></sup>',
		'bone marrow',
		'Soft, sponge-like area in the center of large bones that contains hematopoietic stem cells for production of white blood cells, red blood cells, and platelets',
		'cytokines',
		'A substance made by an immune cell',
		'femur',
		'Long bone of the leg (thigh bone)',
		'humerus',
		'Upper arm bone',
		'indolent',
		'Slow to develop',
		'M-protein',
		'An antibody found in unusually large amounts in the blood or urine of people with multiple myeloma and other types of plasma cell tumors. Also called monoclonal protein.',
		'Monoclonal gammopathy of undetermined significance',
		'A benign condition in which the levels of M-proteins are higher than normal. Also called MGUS<sup><b>41</b></sup>. ',
		'osteolytic lesions',
		'Breakdown of the bone',
		'plasma cells',
		'A type of white blood cell that produces antibodies',
		'platelet',
		'A type of blood cell that helps prevent bleeding by causing blood clots to form. Also called a thrombocyte.',
		'red blood cells',
		'A cell that carries oxygen throughout the body. Also called erythrocyte<sup><b>42</b></sup>. ',
		'smoldering myeloma',
		'A slow-developing myeloma that often causes no symptoms<sup><b>43</b></sup>. ',
		'sternum',
		'The long flat bone that forms the center front of the chest. Also called the breastbone<sup><b>44</b></sup>. ',
		'white blood cells (WBCs)',
		'Infection-fighting blood cells made in the bone marrow. There are two main types of white blood cells: lymphocytes and myeloid cells. As some myeloid cells and some lymphocytes only live for a few days, the bone marrow is constantly making new cells to replace the old ones in the blood. The bone marrow normally makes millions of blood cells every day. When they are mature enough to leave the bone marrow, the white blood cells are released into the bloodstream to circulate around the body. Lymphocytes, unlike the myeloid cells, also circulate in the lymphatic system.'
);

function glossary_markTerms(obj) {
    $(obj).replace('a', 'b');
}

function openUserForm(link, container) {
    if ($('#' + container).is(':visible')) {
        $(link).children('span').html('Edit');
        $('#' + container).slideUp();      
    } else {
        $(link).children('span').html('Cancel');
        $('#' + container).slideDown();
    }
}

function showEditButtons(edit_container, delete_container) {
    if (!$('#' + edit_container).is(':visible')) {
        openUserForm(this, edit_container);
        $('#' + delete_container + '-link').hide();
    }
}

// ---------Rating related scripts--------//////
function DisplayRatings() {
    $('a.ratingBar').each(function() {
        var $this = $(this);
        $this.raty({
            showCancel: false,
            readOnly: false,
            showHalf: true,
            start: $this.attr('value'),
            onClick: function(score) {                
                document.getElementById("ctl00_MainContentPlaceHolder_ratingLinkID").value = $this.attr('rel');
                document.getElementById("ctl00_MainContentPlaceHolder_ratingLinkVal").value = score;
              
            }
        });
    });
}

function BrokenLinkMessage() {
    $("#brokenlink").overlay({

        // custom top position
        top: 272,
        // some expose tweaks suitable for facebox-looking dialogs
        expose: {
            // you might also consider a "transparent" color for the mask
            color: '#000',
            // load mask a little faster
            loadSpeed: 200,
            // highly transparent
            opacity: 0.7
        },
        // disable this for modal dialog-type of overlays
        closeOnClick: false,
        // we want to use the programming API
        api: true
        // load it immediately after the construction
    }).load();

    return false;
}

//------Manager Users scripts----------
function ViewEdit(id) {
    HideEdit();
    CancelUser();
    var divid = 'divEdit' + id;
    $('#' + divid).show();

    var edit = 'edit' + id;
    var cancel = 'cancel' + id;
    $('#' + edit).hide();
    $('#' + cancel).show();
}

function SetUserDetails(id) { 
    var divid = 'millennium_user_form' + id;
    var name = $('#hdnName' + id).attr('value');
    $('#' + divid).find('INPUT.Name').val(name);

    var password = $('#hdnPassword' + id).attr('value');
    $('#' + divid).find('INPUT.Password').val(password);
   
}

function CancelEdit(id) {
    var divid = 'divEdit' + id;
    $('#' + divid).hide();

    var edit = 'edit' + id;
    var cancel = 'cancel' + id;
    $('#' + edit).show();
    $('#' + cancel).hide();
}


function HideEdit() {

    $('DIV.divUserEdit').each(function() {
        var id = $(this).attr('id');
        $('#' + id).hide();

    });

    $('a.userEdit').each(function() {
        var id = $(this).attr('id');
        $('#' + id).show();

    });
    $('a.userCancel').each(function() {
        var id = $(this).attr('id');
        $('#' + id).hide();

    });
}

function AddUser() {
    $("a#btnAdd").hide();
    $("DIV#AddUser").show();
    $("a#btnCancel").show();
    HideEdit();
}
function CancelUser() {
    $("a#btnAdd").show();
    $("DIV#AddUser").hide();
    $("a#btnCancel").hide();
}
//------ End of Manager Users-----------
// --------Manage Topics scripts----------
function AddTopic() {
    $("#btnAddTopic").hide();
    $("#AddTopicDiv").show();
    $("#btnCancelTopic").show();
    HideTopicEdit();
}
function CancelTopic() {
    $("#btnAddTopic").show();
    $("#AddTopicDiv").hide();
    $("#btnCancelTopic").hide();
}

function ViewTopicEdit(id) {  
    HideTopicEdit();
    CancelTopic();
    var divid = 'divTopicEdit' + id;
    $('#' + divid).show();    

    var edit = 'topicedit' + id;
    var cancel = 'topiccancel' + id;
    $('#' + edit).hide();
    $('#' + cancel).show();
}

function SetTopicName(id) {

    var divId = 'divTopic' + id;
    var text = $('#hdnTopicName' + id).attr('value');
    $('#' + divId).find('INPUT.TopicDescription').val(text);
        
  
}

function CancelTopicEdit(id) {
    var divid = 'divTopicEdit' + id;
    $('#' + divid).hide();

    var edit = 'topicedit' + id;
    var cancel = 'topiccancel' + id;
    $('#' + edit).show();
    $('#' + cancel).hide();
}


function HideTopicEdit() {

    $('DIV.divtopicedit').each(function() {
        var id = $(this).attr('id');
        $('#' + id).hide();

    });

    $('a.topicedit').each(function() {
        var id = $(this).attr('id');
        $('#' + id).show();

    });
    $('a.topiccancel').each(function() {
        var id = $(this).attr('id');
        $('#' + id).hide();

    });
}
//------ End of Manager Topics-----------

//Start: Script for admin tool 

function close_facebox(id) {
    if (id == "addlink") {
        $('#' + id).css('display', 'none');
        $('#' + id).overlay().close();
    } else if (id == "edit-topics") {
        $('#' + id).css('display', 'none');
        $('#' + id).overlay().close();
    }
    else {
        $('#' + id).css('display', 'none');
        $('div:last').css('display', 'none');
    }
}

//End: Script for admin tool
