
/**
 * login.js - Login script OPEN
 *
 * NOTICE: The currentDomain variable will not function for shortened names
 *         or IP addresses. The domain must be supplied as part of the
 *         address.
 *
 *         Good Address: http://janus-dev1.firsthealth.com
 *          Bad Address: http://janus-dev1
 *                       http://10.2.120.22
 */

function authentLogin(origURI)
{
    var stringLocation = new String(window.location);
    var isSecure = (stringLocation.indexOf('https') != -1);
    var hostName = location.host;
    var currentDomain = '';
    var suffix = hostName.substr(hostName.length - 3);

    currentDomain = (suffix.toLowerCase() != 'com' ? '' : ';domain=' +
                    hostName.substr(hostName.indexOf('.')));

    window.name = "fh" + (new Date()).getTime();

    var iWidth  = 401;
    var iHeight = 202;
    var iX      = (screen.width - iWidth) / 2;
    var iY      = (screen.height - iHeight) / 2;

    var args  = 'toolbar=no,location=no,directories=no,status=no';
        args += ',menubar=no,scrollbars=no,resizable=no';
        args += ',copyhistory=no,width=' + iWidth + ',height=' + iHeight;
        args += ',screenX=' + iX + ',screenY=' + iY ;
        args += ',top=' + iX + ',left=' + iY;

    if (isSecure)
    {
        document.cookie = "FHLogin=" + origURI + currentDomain + ";path=/";

        var authentLogin = 'https://' + hostName +
                           '/authent/login.html?openerName=' + window.name +
                           '&ct_orig_uri=' + origURI;
    }
    else
    {
        document.cookie = "FHLogin=/authent/redirect.html?redirectTo=" +
                          origURI + currentDomain + ";path=/";

        var authentLogin = 'https://' + hostName +
                           '/authent/login.html?openerName=' + window.name +
                           '&ct_orig_uri=/authent/redirect.html?redirectTo=' +
                           origURI;
    }

    var Login = window.open(authentLogin, 'LogIn', args);
}


/*function authentLoginNew(CTAuthMode,CTOverrideUriRetention, CTOrigUrl)
{
    var stringLocation = new String(window.location);
    var isSecure = (stringLocation.indexOf('https') != -1);
    var hostName = location.host;
    var currentDomain = '';
    var suffix = hostName.substr(hostName.length - 3);

    currentDomain = (suffix.toLowerCase() != 'com' ? '' : ';domain=' +
                    hostName.substr(hostName.indexOf('.')));

    window.name = "fh" + (new Date()).getTime();

    var iWidth  = 401;
    var iHeight = 202;
    var iX      = (screen.width - iWidth) / 2;
    var iY      = (screen.height - iHeight) / 2;

    var args  = 'toolbar=no,location=no,directories=no,status=no';
        args += ',menubar=no,scrollbars=no,resizable=no';
        args += ',copyhistory=no,width=' + iWidth + ',height=' + iHeight;
        args += ',screenX=' + iX + ',screenY=' + iY ;
        args += ',top=' + iX + ',left=' + iY;

    if (isSecure)
    {
        document.cookie = "FHLogin=" + origURI + currentDomain + ";path=/";

        var authentLogin = 'https://' + hostName +
                           '/authent/login.html?openerName=' + window.name +
                           '&CT_ORIG_URL=' + CTOrigUrl+'&override_uri_retention=' +CTOverrideUriRetention+'&CTAuthMode=' +CTAuthMode;
    }
    else
    {
        document.cookie = "FHLogin=/authent/redirect.html?redirectTo=" +
                          origURI + currentDomain + ";path=/";

        var authentLogin = 'https://' + hostName +
                           '/authent/login.html?openerName=' + window.name +
                           '&CT_ORIG_URL=/authent/redirect.html?redirectTo=' +
                           CTOrigUrl+'&override_uri_retention=' +CTOverrideUriRetention+'&CTAuthMode=' +CTAuthMode;
    }

    var Login = window.open(authentLogin, 'LogIn', args);
}*/

/**
 * login.js - Login script OPEN
 *
 * NOTICE: The currentDomain variable will not function for shortened names
 *         or IP addresses. The domain must be supplied as part of the
 *         address.
 *
 *         Good Address: http://janus-dev1.firsthealth.com
 *          Bad Address: http://janus-dev1
 *                       http://10.2.120.22
 * This method will force the user to stay on SSL server after authentication
 */

function authentLoginToSSL(origURI)
{
    var stringLocation = new String(window.location);
    var hostName = location.host;
    var currentDomain = '';
    var suffix = hostName.substr(hostName.length - 3);

    currentDomain = (suffix.toLowerCase() != 'com' ? '' : ';domain=' +
                    hostName.substr(hostName.indexOf('.')));

    window.name = "fh" + (new Date()).getTime();

    var iWidth  = 401;
    var iHeight = 202;
    var iX      = (screen.width - iWidth) / 2;
    var iY      = (screen.height - iHeight) / 2;

    var args  = 'toolbar=no,location=no,directories=no,status=no';
        args += ',menubar=no,scrollbars=no,resizable=no';
        args += ',copyhistory=no,width=' + iWidth + ',height=' + iHeight;
        args += ',screenX=' + iX + ',screenY=' + iY;
        args += ',top=' + iX + ',left=' + iY;

   
        document.cookie = "FHLogin=/authent/redirectSSL.html?redirectTo=" +
                          origURI + currentDomain + ";path=/";

        var authentLogin = 'https://' + hostName +
                           '/authent/login.html?openerName=' + window.name +
                           '&ct_orig_uri=/authent/redirectSSL.html?redirectTo=' +
                           origURI;
   
    var Login = window.open(authentLogin, 'LogIn', args);
}

/** 
*
*Added for the TRISTAR client
*/
function authentLoginTriStar(origURI)
{
	
    var stringLocation = new String(window.location);
    var isSecure = (stringLocation.indexOf('https') != -1);
    var hostName = location.host;
    var currentDomain = '';
    var suffix = hostName.substr(hostName.length - 3);

    currentDomain = (suffix.toLowerCase() != 'com' ? '' : ';domain=' +
                    hostName.substr(hostName.indexOf('.')));

    window.name = "fh" + (new Date()).getTime();

    var iWidth  = 401;
    var iHeight = 202;
    var iX      = (screen.width - iWidth) / 2;
    var iY      = (screen.height - iHeight) / 2;

    var args  = 'toolbar=no,location=no,directories=no,status=no';
        args += ',menubar=no,scrollbars=no,resizable=no';
        args += ',copyhistory=no,width=' + iWidth + ',height=' + iHeight;
        args += ',screenX=' + iX + ',screenY=' + iY;
        args += ',top=' + iX + ',left=' + iY;

    if (isSecure)
    {
        document.cookie = "FHLogin=" + origURI + currentDomain + ";path=/";

        var authentLogin = 'https://' + hostName +
                           '/authent/loginTristar.html?openerName=' + window.name +
                           '&ct_orig_uri=' + origURI;
    }
    else
    {
        document.cookie = "FHLogin=/authent/redirect.html?redirectTo=" +
                          origURI + currentDomain + ";path=/";

        var authentLogin = 'https://' + hostName +
                           '/authent/loginTristar.html?openerName=' + window.name +
                           '&ct_orig_uri=/authent/redirect.html?redirectTo=' +
                           origURI;
    }

    var Login = window.open(authentLogin, 'LogIn', args);
}
