// Fenza 10/06/05: se si è premuto enter esegue 'esegui'
function onEnter(esegui, e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return;

	if (keycode == 13)	{
		eval(esegui);
	}
}
// *****************************************************

//var gbl_flagFrameChanged;
//	gbl_flagFrameChanged = 0; //<%=C_GEN_FRAME_NOCHANGED%>

//function check_frame_changed()
//{	
//	if (gbl_flagFrameChanged == 1)  //<%'=C_GEN_FRAME_CHANGED%>
//	{
//		gbl_flagFrameChanged = 0;   //<%'=C_GEN_FRAME_NOCHANGED%>
//		if (confirm("Salvare i dati ?"))
//			invia('Update')
//	}
//}

// Per submit dei vari browser con azione=CambioPag
function invia_forma(val,criterio)
{
	
	//alert("invia_forma...")
	
	var f = document.forma
	if (val != "")
	{
		f.hAZIONE.value = "CambioPag";
		f.hDirezione.value = val;
		f.hCriterio.value = criterio;	// Costante relativa alla pagina
	
		f.submit();
	}
}

//function chiedi_conferma(cosa,quale,dove,quale_campo,domanda)
//{
//	if (confirm(domanda))
//	{		
//		document.forma[quale_campo].value	= quale;
//		document.forma.hAZIONE.value		= cosa;
//		document.forma.submit();
//	}
//}

//function chiedi_conferma_2par(cosa,quale,quale2,dove,quale_campo,quale_campo2,domanda)
//{
//	if (confirm(domanda))
//	{		
//	
//		document.forma[quale_campo].value	= quale;
//		document.forma[quale_campo2].value	= quale2;
//		document.forma.hAZIONE.value		= cosa;
//		document.forma.submit();
//	}
//	else 
//	{
//	
//	}
//}

//function erase(campodesc, campoID)
//{
//	document.forma[campodesc].value = ""
//	document.forma[campoID].value = ""
//}

function invia(azione)
{
	document.forma.hAZIONE.value = azione;
	document.forma.submit();
}

function Scrivi_Testo(txt,id)
{
	document.forma.TXT_GRUPPO.value = txt;
	document.forma.ID_GRUPPO.value = id;
	document.forma.submit();
}

// Serve per il controllo su OnClick dei checkbox. 
// E' essenziale che i campi di tipo CheckBox abbiano
// un id: non ci sono particolari regole per il nome 
// dell'id.
function scriviCheckBox(chekked,cboxhidden,controllo)
{
	var pippo;
	if(chekked== false )
		pippo = 0;
	else 
		pippo = 1;
	document.forma[cboxhidden].value=pippo;
	document.forma[controllo].value="CHANGED";
}

function DoCheck(TheObj)
{
	var v;
	v = document.getElementById(TheObj.id);
	
	if (v.checked)
	{
		v.checked = true;
		document.forma[TheObj.name].value = 1;
		
	}
	else
	{
		v.checked = false;
		document.forma[TheObj.name].value = 0;
	}
	
}

function closeAll()
{
var i;
 
	for(i=0; i<openWins.length; i++) 
	{
		if (openWins[i] && !openWins[i].closed) 
		{
			openWins[i].close();
		}
	}
}

//***********************FUNZIONI PAGINAZIONE ******************
//**************************************************************
function Refresh()
{
	document.forma.submit();
}

function ReSort(SortString)
{	
	document.forma.SortBy.value = SortString;
	document.forma.ReSort.value = "yes";
	Refresh();
}

function MoveToPage(PageNumber)
{
// Select the page number to go to, then submit the page.
	if (PageNumber != -1)
		{document.forma.lstPages[PageNumber].selected = true;}
		//document.frmOrders.ReSort.value = "no";}
	else
		{document.forma.lstPages[0].selected = true;}
	Refresh();
}

function Chiudi_maschera()
{	
	document.forma.hAZIONE.value = "Chiudi_maschera";
	document.forma.submit();
}

function openNewWindowReturnWin(fileName,windowName,theWidth,theHeight,menubar,scroll,resizable) 
{	
	return openNewWindowFrom(null, fileName,windowName,theWidth,theHeight,menubar,scroll,resizable);
}
	
function openNewWindow(fileName,windowName,theWidth,theHeight,menubar,scroll,resizable) 
{	
	openNewWindowFrom(null, fileName,windowName,theWidth,theHeight,menubar,scroll,resizable);
}

function openNewWindowFrom(obj, fileName,windowName,theWidth,theHeight,menubar,scroll,resizable)
{
	if (windowName == "newAddressWindow") 
	{
		uniqueName = new Date();
		windowName = uniqueName.getTime();
	}	
	
	// Fenza 12/05/05 : pongo la finestra al centro dello schermo
	var lft = screen.width / 2 - theWidth / 2;
	var tp = screen.height / 2 - theHeight / 2;
	
	if (obj!=null)
		return obj.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=" + menubar + ",scrollbars=" + scroll + ",resizable=" + resizable + ",left="+lft+", top="+tp+",width="+theWidth+",height="+theHeight);
	else
		return window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=" + menubar + ",scrollbars=" + scroll + ",resizable=" + resizable + ",left="+lft+", top="+tp+",width="+theWidth+",height="+theHeight);
}

function message(DisplayText)
{
	window.status = DisplayText;
	setTimeout("remove_message()",2500);
}

function remove_message()
{
	window.status="";
}

//**************************************************************
//*********************** POPUP CALENDAR - *********************
//**************************************************************

var today = new Date();
var day   = today.getDate();
var month = today.getMonth();
var year  = y2k(today.getYear());

function y2k(number)
{
	return (number < 1000) ? number + 1900 : number;
}

function padout(number)
{
	return (number < 10) ? '0' + number : number;
}

function GetMyDate(TheObj)
{
	document.forma[TheObj].value = '' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year;
	document.forma[TheObj].focus();
	mywindow.close();
}

function DatePopup(TheObj)
{
	var CmdStr;
	
	CmdStr = "../COMMON/cal.asp?OGGETTO=" + TheObj;
	
	mywindow = open(CmdStr,'Seleziona_una_data','resizable=no,width=210,height=265');
	mywindow.location.href = CmdStr;
	if (mywindow.opener == null)
		mywindow.opener = self;
}

//Per mostrare il mese della data scelta dall'utente, altrimenti la data attuale.	SGA 27/05/2002
function DatePopupScelta(TheObj)
{
	var CmdStr;
	if(document.forma[TheObj].value=="")
		CmdStr = "../COMMON/cal.asp?DataScelta=01/01/1950&OGGETTO=" + TheObj;
	else
		CmdStr = "../COMMON/cal.asp?DataScelta=" + document.forma[TheObj].value + "&OGGETTO=" + TheObj;
	
	mywindow = open(CmdStr,'Seleziona_una_data','resizable=no,width=210,height=265');
	mywindow.location.href = CmdStr;
	if (mywindow.opener == null)
		mywindow.opener = self;
}


//**********************************************************
//************************ DECIMAL *************************
//**********************************************************

/*************** CARET ***************************/
function ReturnCaretPOS(myobject) {
	// copy current value
	var txt = myobject.value;
	// create textrange
	//myobject.caretPos = document.selection.createRange().duplicate();
	// insert my char
	myobject.caretPos.text = "|";
	// find index of my char
	var i = myobject.value.indexOf("|");
	// return old value string
	myobject.value = txt;
	// return i as the caretPOS
	return i;
}

function storeCaret (textEl) {
	if (textEl.createTextRange) {
		textEl.caretPos = document.selection.createRange().duplicate();
	}
     }


function SelectRange(input, selectionStart, selectionEnd) {
	if (input.setSelectionRange) {
		input.focus();
		input.setSelectionRange(selectionStart, selectionEnd);
	}
	else if (input.createTextRange) {
		var range = input.createTextRange();
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}
}

function setCaretToEnd (input) {
	SelectRange(input, input.value.length, input.value.length);
}

function setCaretToBegin (input) {
	SelectRange(input, 0, 0);
}

function setCaretToPos (input, pos) {
	SelectRange(input, pos, pos);
}

function selectString (input, string) {
	var match = new RegExp(string, "i").exec(input.value);
	if (match) {
		SelectRange (input, match.index, match.index + match[0].length);
	}
}

function replaceSelection (input, replaceString) {
	if (input.setSelectionRange) {
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart)
			+ replaceString
			+ input.value.substring(selectionEnd);
		if (selectionStart != selectionEnd) // has there been a selection
			SelectRange(input, selectionStart, selectionStart + replaceString.length);
		else // set caret
			setCaretToPos(input, selectionStart + replaceString.length);
	}
	else if (document.selection) {
		var range = document.selection.createRange();
		if (range.parentElement() == input) {
			var isCollapsed = range.text == '';
			range.text = replaceString;
			if (!isCollapsed)  { // there has been a selection
			//it appears range.select() should select the newly
			//inserted text but that fails with IE
				range.moveStart('character', -replaceString.length);
				range.select();
			}
		}
	}
}
/*************** CARET ***************************/

//formatDecimal function
//Print the floating point number with certain decimal point.
//
//Syntax
//formatDecimal(number, boolean, decimal)
//number is the floating point number which will be formatted.
//boolean is used to decide whether add "0" at the end of the
//floating point number or not.
//decimal is how many decimal point you wnat. (Default is 2)
//
//Description
//This function will print the floating point number passed in with the decimal
//point that users need.
//
//Examples
//formatDecimal("123.2333", true, 2);	will return "123.23".
//formatDecimal("123", true, 2);	will return "123.00".
//formatDecimal("123", false, 2);	will return "123".
//formatDecimal("123.2", true, 2);	will return "123.20".
//formatDecimal("123.2", false, 2);	will return "123.2".
//formatDecimal("123.456", true, 2);	will return "123.46".
//formatDecimal(".235", true, 2);	will return "0.24".
//formatDecimal("0.9999", true, 2);	will return "1.00".
//formatDecimal("0.9999", false, 2);	will return "1".


function formatDecimal(argvalue, addzero, decimaln) {
	var numOfDecimal = (decimaln == null) ? 2 : decimaln;
	var number = 1;

	number = Math.pow(10, numOfDecimal);

	argvalue = Math.round(parseFloat(argvalue) * number) / number;
	// If you're using IE3.x, you will get error with the following line.
	// argvalue = argvalue.toString();
	// It works fine in IE4.
	argvalue = "" + argvalue;

	if (argvalue.indexOf(".") == 0)
		argvalue = "0" + argvalue;

	if (addzero == true) {
		if (argvalue.indexOf(".") == -1)
			argvalue = argvalue + ".";

		while ((argvalue.indexOf(".") + 1) > (argvalue.length - numOfDecimal))
			argvalue = argvalue + "0";
	}
	return argvalue;
}


//formatValue function
//Print a number according to the format specified. Used for currency format.
//
//Syntax
//formatValue(argvalue, format)
//argvalue is the number which will be formatted.
//format is the format of the result.
//
//Description
//The number passed in will be formatted according to the format specified by the user.
//This function is written for formatting a currency number.
//formatDecimal function is needed.
//
//Examples
//formatValue(1223.434, "$##.###,##")		will return "$1.223,43"
//formatValue(1223.43, "$##.###,##")		will return "$1.223,43"
//formatValue(1223., "$##.###,##")		will return "$1.223,00"
//formatValue(1223, "$##.###,##")		will return "$1.223,00"
//formatValue(23., "$##.###,##")		will return "$23,00"
//formatValue(23.3, "$##.###,##")		will return "$23,30"
//formatValue(23.3, "$##.###")			will return "$23"
//formatValue(23, "$##.###")			will return "$23"
//formatValue(124343423.3, "$###.###.###,##")	will return "$124.343.423,30"


function formatValue(argvalue, format) {
//AR
	if(argvalue == "")
		argvalue = "0.00"
//AR

	var TheMinus = argvalue.substring(0,1);
	if (TheMinus == "-")
		argvalue = argvalue.substring(1,argvalue.length);

	var numOfDecimal = 0;
	if (format.indexOf(",") != -1) {
		numOfDecimal = format.substring(format.indexOf(",") + 1, format.length).length;
		argvalue = formatDecimal(argvalue, true, numOfDecimal);
		strBeforeDot = format.substring(0, format.indexOf(","));
	}
	else
	{
		argvalue = formatDecimal(argvalue, false, numOfDecimal);
		strBeforeDot = format;
	}

	argvalueBeforeDot = argvalue.substring(0, argvalue.indexOf("."));

	retValue = argvalue.substring(argvalue.indexOf("."), argvalue.length);

	if (retValue.length != 0)
		if (navigator.appName == "Microsoft Internet Explorer")
			retValue = retValue.replace(".",",");
		else //if (navigator.appName == "Netscape")
			retValue = retValue.replace(".",",");
		

	if (argvalueBeforeDot.length == 0)
	{
		argvalueBeforeDot = retValue;
		retValue = "";
	}

	for (var n = strBeforeDot.length - 1; n >= 0; n--) {
		oneformatchar = strBeforeDot.substring(n, n + 1);
		if (oneformatchar == "#") {
			if (argvalueBeforeDot.length > 0) {
				argvalueonechar = argvalueBeforeDot.substring(argvalueBeforeDot.length - 1, argvalueBeforeDot.length);
				retValue = argvalueonechar + retValue;
				argvalueBeforeDot = argvalueBeforeDot.substring(0, argvalueBeforeDot.length - 1);
			}
		}
		else {
			if (argvalueBeforeDot.length > 0 || n == 0)
				retValue = oneformatchar + retValue;
		}
	}

	if (TheMinus == "-")
		retValue = TheMinus + retValue;

	return retValue;
}


function ConvertToDecimal(TheName)
{
	var str, lstr, hidden, dec, oldstr;
	stringFilter(TheName);

	str = document.forma[TheName].value;
	lstr = str.length

	hidden = TheName;

	hidden = hidden.replace("dec","");

	if (lstr != 0)
	{
		if (navigator.appName == "Microsoft Internet Explorer")
			dec = str.replace(".","");
		if (navigator.appName == "Netscape")
			dec = str.replace("[.]","");

		while (dec.search("[.]") != -1)
		{
			if (navigator.appName == "Microsoft Internet Explorer")
				dec = dec.replace(".","");
			if (navigator.appName == "Netscape")
				dec = dec.replace("[.]","");
		}
		document.forma[TheName].value = dec;

		if (navigator.appName == "Microsoft Internet Explorer")
			dec = dec.replace(",",".");
		if (navigator.appName == "Netscape")
			dec = dec.replace("[,]",".");

		document.forma[hidden].value = dec;
	}
	else
	{
		document.forma[TheName].value = "";
		document.forma[hidden].value = "";
	}
}


function ShowThousands(TheName)
{
	var str, pos, dec;

	str = document.forma[TheName].value;

	pos = str.search("[,]");

	if (pos == -1)
		pos = str.length;

	if (pos > 3)
	{
		while (pos > 3)
		{
			pos -= 3;
			str = str.substr(0,pos) + "." + str.substr(pos);
			pos = str.search("[.]");
		}
	}

	if (navigator.appName == "Microsoft Internet Explorer")
		str = str.replace("-.","-");
	if (navigator.appName == "Netscape")
		str = str.replace("[-.]","[-]");

	document.forma[TheName].value = str;
}


function AddComma(TheName)
{
	var str;

	str = document.forma[TheName].value;

	if (str.substr(str.length-1) == ".")
	{
		str = str.substr(0,str.length-1) + ",";
		document.forma[TheName].value = str;
	}
}


function stringFilter (TheName)
{
	var TheStr = document.forma[TheName].value;
	var filteredValues = "1234567890,-";     // Characters to be not stripped out
	var i;
	var returnString = "";

	// Search through string and append to unfiltered values to returnString.
	for (i = 0; i < TheStr.length; i++)
	{
		var c = TheStr.charAt(i);
		if (filteredValues.indexOf(c) != -1)
			returnString += c;
	}
	document.forma[TheName].value = returnString;
}


function innerFilter (TheName,TheFormat)
{
	var TheStr = document.forma[TheName].value;
	var filteredValues;  // Characters to be not stripped out
	var i;
	var returnString = "";
	var booComma, booMinus;

	if (TheFormat.search("[,]") != -1)
		filteredValues = "1234567890.,-";
	else
		filteredValues = "1234567890.-";

	// Search through string and append to unfiltered values to returnString.
	booComma = false;
	booMinus = false;
	for (i = 0; i < TheStr.length; i++)
	{
		var c = TheStr.charAt(i);
		if (filteredValues.indexOf(c) != -1)
		{
			if (	(c != "," && c != "-" ) ||
				(c == "," && !booComma && i != 0) ||
				(c == "-" && !booMinus && i == 0) )
					returnString += c;
		}
		if (c == "," && !booComma)
			booComma = true;
		if (c == "-" && !booMinus)
			booMinus = true;
	}

	document.forma[TheName].value = returnString;
}


function tastoPermesso(e)
{
	var tmp;

	if (navigator.appName == "Microsoft Internet Explorer")
	{
		tmp = window.event.keyCode;
		// FrecciaSinistra(37), FrecciaDestra(39), Tab(9), Shift(16)
		// Home(36), End(35)
		if((tmp == 37) || (tmp == 39)|| (tmp == 9) || (tmp == 16) || (tmp == 36)|| (tmp == 35))
			return false;
	}
	return true;
}

function Changed()
{	//Funzione chiamata in prevalenza dai campi che sfruttano il Validate.	
	document.forma.hChanged.value = 1;		
}

function DoMyDec(TheName,booThousand,TheFormat)
{
	// Se sto inserendo, cambia il punto decimale con una virgola
	if (booThousand)
		AddComma(TheName);
	// Cancella dall'input anche la virgola se il formato non prevede decimali
	if (tastoPermesso() || (navigator.appName == "Netscape"))
		innerFilter(TheName,TheFormat);
	// La stringa in input
	var argvalue = document.forma[TheName].value;
	// Se c'è un meno davanti, non lo devo conteggiare nel formato
	var TheMinus = false;
	if (tastoPermesso() && booThousand && argvalue.substring(0,1) == "-")
	{
		TheMinus = true;
		argvalue = argvalue.substring(1,argvalue.length);
		document.forma[TheName].value = argvalue;
	}

	// Se il formato prevede la virgola, è la parte intera dell'input
	var argvalueInt = argvalue.substring(0,argvalue.indexOf(","));
	// Se il formato prevede la virgola, è la parte decimale dell'input,
	// altrimenti ne è la parte intera
	var argvalueDec = argvalue.substring(argvalue.indexOf(","), argvalue.length);

	if (argvalueInt.length == 0)
	{
		argvalueInt = argvalueDec;
		argvalueDec = "";
	}

	// Se il formato prevede la virgola, ne è la parte intera
	var intPart = TheFormat.substring(0, TheFormat.indexOf(","));
	// Se il formato prevede la virgola, ne è la parte decimale (compresa la virgola),
	// altrimenti ne è la parte intera
	var decPart = TheFormat.substring(TheFormat.indexOf(","), TheFormat.length);

	if (intPart.length == 0)
	{
		intPart = decPart;
		decPart = "";
	}

	// Se nell'input c'è una virgola, ne è la posizione, altrimenti vale -1
	var commaPresent = argvalue.search("[,]");
	// Se nell'input c'è un punto, ne è la posizione, altrimenti vale -1
	var dotPresent = argvalue.search("[.]");

	var dec = intPart;

	// Se nella stringa non ci sono punti devo confrontare
	// con un formato senza punti
	if (dotPresent == -1)
	{
		if (navigator.appName == "Microsoft Internet Explorer")
			dec = dec.replace(".","");
		if (navigator.appName == "Netscape")
			dec = dec.replace("[.]","");

		while (dec.search("[.]") != -1)
		{
			if (navigator.appName == "Microsoft Internet Explorer")
				dec = dec.replace(".","");
			if (navigator.appName == "Netscape")
				dec = dec.replace("[.]","");
		}
	}

	if (tastoPermesso() && booThousand)
	{
		if (argvalueInt.length > dec.length)
		{
			argvalue = argvalueInt.substring(0, argvalueInt.length-1)+argvalueDec;
			document.forma[TheName].value = argvalue;
		}
		else if ((argvalue.length > TheFormat.length) ||
		    (commaPresent != -1 && argvalueDec.length > decPart.length))
		{
			argvalue = argvalue.substring(0, argvalue.length-1);
			if (TheMinus)
				argvalue = "-" + argvalue;
			document.forma[TheName].value = argvalue;
			return;
		}
	}

	if (tastoPermesso() || (navigator.appName == "Netscape"))
	{
		ConvertToDecimal(TheName);
		if (booThousand)
		{
			ShowThousands(TheName);
			argvalue = document.forma[TheName].value;
			if (commaPresent == -1 && argvalue.length > 0 && decPart != "")
			{
				if (argvalue.length == intPart.length)
				{
					if (argvalue.substring(argvalue.length - 1, argvalue.length) != ",")
						document.forma[TheName].value = argvalue + ",";
				}
			}
			argvalue = document.forma[TheName].value;
			if (TheMinus)
				argvalue = "-" + argvalue;
			document.forma[TheName].value = argvalue;
		}
	}
	else if (tastoPermesso() && TheMinus)
	{
		argvalue = "-" + argvalue;
		document.forma[TheName].value = argvalue;
	}
}


function DoFormat(TheObj,TheFormat)
{
	var hidden = TheObj.name;
	hidden = hidden.replace("dec","");

	if(TheObj.value != "")
	{
		ConvertToDecimal(TheObj.name);
		TheObj.value = formatValue(document.forma[hidden].value,TheFormat);
	}
	else
	{
		TheObj.value = formatValue(document.forma[hidden].value,TheFormat);
	}
}

function DoFormatPrev(TheObj,TheFormat)
{
	var hidden = TheObj.name;
	hidden = hidden.replace("dec","");

	if(TheObj.value != "")
	{
		ConvertToDecimal(TheObj.name);
		TheObj.value = formatValue(document.forma[hidden].value,TheFormat);
	}
}


function DoDec(TheObj,booThousand,TheFormat)
{
	if (tastoPermesso())
	{
		var TheChars = TheObj.value.length;
		storeCaret(TheObj);
		var selectedPos = ReturnCaretPOS(TheObj);
		DoMyDec(TheObj.name,booThousand,TheFormat);
		var FinalText = TheObj.value;
		var Minus = 0;
		if (FinalText.substring(0,1) == "-")
			TheFormat = "-" + TheFormat;
		var theDiff = TheObj.value.length - TheChars;
		if (TheChars < TheFormat.length && theDiff != -1)
			selectedPos = selectedPos + theDiff;
		else if (TheChars >= TheFormat.length && TheFormat.substring(selectedPos,selectedPos+1) == ".")
			selectedPos = selectedPos + 1;
		else if (TheChars >= TheFormat.length && TheFormat.substring(selectedPos,selectedPos+1) == ",")
			selectedPos = selectedPos + 1;
		setCaretToPos(TheObj,selectedPos);
	}
}

//////////////////////////////////////////
// Gestione layer per ricerca Provincie //
//////////////////////////////////////////

function saveHTML(TheDIV, TheBKP)
{
	document.getElementById(TheBKP).innerHTML = document.getElementById(TheDIV).innerHTML
	document.getElementById(TheDIV).innerHTML = ""
}

function restoreHTML(TheDIV, TheBKP)
{
	document.getElementById(TheDIV).innerHTML = document.getElementById(TheBKP).innerHTML
	document.getElementById(TheBKP).innerHTML = ""
}

function notEmptyHTML(TheDIV)
{
	return (trim(document.getElementById(TheDIV).innerHTML) != "")
}

function showHTML(whatsubmenu) 
{
	var opensubmenu = eval("document.all."+whatsubmenu+".style")
	var bkpsubmenu = whatsubmenu+'Bkp'
	if (opensubmenu.visibility=="visible")
	{
		saveHTML(whatsubmenu,bkpsubmenu)
		opensubmenu.visibility="hidden"
	}
	else
	{
		if (notEmptyHTML(bkpsubmenu))
		{
			restoreHTML(whatsubmenu,bkpsubmenu)
		}
		opensubmenu.visibility="visible"
	}
}

function gotoHTML(TheID)
{
//	parent.frames[1].document.body.scrollTop = parent.frames[1].document.getElementById(TheID).offsetTop;
}

function apri_finestra(url_pag,windowsname,dime,dimes,left,top)
{
	var hWnd=window.open(url_pag,windowsname,"toolbar=no,width="+dime+",height="+dimes+",left="+left+",top="+
	top+",directories=no,status=no,statusbar=no,resizable=1,menubar=no,scrollbars=yes,location=no");
	if(!hWnd.opener) hWnd.opener=self;
	if(hWnd.focus!=null) hWnd.focus();
}

function trim(inputString)
{
   // Toglie gli spazi all'inizio e alla fine della stringa.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }

   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

//layer visibility/////////////////////////
function hideLayer(lyr)
{
	lyr.style.visibility="hidden";
}
function showLayer(lyr)
{
	lyr.style.visibility="visible";
}

function getLayer(name) 
{
	return eval('document.all.' + name);
}
///////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////
//Funzione utilizzata per gestire solo i riepiloghi di CANALE e TARGET
//Viene chiamata da liste_mydirect.asp, preventivo.asp e frm_salva.asp

function Cambia_Riep(Val,Nome)
{
	var f = document.forma;
	if(Nome == "txt_canale")
	{
		if(Val == "TM")
			document.getElementById("riep_canale").innerHTML = "Telemarketing"
		else
			document.getElementById("riep_canale").innerHTML = "Direct marketing"
	}

	if(Nome == "txt_contatti" || Nome == "N_TARGET" || Nome == "LIS_N_TARGET")
		document.getElementById("riep_contatti").innerHTML = Val

}

/////////////////////////////////////////////////////////////////////////////////////

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
