function FormChecker (formId) {
	this.isOk = true;
	this.isError = false;
	this.form = document.getElementById(formId);
	
	this.signalError = function(id) {
		document.getElementById(id).style.color= "red";
		this.isOk = false;
		this.isError = true;
	}
	
	this.signalCorrection = function(id) {
		document.getElementById(id).style.color= "black";
	}
	
	this.check = function() {
		// reset status
		this.isOk = true;
		this.isError = false;
		// check fields
		if (this.form.author.value=="") this.signalError("ff_author");
		if (this.form.location.value=="") this.signalError("ff_location");
		if (this.form.comments.value=="") this.signalError("ff_comments");
		if (this.form.securityCode.value=="") this.signalError("ff_security");
		if (this.isOk) this.form.submit();
		else document.getElementById("error-message").innerHTML="Lütfen zorunlu alanları doldurunuz.";
	}
	
	this.fieldChanged = function (fieldName) {
		var orForm = this.form;
		if (this.isError==false) return;	// If no error state we have no other business here
		
		switch (fieldName) {
			case "author-field":
				if (orForm.author.value != "") this.signalCorrection("ff_author");
				else this.signalError("ff_author");
				break;
			case "location-field":
				if (orForm.location.value != "") this.signalCorrection("ff_location");
				else this.signalError("ff_location");
				break;
			case "comments-field":
				if (orForm.comments.value != "") this.signalCorrection("ff_comments");
				else this.signalError("ff_comments");
				break;
			case "security-field":
				if (orForm.securityCode.value != "") this.signalCorrection("ff_security");
				else this.signalError("ff_security");
				break;
		}
		
		// A global check
		if ( (orForm.author.value != "")
					&& (orForm.location.value != "")
					&& (orForm.comments.value != "")
					&& (orForm.securityCode.value != "") ) {
			// Remove error message or Display positive feedback
			isFormOk=true;
			document.getElementById("error-message").innerHTML="";
		} else {
			isFormOk=false;
			// Display error message
			document.getElementById("error-message").innerHTML="Lütfen zorunlu alanları doldurunuz.";
		}
		
	}
	
}

function postEvent(event) {
	var eventForm = document.getElementById("post-event");
	eventForm.event.value = event;
	eventForm.submit();
}

function removeEntry(entryId) {
	if (confirm("Bu anıyı silerseniz işlemi geri döndüremezsiniz. Bu anıyı silmek istiyor musunuz?")) {
		var eventForm = document.getElementById("post-event");
		eventForm.event.value = "remove_entry";
		eventForm.entry_id.value = entryId;
		eventForm.submit();
	}
}

function limitTextarea(id, maxLength, maxRow) {
	var t = document.getElementById(id);
	//alert(t.value.split("\n").length);
	if (t.value.split("\n").length > maxRow) t.value = t.value.substring(0, t.value.length-1);
	if (t.value.length > maxLength) t.value = t.value.substring(0, maxLength);
}