// this happens for dialog windows
function file__returnFile (fileData) {
	var dialog = window.opener.dialog__returnData;
	dialog.returnValue = fileData;
	if ('undefined' != typeof fileData.CKEditorFuncNum && fileData.CKEditorFuncNum) {
		window.opener.CKEDITOR.tools.callFunction (fileData.CKEditorFuncNum, fileData.url);
	} else if ('undefined' != typeof dialog.returnFunction && dialog.returnFunction) {
		dialog.returnFunction (dialog.returnValue, dialog.objectId);
	}
	window.close ();
}

// this is the normal browser in admin/
function file__selectFile (fileData) {
	window.location=fileData.url;
}

// when a file-as-relation is edited
// this is called for opening the file chooser window
// and later modifying the relation-editor contents
function file__openRelationChooser (relationId, targetUrl) {
	var dialog = window.dialog__returnData;
	dialog.returnFunction = window.file__setRelation;
	dialog.objectId = relationId;
	dialogWidth = 500;
	dialogHeight = 500;
	window.open (targetUrl,'','status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=true,scrollbars=1,width=' + dialogWidth + ',height=' + dialogHeight)
}

function file__setRelation (relationData, htmlId) {
	file__updateRelation (relationData.id, htmlId);
}

function file__updateRelation (relationId, htmlId) {
	document.getElementById(htmlId + '_value').value = relationId;
	// document.getElementById(htmlId + '_preview').innerHTML = relationId;
	xajax_assign ('/file/preview/id=' + relationId, htmlId + '_preview');
}

function disableEventPropagation (event) {
   if (event.stopPropagation) {
       event.stopPropagation ();
   } else if (window.event) {
      window.event.cancelBubble=true;
   }
}

