function slyFileForm(parentNode, configuration) {
	
	this.parentNode = parentNode;
	if (!configuration) return;
	this.configuration = configuration;
	if (!this.configuration.entity) { alert('Configuration of slyForm failed. Please provide an entity!'); return; }

	this.id = 'slyFile-' + this.configuration.entity + '-' + (new Date()).getTime();
	this.node = document.createElement('div');
	this.node.id = this.id;
	this.node.className = 'slyWidget slyTable';
	this.parentNode.appendChild(this.node);
	sly.widgets[this.id] = this;

	var html = '';
	html += '<div id="' + this.id + '-navDiv" class="slyForm-NavPanelContainer">';	
	html += '<div class="slyForm-NavPanel">';
	html += '<a id="' + this.id + '-navFirstObject" class="iconButton iconButtonFirstPage" href="" onclick="sly.widgets[\'' + this.id + '\'].firstObject(); return false" title="Erstes Element in der Liste">First object</a> ';
	html += '<a id="' + this.id + '-navPrevObject" class="iconButton iconButtonPrevPage" href="" onclick="sly.widgets[\'' + this.id + '\'].prevObject(); return false" title="Vorheriges Element in der Liste">Previous object</a> ';
	html += '<a id="' + this.id + '-navOverview" class="iconButton iconButtonOverview" href="" onclick="sly.widgets[\'' + this.id + '\'].backToOverview(); return false" title="Zurück zur Liste">Overview</a> ';
	html += '<a id="' + this.id + '-navNextObject" class="iconButton iconButtonNextPage" href="" onclick="sly.widgets[\'' + this.id + '\'].nextObject(); return false" title="Nächstes Element in der Liste">Next object</a> ';
	html += '<a id="' + this.id + '-navLastObject" class="iconButton iconButtonLastPage" href="" onclick="sly.widgets[\'' + this.id + '\'].lastObject(); return false" title="Letztes Element">Last object</a> ';
	html += '</div>';
	html += '<div id="slyForm-NavObjectInfo" class="slyForm-NavPanel">Objekt ' + (this.configuration.rowIndex + 1) + '/' + this.configuration.overviewTable.filteredData.length + '</div>';
	html += '</div>';
	html += '<div style="clear:both"></div>';
	html += '<div id="' + this.id + '-form">';
	html += '<table>';
	html += '<tr><td><span style="font-weight:bold">Name:</span></td><td><input id="slyNewsForm_name" type="text" value="' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].name : '') + '" style="width:636px" /></td></tr>';
	html += '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>';
	html += '<tr><td colspan="2"><div style="position:relative; left:-5px; padding-bottom:5px"><input type="radio" id="slyNewsForm_local" onclick="document.getElementById(\'slyNewsForm_localFile\').style.display = \'block\'; document.getElementById(\'slyNewsForm_remoteFile\').style.display = \'none\'; sly.clearTooltip();" name="slyNewsForm_source" value="local" checked="checked" />Lokale Datei&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" id="slyNewsForm_remote" name="slyNewsForm_source" onclick="document.getElementById(\'slyNewsForm_localFile\').style.display = \'none\'; document.getElementById(\'slyNewsForm_remoteFile\').style.display = \'block\'; sly.clearTooltip();" value="remote" />Remote-Datei</div></td></tr>';
	html += '<tr><td valign="top"><span style="font-weight:bold">Datei:</span></td><td><div id="slyNewsForm_localFile"><div id="slyNewsForm_data"></div></div><div id="slyNewsForm_remoteFile" style="display:none"><input id="slyNewsForm_url" type="text" value="' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].url : '') + '" style="width:636px" /></div></td></tr>';
	html += '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>';
	html += '<tr><td>publiziert:</td><td><input type="checkbox" id="slyNewsForm_published" checked="checked" /></td></tr>';
	html += '<tr><td>Reihenfolge:</span></td><td><input id="slyNewsForm_publishOrder" type="text" style="width:30px" value="' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].publishOrder : '') + '" /></td></tr>';
	html += '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>';
	html += '<tr><td><span style="color:#666666">Dateityp:</span></td><td><span style="color:#666666" id="slyNewsForm_fileType">' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].type : '') + '</span></td></tr>';
	html += '<tr><td><span style="color:#666666">Dateigrösse:</span></td><td><span style="color:#666666" id="slyNewsForm_fileSize">' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].size : '') + ' KB</span></td></tr>';
	html += '<tr><td><span style="color:#666666">Upload-Datum:</span></td><td><span style="color:#666666" id="slyNewsForm_fileDate">' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].date : '') + '</span></td></tr>';
	html += '</table>';
	html += '</div>';
	html += '<div style="text-align:right"><input type="button" value="Zurück" onclick="sly.widgets[\'' + this.id + '\'].backToOverview()" /><input type="button" id="slyNewsForm_saveButton" value="Speichern" onclick="sly.widgets[\'' + this.id + '\'].saveObject()" /></div>';
	this.node.innerHTML = html;

	var ajaxUpload = document.createElement('div');
    ajaxUpload.id = 'ajaxUploadResult';
    ajaxUpload.innerHTML = '<form id="slyAjaxUpload" name="slyAjaxUpload" method="post" enctype="multipart/form-data"><input type="file" name="slyAjaxUploadFile" onchange="document.getElementById(\'slyNewsForm_url\').value = \'\'; sly.ajaxUpload(document.getElementById(\'slyAjaxUpload\'));" /></form>';
    document.getElementById('slyNewsForm_data').parentNode.appendChild(ajaxUpload);
	try { document.getElementById('slyNewsForm_name').focus(); } catch (err) {}
}

slyFileForm.prototype.refresh = function() {
	document.getElementById('slyNewsForm_name').value = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].name;
	document.getElementById('slyNewsForm_url').value = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].url;
	document.getElementById('slyNewsForm_publishOrder').value = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].publishOrder;
	if (this.configuration.overviewTable.filteredData[this.configuration.rowIndex].url) {
		document.getElementById('slyNewsForm_data').innerHTML = '';
		document.getElementById('slyNewsForm_remote').checked = true;
		document.getElementById('slyNewsForm_localFile').style.display = 'none';
		document.getElementById('slyNewsForm_remoteFile').style.display = 'block';
	} else {
		document.getElementById('slyNewsForm_data').innerHTML = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].name;
		document.getElementById('slyNewsForm_local').checked = true;
		document.getElementById('slyNewsForm_localFile').style.display = 'block';
		document.getElementById('slyNewsForm_remoteFile').style.display = 'none';
	}
	document.getElementById('slyNewsForm_fileType').innerHTML = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].type;
	document.getElementById('slyNewsForm_fileSize').innerHTML = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].size + ' KB';
	var val = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].date;
	val = val.substring(8,10) + '.' + val.substring(5,7) + '.' + val.substring(0,4);
	document.getElementById('slyNewsForm_fileDate').innerHTML = val;
	if (this.configuration.overviewTable.filteredData[this.configuration.rowIndex].published == 1) document.getElementById('slyNewsForm_published').checked = true;
	else document.getElementById('slyNewsForm_published').checked = false;
	document.getElementById('slyForm-NavObjectInfo').innerHTML = 'Objekt ' + (this.configuration.rowIndex + 1) + '/' + this.configuration.overviewTable.filteredData.length;
	if (this.configuration.rowIndex == 0) {
		document.getElementById(this.id + '-navFirstObject').className = 'iconButton iconButtonFirstPage iconButtonFirstPageDisabled';
		document.getElementById(this.id + '-navPrevObject').className = 'iconButton iconButtonPrevPage iconButtonPrevPageDisabled';
	} else {
		document.getElementById(this.id + '-navFirstObject').className = 'iconButton iconButtonFirstPage';
		document.getElementById(this.id + '-navPrevObject').className = 'iconButton iconButtonPrevPage';
	}
	if (this.configuration.rowIndex < this.configuration.overviewTable.filteredData.length - 1) {
		document.getElementById(this.id + '-navNextObject').className = 'iconButton iconButtonNextPage';
		document.getElementById(this.id + '-navLastObject').className = 'iconButton iconButtonLastPage';
	} else {
		document.getElementById(this.id + '-navNextObject').className = 'iconButton iconButtonNextPage iconButtonNextPageDisabled';
		document.getElementById(this.id + '-navLastObject').className = 'iconButton iconButtonLastPage iconButtonLastPageDisabled';
	}
	try { document.getElementById('slyNewsForm_name').focus(); } catch (err) {}
};

slyFileForm.prototype.backToOverview = function() {
	if (document.getElementById('tooltip')) {
		document.body.removeChild(document.getElementById('tooltip'));
		clearTimeout(tooltipTimeout);
	}
	document.getElementById(this.configuration.overviewTable.id).style.display = 'block';
	this.configuration.overviewTable.formNode.style.display = 'none';
	try { document.getElementById(this.configuration.overviewTable.id + '-NavFilter').focus(); } catch (err) {}
};

slyFileForm.prototype.firstObject = function() {
	this.configuration.rowIndex = 0;
	this.refresh();
};

slyFileForm.prototype.prevObject = function() {
	if (this.configuration.rowIndex > 0) this.configuration.rowIndex--;
	this.refresh();
};

slyFileForm.prototype.nextObject = function() {
	if (this.configuration.rowIndex < this.configuration.overviewTable.filteredData.length - 1) this.configuration.rowIndex++;
	this.refresh();
};

slyFileForm.prototype.lastObject = function() {
	this.configuration.rowIndex = this.configuration.overviewTable.filteredData.length - 1;
	this.refresh();
};

slyFileForm.prototype.saveObject = function() {
	var _this = this;
	var name = document.getElementById('slyNewsForm_name');
	var data = document.getElementById('slyNewsForm_data');
	var url = document.getElementById('slyNewsForm_url');
	var published = document.getElementById('slyNewsForm_published');
	var publishOrder = document.getElementById('slyNewsForm_publishOrder');
	
	//------------------------- VALIDATIONS --------------------------
	if (name.value == '') {
		new slyTooltip('Geben Sie einen Namen für die Datei ein!', name);
		name.focus();
		return;
	}
	if (document.getElementById('slyNewsForm_local').checked && data.innerHTML == '') {
		new slyTooltip('Geben Sie eine lokale Datei an!', data);
		data.focus();
		return;
	}
	if (document.getElementById('slyNewsForm_remote').checked && url.value == '') {
		new slyTooltip('Geben Sie die URL der externen Datei ein!', url);
		url.focus();
		return;
	}
	if (document.getElementById('slyNewsForm_remote').checked && !url.value.match(/^[^:]+:\/\//)) {
		url.value = 'http://' + url.value;
	}
	
	document.getElementById('slyNewsForm_saveButton').disabled = true;
	
	sly.call('checkURL', {url:url.value}, function(data) {

		if (document.getElementById('slyNewsForm_remote').checked  && data.status == 'invalid') {
			new slyTooltip('Geben Sie eine gültige URL ein!', url);
			url.focus();
			document.getElementById('slyNewsForm_saveButton').disabled = false;
			return;
		}
	
		var obj = {};
		obj.entity = 'files';
		if (_this.configuration.action == 'update') obj.id = _this.configuration.overviewTable.filteredData[_this.configuration.rowIndex].id;
		obj.name = document.getElementById('slyNewsForm_name').value;
		obj.data = document.getElementById('slyNewsForm_data').innerHTML.replace(/^[^>]+>/, '');
		obj.url = document.getElementById('slyNewsForm_url').value;
		obj.page = location.href;
		obj.publishOrder = document.getElementById('slyNewsForm_publishOrder').value;
		obj.published = document.getElementById('slyNewsForm_published').checked ? 1 : 0;
		sly.call('save', obj, function(res) {
			if (res.statusCode != 200) alert(res.statusMessage);
			else {
				_this.configuration.overviewTable.updateNewsList();
				_this.configuration.overviewTable.loadData();
				_this.backToOverview();
			}
			document.getElementById('slyNewsForm_saveButton').disabled = false;
		});
	
	});
};
