function check(f) {
	if(f.nomecognome.value == '') {
		alert('Il campo "Nome e Cognome" è obbligatorio');
		f.nomecognome.focus();
		return false;
	} else if(f.contatto.value == '') {
		alert('Il campo "Contatto" è obbligatorio');
		f.contatto.focus();
		return false;
	} else if(f.commenti.value == '') {
		alert('Il campo "Commenti" è obbligatorio');
		f.commenti.focus();
		return false;
	} else return true;
}

function hideThanks() {
	var t = setInterval(function(){clearInterval(t);new Effect.Fade('thanks');new Effect.SlideUp('thanks');}, 5000);
}








/* EDITORIAL VERSION */
function runEdit() {
	new Ajax.Request('inc/common.php?do=getLoginStatus', {onSuccess:handleLoginStatus, onFailure:function(){alert('failure');}});
}

function handleLoginStatus(ajax) {
	if(ajax.responseText == 'KO') {
		var fadeLayer = Builder.node('DIV', {id: 'fadeLayer', style: 'position:absolute; top:-20px; left:0; width:'+window.innerWidth+'px; height:'+window.innerHeight+'px; background:#000; display:none; zIndex:5'});
		$('pageContainer').appendChild(fadeLayer);
		new Effect.Appear($('fadeLayer'), {from: 0, to: .8, duration: .4, afterFinishInternal:function(){
			var popup = Builder.node('DIV', {id: 'popup', style: 'position:absolute; top:400px; width:335px; height:196px; background:url(i/popup.png) no-repeat; zIndex:10; display:none'}, [
				Builder.node('DIV', {id: 'popupText', style: 'padding: 38px; text-align:left; font-size:16px'}, [
					Builder.node('LABEL', 'Username'),
					Builder.node('INPUT', {type: 'text', name: 'username', id: 'user', value: 'admin'}),
					Builder.node('LABEL', 'Password'),
					Builder.node('INPUT', {type: 'password', name: 'pwd', id: 'pwd', value: 'z3dpr355'}),
					Builder.node('BR'),
					Builder.node('INPUT', {id: 'loginBtn', type: 'button', name: 'invia', value: 'LOGIN', className: 'btnSubmit', style: 'float:none, margin:10px auto'})
				])																																											
			]);
			$('pageContainer').appendChild(popup);
			$('loginBtn').onclick = function() {
				new Ajax.Request('inc/common.php?do=tryLogin&user='+$('user').value+'&pwd='+$('pwd').value, {onSuccess: handleTryLogin});
			}
			$('popup').style.left = (window.innerWidth/2)-167 + 'px';
			$('popup').style.top = (window.innerHeight/2)-98 + 'px';

			new Effect.Appear($('popup'), {duration:.4});
		}});
	} else {
		runEditorEngine();
	}
}

function handleTryLogin(ajax) {
	if(ajax.responseText == 'OK') {
		new Effect.Fade($('popup'), {duration:.4, afterFinishInternal:function(){
			Element.remove($('popup'));
			new Effect.Fade($('fadeLayer'), {duration:.4,  afterFinishInternal:runEditorEngine})
		}});
	} else {
		$('user').style.color = '#333';
		$('pwd').style.color = '#333';
		new Effect.Shake($('popup'));
		if(ajax.responseText == 'ERROR_user') $('user').style.color = 'red';
		else if(ajax.responseText == 'ERROR_pwd') $('pwd').style.color = 'red';
		else {
			$('user').style.color = 'red';
			$('pwd').style.color = 'red';
		}
	}
}

function runEditorEngine() {
	
	
	if($('fadeLayer')) Element.remove($('fadeLayer'));
	
	var elType = 'div';
	
	for(var i=0; i<$$(elType).length; i++) {
		if($$(elType)[i].title == 'editable') {
			if($$(elType)[i].id) var ediID = $$(elType)[i].id;
			else {
				var ediID = 'EDITABLE_'+i;
				$$(elType)[i].id = ediID;
			}
			$$(elType)[i].onmouseover = function() {
				if(this.style.border != '') this.bStyle = this.style.border;
				this.style.border = '1px solid #D5DA0E';
			}
			$$(elType)[i].onmouseout = function() {
				/*if(this.bStyle != '') this.style.border = this.bStyle;
				else */
				this.style.border = '0px !important';
			}
			var ediBtn = Builder.node('DIV', {className: 'ediBtn', id: ediID + '_extCtrl'}, [
				Builder.node('A', {name: '#anchor_'+i, style: 'color:#FFF', href: '#anchor_'+i, onclick:'makeEditable(\''+ediID+'\')'}, 'M')
			]);
			/*var delBtn = Builder.node('DIV', {className: 'delBtn', id: ediID + '_extCtrl'}, [
				Builder.node('A', {name: '#anchor_'+i, style: 'color:#FFF', href: '#anchor_'+i, onclick:'delContent(\''+ediID+'\')'}, '-')
			]);
			var addBtn = Builder.node('DIV', {className: 'addBtn', id: ediID + '_extCtrl'}, [
				Builder.node('A', {name: '#anchor_'+i, style: 'color:#FFF', href: '#anchor_'+i, onclick:'addContent(\''+ediID+'\')'}, '+')
			]);*/
			$('pageContainer').appendChild(ediBtn);
			/*$('pageContainer').appendChild(delBtn);
			$('pageContainer').appendChild(addBtn);*/
			ediBtn.style.top = $$(elType)[i].offsetTop + 'px';
			ediBtn.style.left = $$(elType)[i].offsetLeft + $$(elType)[i].offsetWidth - ediBtn.offsetWidth + 'px';
			/*
			delBtn.style.top = $$(elType)[i].offsetTop + 'px';
			delBtn.style.left = ediBtn.offsetLeft - delBtn.offsetWidth + 'px';
			addBtn.style.top = $$(elType)[i].offsetTop + 'px';
			addBtn.style.left = delBtn.offsetLeft - addBtn.offsetWidth + 'px';
			*/
		}
	}
}
function makeEditable(field) {
	var editor = new Ajax.InPlaceEditor(field, 'inc/common.php?do=setContents', {okButton: false, highlightcolor: 'transparent', callback: function(form, value) { return 'myparam=' + escape(value) + '&id=' + field }, submitOnBlur: true, externalControl: field + '_extCtrl'});
}
function delContent(f) {
	Element.remove($(f).parentNode);
}










