﻿(function($) {
    var loginPath = new Array();
    loginPath[0] = ["chclaims", "http://healtheweb-test.apshealthcare.com/login.aspx?GNo=CH000001"];
    loginPath[1] = ["advocate", "advocate.aspx"];

    loginPath[2] = ["", ""];
    //loginPath[2] = ["ride", "harley_davidson.aspx"];

    loginPath[3] = ["som2002", "maryland.aspx"];
    loginPath[4] = ["statesc", "state_of_south_carolina.aspx"];
    loginPath[5] = ["jps", "jps.aspx"];
    loginPath[6] = ["drivers", "drivers.aspx"];
    loginPath[7] = ["unicare", "unicare.aspx"];
    loginPath[8] = ["uchs", "uchs.aspx"];
    loginPath[9] = ["usfhp", "usfhp.aspx"];
    loginPath[10] = ["wihealth", "whf.aspx"];
    loginPath[11] = ["wtwt", "wtwt.aspx"];
    loginPath[12] = ["gencable", "gencable.aspx"];
    loginPath[13] = ["milco", "milco.aspx"];
    loginPath[14] = ["447pipetrades", "447PipeTrades.aspx"];
    loginPath[15] = ["pipetrades", "447PipeTrades.aspx"];
    loginPath[16] = ["livewell", "ufcw227.aspx"];
    loginPath[17] = ["apsnurses", "http://www.healthwise.net/apshealthcare/"];
    loginPath[18] = ["arizona", "http://www.healthwise.net/apshealthcare/"];
    loginPath[19] = ["bcbsmt", "http://www.healthwise.net/apshealthcare/"];
    loginPath[20] = ["bcpss", "http://www.healthwise.net/apshealthcare/"];
    loginPath[21] = ["bnym", "http://www.healthwise.net/apshealthcare/"];
    loginPath[22] = ["", ""];
    loginPath[23] = ["gapower", "http://www.healthwise.net/apshealthcare/"];
    loginPath[24] = ["generalcable", "http://www.healthwise.net/apshealthcare/"];
    loginPath[25] = ["healthyusf", "healthyusf.aspx"];
    loginPath[26] = ["hpny", "http://www.healthwise.net/apshealthcare/"];
    loginPath[27] = ["ibew701", "http://www.healthwise.net/apshealthcare/"];
    loginPath[28] = ["iboft", "http://www.healthwise.net/apshealthcare/"];
    loginPath[29] = ["ichia", "http://www.healthwise.net/apshealthcare/"];
    loginPath[30] = ["ichia2", "http://www.healthwise.net/apshealthcare/"];
    loginPath[31] = ["iowa", "http://www.healthwise.net/apshealthcare/"];
    loginPath[32] = ["laclede", "http://www.healthwise.net/apshealthcare/"];
    loginPath[33] = ["lakecounty", "http://www.healthwise.net/apshealthcare/"];
    loginPath[34] = ["lhp", "http://www.healthwise.net/apshealthcare/"];
    loginPath[35] = ["local727", "http://www.healthwise.net/apshealthcare/"];
    loginPath[36] = ["louisiana", "http://www.healthwise.net/apshealthcare/"];
    loginPath[37] = ["mcha", "http://www.healthwise.net/apshealthcare/"];
    loginPath[38] = ["mellon", "http://www.apshealthcare.com/mellon.aspx"];
    loginPath[39] = ["micron", "http://www.healthwise.net/apshealthcare/"];
    loginPath[40] = ["mtfep", "http://www.healthwise.net/apshealthcare/"];
    loginPath[41] = ["mus", "http://www.healthwise.net/apshealthcare/"];
    loginPath[42] = ["ncil", "http://www.healthwise.net/apshealthcare/"];
    loginPath[43] = ["njdhs", "http://www.healthwise.net/apshealthcare/"];
    loginPath[44] = ["npebp", "http://www.healthwise.net/apshealthcare/"];
    loginPath[45] = ["pgc", "http://www.healthwise.net/apshealthcare/"];
    loginPath[46] = ["riggers", "http://www.healthwise.net/apshealthcare/"];
    loginPath[47] = ["smw 263", "http://www.healthwise.net/apshealthcare/"];
    loginPath[48] = ["smw263", "http://www.healthwise.net/apshealthcare/"];
	
	loginPath[49] = ["",""];
    //loginPath[49] = ["srmc", "http://www.healthwise.net/apshealthcare/"];
    
	loginPath[50] = ["ufcw1776", "http://www.healthwise.net/apshealthcare/"];
    loginPath[51] = ["ufcw227", "ufcw227.aspx"];
    loginPath[52] = ["ufcw99", "http://www.healthwise.net/apshealthcare/"];
    loginPath[53] = ["ufcwatl", "http://www.healthwise.net/apshealthcare/"];
    loginPath[54] = ["ufcwswoh", "http://www.healthwise.net/apshealthcare/"];
    loginPath[55] = ["westhartford", "westhartford.aspx"];
    loginPath[56] = ["wyoming", "http://www.healthwise.net/apshealthcare/"];
	loginPath[57] = ["703grocers", "http://www.healthwise.net/apshealthcare/"];
	loginPath[58] = ["ufcw1995", "http://www.healthwise.net/apshealthcare/"];
	loginPath[59] = ["coach", "http://www.healthwise.net/apshealthcare/"];



    $.fn.Login = function(options) {
        var opts = $.extend({}, $.fn.Login.defaults, options);

        return this.each(function() {
            var item = $(this);

            setUpLoginUI(item, opts);
        });
    };

    $.fn.Login.defaults = {
        loginText: "Login with your access code:",
        onError: function(errorMsg) { alert("The following error occured: \n" + errorMsg); }
    };
	
	$.fn.Login.bypass = function() {
		_login('', 1);
	};

    function setUpLoginUI(item, opts) {
        item.append('<label>' + opts.loginText + '</label><input type="text" id="userName" /><br/><input type="button" value="Sign In" id="loginButton" class="signInBtn" />');
        $("#loginButton").click(function() { _login(opts, 0); });

        $("#userName").keypress(function(e) {
            if (e.which == 13) {
                _login(opts, 0);
            }
        });
    };

    function _login(opts, opts2) {
        var hitError = false;
		
        for (var i = 0; i < loginPath.length; i++) {
            var a = loginPath[i][0].toLowerCase();
            var b = $("#userName").val().toLowerCase();
            if (a == b) {
                var urlTest = new RegExp(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/);
                var path = loginPath[i][1];
				
                if (urlTest.test(path)) {
                    if ($.support.objectAll) {
						if (opts2 == 1) {
							location.href=loginPath[i][1];
						} else {
							window.open(loginPath[i][1]);
						}
                    } else {
						var link = document.getElementById("link");
						if (opts2 == 1) {
							link.target="";
						} else {
							link.target = "_blank";
						}
                        link.href = loginPath[i][1];  
                        link.click();
                    }
                }
                else {
                    window.location = loginPath[i][1];
                }

                hitError = false;
                break;
            }
            else {
                hitError = true;
            }
        }

        if (hitError) {
            opts.onError("Login invalid, please try again.");
        }

    }
})(jQuery);

