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,4,5,8,0,0,0).format(sformat);
    maintEndDate = new Date(2010,4,7,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/>";

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');
    //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)));
}