/**
 * @param formName the form that shall be submitted
 * @param actionURL the handler the shall be uses (e.g. "/my_app/handler")
 * @param strEvent the action that shall be executed (e.g. "loadTaskList")
 * @param strTarget_inp the target frame
 * @param sourceFrame the frame where the form is located
 */
function submitForm(formName, actionURL, strEvent, strTarget_inp, sourceframe) {
	submitFormToWin(formName, actionURL, strEvent, top, strTarget_inp, sourceframe);
	if(top.frames['foot1'] && top.frames['foot1'].resetCountdown) {
		top.frames['foot1'].resetCountdown();
	}
}

function submitFormToWin(formName, actionURL, strEvent, targetWin, strTarget_inp, sourceframe) {
	// --- init the stuff --- //
	var target_array = strTarget_inp.split(',');
	var strTarget = target_array[0];
	var winWidth  = (target_array.length > 1) ? target_array[1] : 656;
	var winHeight = (target_array.length > 2) ? target_array[2] : screen.availHeight;

	// --- fill optional args --- //
	if ((!sourceframe) || sourceframe=='') {
		sourceframe = "content";
	}
	if (strTarget == '') {
		strTarget = '_self';
/*	} else if (strTarget.indexOf('save') != -1) {
		// change 'save' and 'aftersave' to a unique name
		strTarget = top.getRealFrameName(strTarget);
*/	}

	// --- get Objects to handle --- //
	var theFrame = (top.name == sourceframe) ? top : top.frames[sourceframe];
	if (!theFrame) {
		alert("Source frame '" + sourceframe + "' not found!");
	}
	var theDocument = theFrame.document;
	var theForm = theDocument.forms[formName];
	if (!theForm) {
		alert("Form '" + formName + "' not found in source frame '" + sourceframe + "'!");
	}

	// --- check the form contents --- //
	if (theDocument.checkForm != null) {
		allowSend = theDocument.checkForm(strEvent);
	} else {
		allowSend = true; // evtl strEvent=save oder aehnl. ausschliessen??
	}
	var changesSaved = true;
	if (top.content && top.content.checkChangesSaved != null && top.content.checkChangesSaved != 'undefined') {
		if(sourceframe != 'content'){
			changesSaved = top.content.checkChangesSaved();
		}
	}
	// --- submit the form --- //
	if (theForm && allowSend && changesSaved) {
		// --- make unique --- //
		var mainWin;
		if (targetWin) {
			mainWin = targetWin;
		} else {
			mainWin = (top.name == sourceframe) ? window.opener.top : top;
		}
		try {
			if (mainWin.frames["content"] && mainWin.frames["content"].name=="content" && mainWin.frames["content"].location.href.indexOf("login.jsp") == -1) {
				actionURL = getUniqueString(actionURL, mainWin);
			}
		} catch(e) {
			// do nothing should the content be not accessible
		}
		// --- set values --- //
		theForm.action = actionURL;
		theForm.target = strTarget;
		if (strEvent != '') {
			theForm.elements["event"].value = strEvent;
		}

		// --- submit --- //
		if (theFrame.doSubmit != null) {
			theFrame.doSubmit(formName);
		} else {
			theForm.submit();
		}
	}
}


function getUniqueString(actionURL, mainWin) {
	var splitIndex = (actionURL.indexOf('?') == -1) ? actionURL.length : actionURL.indexOf('?');
	var queryStr = actionURL.substring(splitIndex, actionURL.length);
	var jetzt = new Date();
	var uniqueStr = "" + Date.parse(jetzt) + Math.random();

	return actionURL.substring(0, splitIndex) + "/" + uniqueStr + mainWin.sessionIdStr + queryStr;
}

