function slyNewsForm(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 = 'slyNews-' + 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">Datum:</span></td><td><input id="slyNewsForm_date" type="text" value="' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].title : '') + '" style="width:100px" /></td></tr>';
	html += '<tr><td><span style="font-weight:bold">Titel:</span></td><td><input id="slyNewsForm_title" type="text" value="' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].title : '') + '" style="width:636px" onblur="tinyMCE.execCommand(\'mceFocus\', true, \'slyNewsForm_text\');" /></td></tr>';
	html += '<tr><td valign="top"><span style="font-weight:bold; position:relative; top:35px">Text:</span></td><td><textarea id="slyNewsForm_text" style="height:300px">' + (this.configuration.overviewTable.filteredData.length > 0 ? this.configuration.overviewTable.filteredData[this.configuration.rowIndex].text : '') + '</textarea></td></tr>';
	html += '<tr><td valign="top"><span style="font-weight:bold">Bild:</span></td><td><img id="slyNewsForm_picture" src="res/scripts/slycms/images/empty.png" /></td></tr>';
	html += '<tr><td>publiziert:</td><td><input type="checkbox" id="slyNewsForm_published" checked="checked" /></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;
	
	tinyMCE.execCommand("mceAddControl", true, "slyNewsForm_text")
	new slyDateSelector(document.getElementById('slyNewsForm_date'));
	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="sly.ajaxUpload(document.getElementById(\'slyAjaxUpload\'), true);" /></form>';
    document.getElementById('slyNewsForm_picture').parentNode.appendChild(ajaxUpload);
	try { document.getElementById('slyNewsForm_title').focus(); } catch (err) {}
}

slyNewsForm.prototype.refresh = function() {
	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_date').value = val;
	document.getElementById('slyNewsForm_title').value = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].title;
	tinyMCE.activeEditor.setContent(this.configuration.overviewTable.filteredData[this.configuration.rowIndex].text);
	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('slyNewsForm_picture').src = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].picture;
	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_title').focus(); } catch (err) {}
};

slyNewsForm.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) {}
};

slyNewsForm.prototype.firstObject = function() {
	this.configuration.rowIndex = 0;
	this.refresh();
};

slyNewsForm.prototype.prevObject = function() {
	if (this.configuration.rowIndex > 0) this.configuration.rowIndex--;
	this.refresh();
};

slyNewsForm.prototype.nextObject = function() {
	if (this.configuration.rowIndex < this.configuration.overviewTable.filteredData.length - 1) this.configuration.rowIndex++;
	this.refresh();
};

slyNewsForm.prototype.lastObject = function() {
	this.configuration.rowIndex = this.configuration.overviewTable.filteredData.length - 1;
	this.refresh();
};

slyNewsForm.prototype.saveObject = function() {
	var _this = this;
	var date = document.getElementById('slyNewsForm_date');
	var title = document.getElementById('slyNewsForm_title');
	var text = document.getElementById('slyNewsForm_text');
	var published = document.getElementById('slyNewsForm_published');
	var picture = document.getElementById('slyNewsForm_picture');
	
	//------------------------- VALIDATIONS --------------------------
	if (title.value == '') {
		new slyTooltip('Geben Sie einen Titel für die Neuigkeit ein!', title);
		title.focus();
		return;
	}
	if (tinyMCE.activeEditor.getContent() == '') {
		new slyTooltip('Geben Sie einen Text für die Neuigkeit ein!', document.getElementById('slyNewsForm_text_parent'), 40);
		tinyMCE.execCommand('mceFocus', true, "slyNewsForm_text");
		return;
	}
	if (picture.src == '' || picture.src.match(/\/empty\.png$/i)) {
		new slyTooltip('Sie müssen ein Bild für die Neuigkeit hochladen!', picture, 15);
		picture.focus();
		return;
	}
	
	document.getElementById('slyNewsForm_saveButton').disabled = true;
	
	var obj = {};
	obj.entity = 'news';
	if (this.configuration.action == 'update') obj.id = this.configuration.overviewTable.filteredData[this.configuration.rowIndex].id;
	obj.date = document.getElementById('slyNewsForm_date').value;
	obj.title = document.getElementById('slyNewsForm_title').value;
	obj.text = tinyMCE.activeEditor.getContent();
	if (picture.src != '' && !picture.src.match(/empty\.png$/i)) obj.picture = picture.src;
	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;
	});
};
