﻿
function createAuthUi()
{
    // get the persistent cookie
    var ck = readCookie("J4G_MEM");
    
    // if not found do nothing
    // if found, THIS USED TO hide the login box and write the "logged in" box  
    // but the login box styles have been reused for someting else and we now have an accountBox div, which this replaces the contents of.
    if(ck)
    {
        if(document.getElementById)
        {      
            var accountBox = document.getElementById("accountBox");
            if(accountBox && accountBox.innerHTML)
            { 
                var firstName = "Supporter";
                var parts = ck.split("|");
                if(parts[1])
                {
                    firstName = parts[1];
                }
                
                var repl =  "<h2>Hello!</h2>"
                          + "<p>Welcome back, " + firstName + "!</p>"
                          + "<p><a href=\"/useraccount/Default.aspx?t=1\">Click here to manage your account</a>.</p>"
                          + "<p>Not " + firstName + "? <a href=\"/auth.ashx?op_l=true\">Sign in</a> now.</p>";
                accountBox.innerHTML = repl;
                document.getElementById("yellowRegHere").style.display = "none";                              
            }
        }
    }  
}

function hideElement(elementName)
{
    if(document.getElementById(elementName))
    {
        document.getElementById(elementName).style.display = "none";
    }
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


