/**
 * Editing della foto
 * @name		pa_singlephoto.js
 * @project		LiberoFoto
 * @package		javascripts
 * @author		Giulio D'Ambrosio <g.dambrosio@pisa.iol.it>, <giulio.dambrosio@poste.it>
 * @creation	Thu Dec 18 2008 15:48:10 GMT+0100 (CET)
 * @modified	Thu Dec 18 2008 15:48:10 GMT+0100 (CET)
 * @version		1.0
 */

var lp_mdlg=null;
function lf_editImage(url, returl){
	url+='&nc='+new Date()+'&mode=popup&ret_url='+escape(returl);
	if (lp_mdlg!=null && lp_mdlg.isOpen()){
		Libero.Utils.prototype.closeModalDialog(lp_mdlg);
	}
	lp_mdlg=null;
	lp_mdlg=Libero.Utils.prototype.openModalDialog(window, {mdUrl:url, mdWidth:560, mdHeight:200});
}

function lf_cnc(ta,ml,mh) {
	var success=true;
	if (typeof(ta['oldvalue'])=='undefined'){
		ta.oldvalue='';
	}
	if (typeof ta.value!='undefined') {
		if (ta.value.length > ml) {
			ta.value = ta.oldvalue;
			ta.newvalue=ta.value;
			success=false;
		}
		ta.newvalue=ta.value;
	}
	else {
		if (typeof ta.textContent!='undefined') {
			if (ta.textContent.length > ml) {
				ta.textContent = ta.oldvalue;
				success = false;
			}
			ta.newvalue = ta.textContent;
		}if (typeof ta.innerText!='undefined') {
			if (ta.innerText.length > ml) {
				ta.innerText = ta.oldvalue;
				success=false;
			}
			ta.newvalue=ta.innerText;
		}else{
			if (ta.innerHTML.length > ml) {
				ta.innerHTML = ta.oldvalue;
				success=false;
			}
			ta.newvalue=ta.innerHTML;
		}	
	}
	if (false && typeof ta['createTextRange'] != 'undefined') {
		var tr;
		tr = ta.createTextRange();
		tr.collapse();
		tr.expand("textedit");
		if (tr.boundingHeight < ta.clientHeight) {
			if (ta.clientHeight > mh) {
				$s(ta).height = (tr.boundingHeight + 2) + 'px';
			}
			else {
				$s(ta).height = mh+'px';
			}
		}
		else {
			$s(ta).height = (tr.boundingHeight + 2) + 'px';
		}
	}
	else {
		while (ta.clientHeight > mh && ta.scrollHeight<=ta.clientHeight) {
			$s(ta).height = (ta.clientHeight - mh/2) + 'px';
		}
		if (ta.scrollHeight>ta.clientHeight){
			$s(ta).height=(ta.scrollHeight+2)+'px';
		}
	}

	if (!success) {
		n_alert('Puoi inserire al massimo ' + ml + ' caratteri nel commento!');
	}
	if (typeof ta.value!='undefined') {
		ta.oldvalue=ta.value;
	}
	else {
		if (typeof ta.textContent!='undefined') {
			ta.oldvalue = ta.textContent;
		}if (typeof ta.innerText!='undefined') {
			ta.oldvalue=ta.innerText;
		}else{
			ta.oldvalue=ta.innerHTML;
		}	
	}

	return success;
}
var lastch=null;
function lf_replyComment(cid,eid){
	var cel=$(eid);
	$('commentfid').value=cid;
	$('sendcomment').scrollIntoView(false);
	$('commentbody').focus();
	if (lastch!=null){
		lastch.className=lastch.className.replace(/ highlight/,'');
	}
	cel.className+=' highlight';
	lastch=cel;
	return false;
}
function lf_deleteComment(cid){
	if (confirm("Attenzione:\nEliminando questo commento verranno\neliminate anche tutte le\n eventuali risposte.\nSicuro di volere procedere all'eliminazione ?")) {
		var delform=$('delete_comment_form');
		$('commentdid').value=cid;
		delform.submit();
		return false;
	}else{
		return false;
	}
}

