function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function writeFlashObject(movie, qs, width, height){
	document.write(
				'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id="set_foto" align="middle">\n'+
'<param name="allowScriptAccess" value="sameDomain" />\n'+
'<param name="quality" value="best" />\n'+
'<param name="movie" value="' + movie +'" />\n'+
'<PARAM NAME=FlashVars VALUE="'+qs+'">\n'+
'<PARAM name="wmode" VALUE="transparent">\n'+
'<embed src="' + movie +'" quality="best"  wmode="transparent" bgcolor="#ffffff" FlashVars="'+qs+'" width="' + width + '" height="' + height + '" name="set_foto" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n'+
'</object>');
}
function fnMoney(valore){
	money=""
	if (valore!=""){
		money=valore.replace(".",",");
		PosVirgola=money.lastIndexOf(",");
		if (PosVirgola==-1){
			money=money + ",00";
		}else{
			money=money.substr(0,PosVirgola+3);
		}
	}
	return money;
}

function fnOpenImage(pathImage,page_titolo,width,height){
	win=window.open(pathImage,page_titolo,"width="+width+",height="+height);
	win.focus();
}

function replaceSpecialChars(str){
	return str.replace("'","''").replace('"','""')
}
/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

function fnSvuotaCampi(sValore, aCampi){
	for(i=0; i<aCampi.length;i++){
		if(document.getElementById(aCampi[i]) && sValore==''){
			document.getElementById(aCampi[i]).value = '';
		}
	}
}

function fnResizeDialog(largo,alto) {
	window.dialogLeft = (screen.width-largo)/2;
	window.dialogTop = (screen.height-alto)/2;
	window.dialogWidth = largo + 'px';
	window.dialogHeight = alto + 'px';
}

function fnOperazioniApertura(){
	opener.pseudomodal = self;
}

function fnOperazioniChiusura(){
	opener.pseudomodal = undefined;
}

function resizeWindow(width,height,position){
	// width,height: dimensioni del popup
	// position=0 posiziona il popup in alto a destra
	// position=1 posiziona il popup al centro schermo
	self.resizeTo(width,height);
	if (position==1){
		self.moveTo((window.screen.width - width) / 2,(window.screen.height - height) / 2);
	}else if (position==0){
		self.moveTo(0,0);
	}
}

function lenghtFieldValidate(arrayLabel, arrayCampi, arrayLength){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if ((window.document.getElementById(arrayCampi[i]).value).length>arrayLength[i] && arrayCampi[i]!=""){
			messaggio=messaggio+"- "+arrayLabel[i]+": al massimo "+arrayLength[i]+" caratteri\n";
			errore=true;
		}
	}
	if (errore==true){
		alert("Attenzione i seguenti campi sono limitati a un certo numero di caratteri:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}

function requiredCheckboxValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (!isChecked(arrayCampi[i]) && arrayCampi[i]!=""){
			messaggio=messaggio+"- "+arrayLabel[i]+"\n";
			errore=true;
		}
	}
	if (errore==true){
		alert("Attenzione selezionare almeno uno tra gli elementi contenuti nelle liste dei seguenti campi:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}

function isChecked(field){
	result=false;
	collection_numero_ddt=window.document.getElementsByName(field);
	for (v=0;v<collection_numero_ddt.length;v++){
		//alert(collection_numero_ddt[i].value + " --- " + collection_numero_ddt[i].checked);
		if (collection_numero_ddt[v].checked==true){
			result=true;
		}
	}
	return result;
}

function requiredFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (arrayCampi[i]!=""){
			if (window.document.getElementById(arrayCampi[i]).value==""){
				messaggio=messaggio+"- "+arrayLabel[i]+"\n";
				errore=true;
			}
		}
	}
	if (errore==true){
		alert("Attenzione i seguenti campi sono obbligatori:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}

function rotatedFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=true;
	for (i=0; i<arrayCampi.length; i++){
		messaggio=messaggio+"- "+arrayLabel[i]+"\n";
		if (window.document.getElementById(arrayCampi[i]).value!=""){
			errore=false;
		}
	}
	if (errore==true){
		alert("Attenzione uno dei seguenti campi deve essere riempito:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}

function optionFieldValidate(form, option, arrayLabel, arrayCampi){
	for (i=0; i<arrayCampi.length; i++){
		if (window.document.forms[form][option][i].checked==true){
			break;
		}
	};
	if (window.document.getElementById(arrayCampi[i]).value==""){
		alert("Attenzione il campo " + arrayLabel[i] + " deve essere riempito.");
		return false;
	}
	return true;
}

function intFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (!isNumberInt(window.document.getElementById(arrayCampi[i]).value) && arrayCampi[i]!=""){
			messaggio=messaggio + "- " + arrayLabel[i] + "\n";
			errore=true;
		}
	}
	if (errore){
		alert("Attenzione i seguenti campi devono contenere un valore intero:\n" + messaggio);
	}
	return !errore;
}

function floatFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (!isNumberFloat(window.document.getElementById(arrayCampi[i]).value) && arrayCampi[i]!=""){
			messaggio=messaggio + "- " + arrayLabel[i] + "\n";
			errore=true;
		}
	}
	if (errore){
		alert("Attenzione i seguenti campi devono contenere un valore decimale:\n" + messaggio);
	}
	return !errore;
}

function toFloat(inputString){
	if (isNumberFloat(inputString) && inputString!=""){
		return parseFloat(inputString.replace(",","."));
	}else{
		return 0;
	}
}

function isNumberFloat(inputString){
	n=inputString.indexOf(",")
	m=inputString.lastIndexOf(",");
	s=inputString.indexOf("-");
	t=inputString.lastIndexOf("-");
	if (n==m && s==t) {
		if (s!=0 && inputString.charAt(s)=="-"){
			return false;
		}
		for (x=0; x<inputString.length; x++){
			if (isNaN(inputString.charAt(x)) && inputString.charAt(x)!="," && inputString.charAt(x)!="-"){
				return false;
			}
		}
		return true;
	}
	return false;
}

function isNumberInt(inputString){
	s=inputString.indexOf("-");
	t=inputString.lastIndexOf("-");
	if (s==t) {
		if (s!=0 && inputString.charAt(s)=="-"){
			return false;
		}
		for (x=0; x<inputString.length; x++){
			if (isNaN(inputString.charAt(x))){
				return false;
			}
		}

		return true;
	}
	return false;
}

function isEmail(inputString) {
	//regular expression per controllo email
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(inputString));
}

function emailFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (!isEmail(window.document.getElementById(arrayCampi[i]).value) && arrayCampi[i]!=""){
			messaggio=messaggio+"- "+arrayLabel[i]+"\n";
			errore=true;
		}
	}
	if (errore==true){
		alert("Attenzione i seguenti campi devono contenere una e-mail valida:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}

function fnOra(fieldName,current_time){
	pseudomodal=window.open('/script/time_picker.asp?fieldName='+fieldName+'&current_time='+current_time,'time_picker','width=1,height=1,titlebar=no,status=no,menubar=no,scrollbars=no');
	pseudomodal.focus();
}

function fnToBoolean(s){
	if(s=="True" || s=="Vero"){
		return true;
	}else{
		return false;
	}
}
