function openPopup(theURL,winName,features,w,h) 
{
  //'status=yes,scrollbars=no,resizable=no,width=640,height=420,top=120,left=250'
  LeftPosition = (screen.width) ? (screen.width-w)/2 - 20: 0;
  TopPosition = (screen.height) ? (screen.height-h)/2 - 30: 0;
  settings = features + ',' + 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition;
  window.open(theURL,winName,settings);
}

function msgEditAdmin()
{
	alert("Non ti é permesso modificare l'Amministratore.\r\nVuoi per forza incasinare il posto?");
}

function refreshMainWindow() 
{
	//Esegue il reload della finestra chiamante la popup
	window.opener.location.reload();
	window.close();
}

function selectSection() 
{
	//esegue l'invio della form del Filtro Articoli
	document.currsection.submit();
}

function deleteSpam() 
{
	//esegue la cancellazione dei messaggi di SPAM nel Guestbook previo avviso
	var answer = confirm('Vuoi davvero eliminare i messaggi non approvati?\nL\'operazione é irreversibile.');
	if( answer )
	{
		window.location='http://www.ortobene.it/admin/index.php?file=guestbook&action=spam';
		alert('Operazione eseguita');
	}
}

function refreshSubmitMainWindow() 
{
	//Esegue il reload della finestra chiamante la popup
	
	opener.document.article.submit();
	window.close();
}

function insert_bbcode(form,elem,v)
{
	try {
		if (document.selection)
		{
			var str = document.selection.createRange().text;
			document.forms[form].elements[elem].focus();
			var sel = document.selection.createRange();
			if(v=='img')
			{
				sel.text = "[" + v + "]" + str;
			}
			else
			{
				sel.text = "[" + v + "]" + str + "[/" + v + "]";
			}
			return;
		}
		else if ((typeof document.forms[form].elements[elem].selectionStart) != 'undefined')
		{
			var txtarea = document.forms[form].elements[elem];
			var selLength = txtarea.textLength;
			var selStart = txtarea.selectionStart;
			var selEnd = txtarea.selectionEnd;
			var s1 = (txtarea.value).substring(0,selStart);
			var s2 = (txtarea.value).substring(selStart, selEnd)
			var s3 = (txtarea.value).substring(selEnd, selLength);
			if(v=='img' || v=='hr' )
			{
				txtarea.value = s1 + '[' + v + ']' + s2 + s3;
			}
			else
			{
				txtarea.value = s1 + '[' + v + ']' + s2 + '[/' + v + ']' + s3;
			}
			txtarea.selectionStart = s1.length;
			txtarea.selectionEnd = s1.length + 5 + s2.length + v.length * 2;
			return;
		}
		else 
		{

		}
	}
	catch(e){
	}
}