/*
Function to show or hide pharmacist role drop down box if vacancy type of 'Pharmacist' is selected.
Used in vacancy search pages.
*/

function showHidePharmacistRoleSelection() {

	if (document.forms[0].vacancyType != null)
	{
		var vacancyType = document.forms[0].vacancyType[2];

		if (vacancyType.checked)
		{
			if (navigator.appName == "Netscape")
				document.layers['roleDiv'].visibility = "show";
			else
				document.all['roleDiv'].style.visibility = "visible";
		}
		else
		{
			if (navigator.appName == "Netscape")
				document.layers['roleDiv'].visibility = "hide";
			else
				document.all['roleDiv'].style.visibility = "hidden";
		}

	}
}

function jumpto(x, newWindow) {

	if (document.form1.jumpmenu.value != "null") {
		if (newWindow != "") {
			window.open(x);
		} else {
			document.location.href = x;
		}
	}
}

/*
    Displays a javascript confirmation box. The message displayed is from the struts resource bundle.
*/
function confirmSubmit(message) {
	var okClicked = confirm(message);
	if (okClicked)
		return true;
	else
		return false;
}

/**
 * Sets the drop-down to display all users for a business unit
 * Only if the line manager option has been chosen
 **/
function setUsers()
{
	// check whether a line manager has been chosen
	var lineManagerUser = 4;
	var role = document.getElementById("roleId").value;
	var userSelectBox = document.getElementById("allUserId");
	var userSelectSection = document.getElementById("allUsersDropDown");

	// clear down the options
	userSelectBox.options.length = 0;

	if (role == lineManagerUser) {
		// get all users of the site
		var usersString = document.getElementById("allUsers").value;

		// get the value of the selected business unit
		var selectedBizUnit = document.getElementById("businessId").value;

		keypairs = new Array();
		var i = 0;

		// Split the query string at each ':', storing the left-hand side
		// of the split in a new keypairs[] holder, and chopping the userString
		// so that it gets the value of the right-hand string.
		while (usersString.indexOf(':') > -1) {
			keypairs[i] = usersString.substring(0, usersString.indexOf(':'));
			usersString = usersString.substring((usersString.indexOf(':')) + 1);
			i++;
		}

		// Now set the values of the users drop down menu
		var l = 0;
		for (var j = 0; j < keypairs.length; j++) {
			var userText = keypairs[j].substring(0, keypairs[j].indexOf(','));
			var uIdBizUnit = keypairs[j].substring((keypairs[j].indexOf(',')) + 1);
			var userId = uIdBizUnit.substring(0, uIdBizUnit.indexOf(','));
			var bizUnit = uIdBizUnit.substring((uIdBizUnit.indexOf(',')) + 1);

			if (selectedBizUnit == bizUnit)
			{
				userSelectBox.options[l] = new Option(userText, userId);
				l++;
			}

		}
	}
	// control the users drop-down visibility
	if (userSelectBox.options.length == 0) {
		userSelectSection.style.visibility = "hidden";
	} else {
		userSelectSection.style.visibility = "visible";
	}

}


function countCharacters(maxChars)
{
	var message;
	message = event.srcElement.value;
	if (message.length > maxChars)
	{
		message = message.substr(0, maxChars);
		event.srcElement.value = message;
	}
}