﻿var loc = location.href;
var embededSWF;
var attributes = false;
var flashvars = {
    autostart: 'true',
    path: loc
};
var params = {
    base: "/_flash/",
    wmode: 'transparent',
    allowscriptaccess: 'always'
};
var embedHandler = function(e) {
    if (e.success) {
        embededSWF = document.getElementById("flashHome");
    }
};

function hideModal() {
    var mpe = $find('programmaticModalPopupBehavior');
    if (mpe != null) { mpe.hide(); }
}
function showModal() {
    var mpe = $find('programmaticModalPopupBehavior');
    mpe.show();
    pauseVideo();
}

$(document).ready(function () {

    $('.link-isi').click(function () {
        $('html, body').animate({
            scrollTop: $("#isi_top").offset().top
        }, 1000);
    });

    $('.link-isi2').click(function () {
        $('html, body').animate({
            scrollTop: $("#isi_top").offset().top
        }, 1000);
    });

    $('.see-isi').click(function () {
        $('html, body').animate({
            scrollTop: $("#isi_top").offset().top
        }, 1000);
    });

    $('#facts1T').click(function () {
        $('#facts-1').slideDown('slow');
    });
    $('#facts2T').click(function () {
        $('#facts-2').slideDown('slow');
    });
    $('#facts3T').click(function () {
        $('#facts-3').slideDown('slow');
    });
    $('#facts1F').click(function () {
        $('#facts-1').slideDown('slow');
    });
    $('#facts2F').click(function () {
        $('#facts-2').slideDown('slow');
    });
    $('#facts3F').click(function () {
        $('#facts-3').slideDown('slow');
    });
    $('#facts1Close').click(function () {
        $('#facts-1').slideUp('slow');
    });
    $('#facts2Close').click(function () {
        $('#facts-2').slideUp('slow');
    });
    $('#facts3Close').click(function () {
        $('#facts-3').slideUp('slow');
    });

    $('.showMenu').mouseenter(function () {
        $(this).children('div').fadeIn('fast'); var arrowSrc = $(this).children('a').children('img').attr('src'); $(this).children('a').children('img').attr('src', arrowSrc.replace('_grey', '_white')); var mHeight = $(this).find('ul').height(); $(this).find('.menuContentPop').css('height', mHeight); $(this).find('.menuPop').css('height', mHeight); $(this).find('.menuContentPop').find('div').css('margin-top', vAlign($(this).find('.menuContentPop').find('div'))); $(this).find('.menuContentPop_rev').css('height', mHeight); $(this).find('.menuPop_rev').css('height', mHeight); $(this).find('.menuContentPop_rev').find('div').css('margin-top', vAlign($(this).find('.menuContentPop_rev').find('div'))); var eID = $(this).children('div'); if ($(eID).attr('id') == 'menuContent_res' || $(eID).attr('id') == 'menuContent_cm' || $(eID).attr('id') == 'menuContent_uri') $(eID).offset({ left: $(eID).parent().offset().left - $(eID).width() + $(eID).parent().width() }); $(eID).find('#subMenu4').offset({ left: $(eID).parent().offset().left + $(eID).parent().width() - $(eID).find('#subMenu4').width() });
    }).mouseleave(function () { $(this).children('div').hide(); var arrowSrc = $(this).children('a').children('img').attr('src'); $(this).children('a').children('img').attr('src', arrowSrc.replace('_white', '_grey')); });

    $('.subMenus li').mouseenter(function () {
        var eID = $(this).children('div'); var arrowSrc = $(this).find('img').attr('src'); $(this).find('img').attr('src', arrowSrc.replace('_white', '_purple')); $(eID).show(); $(eID).find('div').css('margin-top', vAlign($(eID).find('div'))); var offSetLeft; if ($(this).parent().attr('id') == 'subMenu4') offSetLeft = $(this).parent().offset().left - $(eID).children('div').width() - 25; else offSetLeft = $(this).parent().offset().left + $(this).parent().width(); $(eID).offset({ top: $(this).parent().offset().top, left: offSetLeft });
    }).mouseleave(function () { var eID = $(this).children('div'); $(eID).hide(); var arrowSrc = $(this).find('img').attr('src'); $(this).find('img').attr('src', arrowSrc.replace('_purple', '_white')); });

});

function openWin(arg_url, arg_name, arg_width, arg_height, arg_scroll, arg_resize) {
    var iMyWidth;
    var iMyHeight;
    iMyWidth = (window.screen.width / 2) - (200 + 10);
    iMyHeight = (window.screen.height / 2) - (100 + 50);

    var features = "scroll:" + arg_scroll + ";resizable:" + arg_resize + ";dialogWidth:" + arg_width + "px;dialogHeight:" + arg_height + "px;center:yes;unadorned:yes;status=no";
    //var win = window.showModalDialog(arg_url, arg_name, 'scrollbars=' + arg_scroll + ',resizable=' + arg_resize + ',width=' + arg_width + ',height=' + arg_height + ",left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight);
    var win = window.showModalDialog(arg_url, arg_name, features);
}

function printGuide() {
    //window.open("discussion_guide_print.aspx", "printGuide", 'width=917,height=600,scrollbars=yes,resizable=no,modal=yes');
    parent.location.href = "discussion_guide_print.aspx";
}

function closeWin() {
    window.close();
}

function printWin() {
    try {
        document.execCommand('print', false, null);  //To fix IE7 iFrame print problem
    }
    catch (e) {
        window.print();
    }
}

function confirmExit(url) {
    openWin('/helpful-resources/exit.aspx?continueUrl=' + url, 'exitWin', 416, 320, "yes", "no");
}

function unavailableDownload() {
    openWin('/helpful-resources/unavailable_download.aspx', 'noDownload', 416, 320, "yes", "no");
    return false;
}
function unavailableDownload2() {
    openWin('/helpful-resources/unavailable_download2.aspx', 'noDownload', 416, 320, "yes", "no");
    return false;
}
function continueToUrl(url) {
    window.open(url);
    setTimeout('closeWin()', 3000);
}

// rollover
function chgImg(imgName, imgSrc) {
    document.images[imgName].src = imgSrc;
}

function EnlargeTextSize(cssClass) {
    if (document.getElementById) {
        if (document.getElementById("globalbody")) {
            currClass = document.getElementById("globalbody").className;
            
            if (currClass == "screenlarge") { cssClass = "screenmedium"; }
            
            document.getElementById("globalbody").className = cssClass;

            // set cookie if parameter is present
            //if (setC) {
                setCookie("screensize", cssClass, 365);
            //}
        }
    }
}

function setCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

// check text size cookie
function checkCookie() {
    if (document.getElementById("globalbody")) {
        var body = document.getElementById("globalbody");
        var cookie = getCookie("screensize");
        var className = cookie != null ? EnlargeTextSize(cookie) : EnlargeTextSize("screenlarge");
        //    if (body != null)
        //        body.className = "screenLarge";
    }        
}

var faqPrev = "faqWhat";
var hstPrev;  // initialized on the page
var cervTypePrev = "cervical_type4";

var faqItemOpen = "";
var faqOpenItemPrev = "";

function openFaq(elm, idx) {

    faqItemOpen = elm + '_' + idx;

    document.getElementById(elm).style.display = "none";
    document.getElementById(faqItemOpen).style.display = "block";

}

function showFaq(elm) {

    document.getElementById(elm + '_Q').style.color = "#ffffff";
    document.getElementById(elm + '_Q').style.background = "url('/_images/common/btn_on.gif') repeat-x";

    var tempFaq = $('#' + elm);
    tempFaq.removeClass('hideFaq');
    tempFaq.addClass('showFaq');
    document.getElementById(elm).style.display = "block";
    if (faqPrev != elm) {
        $('#' + faqPrev).removeClass('showFaq');
        $('#' + faqPrev).addClass('hideFaq');        
        document.getElementById(faqPrev).style.display = "none";
        document.getElementById(faqPrev + '_Q').style.color = "#885ea7";
        document.getElementById(faqPrev + '_Q').style.background = "url('/_images/common/btn_off.gif') repeat-x";
    }
    if (faqItemOpen != "") {
        document.getElementById(faqItemOpen).style.display = "none";
    }


    faqPrev = elm;

}

function showHst(elm) {
    if (hstPrev != null) {
        $(hstPrev).removeClass("imgHistoryEnabled").addClass("imgHistoryDisabled");
        $('#' + hstPrev.id + '_txt').removeClass("txtHistoryEnabled").addClass("txtHistoryDisabled");
        $('#' + hstPrev.id + '_year').removeClass("yearEnabled").addClass("yearDisabled");
    }

    if (hstPrev != elm) {
        $(elm).removeClass("imgHistoryDisabled").addClass("imgHistoryEnabled");
        $('#' + elm.id + '_txt').removeClass("txtHistoryDisabled").addClass("txtHistoryEnabled");
        $('#' + elm.id + '_year').removeClass("yearDisabled").addClass("yearEnabled");
    }
    if (hstPrev == elm) hstPrev = null; else hstPrev = elm;
}

function cervical_typeFlip(elm) {
    if (cervTypePrev != null) {
        $('#' + cervTypePrev + '_desc').removeClass("cervical_types_desc").addClass("cervical_types_hide");
        $('#' + cervTypePrev + '_img').removeClass("imgCervEnabled").addClass("imgCervDisabled");

    }

    if (cervTypePrev != elm) {
        $('#' + elm + '_desc').removeClass("cervical_types_hide").addClass("cervical_types_desc");
        $('#' + elm + '_img').removeClass("imgCervDisabled").addClass("imgCervEnabled");
    }
    if (cervTypePrev == elm) cervTypePrev = null; else cervTypePrev = elm;
}

function getVideo(name) {
    embededSWF.loadVideo(name);
    $(document).ready(function() {
        $('html, body').animate({ scrollTop: 0 }, 'fast');
        return false;
    });
}
function pauseVideo() {
    setTimeout("embededSWF.pauseVideo()", 2000);
}
function vAlign(el) {
    var ah = $(el).height();
    var ph = $(el).parent().height();
    return mh = (ph - ah) / 2 - 5;
}
function disableEnterKey(e)
{
    var key = (window.event) ? event.keyCode : e.which;
    return (key != 13);
}
window.onload = function (e) {
    checkCookie();
}
