var pga_msMsibConfig = {
	"pga_msDomain" : "pga.com",
	"pga_msMsibRoot" : "https://secure.audience.pga.com/services/pga",
	"pga_msMsibRegister": "/flow?_flowId=register-flow",
	"pga_msMsibEditUser": "/authn/flow?_flowId=editUser-flow",
	"pga_msMsibExternalLogin": "/flow?_flowId=external-login-flow",
	"pga_msMsibExternalResetPassword": "/flow?_flowId=requestPasswordReset-external-flow"
};
var pga_msUserData = {
	"pga_msLoginErrorMessage": "",
	"pga_msResetErrorMessage": "",
	"pga_msRememberEmailAddress": "",
	"pga_msUserFirstname": "",
	"pga_msTedId": "",
	"pga_msAuthId": ""
};
function pga_msLoadUserData() {
	// pga_msCookie.get return null if no cookie found
	pga_msUserData.pga_msLoginErrorMessage = pga_msCookie.get("LoginErrorMessage");
	pga_msUserData.pga_msResetErrorMessage = pga_msCookie.get("ResetErrorMessage");
	pga_msUserData.pga_msRememberEmailAddress = pga_msCookie.get("RememberEmailAddress");
	pga_msUserData.pga_msUserFirstname = pga_msCookie.get("UserFirstname");
	pga_msUserData.pga_msTedId = pga_msCookie.get("TEGId");
	pga_msUserData.pga_msAuthId = pga_msCookie.get("authid");
}

function pga_msInit() {
	
	// config
	var pga_msLayer_id = '';

	// load user data
	pga_msLoadUserData();
	
	if(pga_msUserData.pga_msUserFirstname != null && pga_msUserData.pga_msTedId != null && pga_msUserData.pga_msAuthId != null) { // if tedid and authid and user first name
		// show user first name and update account | logout options
		pga_msDrawUserLoggedIn();
	} else { // else display normal login
		// show normal login | register options
		if(pga_msUserData.pga_msRememberEmailAddress != null) { // if remember email address
			$('emailAddress').value = pga_msUserData.pga_msRememberEmailAddress;
			pga_msShowCheckedRememberBox();
		}
		pga_msDrawLoginOptions();
	}
	
	if(pga_msUserData.pga_msLoginErrorMessage != null) { // if login error message
		// show login error
		pga_msDrawLoginError();
	} else if(pga_msUserData.pga_msResetErrorMessage != null) { // if reset error message
		// show reset error
		pga_msDrawResetError();
		
	}
}

// onload
Event.observe(window, 'load', function() {
	document.domain = pga_msMsibConfig.pga_msDomain;
	pga_msInit();
});
