//hhhh

var Application = Class.create();

Application.prototype = {

	nodeActionUrl: '/pages/nodeAction.aspx',
	dataFrameUrl: '/pages/dataFrame.aspx',
	contentFrameUrl: '/pages/contentFrame.aspx',
	treeFrameUrl: '/pages/treeFrame.aspx',
	treeFragmentUrl: '/pages/treeFragment.aspx',
	treeActionUrl: '/pages/treeAction.aspx',
	dialogWithoutTreeUrl: '/pages/nodeDialog.aspx',
	dialogWithTreeUrl: '/pages/nodeDialog.aspx',
	dialogActionUrl: '/pages/dialogAction.aspx',
	searchFrameUrl: '/pages/searchFrame.aspx',
	searchInfoUrl: '/pages/searchInfo.aspx',
	trackingSearchUrl: '/pages/TrackingSearch.aspx',
	standardSearchUrl: '/pages/StandardSearch.aspx',
	rdfSearchUrl: '/pages/RdfSearch.aspx',
	solrResultsUrl: '/pages/solrResults.aspx',
	userManagementUrl: '/pages/usermanagement.aspx',
	statusManagementUrl: '/pages/statusmanagement.aspx',
	groupManagementUrl: '/pages/groupmanagement.aspx',
	importManagementUrl: '/pages/importmanagement.aspx',
	mappingUrl: '/pages/mappingmanagement.aspx',
	authorizationManagementUrl: '/pages/authorizationmanagement.aspx',
	keepAliveUrl: '/pages/keepAlive.aspx',

	initialize: function(referenceStructureId, rootNodeId, nodeId, uri, subUri) {
		this.referenceStructureId = referenceStructureId;
		this.rootNodeId = rootNodeId;
		this.nodeId = nodeId;
		this.uri = uri;
		this.subUri = subUri;
		this.moveMode = 'noMove';
		this.moveButtonId = null;
		this.mergeMode = 'noMerge';
		this.mergeButtonId = null;
		this.mode = "view";
		this.persistentMode = true;
		this.showTreeOnly = false;
		this.isReferred = false;
		this.isReferredNode = false;
		this.annexNodeId = undefined;
	},

	toString: function() {
		var sp = "\n";
		return ("uri: " + this.uri + sp + "subUri: " + this.subUri + sp + "mode: " + this.mode);
	},

	showAllStructures: function() {
		var pageURL = application.treeFrameUrl;
		var action = "showList";
		var myAjax = new Ajax.Updater({ success: 'column1' }, pageURL, { method: 'get', parameters: { action: action }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				//applicationSetTreeSelection();
			}
		}
			);
	},

	showTree: function(showItemInOwnContext) {
		applicationStartWait();
		var pageURL = application.treeFrameUrl;
		var action = "showTree";
		var treeViewMode = (treeEditor.viewModes[application.referenceStructureId]) ? treeEditor.viewModes[application.referenceStructureId] : "conceptFirst";
		var myAjax = new Ajax.Updater({ success: 'column1' }, pageURL, { method: 'get', parameters: { nodeId: application.nodeId, uri: application.uri, treeViewMode: treeViewMode, action: action, showItemInOwnContext: showItemInOwnContext }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				applicationEndWait();
				//applicationSetTreeSelection();
			}
		}

			);
	},

	showSelectionTree: function(allowedRdfTypes, predicateUri) {
		var pageURL = application.treeFragmentUrl;
		var onBuildNode = true;
		var show = true;
		var isNodeRebuilded = 'false';
		var treeFragment = 'node';
		var action = "showTreeFragment";
		var treeViewMode = "conceptFirst";
		var postBody = ""; //"allowedRdfTypes=" + allowedRdfTypes + "&allowedSubContentItemSubTypes=" + allowedSubContentItemSubTypes;

		var myAjax = new Ajax.Updater({ success: 'treeContainer' }, pageURL, { method: 'post', parameters: { referenceStructureId: application.referenceStructureId, nodeId: application.nodeId, treeFragment: treeFragment, isNodeRebuilded: isNodeRebuilded, treeViewMode: treeViewMode, action: action, postBody: postBody, allowedRdfTypes: allowedRdfTypes, predicateUri: predicateUri }, asynchronous: false,
			onComplete: function(t) {
				applicationSetTreeSelection()
			}
		}
			);
	},

	updateNodeMoveStructure: function(source, target, moveMode) {
		var pageURL = application.treeFrameUrl;
		var action = "moveStructureListNode";
		var myAjax = new Ajax.Updater({ success: 'column1' }, pageURL, { method: 'get', parameters: { action: action, source: source, target: target, moveMode: moveMode }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				//applicationSetTreeSelection();					
			}
		}
		);
	},

	deleteStructureListFolder: function(source) {
		var pageURL = application.treeFrameUrl;
		var action = "deleteFolder";
		var myAjax = new Ajax.Updater({ success: 'column1' }, pageURL, { method: 'get', parameters: { action: action, source: source }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				//applicationSetTreeSelection();					
			}
		}
		);
	},

	renameStructureListFolder: function(source, folderName) {
		var pageURL = application.treeFrameUrl;
		var action = "renameFolder";
		var myAjax = new Ajax.Updater({ success: 'column1' }, pageURL, { method: 'get', parameters: { action: action, source: source, folderName: folderName }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				//applicationSetTreeSelection();					
			}
		}
		);
	},

	newStructureListFolder: function(target, folderName) {
		var pageURL = application.treeFrameUrl;
		var action = "newFolder";
		var myAjax = new Ajax.Updater({ success: 'column1' }, pageURL, { method: 'get', parameters: { action: action, target: target, folderName: folderName }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				//applicationSetTreeSelection();					
			}
		}
		);
	},

	showData: function(uri, sysTab, mode, nodeContext, pageNumber) {
		applicationStartWait();
		var pageURL = application.dataFrameUrl;
		var myAjax = new Ajax.Updater({ success: 'column2' }, pageURL, { method: 'get', parameters: { uri: uri, sysTab: sysTab, mode: mode, nodeId: nodeContext, pageNumber: pageNumber }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				applicationUpdateMd5ForForm();
				applicationEndWait();
			}
		});
	},

	showExpandData: function(uri, sysTab, mode, nodeContext, pageNumber, targetElementId) {
		applicationStartWait();
		var pageURL = application.contentFrameUrl;
		var myAjax = new Ajax.Updater({ success: targetElementId }, pageURL, { method: 'get', parameters: { uri: uri, renderMode: "inline", sysTab: sysTab, mode: mode, nodeId: nodeContext, pageNumber: pageNumber }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				//applicationUpdateMd5ForForm();
				applicationEndWait();
			}
		});
	},

	showSearch: function(mode, searchTab, reload) {
		applicationStartWait();
		var pageURL = application.searchFrameUrl;
		var myAjax = new Ajax.Updater({ success: 'column3' }, pageURL, { method: 'get', parameters: { searchType: mode, tabName: searchTab }, asynchronous: false, evalScripts: true,
			onComplete: function(t) {
				dynamicLayout();
				applicationEndWait();
			}
		});
	},

	updateTitle: function(s) {
		document.title = s + ((s != "") ? " - " : "") + strings.applicationTitle;
	},

	selectInnerHTMLForClipBoard: function(obj) {
		if ($(obj.id)) {
			if (document.all) {
				// ie >> copy selected text to clipboard
				var copy = $(obj.id).createTextRange();
				copy.execCommand("RemoveFormat");
				copy.execCommand("Copy");
			}
			// all other browsers: only select text
			$(obj.id).focus();
			$(obj.id).select();
		}
	}
}
