var today = new Date();
var expired = new Date(today.getTime() - 48 * 60 * 60 * 1000); // less 2 days
var newExpire = new Date(today.getTime() + 24 * 365 * 60 * 60 * 1000); // 1
                                                                       // year
                                                                       // expire
function printMemberName() {
    var allCookies = document.cookie;
    var cookieName = "travwell_member_name";
    var cookiePrefix = cookieName.concat( "=" );
    var pos = allCookies.indexOf( cookiePrefix );
    if( pos != -1 ) {
        var valStart = pos + cookiePrefix.length;
        var valEnd = allCookies.indexOf( ";", valStart );
        if( valEnd == -1 ){
            valEnd = allCookies.length;
        }
        var value = allCookies.substring( valStart, valEnd );
        value = unescape( value );
        return value;
    }
}

//delete cookie
function dC(name) {
    document.cookie=name + "=; domain=" + travwellDomain + "; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

//alert(document.cookie)
dC("travwell_agency");
//alert(document.cookie)
document.cookie = "travwell_agency=" + travwellAgency + "; domain=" + travwellDomain + "; path=" + zoneSubdir + "; expires=" + newExpire.toGMTString();
//alert(document.cookie)

var allcookies = document.cookie;
var ck = "";
//get cookie
function gC(ck) {
    var pos = allcookies.indexOf(ck);
    if (pos != -1) {
        var start = pos + ck.length;
        var end = allcookies.indexOf(";", start);
        if (end == -1) end = allcookies.length;
        var value = allcookies.substring(start, end);
        return unescape(value);
    }
}

function printBasicLoginBegin(){
    document.write("<tr valign=\"top\">" );
    document.write("<td class=\"body\" colspan=\"2\" bgcolor=\"#ffffff\">" );
    document.write("<div align=\"center\">Welcome, " + printMemberName() + "<br>" );
    document.write("<span class=\"bodySmall\">If you are not " + printMemberName() + ", <a href=\"" + secureURL + "/do/ProcessLoginLogout?logout=2&ag=" + travwellAgency + "\">click here" );
    document.write("</a>" );
    document.write("</span></div>" );
    document.write("</td>" );
    document.write("</tr>" );
}

function printLoggedIn(path, label, extended) {
    document.write("<tr>" );
    document.write("<td class=\"body\" width=\"68\">" );
    document.write("<a href=\"" + secureURL + "/do/LoginLogout?ag=" + travwellAgency + "\"> <img src=\"" + zoneSubdir + "/common/images/button_login_logout.gif\" align=\"left\" border=\"0\" alt=\"Login&#47;Logout\"></a></td>" );

    document.write("<td class=\"body\">" );
    if (path != null) {
        document.write("<a href=\"" + secureURL + path + "?ag=" + travwellAgency + "\">" + label + "</a>");
    }
    document.write("</td>" );
    document.write("</tr>" );
}

document.write("<div class=\"loginBoxSeparatorTop\">");
document.write("<table width=\"96%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><tr><td></td></tr></table>");
document.write("</div>");
document.write("<table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" class=\"loginBorder\" bgcolor=\"#ffffff\" style=\"margin-left:auto;margin-right:auto;margin-top:3px;margin-bottom:3px;\">");
switch (gC("travwell_member_type=")) {
case "16":
case "8":
    printBasicLoginBegin();

    if (gC("support=") == "true") {
        printLoggedIn("/do/support/SupportHome", "Admin", true);
    } else {
        printLoggedIn(null,null, true);
    }
    break;

case "4":
    printBasicLoginBegin();
    printLoggedIn("/do/agent/AgentMain", "Agent Admin", false);
    break;

case "2":
    printBasicLoginBegin();
    printLoggedIn("/do/agent/AgentMain", "Agency Admin", false);
    break;

case "1":
    printBasicLoginBegin();
    printLoggedIn("/do/admin/AdminHome", "Agency Admin", false);
    break;
    
default:
    document.write("<tr valign=\"top\">" );
    document.write("<td class=\"body\" valign=\"middle\" bgcolor=\"#ffffff\">" );
    document.write("<div align=\"center\">You are not logged in.<br>" );
    document.write("<span class=\"body\">Please <a href=\"" + secureURL + "/do/LoginLogout?ag=" + travwellAgency + "\">Login</a> to the <br> Travel Center or<br> <a href=\"" + secureURL + "/do/join/ChooseMembershipType?agency=" + travwellAgency + "\">Join Now</a>" );
    document.write("</span></div>" );
    document.write("</td>" );
    document.write("</tr>" );
    break;
}

document.write("</table>");
document.write("<div class=\"loginBoxSeparatorBottom\">");
document.write("  <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><tr><td></td></tr></table>");
document.write("</div>");