// JavaScript Document
function checkContent() {	
	var returnValue = true;
	var title = document.getElementById('title');
	var subtitle = document.getElementById('subtitle');	
	var text = document.getElementById('text');
	
	if(!title || !text)	
		return false;
		
	if(title.value == '') {	
		openBox(title.id+'Box', 'inserire un titolo', 'error', 'span');		
		returnValue = false;
	}
	
	if(text.value == '') {	
		openBox(text.id+'Box', 'inserire il testo', 'error', 'span');
		returnValue = false;		
	}	
	
	if(subtitle) {
		if(subtitle.value == '') {			
			openBox(subtitle.id+'Box', 'inserire un testo valido', 'error', 'span');
			returnValue = false;		
		}	
	}
	
	return returnValue;
}

function addContent(typeId) {
	var id = 'addContent';
		
	var callback = function(id, response) {
		openBox(id, response, 'inputBox');
	}
	
	var uri = "./Modules/Content.php?contentType="+typeId;
	ajaxGet(id, uri, callback);	
}

function editContent(itemId, typeId) {
	var id = 'editContent'+itemId;
	
	var callback = function(id, response) {
		openBox(id, response, 'inputBox');
	}
	
	var uri = "Modules/Content.php?contentType="+typeId+"&contentId="+itemId;
	ajaxGet(id, uri, callback);	
}

function dropContent(itemId) {
	if(confirm("Eliminare definitivamente l'articolo e i commenti?")) {
		var uri = "?dropContent=1&contentId="+itemId;
		window.location.href = uri;
	}
}

function archiveContent(itemId) {
	if(confirm("Archiviare l'articolo e i commenti?")) {
		var uri = "?archiveContent=1&contentId="+itemId;
		window.location.href = uri;
	}	
}

function publishContent(itemId) {
	if(confirm("Ripubblicare l'articolo e i commenti?")) {
		var uri = "?publishContent=1&contentId="+itemId;
		window.location.href = uri;
	}	
}


function addComment(itemId, typeId, type) {
	var id = type+itemId;

	var callback = function(id, response) {
		var obj = document.getElementById(id);
		var box = document.getElementById(id+'Box');
		
		if(!box) {
			var box = document.createElement('div');
			box.id = id+'Box';
			box.className = 'commentBox';
			obj.appendChild(box);		
		}
		
		box.innerHTML = response;
	}
	
	var uri = "Modules/Comment.php?contentId="+itemId+"&contentType="+typeId;
	ajaxGet(id, uri, callback);
}

function addObject(typeId) {
	var id = 'addObject';
		
	var callback = function(id, response) {
		openBox(id, response, 'inputBox');
	}
	
	var uri = "./Modules/ObjectInput.php?objectType="+typeId;
	ajaxGet(id, uri, callback);	
}

function checkComment() {	
	var returnValue = true;
	var username = document.getElementById('username');
	var comment = document.getElementById('comment');
	
	if(!username || !comment)	
		return false;
		
	if(username.value == '') {	
		openBox('usernameBox', 'inserire un nickname', 'error', 'span');		
		returnValue = false;
	}
	
	if(comment.value == '') {	
		openBox('commentBox', 'inserire un commento', 'error', 'span');
		returnValue = false;		
	}	
	
	return returnValue;
}