// When your logout page receives a "msg" parameter,
// it prints a message to the page to let the user know
// ** CUSTOMIZE YOUR LOGOUT MESSAGES HERE:

var logoutMsg = {
	normalLogout:		"",
	sessionTimeout:		"Your session has timed out.",
	incorrectLogin:		"Incorrect username or password. Please try again."
}


function appendEnterprise(unmField,enterpriseName) {
// Append enterprise suffix: +.ENTERPRISE_NAME
	var unm = unmField.value;	// The form will ultimately submit this value
	var thisForm = unmField.form;	
	
	if (unm==0) {
		unmField.focus();
		return false;
    } else {
		// Check to see if there is already an "." after the username...
		if(unm.indexOf(".") == (unm.length-1)) {
			unm = unmField.value+enterpriseName;
		}
		// Append full suffix: +.ENTERPRISE_NAME
        else if (unmField.value.indexOf(".") == -1) {
			unm = unmField.value + "." + enterpriseName;
		}
		// Update form field "unm"
		thisForm.unm.value=unm;
		return true;
    }
}

		
function getMsgParam() {	
// Description
// Generates code for a link that preserves the query of the current document.

	var qs = document.location.search.substr(1);	//query string (everything after ?)
	var params = qs.split("&")			//array of params (split up by &)
	var i;						//(i)teration
	var msg;					//Store message value (numeric)

	for(i = 0; i < params.length; i++) {
	var nv = params[i].split("=");		//stores number value when "msg" param is located
	if( nv[0].toLowerCase() == "msg" ) {
		msg = nv[1];
		break;				//stop after the msg value is assigned
		}
	}
		// If an invalid value is found, default msg = 0 
	if ((msg != 0) && (msg != 1) && (msg != 2)) {
		msg = 0;
	}
	
	return msg;
}

function setStatusMsg() {
// Description
// Decodes number value into a usable status message:
//	0: Normal logout
//	1: Session Timeout/Overwrite
//	2: Login error occurred			

	var msgNum = getMsgParam();
	var msgStrings = new Array(3);
	msgStrings[0] = logoutMsg.normalLogout;
	msgStrings[1] = logoutMsg.sessionTimeout;
	msgStrings[2] = logoutMsg.incorrectLogin;

	return msgStrings[msgNum];
}


function displayStatusMsg() {
// Description
// Display the status message to the screen: SPAN w/ ID="statusMsg"
	var statusMsg = setStatusMsg();

	// Update the message on the page:
	document.getElementById("statusMsg").innerHTML = statusMsg;

	// Update the page title: COMPANY - SYS_MESSAGE
	if (statusMsg != "") {
		document.title = document.title + " - " + statusMsg;
	}
}
