//e=oggetto evento 
//o=oggetto che deve effettuare evento click deve essere un button
//es onKeyPress="return simulaInvio(event,document.Form1.cmdLogin)"
//di solito lo poniamo su di un textbox ma non è indispensabile
function simulaInvio(e,button)
{
	if(isEnterKey(e))
	{
		//alert("Hello");
		button.click();
		return false;
	}
}

//oggetto evento in entrata
function isEnterKey(e)
{ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable
	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	//alert(characterCode);
	//machintosh entercode characterCode == 3
	if(characterCode == 13 || characterCode == 3)
	{ 
		//if generated character code is equal to ascii 13 (if enter key)
		//document.forms[0].submit() //submit the form
		//document.Form1.cmdLogin.click();
		//alert("Cliccare con il mouse sul tasto Login per autenticarsi \noppure con il tasto TAB selezionare il pulsante Login e quindi premere Invio.");
		return true;
	}
	else
	{
		return false;
	}
}

function showHide(eId)
{
	if(typeof(eId) == "object")
	{
		var o = eId;
		if(o){ if(o.style.display == 'none') o.style.display = 'block';	else o.style.display = 'none';}
	}
	else
	{
		if(document.getElementById)
		{
			var o = document.getElementById(eId)
			if(o) {	if(o.style.display == 'none') o.style.display = 'block'; else o.style.display = 'none'; }
		}
	}
}

//formattazione emoticon
function formatta(startTag,defaultText,endTag,replace)
{
	if(document.getElementsByTagName)
	{
		elements = document.getElementsByTagName("textarea")
			
		if(elements.length == 1)
		{
			//alert(startTag);
			//alert(defaultText);
			//alert(endTag);
	
			t = elements[0];
			//debug(t);
			if(t.createTextRange) 
			{
				t.focus(t.caretPos);
				t.caretPos = document.selection.createRange().duplicate();
				if(t.caretPos.text.length>0) 
				{
					var sel = t.caretPos.text;
					var fin = '';
					while(sel.substring(sel.length-1, sel.length)==' ') 
					{
						sel = sel.substring(0, sel.length-1)
						fin += ' ';
					}
					if(replace) t.caretPos.text = startTag + sel + endTag + fin;
					else t.caretPos.text = sel + fin + startTag + defaultText + endTag;
				} 
				else 
				{
					t.caretPos.text = startTag+defaultText+endTag;
				}
			}
			else 
			{
				//MOZILLA/NETSCAPE support
				if (t.selectionStart || t.selectionStart == "0") 
				{
					var startPos = t.selectionStart;
					var endPos = t.selectionEnd;

					if (startPos != endPos) 
					{
						if(startTag.length > 0)
						{
							t.value = t.value.substring(0, startPos)
			              		+	startTag
					            + t.value.substring(startPos, endPos) 
				              	+ endTag
				              	+ t.value.substring(endPos, t.value.length);
						}
						else
						{
							t.value = t.value.substring(0, endPos)
				              + endTag
				              + t.value.substring(endPos, t.value.length);
						}
					}
					else
					{
						t.value = 	t.value.substring(0, startPos)
									+ endTag
									+ t.value.substring(endPos, t.value.length);
	
						t.selectionStart = (t.value.substring(0, startPos) + endTag).length;
						t.selectionEnd = (t.value.substring(0, startPos) + endTag).length;
					}
				} 
				else 
				{
					t.value += startTag+defaultText+endTag;
				}
			}
		}
	}
}

function openWin(_url, _name, _w, _h)
{
	var _leftPos = (screen.availWidth-_w)/2, _topPos = (screen.availHeight-_h)/2;
	var _args = new Array();
	_args[0] = "alwaysRaised=1";
	_args[1] = "dependent=1";
	_args[2] = "height=" + _h;
	_args[3] = "width=" + _w;
	_args[4] = "top=" + _topPos;
	_args[5] = "left=" + _leftPos;
	_args[6] = "screenY=" + _topPos;
	_args[7] = "screenX=" + _leftPos;
	_args[8] = "menubar=0";
	_args[9] = "resizable=0";
	_args[10] = "status=0";
	_args[11] = "titlebar=0";
	_args[12] = "toolbar=0";
	_args[13] = "scrollbars=1";
	var _win;
	_win = window.open(_url, _name, _args);
}
