function attach(nextAction, fileUploadName, targetForm) {
	var attachmentAction 	= document.getElementsByName("attachmentAction")[0];
	var action 				= document.getElementsByName("action")[0];

	if(nextAction) {
        attachmentAction.value = 'add';
        action.value = nextAction;
	} else {
	    alert("Error: Next action is not defined!");
	}

    if(attachment_check(fileUploadName)) {
		avoidDown4Upload();
        uniqSubmit(targetForm);
    }
}

function avoidDown4Upload() {
	document.onmousedown = document.onkeydown = function () {
		alert('Bitte warte bis der Upload abgeschglossen ist!\nPlease wait until the upload has finished!');
	}
}

function attachment_check(fileUploadName) {
	var attachmentAction 	= document.getElementsByName("attachmentAction")[0];

	if(fileUploadName) {
        var file_upload = document.getElementsByName(fileUploadName)[0];
	} else {
        var file_upload = document.getElementsByName("file_upload")[0];
	}

    if(attachmentAction.value) {
        if(attachmentAction.value == 'add') {
            if(file_upload) {
                if(file_upload.value == '') {
                    alert('Bitte Datei auswählen!\nPlease enter file!');
                    file_upload.focus();
                    return false;
                } else {
                    return true;
                }
            } else {
                alert("Error: No file_upload input found!");
            }
        }
    }

    return false;
}

function uniqSubmit(targetForm) {
    if(!targetForm) {
        targetForm = "compose";
    }

	var form = document.getElementsByName(targetForm)[0];

	if(form) {
	   form.submit();
	} else {
	    alert("Error: No form available for submit!");
	}
}