
$(function() {
    /*
    //http://atlantajones.com/software/easy-reusable-image-rollovers-with-jquery/
    var img = $('[id$="imgMyAccount2"]');

    // Preload all rollovers
    $(img).each(function() {
        // Set the original src
        rollsrc = $(this).attr("src");
        rollON = rollsrc.replace(/.png$/ig, "-over.png");
        $("<img>").attr("src", rollON);
    });

    // Navigation rollovers
    $(img).mouseover(function() {
        imgsrc = $(this).attr("src");
        //imgsrc = $(this).children("img").attr("src");
        matches = imgsrc.match(/-over/);

        // don't do the rollover if state is already ON
        if (!matches) {
            imgsrcON = imgsrc.replace(/.png$/ig, "-over.png"); // strip off extension
            $(this).attr("src", imgsrcON);
            //$(this).children("img").attr("src", imgsrcON);
        }
    });
    $(img).mouseout(function() {
        $(this).attr("src", imgsrc);
        //$(this).children("img").attr("src", imgsrc);
    });
    */
    
    //http://bavotasan.com/tutorials/creating-a-jquery-mouseover-fade-effect/
    $("img.a").hover(
        function() {
            $(this).stop().animate({"opacity": "0"}, 0);
        },
        function() {
            $(this).stop().animate({"opacity": "1"}, 0);
        });
    });

var sformat = 'MM/dd/yyyy h:mm a';
// new Date(year, month, day, hours, minutes, seconds, milliseconds) //month is zero-based; most parameters here are optional. Not specifying causes 0 to be passed in.
// new Date(2009,1,2,1,0,0,0); = 2/2/2009 1:00 AM
var curDate = new Date().format(sformat);
var isLive = true;

var maintStartDate;
var maintEndDate;

if (isLive) {
    maintStartDate = new Date(2010, 7, 15, 8, 0, 0, 0).format(sformat);
    maintEndDate = new Date(2010, 7, 15, 17, 0, 0, 0).format(sformat);
} else {
    maintStartDate = Date.parseString(curDate, sformat).add('m', -1).format(sformat);
    maintEndDate = Date.parseString(curDate, sformat).add('m', 1).format(sformat);
}

var maxWidth = 1024;
var maxHeight = 768;

// Test: put date range at +/- 1 minute of current timestamp
//    var maintStartDate = Date.parseString(curDate,sformat).add('m',-1).format(sformat);
//    var maintEndDate = Date.parseString(curDate,sformat).add('m',1).format(sformat);

// Message text
//var msg = "Tri-Star Systems will be installing a new phone system starting at 2 PM CST, Friday, May 7, 2010 and, barring complications, anticipate only a 30 minute disruption of service.  We apologize in advance for any inconvenience.  If you are unable to reach us Friday afternoon, please try again on Monday.  Our new system will more efficiently direct you to the appropriate department for assistance and will improve our service to you, our valued customer.  Thank you for your patience during this transition.<br/><br/>";
var msg = "Tri-Star Systems is currently undergoing system maintenance and anticipate a successful completion soon. We apologize for any inconvenience this may have caused you. Thank you for your patience.<br/><br/>";

function beneflexMsgDateRange2(override, stopLogin) {

    // either the override or determine if we're in range
    var inRange = isInRange(override);

    // get the page name
    //    var pageName = getPageName();
    //    if ( pageName == 'get-in-touch-with-tri-star' ) {
    //        inRange = false;
    //    }

    // if we're in the specified range, show the popup
    if (inRange) {

        // show the Login link unless we choose to hide it -> (!stopLogin)
        if (!stopLogin) {
            msg += "<a class='linkOrangeOrangeDash' href='javascript:loginPage(true);'>Continue -></a>";
        }
        //var msg = "The participant login will be unavailable until "+maintEndDate+" CST due to maintenance.<br/><br/>";

        // show the popup
        showPopup(msg);
    }
}

function beneflexLoginDateRange2(stopLogin) {

    // either the override or determine if we're in range
    var inRange = isInRange(false);

    // get the page name
    var pageName = getPageName();
    if (pageName == 'get-in-touch-with-tri-star') {
        inRange = false;
    }

    // if we're in the specified range, show the popup
    if (inRange) {

        // show the Login link unless we choose to hide it -> (!stopLogin)
        if (!stopLogin) {
            msg += "<a class='linkOrangeOrangeDash' href='javascript:loginPage(true);'>Continue -></a>";
        }
        //var msg = "The participant login will be unavailable until "+maintEndDate+" CST due to maintenance.<br/><br/>";

        // show the popup
        showPopup(msg);
        // if we're not in the specified range, simply go to the Login
    } else { loginPage(inRange); }
}

function loginPage(hideMsg) {
    if (hideMsg) {
        popAnnouncementLogin.Hide();
    }
    // link is live (meaning, when the participant is able to login). 
    //window.location = 'https://secure.tri-starsystems.com/employee/';
    /*
    setMaxBrowser();    // -> see browserStuff.js
    window.open('https://secure.tri-starsystems.com/employee/','BeneflexSecureLogin', 'width='+maxWidth+',height='+maxHeight+',status=yes,toolbar=yes,scrollbars=1,menubar=yes');
    */
    var pageName = getPageName();
    window.open('https://secure.tri-starsystems.com/employee/login.asp?ref=' + pageName, 'BeneflexSecureLogin', 'status=yes,toolbar=yes,scrollbars=yes,menubar=yes,width=1024,height=768');
    //window.location.href = 'https://secure.tri-starsystems.com/employee/';
}

function showPopup(msg) {
    popAnnouncementLogin.SetContentHTML(msg);
    popAnnouncementLogin.Show();
}

function getPageName() {
    var sPath = window.location.pathname;
    var sWholePage = sPath.substring(sPath.lastIndexOf('/'));
    return sWholePage.substring(1, sWholePage.lastIndexOf('.'));
}

function showRange() {
    var msg = "Start: " + maintStartDate + "\n";
    msg += "Current: " + curDate + "\n";
    msg += "End: " + maintEndDate + "\n";
    msg += "IsAfter: " + Date.parseString(curDate, sformat).isAfter(Date.parseString(maintStartDate, sformat)) + "\n";
    msg += "IsBefore: " + Date.parseString(curDate, sformat).isBefore(Date.parseString(maintEndDate, sformat)) + "\n";

    alert(msg);
}

function isInRange(override) {
    return (override) ? override : (Date.parseString(curDate, sformat).isAfter(Date.parseString(maintStartDate, sformat)) && Date.parseString(curDate, sformat).isBefore(Date.parseString(maintEndDate, sformat)));
}

// Possibly obsolete [8/20/2010]
function beneflexLoginDateRange(override) {
    /*
    var msg = "Start: " + maintStartDate + "\n";
    msg += "Current: " + curDate + "\n";
    msg += "End: " + maintEndDate + "\n";
    msg += "IsAfter: " + Date.parseString(curDate,sformat).isAfter(Date.parseString(maintStartDate,sformat)) + "\n";
    msg += "IsBefore: " + Date.parseString(curDate,sformat).isBefore(Date.parseString(maintEndDate,sformat)) + "\n";
    
    alert(msg);
    */

    var isInActive = (override) ? override : Date.parseString(curDate, sformat).isAfter(Date.parseString(maintStartDate, sformat)) && Date.parseString(curDate, sformat).isBefore(Date.parseString(maintEndDate, sformat));
    beneflexLoginToggle(!isInActive);
}

function beneflexLoginToggle(isActive) {

    if (isActive) {
        // link is live (meaning, when the participant is able to login). 
        //window.location = 'https://secure.tri-starsystems.com/employee/';
        /*
        setMaxBrowser();    // -> see browserStuff.js
        window.open('https://secure.tri-starsystems.com/employee/','BeneflexSecureLogin', 'width='+maxWidth+',height='+maxHeight+',status=yes,toolbar=yes,scrollbars=1,menubar=yes');
        */
        window.open('https://secure.tri-starsystems.com/employee/', 'BeneflexSecureLogin', 'status=yes,toolbar=yes,scrollbars=yes,menubar=yes');
        //window.location.href = 'https://secure.tri-starsystems.com/employee/';
    } else {
        // disable link and display pop up message.
        var msg = "The participant login will be unavailable until " + maintEndDate + " CST due to maintenance.<br/><br/>";
        //var msg = "The participant login will be unavailable from "+maintStartDate+" CST to "+maintEndDate+" CST due to maintenance.<br/><br/>";
        //var msg = "The participant login is unavailable due to maintenance.<br/><br/>";
        //msg += "<a class='linkOrangeOrangeDash' href='https://secure.tri-starsystems.com/employee/'>Continue -></a>";
        popAnnouncementLogin.SetContentHTML(msg);
        popAnnouncementLogin.Show();
    }
}

