function insertTagDescription(strTag, strClose, defaultText) {

	obj = document.forms['article'].description;
	
	// InternetExplorer
	if (document.selection) {
		var actualSelection = document.selection.createRange().text;
		if(!actualSelection) {
		  actualSelection = defaultText;
    }
		obj.focus();
		document.selection.createRange().text = strTag + actualSelection + strClose;
	// Mozilla
	} else if (obj.selectionStart || obj.selectionStart == '0') {
 		var startPos = obj.selectionStart;
		var endPos = obj.selectionEnd;
		var scrollTop=obj.scrollTop;
		var tmpText = (obj.value).substring(startPos, endPos);
		if(!tmpText) {
      tmpText = defaultText;
    }
		subst = strTag + tmpText + strClose;
		obj.value = obj.value.substring(0, startPos) + subst + obj.value.substring(endPos, obj.value.length);
		obj.focus();
		var cPos = startPos + tmpText.length;
		obj.selectionStart = cPos;
		obj.selectionEnd = cPos;
		obj.scrollTop = scrollTop;
	// All others
	} else {
		// Append at the end: Some people find that annoying
		//obj.value += tagOpen + sampleText + tagClose;
		//obj.focus();
		obj.value += strTag;
		obj.focus();
	}
	// reposition cursor if possible
	if (obj.createTextRange) {
    obj.caretPos = document.selection.createRange().duplicate();
 }
}

function insertTag(obj, strTag) {
	var defaultText = '';
	// InternetExplorer
	if (document.selection) {
		var actualSelection = document.selection.createRange().text;
		if(!actualSelection) {
		  actualSelection = defaultText;
    }
		obj.focus();
		document.selection.createRange().text = strTag + ' ' + actualSelection;
	// Mozilla
	} else if (obj.selectionStart || obj.selectionStart == '0') {
 		var startPos = obj.selectionStart;
		var endPos = obj.selectionEnd;
		var scrollTop=obj.scrollTop;
		var tmpText = (obj.value).substring(startPos, endPos);
		if(!tmpText) {
      tmpText = defaultText;
    }
		subst = strTag + ' ' + tmpText;
		obj.value = obj.value.substring(0, startPos) + subst + obj.value.substring(endPos, obj.value.length);
		obj.focus();
		var cPos = startPos + tmpText.length;
		obj.selectionStart = cPos;
		obj.selectionEnd = cPos;
		obj.scrollTop = scrollTop;
	// All others
	} else {
		// Append at the end: Some people find that annoying
		//obj.value += tagOpen + sampleText + tagClose;
		//obj.focus();
		obj.value += strTag;
		obj.focus();
	}
	// reposition cursor if possible
	if (obj.createTextRange) {
    obj.caretPos = document.selection.createRange().duplicate();
 }
}

/*
 * Richiamata dall'evento onkeyup
 * limita il numero di caratteri inseribili in una textArea
 * uso: onkeyup="textLimit(this, 120)
 */
	function textLimit(obj, lim) {
		var max = lim - obj.value.length;
		if (max <= 0 ){
			//tolgo i caratteri in eccesso
			obj.value = obj.value.substring(0, lim);
			return false;
		} else {
			return true;
		}
	}


/*
 * visualizza un articolo per poterlo stampare senza menu, banner ecc...
 * 
 */
 function printArticle(lnk){
 	 document.forms['article'].action = lnk;
 	 //document.forms['article'].target = "_blank";
	 document.forms['article'].submit();
 }

/*
 * apre la dialog di stampa
 */
function printPage() {
	window.print();
}

/*
 * visualizza il calendario
 * passando il nome form e nome elemento per aggiornarlo
 */
function showCalendar(f, e, loc) {
	var w = window.open('cal.asp?locale=' + loc + '&f=' + f + '&e=' + e ,'CAL',
		'width=155,height=185,toolbar=no,status=no,scrollbars=no,menubar=no,location=no,resizable=no,directories=no');
	w.focus()
}
function execute(idi,act,idm){
	var objd=document.forms["document"];
	objd.idItem.value = idi;
	objd.idItemParent.value = idm;
	executeConfirm(act);
}
function executeToFolder(idi,act,idm, idf){
	var objd=document.forms["document"];
	objd.action = "default.asp?r=" + idf + ".0.0#edit";
	objd.idItem.value = idi;
	objd.idItemParent.value = idm;
	executeConfirm(act);
}

function executeConfirm(act){
	var objd=document.forms["document"];
	if (act == 'delete' || act == 'menudelete'){
		if(confirm('Confermi l\'eliminazione?') == true){
			objd.actionMode.value = act;
			submitForm();
			return true;
		}else{
			return false
		}
	}else{
		objd.actionMode.value=act;
		if (act == 'new' || act == 'edit') {
			objd.submit();
		} else {
			submitForm();
		}
		return true;
	}
}
function submitForm() {
	var objd=document.forms["document"];
	objd.isSubmit.value = "yes";
	objd.submit();
}
function submitCancel() {
	var objd=document.forms["document"];
	objd.isSubmit.value = "no";
	objd.actionMode.value = "";
	//objd.actionModePrec.value = "";
	objd.submit();
}
/* imposta il focus */
function setFocus(e) {
  document.forms["glForm"].elements[e].focus();
}
