var LogCookie;
var root;

// utility function called by getCookie( )
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}

   
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


// read the Log cookie into a global variable
function getLogCookie( ) {
	if (location.hostname == "lap.rtheo")
	{ root = "/softswift_dev/"; }
	else
	{ root = "/"; }

	LogCookie = getCookie("LoggedIn");
	if (LogCookie.length > 1) {
	document.write(LogCookie + "<br>")
	document.write("<a href='" + root + "logout.aspx'><img border='0' src='" + root + "images/logout_button.gif' alt='logout' width='65' height='24'></a><br>");
	document.write("<a href='" + root + "Secure/account.aspx'><img border='0' src='" + root + "images/account_button.gif' alt='account' width='65' height='24'></a>");
	} else {
	document.write("<br>")
	document.write("<a href='" + root + "login.aspx'><img border='0' src='" + root + "images/login_button.gif' alt='login' width='65' height='24'></a><br>");
	document.write("<a href='" + root + "NewAccount.aspx'><img border='0' src='" + root + "images/register_button.gif' alt='register' width='65' height='24'></a>");
	}
}

function showdate() {
	document.write("&nbsp;&nbsp;&nbsp;" + new Date().toLocaleDateString());
}

function imagewindow(url) {
	window.open(url,"Screenshot","width=840,height=640");
}
