

function svuota(campo,stringa) {
	if (campo.value==stringa)  campo.value='';
}

//	/////////////////////////////////////////////

function vai(url) {
	setTimeout('parent.location.href="'+ url +'"',1);
}

//	/////////////////////////////////////////////
  
function showtip(current,e,varString)
{
	if (document.layers) // Netscape 4.0+
	{
		 theString="<DIV CLASS='ttip'>"+varString+"</DIV>"
		 document.tooltip.document.write(theString)
		 document.tooltip.document.close()
		 document.tooltip.visibility="show"
	}
	else
	{
		if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
		{
			elm=document.getElementById("tooltip")
			tcat=document.getElementById("tc")
			elml=current
			elm.innerHTML=varString
			elm.style.height=elml.style.height
			elm.style.top=elml.style.top;//parseInt(elml.offsetTop+elml.offsetHeight)
            elm.style.left=elml.style.left;//parseInt(elml.offsetLeft+elml.offsetWidth)
			elm.style.visibility = "visible"
			tcat.style.visibility = "hidden"
		}
	}
}

function hidetip(){
if (document.layers) // Netscape 4.0+
   {
    document.tooltip.visibility="hidden"
   }
else
  {
	if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
	{
		elm.style.visibility="hidden"
		tcat.style.visibility = "visible"
	}
  } 
}

//	//////////////////////////////////////////////

var BV = parseInt(navigator.appVersion);
var BN = "";
if (navigator.userAgent.indexOf("MSIE") >= 0) {BN = "e";}
else {
    if (navigator.appName.indexOf("Netscape") >= 0) {BN = "n";}
    else {BN = "g"}
}
if (!(top.ad)) {
    l = (document.all) ? location : location.pathname.toString();
    // location = "/frame.html?p=" + l;
}
/*function openwin(url) {
var winFeatures = 'width=650,height=435,top=100,scrollbars=yes,resizable=yes,toolbar=yes';
win = open(url,'feature',winFeatures);
if (BV == 2 && (navigator.appVersion.indexOf('mac')>= 0)) {win = open('url','feature',winFeatures)}
if (BV == 2 && BN == 'n') {win.opener = top.self;}
}*/




/*
  function ContaParole(campo) {
      // Numero di parole della biografia aggiornato al volo
     var nCaratteri = campo.value.length;
  	 var stringaPiena = campo.value + " ";
  	 var regExp_spazioIniziale = /^[^A-Za-z0-9]+/gi;
  	 var stringaTagliataSinistra = stringaPiena.replace(regExp_spazioIniziale, "");
  	 var regExp_nonalfanumerici = rExp = /[^A-Za-z0-9]+/gi;
  	 var stringaPulita = stringaTagliataSinistra.replace(regExp_nonalfanumerici, " ");
  	 var stringaDivisa = stringaPulita.split(" ");
  	 var nParole = stringaDivisa.length -1;
  	 document.modulo.outputPar.value="<?echo$testo_parole?>: "+nParole;
  }
*/


//	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// browser identification

agt = navigator.userAgent.toLowerCase();
is_ie	   = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
is_opera  = (agt.indexOf("opera") != -1);
is_mac	   = (agt.indexOf("mac") != -1);
is_mac_ie = (is_ie && is_mac);
is_win_ie = (is_ie && !is_mac);
is_gecko  = (navigator.product == "Gecko");

// variable used to pass the object to the popup editor window.
_object = null;

// function that returns a clone of the given object
cloneObject = function(obj) {
	var newObj = new Object;

	// check for array objects
	if (obj.constructor.toString().indexOf("function Array(") == 1) {
		newObj = obj.constructor();
	}

	// check for function objects (as usual, IE is fucked up)
	if (obj.constructor.toString().indexOf("function Function(") == 1) {
		newObj = obj; // just copy reference to it
	} else for (var n in obj) {
		var node = obj[n];
		if (typeof node == 'object') { newObj[n] = cloneObject(node); }
		else                         { newObj[n] = node; }
	}

	return newObj;
};

// FIXME!!! this should return false for IE < 5.5
checkSupportedBrowser = function() {
	if (is_gecko) {
		if (navigator.productSub < 20021201) {
			alert("You need at least Mozilla-1.3 Alpha.\n" +
			      "Sorry, your Gecko is not supported.");
			return false;
		}
		if (navigator.productSub < 20030210) {
			alert("Mozilla < 1.3 Beta is not supported!\n" +
			      "I'll try, though, but it might not work.");
		}
	}
	return is_gecko || is_ie;
};


// event handling

_addEvent = function(el, evname, func) {
	if (is_ie) {
		el.attachEvent("on" + evname, func);
	} else {
		el.addEventListener(evname, func, true);
	}
};

_addEvents = function(el, evs, func) {
	for (var i in evs) {
		_addEvent(el, evs[i], func);
	}
};

_removeEvent = function(el, evname, func) {
	if (is_ie) {
		el.detachEvent("on" + evname, func);
	} else {
		el.removeEventListener(evname, func, true);
	}
};

_removeEvents = function(el, evs, func) {
	for (var i in evs) {
		_removeEvent(el, evs[i], func);
	}
};

_stopEvent = function(ev) {
	if (is_ie) {
		ev.cancelBubble = true;
		ev.returnValue = false;
	} else {
		ev.preventDefault();
		ev.stopPropagation();
	}
};


//	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function openwin(url, action, init) {
	if (typeof init == "undefined") {
		init = window;	// pass this window object by default
	}
	openwin._geckoOpenModal(url, action, init);
};

openwin._parentEvent = function(ev) {
	if (openwin._modal && !openwin._modal.closed) {
		openwin._modal.focus();
		_stopEvent(ev);
	}
};

// should be a function, the return handler of the currently opened dialog.
openwin._return = null;

// constant, the currently opened dialog
openwin._modal = null;

// the dialog will read it's args from this variable
openwin._arguments = null;

openwin._geckoOpenModal = function(url, action, init) {
	self.name = "main";
	var dlg = window.open(url, "hadialog",
			      "toolbar=yes,menubar=no,personalbar=no,width=660,height=500," +
			      "scrollbars=yes,resizable=yes");
	dlg.creator = self;
	openwin._modal = dlg;
	openwin._arguments = init;

	// capture some window's events
	function capwin(w) {
		_addEvent(w, "click", openwin._parentEvent);
		_addEvent(w, "mousedown", openwin._parentEvent);
		_addEvent(w, "focus", openwin._parentEvent);
	};
	// release the captured events
	function relwin(w) {
		_removeEvent(w, "click", openwin._parentEvent);
		_removeEvent(w, "mousedown", openwin._parentEvent);
		_removeEvent(w, "focus", openwin._parentEvent);
	};
	capwin(window);
	// capture other frames
	for (var i = 0; i < window.frames.length; capwin(window.frames[i++]));
	// make up a function to be called when the openwin ends.
	openwin._return = function (val) {
		if (val && action) {
			action(val);
		}
		relwin(window);
		// capture other frames
		for (var i = 0; i < window.frames.length; relwin(window.frames[i++]));
		openwin._modal = null;
	};
};



//            /////////////////////////////////////
function insertTags(tagOpen, tagClose, sampleText, taname) {
	if(taname=='text')
		var txtarea = document.form.text;//wpTextbox1;
	else if(taname=='post_text')
		var txtarea = document.form.post_text;//wpTextbox1;
	// IE
	if(document.selection  && !is_gecko) {
		var theSelection = document.selection.createRange().text;
		if(!theSelection) { theSelection=sampleText;}
		txtarea.focus();
		if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
 		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		var scrollTop=txtarea.scrollTop;
		var myText = (txtarea.value).substring(startPos, endPos);
		if(!myText) { myText=sampleText;}
		if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		} else {
			subst = tagOpen + myText + tagClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst +
		  txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();

		var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
		txtarea.selectionStart=cPos;
		txtarea.selectionEnd=cPos;
		txtarea.scrollTop=scrollTop;

	// All others
	} else {
		var copy_alertText=alertText;
		var re1=new RegExp("\\$1","g");
		var re2=new RegExp("\\$2","g");
		copy_alertText=copy_alertText.replace(re1,sampleText);
		copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose);
		var text;
		if (sampleText) {
			text=prompt(copy_alertText);
		} else {
			text="";
		}
		if(!text) { text=sampleText;}
		text=tagOpen+text+tagClose;
		document.infoform.infobox.value=text;
		// in Safari this causes scrolling
		if(!is_safari) {
			txtarea.focus();
		}
		noOverwrite=true;
	}
	// reposition cursor if possible
	if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}

