(function()
{
    var loaded = function(result)
    {
        if (result.ok === true)
        {
            var blockElems, inlineElems;
            
            if ((result.responseText.length > 4) && (result.responseText.substr(0, 4).toLowerCase() == "http")) {
            
                //In CM mode, take to CM login page
                window.location.replace(result.responseText);
            }
        }
    }
    var init = function()
    {

        if (GetCookie("SC", "cmUserName") && GetCookie("SC", "cmIsMigrated") && (GetCookie("SC", "cmIsMigrated") == "0")) {
        
            //cmUserName is populated, and account is not migrated
            var url = window.location.toString().substring(window.location.toString().lastIndexOf("/"));

            if (url.toLowerCase() == "/customercentral2.html") {

                //If already on CustomerCentral2, do not forward to CustomerCentral2
                
                document.getElementById("loginForm").style.visibility = "visible";

                document.getElementById("userName").disabled = true;
                document.getElementById("userName").value = GetCookie("SC", "cmUserName");
                document.getElementById("cimaUserName").value = GetCookie("SC", "cmUserName");
                document.getElementById("cimaUserName").disabled = true;
                document.getElementById("cimaUserNameHidden").value = GetCookie("SC", "cmUserName");
                document.getElementById("userNameHidden").value = GetCookie("SC", "cmUserName");
                
                //FF requires a delay
                //try/catch added for pages that hide this control using DOM/jscript - causes an IE error without
                setTimeout("try{document.getElementById('password').focus();}catch(err){}", 500);
            } else {

                //Forward to CustomerCentral2.html
                
                window.location.replace("CustomerCentral2.html");
            }
        } else {

            //Check to see if we are in CM mode, if we are, then take new CM login page
            
            var svcUrl = "/Customers/CredentialMigrationLoginService.asmx/InCredentialMigration";
            DF.connection.asyncConnect("GET", svcUrl, loaded.createDelegate(this), false, null);
        }
    }
    DF.evt.AddDomLoadEvent(init);
} ());