/**
 * Title:         ICSS
 * Description:   Internet Customer Self Service
 * Copyright:     Copyright (c) 2004, All rights reserved
 * Company:       SAP AG
 * JS file:       util.js
 */

/*******************************************/
/** This function creates a new window if **/
/** it does not exist and opens it        **/
/*******************************************/
function openWindow(windowName, content) {
	/* Looking if the wihdow already exists in the windows list */
	/*
	if(windowList !== null)
	{
	for (localIndex in windowList)
		if (!windowList[localIndex].closed && windowList[localIndex].name == windowName) {
			if (windowList[localIndex].name == 'winHelp') {
				windowList[localIndex].close();
				openWindow(windowName, content);
				return;
			}

			windowList[localIndex].focus();
			return;
		}
	}
	var windowProperties = "";

	if (windowName == 'login') windowProperties = 'width=600,height=510,screenX=250,screenY=180,left=250,top=180,menubar=no,locationbar=no,status=yes,scrollbars=yes,resizable=yes';
	else windowProperties = 'width=650,height=560,screenX=200,screenY=100,left=250,top=100,menubar=no,locationbar=no,status=yes,scrollbars=yes,resizable=yes';

	var windowId = window.open(content, windowName, windowProperties);
	windowList[index++] = windowId; /* add the opened window in the windows list */

	//windowId.focus();
	
}

/*******************************************/
/** This function closes all of the child **/
/** windows.                              **/
/*******************************************/
function closeChilds() {
	var localIndex;

	for (localIndex in headerTop.windowList) headerTop.windowList[localIndex].close();
}

/*******************************************/
/** This function sets the currect urls   **/
/** in the organizer, workarea, and       **/
/** the header bottom frames              **/
/*******************************************/
function refreshFrames(headerBottomUrl, organizerUrl, workAreaUrl) {
//	resetFocus();

	/** reload the header bottom frame **/
	parent.headerBottom.location.href = headerBottomUrl;

	/** reload the navigation frame **/
	parent.organizer.location.href = organizerUrl;

	/** reload the workarea frame **/
	parent.workarea.location.href = workAreaUrl;
}

/*************************************************/
/** Disable the login button of the parent page **/
/*************************************************/
function loginButtonDisable() {
	if (opener.parent.headerTop) if (opener.parent.headerTop.document.CRMForm) if (opener.parent.headerTop.document.CRMForm.login) opener.parent.headerTop.document.CRMForm.login.disabled = true;
}

/*************************************************/
/** Enable the login button of the parent page  **/
/*************************************************/
function loginButtonEnable() {
	if (document.all) document.body.style.cursor = "default";

	if (opener.parent.headerTop) if (opener.parent.headerTop.document.CRMForm) if (opener.parent.headerTop.document.CRMForm.login) opener.parent.headerTop.document.CRMForm.login.disabled = false;
}

/*****************************************************/
/** Submit a form, but only once. The submitForm    **/
/** returns true if the form has not been submitted **/
/** and disable the "cancel" button in the form     **/
/** if disableCancelButton is true.                 **/
/** if also change the cursor style of the document **/
/*****************************************************/
var formSubmitted = false; /* Tells if the form has been submitted already */

function submitForm(formName, disableCancelButton) {
	if (!formSubmitted) {
		formSubmitted = true;
		var disableCB = eval('document.' + formName + '.cancel');

		if (disableCancelButton) disableCB.disabled = true;

		if (document.all) document.body.style.cursor = "wait";

		return true;
	}

	return false;
}
