/**
 * Determines the window size and sets it in the fields of the window size form.
 */
function determineWindowSize() {
	// the id of the window size form
	var formID = 'windowSizeForm';
	// the window size form
	var form = document.getElementById(formID);

	// the values for window width and height are browser-dependent
	if (window.innerWidth) {
		form.windowWidth.value = window.innerWidth;
		form.windowHeight.value = window.innerHeight;
	} else if (document.body.clientWidth) {
		form.windowWidth.value = document.body.clientWidth;
		form.windowHeight.value = document.body.clientHeight;
	} else if (document.documentElement.clientWidth) {
		form.windowWidth.value = document.documentElement.clientWidth;
		form.windowHeight.value = document.documentElement.clientHeight;
	}

	form.submit();
}

/**
 * Submits the task form in task.jsp, so the input data of the form fields is
 * saved automatically.
 * 
 * @param frameName
 *            The name of the iframe from which the function is called.
 * @param url
 *            The url of the next page.
 * @param origin
 *            The name of the page which is currently displayed.
 */
function saveTaskInput(frameName, url, origin) {
	// the task or memo form
	var form;
	// the input field where the forward url is to be written in
	var urlInput;
	// the id of the task/memo form
	var formID = 'taskForm';
	// the id of the forward url input field
	var urlInputID = 'forwardURL';
	// indicates whether the current work sheet should be saved
	var saveWorkSheet = false;

	// check if the function was called from the task page or the menu
	if (frameName == '') {
		form = document.getElementById(formID);
		urlInput = document.getElementById(urlInputID);
	} else {
		form = window.contentArea.document.getElementById(formID);
		urlInput = window.contentArea.document.getElementById(urlInputID);
	}

	// ask for a save action if the current work sheet is left
	if (origin == 'save' || origin == 'workSheets' || origin == 'chat') {
		saveWorkSheet = confirm(confirmSaveText);

		// append a save command if the user wants to save the current work
		// sheet
		if (saveWorkSheet == true) {
			url += '&save=yes';
		}
	}

	// submit the form if the current task page is left or a save action is to
	// be done
	if (origin != 'save' || saveWorkSheet == true) {
		urlInput.value = url;
		form.action = '../' + url;
		form.submit();
	}
}

/**
 * Shows a confirm window. The user can choose if he wants to save the current
 * work sheet. If so, a parameter which indicates a save operation is added to
 * the url of the next page to be shown.
 * 
 * @param source
 *            The element from which the function was called.
 */
function promptSave(source) {
	// ask for a save action
	var saveWorkSheet = confirm(confirmSaveText);

	// append a save command if the user wants to save the current work sheet
	if (saveWorkSheet == true) {
		if (source.href) {
			source.href += '&save=yes';
		}

		if (source.form) {
			source.form.action += '&save=yes';
		}
	}
}

/**
 * Makes an element visible.
 * 
 * @param elementID
 *            The id of the element to be shown.
 */
function show(elementID) {
	element = document.getElementById(elementID);
	element.style.display = 'inline';
}

/**
 * Sets the "action parameter" of the given form to "change language" and
 * submits the form. This is just to tell the application that the user just
 * changed the language and did not want to log on.
 * 
 * @param form
 *            The login form.
 */
function changeLanguage(form) {
	form.login.value = 'changeLanguage';
	form.submit();
}