/* Elimina spazi bianchi da una stringa */
<!--//
function trim(stringa){
	while(stringa.substring(0,1) == ' '){
		stringa = stringa.substring(1, stringa.length);
	}
	while(stringa.substring(stringa.length-1, stringa.length) == ' '){
		stringa = stringa.substring(0,stringa.length-1);
	}
	return stringa;
}

function shouts(str) {searchWin = window.open(str,'shouts','scrollbars=yes,resizable=yes,width=400,height=640,status=no,location=no,toolbar=no');}
function photo_enlarge(str) {searchWin = window.open(str,'foto','scrollbars=yes,resizable=yes,width=950,height=700,status=no,location=no,toolbar=no');}
/* Invia modulo di ricerca */
function esegui_ricerca(){
	document.getElementById('hidden_cerca').value = document.getElementById('cerca_text').value;
	document.getElementById('hidden_search').submit();
}
function openChild(file,window) {
	childWindow=open(file,window,'resizable=yes,scrollbars=yes,width=800,height=600');
	if (childWindow.opener == null) childWindow.opener = self;
}
function enlarge(str) {searchWin = window.open(str,'image','scrollbars=yes,resizable=yes,width=800,height=600,status=no,location=no,toolbar=yes');}
function fixImage(img) {
     if(img.width>200) img.width=200;
}

function addText(elname, wrap1, wrap2) {
	if (document.selection) { // for IE
		var str = document.selection.createRange().text;
		document.forms['inputform'].elements[elname].focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	} else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var txtarea = document.forms['inputform'].elements[elname];
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		//if (selEnd == 1 || selEnd == 2)
		//selEnd = selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	} else {
		insertText(elname, wrap1 + wrap2);
	}
}

function insertText(elname, what, fname) {
	if (document.forms[fname].elements[elname].createTextRange) {
		document.forms[fname].elements[elname].focus();
		document.selection.createRange().duplicate().text = what;
	} else if ((typeof document.forms[fname].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var tarea = document.forms[fname].elements[elname];
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter =  tarea.value.substring(selEnd, txtLen);
		var oldScrollTop = tarea.scrollTop;
		tarea.value = txtbefore + what + txtafter;
		tarea.selectionStart = txtbefore.length + what.length;
		tarea.selectionEnd = txtbefore.length + what.length;
		tarea.scrollTop = oldScrollTop;
		tarea.focus();
	} else {
		document.forms[fname].elements[elname].value += what;
		document.forms[fname].elements[elname].focus();
	}
}

function del_art_comment(art_id,id){
	if(confirm("Sei sicuro di voler eliminare questo commento?")){
			document.location = 'index.php?m=art&art='+art_id+'&del='+id;
	}	
}

function del_photo_comment(photo_id,id,dest){
	if(confirm("Sei sicuro di voler eliminare questo commento?")){
			document.location = 'index.php?m='+dest+'&fid='+photo_id+'&del='+id;
	}	
}

function del_album_comment(album_id,id,dest){
	if(confirm("Sei sicuro di voler eliminare questo commento?")){
			document.location = 'index.php?m='+dest+'&aid='+album_id+'&del='+id;
	}	
}
function del_admin_foto(foto_id){
	if(confirm("Sei sicuro di voler eliminare questa foto?")){
		document.location = 'index.php?m=ugallery&delf='+foto_id;
	}
}
function del_admin_foto_p(foto_id){
	if(confirm("Sei sicuro di voler eliminare questa foto?")){
		document.location = 'index.php?m=gallery&delf='+foto_id;
	}
}
//-->
