function ConfirmOperation(sMsg)
	{
	if (!(confirm(sMsg)))
		{
		return false;
		}
	else
		{
		return true;
		}		
	}
	
function CheckForm(formName, fieldList) 
	{
	var fieldArr = fieldList.split(",");
	//var FormName = window.event.srcElement.parentElement.id; -> funziona solo con IE
	var strEmpyFields = ""
	
	for (i = 0; i < (fieldArr.length); i++)
		{
		fieldId = fieldArr[i].substring(0, fieldArr[i].indexOf("-"));
		if ( document.forms[formName].elements[fieldId] == null){return true}
		fieldValue = document.forms[formName].elements[fieldId].value;
		fieldName = fieldArr[i].substring(fieldArr[i].indexOf("-") + 1, fieldArr[i].length);
		if (fieldValue == "")
			{
			strEmpyFields = strEmpyFields + "\n" + fieldName;
			}	
		}
	
	if (strEmpyFields != "")
		{
		alert("ATTENZIONE\nI seguenti campi richiesti non sono stati compilati:\n" + strEmpyFields + "\n\nImpossibile procedere con le operazioni.");
		return false;	
		}
	else
		{
		return true;
		}
	}
	
function IsValidMail(sMail)
	{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(sMail)) return true;
	else return false;
	}
		
function CheckLength(formName, txtArea, txtCountdown, fieldName, fieldMaxlength)
	{
	var strTypedtext = document.forms[formName].elements[txtArea].value; //window.event.srcElement.value  -> funziona solo con IE
    var intTextlenght = document.forms[formName].elements[txtArea].value.length;
    document.forms[formName].elements[txtCountdown].value = fieldMaxlength - intTextlenght; // window.event.srcElement.value.length; -> funziona solo con IE
    if (intTextlenght > fieldMaxlength)
		{
        alert('Hai raggiunto la lunghezza massima consentita per il campo [' + fieldName + '] (' + fieldMaxlength + ' caratteri).');
        document.forms[formName].elements[txtArea].value= strTypedtext.substring(0, fieldMaxlength);
        document.forms[formName].elements[txtCountdown].value= "0";
        return false;                         
        }
    }

function ValorizzaOpenerField(sField, sText)
	{
	window.opener.document.forms[0].elements[sField].value = sText;
	window.close;
	return true;
	}
	
function OpenWindow(sPage, iWidth, iHeight)
	{
	window.open(sPage, 'Pop', 'left=0 top=0 width=' + iWidth + ' height=' + iHeight + ' toolbar=no status=yes scrollbars=yes') 
	return true; //Restituisce True -> la pagina che la chiama effettuerà il postback
	}
	

function OpenWindowEx(sPage, iWidth, iHeight)
	{
	window.open(sPage, 'Pop', 'left=0 top=0 width=' + iWidth + ' height=' + iHeight + ' toolbar=no status=yes scrollbars=yes') 
	return false; //Restituisce False -> la pagina che la chiama NON effettuerà il postback
	}
	
function RedirectPage(sPage)
	{
	window.location.replace(sPage);
	return false;
	}

var winModalWindow //Variabile globale


function IgnoreEvents(e)
{
  return false
}

 
function ShowModalWindow(sUrl, iWidth, iHeight)
{
  if (window.showModalDialog)
  {
    window.showModalDialog(sUrl,null,
    "dialogWidth=" + iWidth + "px;dialogHeight=" + iHeight + "px")
  }
  else
  {
    window.top.captureEvents (Event.CLICK|Event.FOCUS)
    window.top.onclick=IgnoreEvents
    window.top.onfocus=HandleFocus 
    winModalWindow = 
    window.open (sUrl,"ModalChild",
       "dependent=yes,width=" + iWidth + ",height=" + iHeight)
    winModalWindow.focus()
  }
}

 
function HandleFocus()
{
  if (winModalWindow)
  {
    if (!winModalWindow.closed)
    {
      winModalWindow.focus()
    }
    else
    {
      window.top.releaseEvents (Event.CLICK|Event.FOCUS)
      window.top.onclick = ""
    }
  }
  return false
}

function PrintPage(){
window.print();
return false;
}

function IndietroBrowser(){
history.back();
return false;
}

function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = /  /g;
   while (temp.match(obj)) { temp = temp.replace(obj, " "); }
   return temp;
}
	
	

function ApriFormRicerca(sUrl, bReturn)
	{
	//prendo le dimensioni esatte di un afinestra atutto schermo
	iWidth = screen.width - 10;
	iHeight = screen.height - 80;
	
	//Modifico le dimensioni per renderle minori di quelle dello schermo
	//iWidth = screen.width - 50;
	//iHeight = screen.height - 120;
	
	sParam = "popup=1" //Parametro che indica alla form aperta (al left) che è una popup di ricerca
	
	//Cerco se c'è almeno il primo parametro
	iPosFirstParam = sUrl.indexOf("x?")
		
	//Se non ho trovato il primo parametro
	if (iPosFirstParam == -1)
		{
		sUrl += "?" + sParam
		}
	else
		{
		sUrl += "&" + sParam
		}
	
	finestra = window.open(sUrl, 'FormRicerca', 'left=0 top=0 width=' + iWidth + ' height=' + iHeight + ' scrollbars=yes toolbar=no status=yes resizable=yes screenx=0 screeny=0');
	finestra.focus();
	if (bReturn != undefined)
		{return bReturn;}
	else
		{return false;}
	}
	
function IsValidDate(sDate)
	{
	var re;
	re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
	if (re.test(sDate) == true)
		return true
	else 
		return false;
	}
	
	
