var currentEntryFieldValue = "";
var text_removeObjectFromListConfirmMessage = "Wollen Sie das Objekt wirklich aus der Liste löschen?";
var text_removeObjectConfirmMessage = "Wollen Sie das Objekt wirklich löschen?";
var text_archiveObjectConfirmMessage = "Wollen Sie das Objekt wirklich archivieren?";
var isAdmin = false;
var businessObjectAdminAction = "/servlet/services?object=BusinessObjectAdmin";
var businessObjectAction = "/servlet/services?object=BusinessObject";              

function initAction() {
	form = document.BusinessObjectForm;
	if (form.isAdmin != null && form.isAdmin.value == "true") {
		isAdmin = true;
	} 
	if (form.action.match(/object=BusinessObjectAdmin/)) {
		isAdmin = true;
	}
	if (isAdmin) {
		form.action = businessObjectAdminAction;
	} else {
		form.action = businessObjectAction;
	}
}

function initBusinessObjectAdminAction() {
		
	form.action = businessObjectAdminAction;
}

function initBusinessObjectAction() {

	form.action = businessObjectAction;
}
               
function checkboxClicked (anObject) {

	this.valueChanged(anObject)
}

function toggleCheckboxClicked (anObject) {

	value = anObject.value;
	box = eval("document.BusinessObjectForm." + anObject.name); 
	for (i = 0; i < box.length; i++) {
		if (box[i].value != value) box[i].checked = false;
	}	
	this.valueChanged(anObject)
}


function handleOnFocusInEntryField(entryField) {
			
	currentEntryFieldValue = entryField.value;
	if (isObjectRegistered(entryField.name)) return;
	
	entryField.onkeyup = handleKeyUpEventInEntryField;
	entryField.onkeydown = handleKeyDownEventInEntryField;
	
}

function handleKeyDownEventInEntryField(event) {
	
	isKeyDownHandled = true;
	keyDownReturnValue = true;
	
	if (isNav) lastKey = event.which;
	if (isIE) lastKey = window.event.keyCode;
	
	if (lastKey >= 112 && lastKey <= 123) {			
		isKeyDownHandled = false;
		return true;
	}
	entryField = this;
	currentEntryFieldValue = entryField.value;
	
}

function handleKeyUpEventInEntryField(event) {
	
	isKeyUpHandled = true;
	keyUpReturnValue = true;
	
	if (isNav) lastKey = event.which;
	if (isIE) lastKey = window.event.keyCode;
	
	entryField = this;
	if (currentEntryFieldValue != entryField.value) valueChanged(entryField);
}

function valueChangedInEntryField(entryField) {
	
	if (currentEntryFieldValue != entryField.value) valueChanged(entryField);
}

var currentTextAreaValue = "";

function handleOnFocusInTextArea(entryField) {
			
	currentTextAreaValue = entryField.value;
	if (isObjectRegistered(entryField.name)) return;
	
	entryField.onkeyup = handleKeyUpEventInTextArea;
	entryField.onkeydown = handleKeyDownEventInTextArea;
	
}

function handleKeyDownEventInTextArea(event) {
	
	isKeyDownHandled = true;
	keyDownReturnValue = true;

	if (isNav) lastKey = event.which;
	if (isIE) lastKey = window.event.keyCode;
	
	if (lastKey >= 112 && lastKey <= 123) {			
		isKeyDownHandled = false;
		return true;
	}
	entryField = this;
	currentTextAreaValue = entryField.value;
	
}

function handleKeyUpEventInTextArea(event) {
	
	isKeyUpHandled = true;
	keyUpReturnValue = true;

	if (isNav) lastKey = event.which;
	if (isIE) lastKey = window.event.keyCode;
	
	entryField = this;
	if (currentTextAreaValue != entryField.value) valueChanged(entryField);
}

function valueChangedInTextArea(entryField) {
	
	if (currentTextAreaValue != entryField.value) valueChanged(entryField);
}

function valueChanged(anObject) {

}


function goTo(url) {
	
	form = document.BusinessObjectForm;
	form.action = url;
	form.target = "";
	form.submit();
				
}

function adminObjectPrivileges() {
      
	initAction();  
	form = document.BusinessObjectForm;
	form.command.value = "adminPrivileges";
	form.target = "";
	form.submit();
				
}

function saveObjectPrivileges() {

	initAction();
	form = document.BusinessObjectForm;
	form.command.value = "savePrivileges";
	form.target = "";
	form.submit();
				
}

function saveBusinessObject() {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "save";
	form.target = "";
	form.submit();
				
}

function saveLocalBusinessObject() {

	initAction();
	form = document.BusinessObjectForm;
	form.command.value = "saveLocal";
	form.action = action;
	form.target = "";
	form.submit();
				
}

function sendBusinessObject() {

	initAction();
	form = document.BusinessObjectForm;
	form.command.value = "send";
	form.target = "";
	form.submit();
				
}


function newBusinessObject() {

	initAction();
	form = document.BusinessObjectForm;
	form.command.value = "new";
	form.target = "";
	form.submit();
				
}

function copyBusinessObject() {

	initAction();
	form = document.BusinessObjectForm;
	form.command.value = "copy";
	form.target = "";
	form.submit();
				
}

function deleteBusinessObject(anObjectId) {

	initAction();  	
	if (window.confirm(text_removeObjectConfirmMessage)) {
		form = document.BusinessObjectForm;
		form.command.value = "delete";
		if (anObjectId != null) {
			currentObjectId = form.oid.value;
			form.oid.value = anObjectId;
		}		
		form.target = "";
		form.submit();
		form.oid.value = currentObjectId;
	}
				
}


function markBusinessObjectAsDeleted() {

	initAction();  	
	if (window.confirm(text_removeObjectConfirmMessage)) {
		form = document.BusinessObjectForm;
		form.command.value = "markAsDeleted";
		form.target = "";
		form.submit();
	}
				
}

function upload() {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "upload";
	form.target = "";
	form.submit();				
}

function uploadAndSave() {
	
	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "uploadAndSave";
	form.target = "";
	form.submit();				
}

function archiveBusinessObject() {

	initAction();  	
	if (window.confirm(text_archiveObjectConfirmMessage)) {
		form = document.BusinessObjectForm;
		form.command.value = "archive";
		form.target = "";
		form.submit();
	}
				
}

function setCurrentBusinessObject() {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "setCurrent";
	form.target = "";
	form.submit();
				
}


function executeCommand(aCommandName) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = aCommandName;
	form.target = "";
	form.submit();
	
				
}


function nextBusinessObject() {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "next";
	form.target = "";
	form.submit();
				
}

function previousBusinessObject() {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "previous";
	form.target = "";
	form.submit();
				
}

function resetBusinessObject() {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "reload";
	form.target = "";
	form.submit();
				
}


function showRelationship(aRelationshipName) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "showRelationship";
	form.relationshipName.value = aRelationshipName;
	form.target = "";
	form.submit();

}

var newWindow;

function showRelationshipInNewWindow(aRelationshipName, name, w, h) {

	initAction();  	
	newWindow = "";
  	newWindow = window.open("", name, "width=" + w + ",height=" + h + ",scrollbars=yes");
	form = document.BusinessObjectForm;
	form.command.value = "showRelationship";
	form.relationshipName.value = aRelationshipName;
	form.target = newWindow.name;
	form.submit();
  	setTimeout("newWindow.focus()", 500);

}


function addToRelationshipUsingChildWindow(aRelationshipName, name, w, h) {

	initAction();  	
	newWindow = "";
  	newWindow = window.open("", name, "width=" + w + ",height=" + h + ",scrollbars=yes");
	form = document.BusinessObjectForm;
	form.command.value = "chooseFromRelationship";
	form.relationshipName.value = aRelationshipName;
	form.target = newWindow.name;
	form.submit();
  	setTimeout("newWindow.focus()", 500);

}

function addAllToRelationship(aRelationshipName, aResultSetId) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "addAllToRelationship";
	form.relationshipName.value = aRelationshipName;
	form.roid.value = aResultSetId;
	form.target = "";
	form.submit();
}

function addToRelationship(aRelationshipName, anObjectId) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "addToRelationship";
	form.relationshipName.value = aRelationshipName;
	form.roid.value = anObjectId;
	form.target = "";
	form.submit();

}

function removeFromRelationship(aRelationshipName, anObjectId) {

	initAction();  	
	if (window.confirm(text_removeObjectFromListConfirmMessage)) {
		form = document.BusinessObjectForm;
		form.command.value = "removeFromRelationship";
		form.relationshipName.value = aRelationshipName;
		form.roid.value = anObjectId;
		form.submit();
	}

}

function addNewAggregation(aRelationshipName, anOid) {

	initAction();  	
	form = document.BusinessObjectForm;
	oldOid = form.oid.value;
	if (anOid != null) form.oid.value = anOid;
	form.command.value = "addNewAggregation";
	form.relationshipName.value = aRelationshipName;
	form.target = "";
	form.submit();
	form.oid.value = oldOid;
}


function addNewAggregationUsingChildWindow(aRelationshipName, name, w, h) {

	initAction();  	
	newWindow = "";
  	newWindow = window.open("", name, "width=" + w + ",height=" + h + ",scrollbars=yes");
	form = document.BusinessObjectForm;
	form.command.value = "addNewAggregation";
	form.relationshipName.value = aRelationshipName;
	form.target = newWindow.name;
	form.submit();
  	setTimeout("newWindow.focus()", 500);

}

function showBusinessObjectAdmin(anObjectId) {

	form = document.BusinessObjectForm;
	form.action = businessObjectAdminAction;
	form.command.value = "show";
	form.action += "&oid=" + anObjectId;
	form.target = "";
	form.submit();

}

function showBusinessObject(anObjectId) {

	form = document.BusinessObjectForm;
	form.action = businessObjectAction;
	form.command.value = "show";
	form.action += "&oid=" + anObjectId;
	form.target = "";
	form.submit();

}

function showOtherBusinessObject(anObjectId) {

	form = document.BusinessObjectForm;
	form.action = businessObjectAction;
	form.command.value = "show";
	form.action += "&oid=" + anObjectId + "&url=none";;
	form.target = "";
	form.submit();

}

function showOtherBusinessObjectAdmin(anObjectId) {
           
	form = document.BusinessObjectForm;
	form.action = businessObjectAdminAction;
	form.command.value = "show";
	form.action += "&oid=" + anObjectId + "&url=none";;
	form.target = "";
	form.submit();

}

function expandBusinessObject(anObjectId) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "expand";
	form.action += "&boid=" + anObjectId;
	form.target = "";
	form.submit();

}

function expandRelationship(anObjectId, aRelationshipName) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.relationshipName.value = aRelationshipName;
	form.command.value = "expandRelationship";
	form.action += "&boid=" + anObjectId;
	form.target = "";
	form.submit();

}


function changeSelectedCodeListUsingChildWindow(anAttributeName,  windowName, w, h) {

	initAction();  	
	attributeWindow = "";
  	attributeWindow = window.open("", windowName, "width=" + w + ",height=" + h + ",scrollbars=yes");
	form = document.BusinessObjectForm;
	form.command.value = "changeSelectedCodeList" + "@" + anAttributeName;
	form.target = attributeWindow.name;
	form.submit();
  	setTimeout("attributeWindow.focus()", 500);

}

function showSelectedCodeListUsingChildWindow(anAttributeName,  windowName, w, h) {

	initAction();  	
	attributeWindow = "";
  	attributeWindow = window.open("", windowName, "width=" + w + ",height=" + h + ",scrollbars=yes");
	form = document.BusinessObjectForm;
	form.command.value = "showSelectedCodeList" + "@" + anAttributeName;
	form.target = attributeWindow.name;
	form.submit();
  	setTimeout("attributeWindow.focus()", 500);

}


function setRelationInfo(anObjectId, anInfoName, multipleSelectable) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "setRelationInfo";
	form.action += "&boid=" + anObjectId + "&infoName=" + anInfoName + "&multipleSelectable=" + multipleSelectable;;
	form.target = "";
	form.submit();

}

function setRelationInfoForRelationName(anObjectId, anInfoName, anRelationshipName, multipleSelectable) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "setRelationInfo";
	form.action += "&boid=" + anObjectId  + "&relationName=" + anRelationshipName + "&infoName=" + anInfoName + "&multipleSelectable=" + multipleSelectable;
	form.target = "";
	form.submit();

}


function up(anObjectId) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "up";
	form.action += "&boid=" + anObjectId;
	form.submit();

}

function down(anObjectId) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "down";
	form.action += "&boid=" + anObjectId;
	form.submit();

}

function printReport(anObjectType, anExportType) {
	
	initAction();  	
	form = document.BusinessObjectForm; 
	form.command.value = "printReport";
	form.action += "&exportObjectType=" + anObjectType + "&exportType=" + anExportType;
	form.target="";
	form.submit();
				
}              

function nextResults(aResultSetId) {
	
	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "nextResults";
	form.roid.value = aResultSetId;
	form.target="";
	form.submit();				
}

function previousResults(aResultSetId) {

	initAction();  	
	form = document.BusinessObjectForm;
	form.command.value = "previousResults";
	form.roid.value = aResultSetId;
	form.target="";
	form.submit();
				
}
