/*=================================================*
 *          Funzioni di utilita'                   * 
 *=================================================*/
var _formSubmitted = false;var _windowName = window.name;
/* *  * Cerca un form con l'id specificato. *  */
function getFormByID(formID) {
	if (!document.getElementById) {		alert(I18N.t("Browser non supportato !\n(document.getElementById) !"));	}
	if (formID == null) {		alert(I18N.t("parametro formID nullo"));		return null;	}
	var theForm = document.getElementById(formID);
	if (theForm == null) {		alert(I18N.t("Form non trovato: {0}", formID));		return null;	}	return theForm;}
function getFormElement(formID, inputName) {
	var f = getFormByID(formID);	var elem = f.elements[inputName];	return elem;}
function form_addOption(formName, fieldName, opt)
{
   var frm = document.forms[formName];
   var field = frm[fieldName];
   var pos = field.options.length;
   
   if (opt == null)
           return;
           
   var key = opt.key;
   var desc = opt.desc;
   
   if (key == '' || desc == '')
     return;
   
   field.options[pos] = new Option(key,desc);
}

function form_removeOption(formName, fieldName)
{
   var frm = document.forms[formName];
   var field = frm[fieldName];
   var lenght = field.options.length;
   
   for(i = 0 ; i < lenght ; ++i)
   {
      var value = field.options[i];
      if (value.selected)   
      {      
         field.options[i] = null;
         i--;
         lenght--;
      }
   }   
}

/******************************************************************************* * ================================================= *  * Funzioni utilizzabili dalle pagine * *  * ================================================= */
function canSubmit() {	//var w = window._windowName == "MSM_main" ? window : opener;	var w = window;	if (w._formSubmitted) {		alert(I18N.t('Elaborazione in corso ...'));		return false;	}	w._formSubmitted = true;	showWaitMessage();	return true;} function clearSubmit() {		//var w = window._windowName == "MSM_main" ? window : opener;	var w = window;	w._formSubmitted = false;	resetWaitMessage();}
/* *  * Esegue il submit del form con l'attributo "id" specificato. *  */
function submitFormByID(formID, action, cmd, target) {	var theForm = getFormByID(formID);
	if (!canSubmit()) {		return;	}
	if (action) {		theForm.action = action;	}
	if (target && target != "") { 		theForm.target = target;				if (target != "MSM_main") {			clearSubmit();		}		} else { 				theForm.target = '';	}
	if (theForm.cmd && cmd) {		theForm.cmd.value = "_GLOBAL_CMD_" + cmd;	}
	// salva la posizione del "MainPanel" se esiste	saveMainPanelScrollPosition();
	theForm.submit();}
function saveMainPanelScrollPosition () {
	var d = document.getElementById('mainPanel');
	var form = document.forms[0];
	if (d && d != null && form && form != null) {
		form.scrollTop.value = d.scrollTop;		form.scrollLeft.value = d.scrollLeft;    }}
function loadMainPanelScrollPosition () {
	var d = document.getElementById('mainPanel');
	var form = document.forms[0];	if (d && d != null && form && form != null) {
		d.scrollTop = form.scrollTop.value;		d.scrollLeft = form.scrollLeft.value;    }}
function showWaitMessage() {
	var waitMessage = document.getElementById('waitMessage');
	if (!waitMessage && parent.header) {		waitMessage = parent.header.document.getElementById('waitMessage');	}
	if (!waitMessage && window.opener) {
		waitMessage = window.opener.document.getElementById('waitMessage');	}
	if (waitMessage) {
		waitMessage.style.display = 'block';	}}
function resetWaitMessage() {
	var waitMessage = document.getElementById('waitMessage');
	if (!waitMessage && parent.header) {
		waitMessage = parent.header.document.getElementById('waitMessage');	}
	if (waitMessage) {
		waitMessage.style.display = 'none';	}}
function openLink(url) {	if (!canSubmit()) {		return;	}
    window.location.href = url + "?cmd=_GLOBAL_CMD_";}

/* *  * Apre una finestra, parametri: *  - myURL URL da aprire *  - windowName nome da assegnare alla finestra *  - customProperties features aggiuntive, verranno aggiunte alla fine della * stringa delle specifiche dopo una virgola *  *  *  * Restituisce l'oggetto Window creato *  */
function newWindowCustom(myURL, newName, customProperties) {
  var newWin = window.open(myURL, newName, customProperties);
  
  if (parseInt(navigator.appVersion) >= 4) { 
      newWin.focus(); 
  }
  
  return newWin; 
}

/* *  * Apre una finestra, parametri: *  - myURL URL da aprire *  - windowName nome da assegnare alla finestra *  - w, h larghezza, altezza *  - location (true / false) barra dell'indirizzo *  - toolbar (true / false) barra dei pulsanti *  - scrollbars (true / false) *  - customProperties features aggiuntive, verranno aggiunte alla fine della * stringa delle specifiche dopo una virgola *  *  *  * Restituisce l'oggetto Window creato *  */
function newWindow(myURL, newName, w, h, location, toolbar, scrollbars, resizable, customProperties) {
  var winLeft = (screen.availWidth - w) / 2;
  var winTop = (screen.availHeight - h) / 2;
  
  w -= 10;
  // sottrai spazio occupato task bar
  h -= 30;
  
  if (location == null)
    location = true;
  if (toolbar == null)
    toolbar = true;
  if (scrollbars == null)
    scrollbars = true;
  if (resizable == null)
    resizable = true;
  
  var winprops = "height=" + h;
  winprops += ",innerHeight=" + h;
  winprops += ",width=" + w;
  winprops += ",innerWidth=" + w;
  winprops += ",left=" + winLeft;
  winprops += ",top=" + winTop;
  
  if (location)
    location += ",location=yes";
  else
    location += ",location=no";
    
  if (toolbar)
    winprops += ",toolbar=yes";
  else
    winprops += ",toolbar=no";
  
  if (scrollbars)
    winprops += ",scrollbars=yes";
  else
    winprops += ",scrollbars=no";
  
  if (resizable)
    winprops += ",resizable=yes";
  else
    winprops += ",resizable=no";
  
  if (customProperties)
    winprops += "," + customProperties;
  
  return newWindowCustom(myURL, newName, winprops);
}

function checkSave() {
    // var f = document.forms[0];
    // if (f.exitWithoutSave.value == 0) {
        if (confirm(I18N.t('Vuoi salvare?'))) {
            // setExitWithoutSave(1);
            alert(I18N.t('non deve andare alla pagina di login'));
            self.location = 'www.pippo.it';
        }
    // }
}

/* *  * Assegna il valore specificato all'elemento del form. *  * Parametri: *  - formID *  - inputName *  - newValue *  *  *  * Restituisce il valore precedente, se presente. *  */
function setFieldValue(formID, inputName, newValue) {
  var elem = getFormElement(formID, inputName);
  if (! elem) {
    alert(I18N.t("ERRORE: elemento \"{0}\" del form \"{1}\" non trovato !", inputName, formID));
    return;
  }
  var oldValue = elem.value;
  elem.value = newValue;
  
  return oldValue;
}

function getFieldValue(formID, inputName) {
  var elem = getFormElement(formID, inputName);
  if (! elem) {
    alert(I18N.t("ERRORE: elemento \"{0}\" del form \"{1}\" non trovato !", inputName, formID));
    return;
  }
  return elem.value;
}

function clearLookup(formID, cdField, field1, field2) {
    var f = getFormByID(formID);
    if (f.elements[cdField].value != "") {
        f.elements[cdField].value = "";
        // f.elements[field1].value = "";
    }
    f.elements[field2].value = "";
}

function setBlank(formID, nameField) {
    var f = getFormByID(formID);
    if(!f.elements[nameField].readOnly) {
        f.elements[nameField].value = "";  
    }
}

function setReadOnly(formID, nameField, value)  {
    var f = getFormByID(formID);
    f.elements[nameField].readOnly = value;
}

// se elem ? checkato, il nameField viene reso editabile
function setDisabled(formID, nameField, elem)  {
    var f = getFormByID(formID);
    if(elem.checked)    
        f.elements[nameField].disabled = true;
    else                
        f.elements[nameField].disabled = false;
}

// se elem ? checkato, il nameField viene reso readonly
function setEnabled(formID, nameField, elem)  {
    var f = getFormByID(formID);
    if(elem.checked)
        f.elements[nameField].disabled = false;
    else
        f.elements[nameField].disabled = true;
}

function trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function encodeHtml(toEncode) {
   return toEncode.replace(/&/gi, '&amp;').replace(/\"/gi, '&quot;').replace(/</gi, '&lt;').replace(/>/gi, '&gt;');

}
/* *  * Cattura l'evento di tipo Enter sul documento. *  * Implementare la funzione doEnterFunction() e aggiungere al onload del body *  * la funzione captureEvent() *  */
function captureEnter(eventObj)
{
    if (event.keyCode == 13)
        doEnterFunction();
} 
 
function captureEvent()
{
    // NETSCAPE NAVIGATOR 4
    if (document.layers) {
        document.captureEvents( Event.KEYPRESS );
        document.onkeypress = captureEnter;
    // INTERNET EXPLORER 4+
    } else if (document.all) {
        document.onkeypress = captureEnter;
    // Netscape 6/Gecko
    } else if (document.getElementById) {
        var targetObject = document;
        targetObject.addEventListener ("keypress",captureEnter,false);
    }
}



/******************************************************************************* * ================================================= *  * Dialog ricerca cliente *  * ================================================= */

var currentDialog;

function ClientiDialogPage() {

    var callbackFunction = "";

    var anagType;
    var commDaChiu;
	var onlyOpen;

    var anagCdAnag;
    var anagCeAnag = undefined;
    var anagDeRsoc = undefined;
    var anftDsPiva = undefined;
    var anftDsCofi = undefined;
    var anagCdAgen = undefined;

    var anagCdAnagField = undefined;
    var anagCeAnagField = undefined;
    var anagDeRsocField = undefined;
    var anftDsPivaField = undefined;
    var anftDsCofiField = undefined;
	// AF008
	var uffiCdAcqu = undefined;
	var anagCdAgenScope = undefined;	
	var extraPortafoglio = undefined;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getAnagType = getAnagType;
    this.setAnagType = setAnagType;
    this.getAnagCdAnag = getAnagCdAnag;
    this.setAnagCdAnag = setAnagCdAnag;
    this.getAnagCeAnag = getAnagCeAnag;
    this.setAnagCeAnag = setAnagCeAnag;
    this.getAnagDeRsoc = getAnagDeRsoc;
    this.setAnagDeRsoc = setAnagDeRsoc;
    this.getAnftDsPiva = getAnftDsPiva;
    this.setAnftDsPiva = setAnftDsPiva;
    this.getAnftDsCofi = getAnftDsCofi;
    this.setAnftDsCofi = setAnftDsCofi;
    this.setAnagCdAgen = setAnagCdAgen;
    this.getAnagCdAgen = getAnagCdAgen;
    this.getCommDaChiu = getCommDaChiu;
    this.setCommDaChiu = setCommDaChiu;
    this.isOnlyOpen = isOnlyOpen;
    this.setOnlyOpen = setOnlyOpen;
    this.getUffiCdAcqu = getUffiCdAcqu; 
	this.setUffiCdAcqu = setUffiCdAcqu;
    this.getAnagCdAgenScope = getAnagCdAgenScope; 	this.setAnagCdAgenScope = setAnagCdAgenScope;	
    this.getExtraPortafoglio = getExtraPortafoglio; 
	this.setExtraPortafoglio = setExtraPortafoglio;
	
    this.getAnagCdAnagField = getAnagCdAnagField;
    this.setAnagCdAnagField = setAnagCdAnagField;
    this.getAnagCeAnagField = getAnagCeAnagField;
    this.setAnagCeAnagField = setAnagCeAnagField;
    this.getAnagDeRsocField = getAnagDeRsocField;
    this.setAnagDeRsocField = setAnagDeRsocField;
    this.getAnftDsPivaField = getAnftDsPivaField;
    this.setAnftDsPivaField = setAnftDsPivaField;
    this.getAnftDsCofiField = getAnftDsCofiField;
    this.setAnftDsCofiField = setAnftDsCofiField;

    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {
        if (this.anagType == undefined) {
            alert(I18N.t("(errore interno) E' necessario specificare anagType"));
            return;
        }

        if (this.anagCeAnag != undefined && this.anagCeAnag.length == 0 &&
            this.anagDeRsoc != undefined && this.anagDeRsoc.length == 0 &&
            this.anftDsPiva != undefined && this.anftDsPiva.length == 0 &&
            this.anftDsCofi != undefined && this.anftDsCofi.length == 0) {

            alert(I18N.t("Per la ricerca specificare il Codice esteso,  la Ragione Sociale, il Codice Fiscale oppure la Partita IVA"));
            return;
        }

        if (this.anagCeAnag != undefined && this.anagCeAnag != "" && this.anagCeAnag.length < 1) {

            alert(I18N.t("Inserire almeno un carattere per la ricerca."));
            return;
        }

        if (this.anagDeRsoc != undefined && this.anagDeRsoc != ""  && this.anagDeRsoc.length < 3) {

            alert(I18N.t("Inserire almeno tre caratteri per la ricerca."));
            return;
        }
        
        if (((this.anagCeAnag == undefined) || this.anagCeAnag != undefined && this.anagCeAnag.length == 0) &&
            ((this.anagDeRsoc == undefined) || this.anagDeRsoc != undefined && this.anagDeRsoc.length == 0) &&
            ((this.anftDsPiva == undefined) || this.anftDsPiva != undefined && this.anftDsPiva.length == 0) &&
            ((this.anftDsCofi == undefined) || this.anftDsCofi != undefined && this.anftDsCofi.length == 0) &&
            ((this.anagCdAgen == undefined) || this.anagCdAgen != undefined && this.anagCdAgen == 0)) {

            alert(I18N.t("Specificare i parametri di ricerca"));
            return;
        }

        if (!this.anagCeAnag && !this.anftDsPiva && !this.anftDsCofi && (!this.anagCdAgen || this.anagCdAgen == 0) &&
            this.anagDeRsoc == undefined && this.anagDeRsoc.length == 0) {

            alert(I18N.t("Inserire almeno tre caratteri per la ricerca."));
            return;
        }

        this.callbackFunction = callbackFunction;
        var actionURL = "searchCliente.do"
        actionURL += "?cmd=" + this.anagType;
        if (this.anagCeAnag != undefined)
            actionURL += "&anagCeAnag=" + escape(this.anagCeAnag);
        if (this.anagDeRsoc != undefined)
            actionURL += "&anagDeRsoc=" + escape(this.anagDeRsoc);
        if (this.anftDsPiva != undefined)
            actionURL += "&anftDsPiva=" + escape(this.anftDsPiva);
        if (this.anftDsCofi != undefined)
            actionURL += "&anftDsCofi=" + escape(this.anftDsCofi);
        if (this.anagCdAgen != undefined)
            actionURL += "&anagCdAgen=" + escape(this.anagCdAgen);
		if (this.commDaChiu != undefined)
            actionURL += "&commDaChiuStr=" + escape(this.commDaChiu);
		if (this.onlyOpen != undefined)
            actionURL += "&onlyOpen=" + escape(this.onlyOpen);
		if (this.uffiCdAcqu != undefined)
            actionURL += "&cdUffiAcqu=" +  escape(this.uffiCdAcqu);
		if (this.anagCdAgenScope != undefined)            actionURL += "&anagCdAgenScope=" +  escape(this.anagCdAgenScope);		if (this.extraPortafoglio != undefined)
            actionURL += "&extraPortafoglio=" +  escape(this.extraPortafoglio);

        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchCliente", 700, 400, false, false, true);
    }

    // AF008
    function getUffiCdAcqu(){
    	return this.uffiCdAcqu;
    }
    
    function setUffiCdAcqu(uffiCdAcqu){
    	this.uffiCdAcqu = uffiCdAcqu;
    }
    function getAnagCdAgenScope(){    	return this.anagCdAgenScope;    }        function setAnagCdAgenScope(anagCdAgenScope){    	this.anagCdAgenScope = anagCdAgenScope;    }    
    function getAnagType() {
        return this.anagType;
    }

    function setAnagType(anagType) {
        this.anagType = anagType;
    }

    function getAnagCdAnag() {
        return this.anagCdAnag;
    }

    function setAnagCdAnag(anagCdAnag) {
        this.anagCdAnag = anagCdAnag;
    }

    function getAnagCeAnag() {
        return this.anagCeAnag;
    }

    function setAnagCeAnag(anagCeAnag) {
        this.anagCeAnag = anagCeAnag;
    }

    function getAnagDeRsoc() {
        return this.anagDeRsoc;
    }

    function setAnagDeRsoc(anagDeRsoc) {
        this.anagDeRsoc = anagDeRsoc;
    }

    function getAnftDsPiva() {
        return this.anftDsPiva;
    }

    function setAnftDsPiva(anftDsPiva) {
        this.anftDsPiva = anftDsPiva;
    }

    function getAnftDsCofi() {
        return this.anftDsCofi;
    }

    function setAnftDsCofi(anftDsCofi) {
        this.anftDsCofi = anftDsCofi;
    }

    function getAnagCdAgen() {
        return this.anagCdAgen;
    }

    function setAnagCdAgen(anagCdAgen) {
        this.anagCdAgen = anagCdAgen;
    }

    function getCommDaChiu() {
        return this.commDaChiu;
    }

    function setCommDaChiu(commDaChiu) {
        this.commDaChiu = commDaChiu;
        if (commDaChiu != null)
            this.onlyOpen = true;
        else
            this.onlyOpen = false;
    }
    
    function isOnlyOpen() {
        return this.onlyOpen;
    }
    
    function setOnlyOpen(onlyOpen) {
        this.onlyOpen = onlyOpen;
    }
    
    function getAnagCdAnagField() {
        return this.anagCdAnagField;
    }

    function setAnagCdAnagField(anagCdAnagField) {
        this.anagCdAnagField = anagCdAnagField;
    }

    function getAnagCeAnagField() {
        return this.anagCeAnagField;
    }

    function setAnagCeAnagField(anagCeAnagField) {
        this.anagCeAnagField = anagCeAnagField;
    }

    function getAnagDeRsocField() {
        return this.anagDeRsocField;
    }

    function setAnagDeRsocField(anagDeRsocField) {
        this.anagDeRsocField = anagDeRsocField;
    }

    function getAnftDsPivaField() {
        return this.anftDsPivaField;
    }

    function setAnftDsPivaField(anftDsPivaField) {
        this.anftDsPivaField = anftDsPivaField;
    }

    function getAnftDsCofiField() {
        return this.anftDsCofiField;
    }

    function setAnftDsCofiField(anftDsCofiField) {
        this.anftDsCofiField = anftDsCofiField;
    }
    
    function getExtraPortafoglio() {
        return this.extraPortafoglio;
    }

    function setExtraPortafoglio(extraPortafoglio) {
        this.extraPortafoglio = extraPortafoglio;
    }
}

/******************************************************************************* * ================================================= *  * Funzioni di utilita' per usare il dialog cliente *  * ================================================= */

// AF008
function popupCliente (	cdAnagField, ceAnagField, deRsocField, dsPivaField, dsCofiField, cdUffi, anagCdAgenScope,
						anagType, onlyOpen, daChiu, cdAgenField, extraPortafoglio, callbackFuncName) {
	
    var f = getFormByID('mainForm');
    var d = new ClientiDialogPage();
    d.setAnagType(anagType);
    d.setCommDaChiu(daChiu);
    d.setOnlyOpen(onlyOpen);
    d.setAnagCeAnag(f[ceAnagField].value);
    d.setAnagDeRsoc(f[deRsocField].value);
    if (f[dsPivaField]) {
        d.setAnftDsPiva(f[dsPivaField].value);
        d.setAnftDsCofi(f[dsCofiField].value);
    }

    if (cdAgenField && f[cdAgenField]) {
 	   d.setAnagCdAgen(f[cdAgenField].value);
	}
	
    d.setAnagCdAnagField(cdAnagField);
    d.setAnagCeAnagField(ceAnagField);
    d.setAnagDeRsocField(deRsocField);
    d.setAnftDsPivaField(dsPivaField);
    d.setAnftDsCofiField(dsCofiField);
    
    d.setExtraPortafoglio(extraPortafoglio);
    
	if (cdUffi != 0)
		d.setUffiCdAcqu(cdUffi);
	if (anagCdAgenScope != 0)		d.setAnagCdAgenScope(anagCdAgenScope);
    if (callbackFuncName == undefined)
        callbackFuncName = "popupClienteCallback";

    d.show(callbackFuncName);
}

function popupClienteCallback(clientiDialog) {

    var f = getFormByID('mainForm');

    var cdField = clientiDialog.getAnagCdAnagField();
    var ceField = clientiDialog.getAnagCeAnagField();
    var deField = clientiDialog.getAnagDeRsocField();
    var pivaField = clientiDialog.getAnftDsPivaField();
    var cofiField = clientiDialog.getAnftDsCofiField();
    
    f[cdField].value = clientiDialog.getAnagCdAnag();
    f[ceField].value = clientiDialog.getAnagCeAnag();
    f[deField].value = clientiDialog.getAnagDeRsoc();

    if (f[pivaField]) {
        f[pivaField].value = clientiDialog.getAnftDsPiva();
        f[cofiField].value = clientiDialog.getAnftDsCofi();
    }
}

function popupClienteClear(cdAnagField, ceAnagField, deRsocField, pivaField, cofiField, curElem) {

    var f = getFormByID('mainForm');

    f[cdAnagField].value = '0';

    if (curElem != f[ceAnagField]) {
        f[ceAnagField].value = '';
    }

    if (curElem != f[deRsocField]) {
        f[deRsocField].value = '';
    }

    if (f[pivaField]) {

        if (curElem != f[pivaField]) {
            f[pivaField].value = '';
        }

        if (curElem != f[cofiField]) {
            f[cofiField].value = '';
        }
    }
}

/******************************************************************************* * ================================================= *  * Dialog ricerca agente *  * ================================================= */

function AgentiDialogPage() {

    var callbackFunction = "";

    var cdAgtiFieldName;
    var ceAgtiFieldName;
    var deAgtiFieldName;

    var agtiCdAgti;
    var agtiDsAgti;
    var agtiDeRsoc;
    var poagCdPoag;
    var flAgeInte;
    var cdUffi;
    var cdFili;
    var cdTiag;
    var cdClieInte;
    var cdClieFina;
    var flFilterClie;
    var daIniv;
    var daFinv;        var flFitt;        var fromPtrx;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getAgtiCdAgti = getAgtiCdAgti;
    this.setAgtiCdAgti = setAgtiCdAgti;
    this.getAgtiDsAgti = getAgtiDsAgti;
    this.setAgtiDsAgti = setAgtiDsAgti;
    this.getAgtiDeRsoc = getAgtiDeRsoc;
    this.setAgtiDeRsoc = setAgtiDeRsoc;
    this.getPoagCdPoag = getPoagCdPoag;
    this.setPoagCdPoag = setPoagCdPoag;
    this.getFlAgeInte = getFlAgeInte;
    this.setFlAgeInte = setFlAgeInte;
    this.getCdUffi = getCdUffi;
    this.setCdUffi = setCdUffi;
    this.getCdFili = getCdFili;
    this.setCdFili = setCdFili;
    this.getCdTiag = getCdTiag;
    this.setCdTiag = setCdTiag;
    this.setCdAgtiFieldName = setCdAgtiFieldName;
    this.getCdAgtiFieldName = getCdAgtiFieldName;
    this.setCeAgtiFieldName = setCeAgtiFieldName;
    this.getCeAgtiFieldName = getCeAgtiFieldName;
    this.setDeAgtiFieldName = setDeAgtiFieldName;
    this.getDeAgtiFieldName = getDeAgtiFieldName;
    this.getCdClieInte = getCdClieInte;
    this.setCdClieInte = setCdClieInte;
    this.getCdClieFina = getCdClieFina;
    this.setCdClieFina = setCdClieFina;
    this.getFlFilterClie = getFlFilterClie;
    this.setFlFilterClie = setFlFilterClie;
    this.getDaIniv = getDaIniv;
    this.setDaIniv = setDaIniv;
    this.getDaFinv = getDaFinv;
    this.setDaFinv = setDaFinv;        this.getFlFitt = getFlFitt;        this.setFlFitt = setFlFitt;    this.getFromPtrx = getFromPtrx;        this.setFromPtrx = setFromPtrx;
        
    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {


        if (this.cdClieFina == undefined && ((this.agtiDeRsoc != undefined && this.agtiDeRsoc.length < 3) ||
            (this.agtiDsAgti != undefined && this.agtiDsAgti.length < 1))) {

            alert(I18N.t("Inserire almeno tre caratteri per la ricerca."));
            return;
        }


        this.callbackFunction = callbackFunction;

        var actionURL = "searchAgente.do"
        actionURL += "?cmd=srcAgen";
        if (this.agtiDsAgti != undefined)
            actionURL += "&agtiDsAgti=" + escape(this.agtiDsAgti);
        if (this.agtiDeRsoc != undefined)
            actionURL += "&agtiDeRsoc=" + escape(this.agtiDeRsoc);
        if (this.poagCdPoag != undefined)
            actionURL += "&poagCdPoag=" + escape(this.poagCdPoag);
        if (this.flAgeInte != undefined)
            actionURL += "&flAgeInte=" + escape(this.flAgeInte);
        if (this.cdUffi != undefined)
            actionURL += "&cdUffi=" + escape(this.cdUffi);
        if (this.cdFili != undefined)
            actionURL += "&cdFili=" + escape(this.cdFili);
        if (this.cdTiag != undefined)
            actionURL += "&cdTiag=" + escape(this.cdTiag);
        if (this.cdClieInte != undefined)
            actionURL += "&cdClieInte=" + escape(this.cdClieInte);
        if (this.cdClieFina != undefined)
            actionURL += "&cdClieFina=" + escape(this.cdClieFina);
        if (this.flFilterClie != undefined)
            actionURL += "&flFilterClie=" + escape(this.flFilterClie);
        if (this.daIniv != undefined)
            actionURL += "&daInivStr=" + escape(this.daIniv);
        if (this.daFinv != undefined)
            actionURL += "&daFinvStr=" + escape(this.daFinv);                if (this.flFitt != undefined)            actionURL += "&flFitt=" + escape(this.flFitt);        if (this.fromPtrx != undefined)            actionURL += "&fromPtrx=" + escape(this.fromPtrx);
                
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchAgente", 700, 400, false, false, true);
    }

    function getAgtiCdAgti() {
        return this.agtiCdAgti;
    }

    function setAgtiCdAgti(agtiCdAgti) {
        this.agtiCdAgti = agtiCdAgti;
    }        function getFlFitt() {        return this.flFitt;    }    function setFlFitt(flFitt) {        this.flFitt = flFitt;    }
    function getFromPtrx() {        return this.fromPtrx;    }    function setFromPtrx(fromPtrx) {        this.fromPtrx = fromPtrx;    }
    function getAgtiDeRsoc() {
        return this.agtiDeRsoc;
    }

    function setAgtiDeRsoc(agtiDeRsoc) {
        this.agtiDeRsoc = agtiDeRsoc;
    }

    function getAgtiDsAgti() {
        return this.agtiDsAgti;
    }

    function setAgtiDsAgti(agtiDsAgti) {
        this.agtiDsAgti = agtiDsAgti;
    }

    function getPoagCdPoag() {
        return this.poagCdPoag;
    }

    function setPoagCdPoag(poagCdPoag) {
        this.poagCdPoag = poagCdPoag;
    }

    function getFlAgeInte() {
        return this.flAgeInte;
    }

    function setFlAgeInte(flAgeInte) {
        this.flAgeInte = flAgeInte;
    }

    function getCdUffi() {
        return this.cdUffi;
    }

    function setCdUffi(cdUffi) {
        this.cdUffi = cdUffi;
    }

    function getCdFili() {
        return this.cdFili;
    }

    function setCdFili(cdFili) {
        this.cdFili = cdFili;
    }

    function getCdTiag() {
        return this.cdTiag;
    }

    function setCdTiag(cdTiag) {
        this.cdTiag = cdTiag;
    }
        
    function getCdAgtiFieldName() {
        return this.cdAgtiFieldName;
    }

    function setCdAgtiFieldName(cdAgtiFieldName) {
        this.cdAgtiFieldName = cdAgtiFieldName;
    }

    function getCeAgtiFieldName() {
        return this.ceAgtiFieldName;
    }

    function setCeAgtiFieldName(ceAgtiFieldName) {
        this.ceAgtiFieldName = ceAgtiFieldName;
    }

    function getDeAgtiFieldName() {
        return this.deAgtiFieldName;
    }

    function setDeAgtiFieldName(deAgtiFieldName) {
        this.deAgtiFieldName = deAgtiFieldName;
    }
    function getCdClieInte() {
        return this.cdClieInte;
    }

    function setCdClieInte(cdClieInte) {
        this.cdClieInte = cdClieInte;
    }

    function getCdClieFina() {
        return this.cdClieFina;
    }

    function setCdClieFina(cdClieFina) {
        this.cdClieFina = cdClieFina;
    }

    function getFlFilterClie() {
        return this.flFilterClie;
    }

    function setFlFilterClie(flFilterClie) {
        this.flFilterClie = flFilterClie;
    }
    
    function getDaIniv() {
        return this.daIniv;
    }

    function setDaIniv(daIniv) {
        this.daIniv = daIniv;
    }

    function getDaFinv() {
        return this.daFinv;
    }

    function setDaFinv(daFinv) {
        this.daFinv = daFinv;
    }
}

/******************************************************************************* * ================================================= *  * Funzioni di utilita' per usare il dialog agente *  * ================================================= */
function popupAgente(cdAgtiField, ceAgtiField, deRsocField, cdPoagField, flAgeInte, cdUffi, cdFili, cdTiag, isPoagObbligatoria, isFiliObbligatoria, daIniv, daFinv, callbackFuncName) {	popupAgente(cdAgtiField, ceAgtiField, deRsocField, cdPoagField, flAgeInte, cdUffi, cdFili, cdTiag, isPoagObbligatoria, isFiliObbligatoria, daIniv, daFinv, 0, 0, callbackFuncName);	}
function popupAgente(cdAgtiField, ceAgtiField, deRsocField, cdPoagField, flAgeInte, cdUffi, cdFili, cdTiag, isPoagObbligatoria, isFiliObbligatoria, daIniv, daFinv, flFitt, fromPtrx, callbackFuncName) {

    var f = getFormByID('mainForm');
    var d = new AgentiDialogPage();

    d.setCdAgtiFieldName(cdAgtiField);
    d.setCeAgtiFieldName(ceAgtiField);
    d.setDeAgtiFieldName(deRsocField);

    // assegna i valori dei criteri ricerca

    if(f.elements[ceAgtiField].value == "") 
        d.setAgtiDeRsoc(f.elements[deRsocField].value);
    else    
        d.setAgtiDsAgti(f.elements[ceAgtiField].value);
    
    
    if (f.elements[cdPoagField] && f.elements[cdPoagField].value >0 ) {

        d.setPoagCdPoag(f.elements[cdPoagField].value);

    }
    else if (isPoagObbligatoria == true) {

        alert(I18N.t('Posizione agente obbligatoria'));
        return;

    }

    d.setFlAgeInte(flAgeInte);

    d.setCdUffi(cdUffi);
    
    if (isFiliObbligatoria && cdFili == 0){
        alert(I18N.t('Filiale agente obbligatoria'));
        return;
    }   
    
    d.setCdFili(cdFili);
    d.setCdTiag(cdTiag);
    d.setDaIniv(daIniv);
    d.setDaFinv(daFinv);
    d.setFlFitt(flFitt);
    d.setFromPtrx(fromPtrx);
    if (callbackFuncName == undefined)
        callbackFuncName = "popupAgenteCallback";

    d.show(callbackFuncName);
}

function popupAgenteCallback(agentiDialog) {
    var f = getFormByID('mainForm');

    var cdField = agentiDialog.getCdAgtiFieldName();
    var ceField = agentiDialog.getCeAgtiFieldName();
    var deField = agentiDialog.getDeAgtiFieldName();

    f[cdField].value = agentiDialog.getAgtiCdAgti();
    f[ceField].value = agentiDialog.getAgtiDsAgti();
    f[deField].value = agentiDialog.getAgtiDeRsoc();
}

function popupAgenteClear(cdAgtiField, ceAgtiField, deRsocField, cdPoagField, clearMnemonic) {

    var f = getFormByID('mainForm');
    f[cdAgtiField].value = '0';
    if (clearMnemonic) {
        f[ceAgtiField].value = '';
    } else {
        f[deRsocField].value = '';
    }
}

/******************************************************************************* * ================================================= *  * Dialog ricerca indirizzi alternativi *  * ================================================= */

function IndirizziDialogPage() {

    var callbackFunction = "";

    var indiType;

    var anagCdAnag;
    var indiCdIndiField;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getIndiType = getIndiType;
    this.setIndiType = setIndiType;
    this.getAnagCdAnag = getAnagCdAnag;
    this.setAnagCdAnag = setAnagCdAnag;
    this.getIndiCdIndi = getIndiCdIndi;
    this.setIndiCdIndi = setIndiCdIndi;
    this.getIndiCdIndiField = getIndiCdIndiField;
    this.setIndiCdIndiField = setIndiCdIndiField;

    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        if (this.indiType == undefined || this.anagCdAnag == undefined) {
            alert(I18N.t("(errore interno) E' necessario specificare indiType e anagCdAnag"));
            return;
        }

        this.callbackFunction = callbackFunction;

        var actionURL = "viewIndirizzi.do"
        actionURL += "?cmd=" + this.indiType;
        actionURL += "&anagCdAnag=" + this.anagCdAnag;

        currentDialog = this;
        newWindow(actionURL, "viewIndirizzi", 700, 400, false, false, true);
    }

    function getIndiType() {
        return this.indiType;
    }

    function setIndiType(indiType) {
        this.indiType = indiType;
    }

    function getAnagCdAnag() {
        return this.anagCdAnag;
    }

    function setAnagCdAnag(anagCdAnag) {
        this.anagCdAnag = anagCdAnag;
    }

    function getIndiCdIndi() {
        return this.indiCdIndi;
    }

    function setIndiCdIndi(indiCdIndi) {
        this.indiCdIndi = indiCdIndi;
    }

    function getIndiCdIndiField() {
        return this.indiCdIndiField;
    }

    function setIndiCdIndiField(indiCdIndiField) {
        this.indiCdIndiField = indiCdIndiField;
    }
}

/******************************************************************************* * ================================================= *  * Funzioni di utilita' per usare il dialog indirizzi alternativi *  * ================================================= */

function popupIndirizzo(cdAnag, cdIndiField, indiType, callbackFuncName) {

    var f = getFormByID('mainForm');
    var d = new IndirizziDialogPage();
    d.setIndiType(indiType);
    d.setAnagCdAnag(cdAnag);
    d.setIndiCdIndiField(cdIndiField);

    d.show(callbackFuncName);
}

/******************************************************************************* * ================================================= *  * Dialog ricerca azienda *  * ================================================= */

function AziendeDialogPage() {

    var callbackFunction = "";

    var azieCdAzie;
    var azieCeAzie;
    var azieDeRsoc;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getAzieCdAzie = getAzieCdAzie;
    this.setAzieCdAzie = setAzieCdAzie;
    this.getAzieCeAzie = getAzieCeAzie;
    this.setAzieCeAzie = setAzieCeAzie;
    this.getAzieDeRsoc = getAzieDeRsoc;
    this.setAzieDeRsoc = setAzieDeRsoc;

    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        if (this.azieDeRsoc != undefined && this.azieDeRsoc.length < 3 &&
            this.azieCeAzie != undefined && this.azieCeAzie.length < 1) {

            alert(I18N.t("Inserire almeno tre caratteri per la ricerca."));
            return;
        }

        this.callbackFunction = callbackFunction;

        var actionURL = "searchAzienda.do"
        actionURL += "?cmd=srcAzie";
        if (this.azieDeRsoc != undefined)
            actionURL += "&azieDeRsoc=" + escape(this.azieDeRsoc);
        if (this.azieCeAzie != undefined)
            actionURL += "&azieCeAzie=" + escape(this.azieCeAzie);
        
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchAzienda", 700, 400, false, false, true);
    }

    function getAzieCdAzie() {
        return this.azieCdAzie;
    }

    function setAzieCdAzie(azieCdAzie) {
        this.azieCdAzie = azieCdAzie;
    }

    function getAzieCeAzie() {
        return this.azieCeAzie;
    }

    function setAzieCeAzie(azieCeAzie) {
        this.azieCeAzie = azieCeAzie;
    }

    function getAzieDeRsoc() {
        return this.azieDeRsoc;
    }

    function setAzieDeRsoc(azieDeRsoc) {
        this.azieDeRsoc = azieDeRsoc;
    }
}


/******************************************************************************* * ================================================= *  * Dialog ricerca prodotti *  * ================================================= */

function ProdottiDialogPage() {

    var callbackFunction = "";

    var prodCdProd;
    var prodCeProd;
    var prodDeProd;
    var tiprCdTipr;
    var tiprNuTipr;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getProdCdProd = getProdCdProd;
    this.getProdCeProd = getProdCeProd;
    this.getProdDeProd = getProdDeProd;
    this.getTiprCdTipr = getTiprCdTipr;
    this.getTiprNuTipr = getTiprNuTipr;
    this.setProdCdProd = setProdCdProd;
    this.setProdCeProd = setProdCeProd;
    this.setProdDeProd = setProdDeProd;
    this.setTiprCdTipr = setTiprCdTipr;
    this.setTiprNuTipr = setTiprNuTipr;
    
    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        if (this.prodDeProd != undefined && this.prodDeProd.length < 3 &&
            this.prodCeProd != undefined && this.prodCeProd.length < 1) {

            alert(I18N.t("Inserire almeno tre caratteri per la ricerca."));
            return;
        }


        this.callbackFunction = callbackFunction;

        var actionURL = "searchProdotti.do"
        actionURL += "?cmd=read";
        if (this.prodCdProd != undefined)
            actionURL += "&prodCdProd=" + escape(this.prodCdProd);
        if (this.prodCeProd != undefined)
            actionURL += "&prodCeProd=" + escape(this.prodCeProd);
        if (this.prodDeProd != undefined)
            actionURL += "&prodDeProd=" + escape(this.prodDeProd);
        if (this.tiprCdTipr != undefined)
            actionURL += "&tiprCdTipr=" + escape(this.tiprCdTipr);
        if (this.tiprNuTipr != undefined)
            actionURL += "&tiprNuTipr=" + escape(this.tiprNuTipr);
        
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchProdotti", 700, 400, false, false, true);
    }


    function getProdCdProd() {
        return this.prodCdProd;
    }

    function setProdCdProd(prodCdProd) {
        this.prodCdProd = prodCdProd;
    }

    function getProdCeProd() {
        return this.prodCeProd;
    }

    function setProdCeProd(prodCeProd) {
        this.prodCeProd = prodCeProd;
    }

    function getProdDeProd() {
        return this.prodDeProd;
    }

    function setProdDeProd(prodDeProd) {
        this.prodDeProd = prodDeProd;
    }

    function getTiprCdTipr() {
        return this.tiprCdTipr;
    }

    function setTiprCdTipr(tiprCdTipr) {
        this.tiprCdTipr = tiprCdTipr;
    }
    function getTiprNuTipr() {
        return this.tiprNuTipr;
    }

    function setTiprNuTipr(tiprNuTipr) {
        this.tiprNuTipr = tiprNuTipr;
    }

}

function ProdottiClienteDialogPage() {

    var callbackFunction = "";

    var pracCdPrac;
    var procCeProc;
    var procDeProc;
    var procAzieCdAzie;
    var procAnagCdAnag;
	var pracCdPracField;
	var procCeProcField;
	var procDeProcField;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getPracCdPrac = getPracCdPrac;
    this.getProcCeProc = getProcCeProc;
    this.getProcDeProc = getProcDeProc;
    this.setPracCdPrac = setPracCdPrac;
    this.setProcCeProc = setProcCeProc;
    this.setProcDeProc = setProcDeProc;
    this.setProcAzieCdAzie = setProcAzieCdAzie;
    this.getProcAzieCdAzie = getProcAzieCdAzie;
    this.setProcAnagCdAnag = setProcAnagCdAnag;
    this.getProcAnagCdAnag = getProcAnagCdAnag;    
    this.getPracCdPracField = getPracCdPracField;
    this.getProcCeProcField = getProcCeProcField;
    this.getProcDeProcField = getProcDeProcField;
    this.setPracCdPracField = setPracCdPracField;
    this.setProcCeProcField = setProcCeProcField;
    this.setProcDeProcField = setProcDeProcField;
       
    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        this.callbackFunction = callbackFunction;

        var actionURL = "searchProdottiCliente.do"
        actionURL += "?cmd=read";
        if (this.pracCdPrac != undefined)
            actionURL += "&pracCdPrac=" + escape(this.pracCdPrac);
        if (this.procCeProc != undefined)
            actionURL += "&procCeProc=" + escape(this.procCeProc);
        if (this.procDeProc != undefined)
            actionURL += "&procDeProc=" + escape(this.procDeProc);
        if (this.procAzieCdAzie != undefined)
            actionURL += "&procAzieCdAzie=" + escape(this.procAzieCdAzie);
        if (this.procAnagCdAnag != undefined)
            actionURL += "&procAnagCdAnag=" + escape(this.procAnagCdAnag);
        
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchProdottiCliente", 700, 400, false, false, true);
    }


    function getPracCdPrac() {
        return this.pracCdPrac;
    }

    function setPracCdPrac(pracCdPrac) {
        this.pracCdPrac = pracCdPrac;
    }

    function getProcCeProc() {
        return this.procCeProc;
    }

    function setProcCeProc(procCeProc) {
        this.procCeProc = procCeProc;
    }

    function getProcDeProc() {
        return this.procDeProc;
    }

    function setProcDeProc(procDeProc) {
        this.procDeProc = procDeProc;
    }

    function getProcAzieCdAzie() {
        return this.procAzieCdAzie;
    }

    function setProcAzieCdAzie(procAzieCdAzie) {
        this.procAzieCdAzie = procAzieCdAzie;
    }

    function getProcAnagCdAnag() {
        return this.procAnagCdAnag;
    }

    function setProcAnagCdAnag(procAnagCdAnag) {
        this.procAnagCdAnag = procAnagCdAnag;
    }    

	function getPracCdPracField() {
        return this.pracCdPracField;
    }

    function setPracCdPracField(pracCdPracField) {
        this.pracCdPracField = pracCdPracField;
    }

    function getProcCeProcField() {
        return this.procCeProcField;
    }

    function setProcCeProcField(procCeProcField) {
        this.procCeProcField = procCeProcField;
    }

    function getProcDeProcField() {
        return this.procDeProcField;
    }

    function setProcDeProcField(procDeProcField) {
        this.procDeProcField = procDeProcField;
    }

}

/******************************************************************************* * ================================================= *  * Funzioni di utilita' per usare il dialog prod cliente *  * ================================================= */
function popupProdottiCliente(cdPracField, ceProcField, deProcField, cdAnagField, callbackFuncName) {
    var f = getFormByID('mainForm');
    var d = new ProdottiClienteDialogPage();  
   	d.setPracCdPracField(cdPracField);
    d.setProcDeProcField(deProcField);
    d.setProcCeProcField(ceProcField);
    if(f[cdAnagField].value == 0)  {
        alert(I18N.t("Impossibile cercare un prodotto senza aver selezionato il cliente finale"));
        return;
    }
    if(f[ceProcField].value == "" && f[deProcField].value=="") {    	    	f[deProcField].value = '%%%';
    }
    d.setPracCdPrac(f[cdPracField].value);
    d.setProcDeProc(f[deProcField].value);
    d.setProcCeProc(f[ceProcField].value);
   // d.setProcAzieCdAzie(f[cdAzieField].value);    d.setProcAnagCdAnag(f[cdAnagField].value);    
    if (callbackFuncName == undefined)
        callbackFuncName = "popupProdottiClienteCallback";
    d.show(callbackFuncName);
}

function popupProdottiClienteCallback(dialog) {
    
    var f = getFormByID('mainForm');
    
    f[dialog.getPracCdPracField()].value = dialog.getPracCdPrac();
    f[dialog.getProcCeProcField()].value = dialog.getProcCeProc();
    f[dialog.getProcDeProcField()].value = dialog.getProcDeProc();
}

function popupProdottiClienteClear(cdPracField, ceProcField, deProcField, clearMnemonic) {

    var f = getFormByID('mainForm');
    
    f[cdPracField].value = '0';
    if (clearMnemonic) {
        f[ceProcField].value = '';
    } else {
        f[deProcField].value = '';
    }
}

/******************************************************************************* * ================================================= *  * Dialog ricerca dettagli condizione di vendita *  * ================================================= */

function DettagliCvenDialogPage() {

    var callbackFunction = "";

    var indexRigaSel;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getIndexRigaSel = getIndexRigaSel;
    this.setIndexRigaSel = setIndexRigaSel;

    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        if (this.indexRigaSel == -1) {

            alert(I18N.t("Selezionare una riga piano valida"));
            return;
        }

        this.callbackFunction = callbackFunction;

        var actionURL = "offerte.do"
        actionURL += "?cmd=showDetails";
        if (this.indexRigaSel != undefined)
            actionURL += "&selectedIndex=" + escape(this.indexRigaSel);
        
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "showDetails", 730, 400, false, false, true);
    }


    function getIndexRigaSel() {
        return this.indexRigaSel;
    }

    function setIndexRigaSel(indexRigaSel) {
        this.indexRigaSel = indexRigaSel;
    }
}
function popUp_searchAgente(formID, nameCd, nameCe, nameTxt, cdPoag, flAgeInte, cdUffi, isPoagObbligatorio, cdClieInte, cdClieFina, flFilterClie, daIniv, daFinv) {	popUp_searchAgente(formID, nameCd, nameCe, nameTxt, cdPoag, flAgeInte, cdUffi, isPoagObbligatorio, cdClieInte, cdClieFina, flFilterClie, daIniv, daFinv, 0, 0);}

function popUp_searchAgente(formID, nameCd, nameCe, nameTxt, cdPoag, flAgeInte, cdUffi, isPoagObbligatorio, cdClieInte, cdClieFina, flFilterClie, daIniv, daFinv, flFitt, fromPtrx) {
    var f = getFormByID(formID);

    var d = new AgentiDialogPage();

    // assegna i nomi dei campi di destinazione
    d.setCdAgtiFieldName(nameCd);
    d.setCeAgtiFieldName(nameCe);
    d.setDeAgtiFieldName(nameTxt);

    // assegna i valori dei criteri ricerca
    if(f.elements[nameCe].value == "") 
        d.setAgtiDeRsoc(f.elements[nameTxt].value);
    else    
        d.setAgtiDsAgti(f.elements[nameCe].value);
    
    if (f.elements[cdPoag] && f.elements[cdPoag].value >0 ) {

        d.setPoagCdPoag(f.elements[cdPoag].value);

    }
    else if (isPoagObbligatorio == true) {

        alert(I18N.t('Posizione agente obbligatoria'));
        return;

    }
    if(cdClieInte != undefined) {
        d.setCdClieInte(cdClieInte);
    }

    if(cdClieFina != undefined)
        d.setCdClieFina(cdClieFina);


    d.setFlFilterClie(flFilterClie);

    d.setFlAgeInte(flAgeInte);
    d.setCdUffi(cdUffi);
    d.setDaIniv(daIniv);
    d.setDaFinv(daFinv);        d.setFlFitt(flFitt);    d.setFromPtrx(fromPtrx);
    d.show("setAgente");
}

function selectAll(element, name) {
    var value;
    if (element.checked == true) {
        value = true;
    }
    else {
        value = false;
    }

    var nb = document.forms[0].elements.length;
    for (var i=0;i<nb;i++) {
            var e = document.forms[0].elements[i];
            if (e.type == "checkbox" && e.name.indexOf(name) == 0)
                    e.checked = value;
    }
}

/******************************************************************************* * ================================================= *  * Dialog ricerca listini *  * ================================================= */

function ListiniDialogPage() {

    var callbackFunction = "";

    var listCdList;
    var indexRigaSel;
    var indexRigaListinoSel;
    var listImVali;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getListCdList = getListCdList;
    this.setListCdList = setListCdList;
    this.getIndexRigaSel = getIndexRigaSel;
    this.setIndexRigaSel = setIndexRigaSel;
    this.getIndexRigaListinoSel = getIndexRigaListinoSel;
    this.setIndexRigaListinoSel = setIndexRigaListinoSel;
    this.getListImVali = getListImVali;
    this.setListImVali = setListImVali;

    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        if (this.indexRigaSel == -1) {

            alert(I18N.t("Selezionare una riga piano valida"));
            return;
        }

        this.callbackFunction = callbackFunction;

        var actionURL = "offerte.do"
        actionURL += "?cmd=showListini";
        if (this.indexRigaSel != undefined)
            actionURL += "&selectedIndex=" + escape(this.indexRigaSel);
        
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchListini", 700, 400, false, false, false);
    }

    function getListCdList() {
        return this.listCdList;
    }

    function setListCdList(listCdList) {
        this.listCdList = listCdList;
    }

    function getIndexRigaSel() {
        return this.indexRigaSel;
    }

    function setIndexRigaSel(indexRigaSel) {
        this.indexRigaSel = indexRigaSel;
    }

    function getIndexRigaListinoSel() {
        return this.indexRigaListinoSel;
    }

    function setIndexRigaListinoSel(indexRigaListinoSel) {
        this.indexRigaListinoSel = indexRigaListinoSel;
    }

    function getListImVali() {
        return this.listImVali;
    }

    function setListImVali(listImVali) {
        this.listImVali = listImVali;
    }
}

/******************************************************************************* * ================================================= *  * Dialog ricerca note precodificate *  * ================================================= */

function NoteDialogPage() {

    var callbackFunction = "";

    var notpCdNotp;
    var notpCeNotp;
    var notpTxNota;
    var notpNuTipo;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getNotpCdNotp = getNotpCdNotp;
    this.setNotpCdNotp = setNotpCdNotp;
    this.getNotpCeNotp = getNotpCeNotp;
    this.setNotpCeNotp = setNotpCeNotp;
    this.getNotpTxNota = getNotpTxNota;
    this.setNotpTxNota = setNotpTxNota;
    this.getNotpNuTipo = getNotpNuTipo;
    this.setNotpNuTipo = setNotpNuTipo;

    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        if (this.notpTxNota != undefined && this.notpTxNota.length < 3 &&
            this.notpCeNotp != undefined && this.notpCeNotp.length < 1) {

            alert(I18N.t("Inserire almeno tre caratteri per la ricerca."));
            return;
        }

        this.callbackFunction = callbackFunction;

        var actionURL = "searchNote.do"
        actionURL += "?cmd=read";
        if (this.notpTxNota != undefined)
            actionURL += "&notpTxNota=" + escape(this.notpTxNota);
        if (this.notpCeNotp != undefined)
            actionURL += "&notpCeNotp=" + escape(this.notpCeNotp);
        if (this.notpNuTipo != undefined)
            actionURL += "&notpNuTipo=" + escape(this.notpNuTipo);
        
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchNote", 700, 400, false, false, true);
    }

    function getNotpCdNotp() {
        return this.notpCdNotp;
    }

    function setNotpCdNotp(notpCdNotp) {
        this.notpCdNotp = notpCdNotp;
    }

    function getNotpCeNotp() {
        return this.notpCeNotp;
    }

    function setNotpCeNotp(notpCeNotp) {
        this.notpCeNotp = notpCeNotp;
    }

    function getNotpTxNota() {
        return this.notpTxNota;
    }

    function setNotpTxNota(notpTxNota) {
        this.notpTxNota = notpTxNota;
    }

    function getNotpNuTipo() {
        return this.notpNuTipo;
    }

    function setNotpNuTipo(notpNuTipo) {
        this.notpNuTipo = notpNuTipo;
    }
}
/******************************************************************************* * ================================================= *  * Dialog ricerca materiale *  * ================================================= */
function MaterialeDialogPage() {

    this.callbackFunction = "void";
    
    this.getCdMatd = function() {
        return this.cdMatd;
    };
    this.setCdMatd = function(cdMatd) {
        this.cdMatd = cdMatd;
    };
    this.getNuMatd = function() {
        return this.nuMatd;
    };
    this.setNuMatd = function(nuMatd) {
        this.nuMatd = nuMatd;
    };
    
    this.getCeMatd = function() {
        return this.ceMatd;
    };
    this.setCeMatd = function(ceMatd) {
        this.ceMatd = ceMatd;
    };
    this.getNuMatd = function() {
        return this.nuMatd;
    };
    this.setNuMatd = function(nuMatd) {
        this.nuMatd = nuMatd;
    };
    this.getDaRipe = function() {
        return this.daRipe;
    };
    this.setDaRipe = function(daRipe) {
        this.daRipe = daRipe;
    };
    this.getCdTmat = function() {
        return this.cdTmat;
    };
    this.setCdTmat = function(cdTmat) {
        this.cdTmat = cdTmat;
    };
    this.getDeTmat = function() {
        return this.deTmat;
    };
    this.setDeTmat = function(deTmat) {
        this.deTmat = deTmat;
    };
    this.getCdUmat = function() {
        return this.cdUmat;
    };
    this.setCdUmat = function(cdUmat) {
        this.cdUmat = cdUmat;
    };
    this.getDeUmat = function() {
        return this.deUmat;
    };
    this.setDeUmat = function(deUmat) {
        this.deUmat = deUmat;
    };
    this.getCdAnag = function() {
        return this.cdAnag;
    };
    this.setCdAnag = function(cdAnag) {
        this.cdAnag = cdAnag;
    };
    this.getCdProd = function() {
        return this.cdProd;
    };
    this.setCdProd = function(cdProd) {
        this.cdProd = cdProd;
    };
    this.getCdFmti = function() {
        return this.cdFmti;
    };
    this.setCdFmti = function(cdFmti) {
        this.cdFmti = cdFmti;
    };
    this.getNuMmba = function() {
        return this.nuMmba;
    };
    this.setNuMmba = function(nuMmba) {
        this.nuMmba = nuMmba;
    };
    this.getNuMmal = function() {
        return this.nuMmal;
    };
    this.setNuMmal = function(nuMmal) {
        this.nuMmal = nuMmal;
    };
    this.getNuCobn = function() {
        return this.nuCobn;
    };
    this.setNuCobn = function(nuCobn) {
        this.nuCobn = nuCobn;
    };
    this.getFlPpub = function() {
        return this.flPpub;
    };
    this.setFlPpub = function(flPpub) {
        this.flPpub = flPpub;
    };
    this.getShowTmatUmat = function() {
        return this.showTmatUmat;
    }
    this.setShowTmatUmat = function(showTmatUmat) {
        this.showTmatUmat = showTmatUmat;
    }
    
    this.getCallbackFunction = function() {
        return this.callbackFunction;
    };
    this.getDtUsci = function() {
        return this.dtUsci;
    };
    this.setDtUsci = function(dtUsci) {
        this.dtUsci = dtUsci;
    };
    this.getDtRipe = function() {
        return this.dtRipe;
    };
    this.setDtRipe = function(dtRipe) {
        this.dtRipe = dtRipe;
    };
    this.getIsPacchetto = function() {
        return this.isPacchetto;
    };
    this.setIsPacchetto = function(isPacchetto) {
        this.isPacchetto = isPacchetto;
    };
    this.getCopyPacchetto = function() {
        return this.copyPacchetto;
    };    
    this.setCopyPacchetto = function(copyPacchetto) {
        this.copyPacchetto = copyPacchetto;
    };
    this.getCopyDaRipe = function() {
        return this.copyDaRipe;
    };
    this.setCopyDaRipe = function(copyDaRipe) {
        this.copyDaRipe = copyDaRipe;
    };
    this.getCdRdisMat = function() {
        return this.cdRdisMat;
    };
    this.setCdRdisMat = function(cdRdisMat) {
        this.cdRdisMat = cdRdisMat;
    };
    this.getNuMuscMat = function() {
        return this.nuMuscMat;
    };
    this.setNuMuscMat = function(nuMuscMat) {
        this.nuMuscMat = nuMuscMat;
    };
    this.getDeSogg = function() {
        return this.deSogg;
    };
    this.setDeSogg = function(deSogg) {
        this.deSogg = deSogg;
    };
    this.getFlExte = function() {
        return this.flExte;
    };
    this.setFlExte = function(flExte) {
        this.flExte = flExte;
    };
    this.show = function(callbackFunction) {

        this.callbackFunction = callbackFunction;
        
        var win_width = 700;
        var win_height = 400;

        var actionURL = "searchMateriale.do"
        actionURL += "?cmd=read";
        

        if (this.cdAnag != undefined)
            actionURL += "&cdAnag=" + this.cdAnag;
        if (this.cdProd != undefined)
            actionURL += "&cdProd=" + this.cdProd;
        if (this.cdFmti != undefined)
            actionURL += "&cdFmti=" + this.cdFmti;
        if (this.nuMmba != undefined)
            actionURL += "&nuMmbaStr=" + escape(this.nuMmba);
        if (this.nuMmal != undefined)
            actionURL += "&nuMmalStr=" + escape(this.nuMmal);
        if (this.nuCobn != undefined)
            actionURL += "&nuCobn=" + this.nuCobn;
        if (this.cdMatd != undefined)
            actionURL += "&cdMatd=" + this.cdMatd;
        if (this.nuMatd != undefined)
            actionURL += "&nuMatd=" + this.nuMatd;
        if (this.flPpub != undefined)
            actionURL += "&flPpub=" + this.flPpub;
        if (this.cdTmat != undefined)
            actionURL += "&tmatCdTmat=" + this.cdTmat;
        if (this.cdUmat != undefined)
            actionURL += "&umatCdUmat=" + this.cdUmat;
        if (this.showTmatUmat != undefined && this.showTmatUmat == true) {
            win_height = 500;
            actionURL += "&showTmatUmat=" + this.showTmatUmat;
        }
        if (this.dtUsci != undefined)
            actionURL += "&dtUsciStr=" + this.dtUsci;
        if (this.dtRipe != undefined)
            actionURL += "&dtRipeStr=" + this.dtRipe;
        if (this.isPacchetto != undefined)
            actionURL += "&isPacchetto=" + this.isPacchetto;
        if (this.copyPacchetto != undefined)
            actionURL += "&copyPacchetto=" + this.copyPacchetto;
        if (this.copyDaRipe != undefined)
            actionURL += "&copyDaRipe=" + this.copyDaRipe;
        if (this.cdRdisMat != undefined)
            actionURL += "&cdRdisMat=" + this.cdRdisMat;
        if (this.nuMuscMat != undefined)
            actionURL += "&nuMuscMat=" + this.nuMuscMat;  
        if (this.deSogg != undefined)
            actionURL += "&deSogg=" + this.deSogg;
        if (this.flExte != undefined)
            actionURL += "&flExte=" + this.flExte;

        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;

        newWindow(actionURL, "searchMateriale", win_width, win_height, false, false, false);
    }

}

/******************************************************************************* * ================================================= *  * Funzioni di utilita' per usare il dialog materiale *  * ================================================= */

function popupMateriale(
            callbackFuncName,
            cdAnag, cdProd, cdFmti, nuMmba, nuMmal, nuCobn,
            cdMatd, nuMatd,
            flPpub,
            cdTmat, cdUmat,
            showTmatUmat,
            dtUsci, dtRipe, isPacchetto) {
	
    var f = getFormByID('mainForm');

    var d = new MaterialeDialogPage();

    d.setCdAnag(cdAnag);
    d.setCdProd(cdProd);
    d.setCdFmti(cdFmti);
    d.setNuMmba(nuMmba);
    d.setNuMmal(nuMmal);
    d.setNuCobn(nuCobn);
    d.setCdMatd(cdMatd);
    d.setNuMatd(nuMatd);
    d.setFlPpub(flPpub);
    d.setDtUsci(dtUsci);
    d.setDtRipe(dtRipe);
    d.setIsPacchetto(isPacchetto);
    
    if (nuMatd)
        d.setNuMatd(nuMatd);
    
    if (cdTmat)
        d.setCdTmat(cdTmat);
    
    if (cdUmat)
        d.setCdUmat(cdUmat);
    
    if (showTmatUmat != undefined) {
        d.setShowTmatUmat(showTmatUmat);
    }
    
    d.show(callbackFuncName);
}



/******************************************************************************* * ================================================= *  * Dialog ricerca banca concessionaria *  * ================================================= */


function BaccDialogPage() {

    var callbackFunction = "";

    var baccCdBacc = undefined;
    var baccCeAbi = undefined;
    var baccCeCab = undefined;
    var baccDeRsoc = undefined;
    var baccDsProv = undefined;    var baccDeIban = undefined;
    var baccUseMezz = undefined;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;

    this.getBaccCdBacc = getBaccCdBacc;
    this.getBaccCeAbi = getBaccCeAbi;
    this.getBaccCeCab = getBaccCeCab;
    this.getBaccDeRsoc = getBaccDeRsoc;
    this.getBaccDsProv = getBaccDsProv;
    this.getBaccDeIban = getBaccDeIban;    this.getBaccUseMezz = getBaccUseMezz;

    this.setBaccCdBacc = setBaccCdBacc;
    this.setBaccCeAbi = setBaccCeAbi;
    this.setBaccCeCab = setBaccCeCab;
    this.setBaccDeRsoc = setBaccDeRsoc;
    this.setBaccDsProv = setBaccDsProv;
    this.setBaccDeIban = setBaccDeIban;    this.setBaccUseMezz = setBaccUseMezz;

    this.getBaccCdBaccField = getBaccCdBaccField;
    this.getBaccCeAbiField = getBaccCeAbiField;
    this.getBaccCeCabField = getBaccCeCabField;
    this.getBaccDeRsocField = getBaccDeRsocField;
    this.getBaccDsProvField = getBaccDsProvField;
    this.getBaccDeIbanField = getBaccDeIbanField;    this.getBaccUseMezzField = getBaccUseMezzField;

    this.setBaccCdBaccField = setBaccCdBaccField;
    this.setBaccCeAbiField = setBaccCeAbiField;
    this.setBaccCeCabField = setBaccCeCabField;
    this.setBaccDeRsocField = setBaccDeRsocField;
    this.setBaccDsProvField = setBaccDsProvField;
    this.setBaccDeIbanField = setBaccDeIbanField;    this.setBaccUseMezzField = setBaccUseMezzField;

    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        this.callbackFunction = callbackFunction;
        var actionURL = "acomUtils.do";
        actionURL += "?cmd=searchBancaConcessionaria";
        if (this.baccCeAbi != undefined)
            actionURL += "&baccCeAbi=" + escape(this.baccCeAbi);
        if (this.baccCeCab != undefined)
            actionURL += "&baccCeCab=" + escape(this.baccCeCab);
        if (this.baccDeRsoc != undefined)
            actionURL += "&baccDeRsoc=" + escape(this.baccDeRsoc);
        if (this.baccDsProv != undefined)
            actionURL += "&baccDsProv=" + escape(this.baccDsProv);
        if (this.baccDeIban != undefined)            actionURL += "&baccDeIban=" + escape(this.baccDeIban);        if (this.baccUseMezz != undefined)
            actionURL += "&baccUseMezz=" + escape(this.baccUseMezz);

        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchBancaConcessionaria", 700, 400, false, false, true);
    }

    function getBaccCdBacc() {
        return this.baccCdBacc;
    }

    function setBaccCdBacc(baccCdBacc) {
        this.baccCdBacc = baccCdBacc;
    }    
    
    function getBaccCeAbi() {
        return this.baccCeAbi;
    }

    function setBaccCeAbi(baccCeAbi) {
        this.baccCeAbi = baccCeAbi;
    }

    function getBaccCeCab() {
        return this.baccCeCab;
    }

    function setBaccCeCab(baccCeCab) {
        this.baccCeCab = baccCeCab;
    }

    function getBaccDeRsoc() {
        return this.baccDeRsoc;
    }

    function setBaccDeRsoc(baccDeRsoc) {
        this.baccDeRsoc = baccDeRsoc;
    }

    function getBaccDsProv() {
        return this.baccDsProv;
    }

    function setBaccDsProv(baccDsProv) {
        this.baccDsProv = baccDsProv;
    }
    function getBaccDeIban() {        return this.baccDeIban;    }    function setBaccDeIban(baccDeIban) {        this.baccDeIban = baccDeIban;    }
    function getBaccUseMezz() {
        return this.baccUseMezz;
    }

    function setBaccUseMezz(baccUseMezz) {
        this.baccUseMezz = baccUseMezz;
    }

    function getBaccCdBaccField() {
        return this.baccCdBaccField;
    }

    function getBaccCeAbiField() {
        return this.baccCeAbiField;
    }
    
    function getBaccCeCabField() {
        return this.baccCeCabField;
    }

    function getBaccDeRsocField() {
        return this.baccDeRsocField;
    }

    function getBaccDsProvField() {
        return this.baccDsProvField;
    }
    function getBaccDeIbanField() {        return this.baccDeIbanField;    }    
    function getBaccUseMezzField() {
        return this.baccUseField;
    }
    
    function setBaccCdBaccField(baccCdBaccField) {
        this.baccCdBaccField = baccCdBaccField;
    }

    function setBaccCeAbiField(baccCeAbiField) {
        this.baccCeAbiField = baccCeAbiField;
    }
    
    function setBaccCeCabField(baccCeCabField) {
        this.baccCeCabField = baccCeCabField;
    }

    function setBaccDeRsocField(baccDeRsocField) {
        this.baccDeRsocField = baccDeRsocField;
    }

    function setBaccDsProvField(baccDsProvField) {
        this.baccDsProvField = baccDsProvField;
    }
    function setBaccDeIbanField(baccDeIbanField) {        this.baccDeIbanField = baccDeIbanField;    }
    function setBaccUseMezzField(baccUseMezzField) {
        this.baccUseMezzField = baccUseMezzField;
    }
}

/******************************************************************************* * ============================================================= *  * Funzioni di utilita' per usare il dialog banca concessionaria *  * ============================================================= */

function popupBacc(cdBaccField, ceAbiField, ceCabField, deRsocField, dsProvField, deIbanField, useMezzField, callbackFuncName) {
    
	// forzatura perch? non ha un nome standard
    var f = document.forms[0];
    var d = new BaccDialogPage();
    
    d.setBaccCeAbi(f[ceAbiField].value);
    d.setBaccCeCab(f[ceCabField].value);
    d.setBaccDeRsoc(f[deRsocField].value);
    d.setBaccDsProv(f[dsProvField].value);        d.setBaccDeIban(f[deIbanField].value);
    d.setBaccUseMezz(f[useMezzField].value);

    d.setBaccCdBaccField(cdBaccField);
    d.setBaccCeAbiField(ceAbiField);
    d.setBaccCeCabField(ceCabField);
    d.setBaccDeRsocField(deRsocField);
    d.setBaccDsProvField(dsProvField);
    d.setBaccDeIbanField(deIbanField);    d.setBaccUseMezzField(useMezzField);

    if (callbackFuncName == undefined)
        callbackFuncName = "popupBaccCallback";

    d.show(callbackFuncName);
}
function popupBancaComm(useMezzField, callbackFuncName) {	var d = new BaccDialogPage();    d.setBaccUseMezz(useMezzField);    if (callbackFuncName == undefined)        callbackFuncName = "popupBaccCallback";    d.show(callbackFuncName);}
function popupBaccCallback(baccDialog) {

	// forzatura perch? non ha un nome standard
    var f = document.forms[0];

    var cdBaccField = baccDialog.getBaccCdBaccField();
    var ceAbiField = baccDialog.getBaccCeAbiField();
    var ceCabField = baccDialog.getBaccCeCabField();
    var deRsocField = baccDialog.getBaccDeRsocField();
    var dsProvField = baccDialog.getBaccDsProvField();        var deIbanField = baccDialog.getBaccDeIbanField();

    f[cdBaccField].value = baccDialog.getBaccCdBacc();
    f[ceAbiField].value = baccDialog.getBaccCeAbi();
    f[ceCabField].value = baccDialog.getBaccCeCab();
    f[deRsocField].value = baccDialog.getBaccDeRsoc();
    f[dsProvField].value = baccDialog.getBaccDsProv();
    f[deIbanField].value = baccDialog.getBaccDeIban();
}

function popupBaccClear(cdBaccField, ceAbiField, ceCabField, deRsocField, dsProvField, deIbanField, mezzCdMezzField, curElem) {

	// forzatura perch? non ha un nome standard
    var f = document.forms[0];
    
    f[cdBaccField].value = '0';
    f[ceAbiField].value = '';
    f[ceCabField].value = '';
    f[deRsocField].value = '';
    f[dsProvField].value = '';   
    f[deIbanField].value = '';   }

function showMessage(divId, message) {

	var div = document.getElementById(divId);
	var divText = document.getElementById(divId + 'Text');

	if (message.length > 0) {
		divText.innerHTML = message;
		div.style.display = "block";
	} else {
		div.style.display = "none";
	}
}

function popupConfigureGrid(callbackFunction) {

	var w = newWindow("configureGrid.do", "configureGrid", 700, 500, false, false, true);
	window.callbackFunction = callbackFunction;
}

/******************************************************************************* * ================================================= *  * Dialog ricerca utente *  * ================================================= */

function UtentiDialogPage() {

    var callbackFunction = "";

    var cdUtenFieldName;
    var ceUtenFieldName;
    var deRsocFieldName;

    var utenCdUten;
    var utenCeUten;
    var utenDeRsoc;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getUtenCdUten = getUtenCdUten;
    this.setUtenCdUten = setUtenCdUten;
    this.getUtenCeUten = getUtenCeUten;
    this.setUtenCeUten = setUtenCeUten;
    this.getUtenDeRsoc = getUtenDeRsoc;
    this.setUtenDeRsoc = setUtenDeRsoc;
    this.setCdUtenFieldName = setCdUtenFieldName;
    this.getCdUtenFieldName = getCdUtenFieldName;
    this.setCeUtenFieldName = setCeUtenFieldName;
    this.getCeUtenFieldName = getCeUtenFieldName;
    this.setDeRsocFieldName = setDeRsocFieldName;
    this.getDeRsocFieldName = getDeRsocFieldName;
        
    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {


        if ((this.utenDeRsoc != undefined && this.utenDeRsoc.length < 3) ||
            (this.utenCeUten != undefined && this.utenCeUten.length < 1)) {

            alert(I18N.t("Inserire almeno tre caratteri per la ricerca."));
            return;
        }

        this.callbackFunction = callbackFunction;

        var actionURL = "searchUtente.do"
        actionURL += "?cmd=srcUten";
        if (this.utenCeUten != undefined)
            actionURL += "&utenCeUten=" + escape(this.utenCeUten);
        if (this.utenDeRsoc != undefined)
            actionURL += "&utenDeRsoc=" + escape(this.utenDeRsoc);
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchUtente", 700, 400, false, false, true);
    }

    function getUtenCdUten() {
        return this.utenCdUten;
    }

    function setUtenCdUten(utenCdUten) {
        this.utenCdUten = utenCdUten;
    }

    function getUtenDeRsoc() {
        return this.utenDeRsoc;
    }

    function setUtenDeRsoc(utenDeRsoc) {
        this.utenDeRsoc = utenDeRsoc;
    }

    function getUtenCeUten() {
        return this.utenCeUten;
    }

    function setUtenCeUten(utenCeUten) {
        this.utenCeUten = utenCeUten;
    }
        
    function getCdUtenFieldName() {
        return this.cdUtenFieldName;
    }

    function setCdUtenFieldName(cdUtenFieldName) {
        this.cdUtenFieldName = cdUtenFieldName;
    }

    function getCeUtenFieldName() {
        return this.ceUtenFieldName;
    }

    function setCeUtenFieldName(ceUtenFieldName) {
        this.ceUtenFieldName = ceUtenFieldName;
    }

    function getDeRsocFieldName() {
        return this.deRsocFieldName;
    }

    function setDeRsocFieldName(deRsocFieldName) {
        this.deRsocFieldName = deRsocFieldName;
    }
}

/******************************************************************************* * ================================================= *  * Funzioni di utilita' per usare il dialog utente *  * ================================================= */

function popupUtente(cdUtenField, ceUtenField, deRsocField, callbackFuncName) {

    var f = getFormByID('mainForm');
    var d = new UtentiDialogPage();

    d.setCdUtenFieldName(cdUtenField);
    d.setCeUtenFieldName(ceUtenField);
    d.setDeRsocFieldName(deRsocField);

    // assegna i valori dei criteri ricerca

    if(f.elements[ceUtenField].value == "") 
        d.setUtenDeRsoc(f.elements[deRsocField].value);
    else    
        d.setUtenCeUten(f.elements[ceUtenField].value);
    
    if (callbackFuncName == undefined)
        callbackFuncName = "popupUtenteCallback";

    d.show(callbackFuncName);
}

function popupUtenteCallback(utentiDialog) {

    var f = getFormByID('mainForm');

    var cdField = utentiDialog.getCdUtenFieldName();
    var ceField = utentiDialog.getCeUtenFieldName();
    var deField = utentiDialog.getDeRsocFieldName();

    f[cdField].value = utentiDialog.getUtenCdUten();
    f[ceField].value = utentiDialog.getUtenCeUten();
    f[deField].value = utentiDialog.getUtenDeRsoc();
}

function popupUtenteClear(cdUtenField, ceUtenField, deRsocField, clearMnemonic) {

    var f = getFormByID('mainForm');
    f[cdUtenField].value = '0';
    if (clearMnemonic) {
        f[ceUtenField].value = '';
    } else {
        f[deRsocField].value = '';
    }
}


/******************************************************************************* * ================================================= *  * Dialog ricerca ClasseNielsen *  * ================================================= */

function ClasseNielsenDialogPage() {

    var callbackFunction = "";

    var cprnCdCprn;
    var cprnDeCprn;
    var cprnCeCprn;

    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getCprnCdCprn = getCprnCdCprn;
    this.setCprnCdCprn = setCprnCdCprn;
    this.getCprnDeCprn = getCprnDeCprn;
    this.setCprnDeCprn = setCprnDeCprn;
    this.getCprnCeCprn = getCprnCeCprn;
    this.setCprnCeCprn = setCprnCeCprn;
    
    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        if (this.cprnDeCprn != undefined && this.cprnDeCprn.length < 3 &&
            this.cprnCeCprn != undefined && this.cprnCeCprn.length < 1) {

            alert(I18N.t("Inserire almeno tre caratteri per la ricerca."));
            return;
        }

        this.callbackFunction = callbackFunction;

        var actionURL = "searchClasseNielsen.do"
        actionURL += "?cmd=read";
        if (this.cprnDeCprn != undefined)
            actionURL += "&cprnDeCprn=" + escape(this.cprnDeCprn);
        if (this.notpCeNotp != undefined)
            actionURL += "&cprnCeCprn=" + escape(this.cprnCeCprn);
        
        actionURL += "&callback=" + callbackFunction;
        currentDialog = this;
        newWindow(actionURL, "searchClasseNielsen", 700, 400, false, false, true);
    }

    function getCprnCdCprn() {
        return this.cprnCdCprn;
    }

    function setCprnCdCprn(cprnCdCprn) {
        this.cprnCdCprn = cprnCdCprn;
    }

    function getCprnCeCprn() {
        return this.cprnCeCprn;
    }

    function setCprnCeCprn(cprnCeCprn) {
        this.cprnCeCprn = cprnCeCprn;
    }

    function getCprnDeCprn() {
        return this.cprnDeCprn;
    }

    function setCprnDeCprn(cprnDeCprn) {
        this.cprnDeCprn = cprnDeCprn;
    }

}


/******************************************************************************* * ================================================= *  * Dialog ricerca contatto *  * ================================================= */

function ContattiDialogPage() {

    var callbackFunction = "";

    var cdConaFieldName;
    var deConaFieldName;
    
    var conaCdCona;
    var conaDeCona;
    var anagCdAnag;
    
    this.getCallbackFunction = getCallbackFunction;
    this.show = show;
    this.getConaCdCona = getConaCdCona;
    this.setConaCdCona = setConaCdCona;
    this.getConaDeCona = getConaDeCona;
    this.setConaDeCona = setConaDeCona;
    this.getAnagCdAnag = getAnagCdAnag;
    this.setAnagCdAnag = setAnagCdAnag;
    this.setCdConaFieldName = setCdConaFieldName;
    this.getCdConaFieldName = getCdConaFieldName;
    this.setDeConaFieldName = setDeConaFieldName;
    this.getDeConaFieldName = getDeConaFieldName;
        
    function getCallbackFunction() {
        return this.callbackFunction;
    }

    function show(callbackFunction) {

        this.callbackFunction = callbackFunction;

        var actionURL = "viewContatti.do"
        actionURL += "?cmd=" + this.indiType;
        actionURL += "&anagCdAnag=" + this.anagCdAnag;

        currentDialog = this;
        newWindow(actionURL, "viewContatti", 700, 400, false, false, true);
    }

    function getConaCdCona() {
        return this.conaCdCona;
    }

    function setConaCdCona(conaCdCona) {
        this.conaCdCona = conaCdCona;
    }

    function getConaDeCona() {
        return this.conaDeCona;
    }

    function setConaDeCona(conaDeCona) {
        this.conaDeCona = conaDeCona;
    }

    function getCdConaFieldName() {
        return this.cdConaFieldName;
    }

    function setCdConaFieldName(cdConaFieldName) {
        this.cdConaFieldName = cdConaFieldName;
    }

    function getDeConaFieldName() {
        return this.deConaFieldName;
    }

    function setDeConaFieldName(deConaFieldName) {
        this.deConaFieldName = deConaFieldName;
    }
    
    function getAnagCdAnag() {
        return this.anagCdAnag;
    }

    function setAnagCdAnag(anagCdAnag) {
        this.anagCdAnag = anagCdAnag;
    }
}

/******************************************************************************* * ================================================= *  * Funzioni di utilita' per usare il dialog contatti *  * ================================================= */

function popupContatti(cdConaField, deConaField, anagCdAnag, callbackFuncName) {

    var f = getFormByID('mainForm');
    var d = new ContattiDialogPage();

    d.setCdConaFieldName(cdConaField);
    d.setDeConaFieldName(deConaField);
    d.setAnagCdAnag(anagCdAnag);

    if (callbackFuncName == undefined)
        callbackFuncName = "popupContattoCallback";

    d.show(callbackFuncName);
}

function popupContattoCallback(ContattiDialog) {

    var f = getFormByID('mainForm');

    var cdField = ContattiDialog.getCdConaFieldName();
    var deField = ContattiDialog.getDeConaFieldName();

    f[cdField].value = ContattiDialog.getConaCdCona();
    f[deField].value = ContattiDialog.getConaDeCona();
}
/** * AUTOLOGIN - FORCED EDIT */function forcedEdit (formId, forceEdit){	var form = $("form#" + formId);
	var types = ["input", "textarea", "button"];	var typesToDisable = ["select", "input[type=checkbox]"];	var events = ["click", "keyup", "keypress", "keydown", "blur", "change"];	var attributes = ["mask:text-case", "mask:type"];	var classes = ["disablable", "datepicker_trigger"];
	jQuery.each(types, function() {
		var elements = form.find("" + this);
		jQuery.each(elements, function() {
			element = $(this);
			if (forceEdit)			{				element.removeAttr("disabled");				element.removeAttr("readonly");			}			else			{				element.attr("readonly", "readonly");
				// removes messy attributes				jQuery.each(events, function() {					element.removeAttr("on" + this);				});
				jQuery.each(attributes, function() {					element.removeAttr("" + this);				});			}		});	});
	// a special treatment is required for all select elements	// an hidden html is created in their place with the select value while the	// original	// select html element is disabled	jQuery.each(typesToDisable, function() {
		var elements = form.find("" + this);
		jQuery.each(elements, function() {
			element = $(this);
			if (forceEdit)			{				element.removeAttr("disabled");				element.removeAttr("readonly");			}			else			{				if (element.filter("input[type=checkbox]:checked").length > 0)					element.after("<input type='hidden' name='" + element.attr("name") + 									"' value='" + element.attr("value") + "'/>");								element.attr("disabled", "disabled");			}		});	});		if (!forceEdit)	{
		$(".disablable").hide();		$(".datepicker_trigger").hide();	}}
function openPopup (url, name, scrollbars, width, height, resizable, 					status, location, toolbar, directories, menubar) {
	var style =	"toolbar=" + toolbar + ",location=" + location + 				",directories=" + directories + ",status=" + status + 				",menubar=" + menubar + ",scrollbars=" + scrollbars + 				",resizable=" + resizable+",copyhistory=1,";
	if (width != 0) style += "width=" + width + ",";	if  (height != 0) style += "height=" + height + ",";	var left = width != 0 ? ((screen.width / 2) - width / 2) : 50;	var top = height != 0 ? ((screen.height / 2) - height / 2) : 50;	style += "left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;	window.open(url, name, style);}
function fixSrcClieList () {
	var index = 0;	$.each(	$("table.srcClieList tr:even"), 
			function () {
				index++;				row = $(this);				children = $(this).find("td.start");
				// coloro tutte le righe in maniera alternata				if ((index % 2) == 0) children.addClass("even");				else children.addClass("odd");
				// aggiungo l'onHover come evento			    row.hover(
					function () {						children = $(this).find("td");						children.addClass("hover");					}, 
					function () {						children = $(this).find("td");						children.removeClass("hover");					}	    	    );			}	);}/** * "Plugin" per jquery per fixare le select e i checkbox read-only. Esempio di * utilizzo: $(document).ready(function () { jQuery.fixReadOnlyForm(); }); *//* * (function ($) { $.fixReadOnlyForm = function () { // fix per le select * read-only jQuery.each($("select[readonly=readonly]"), function() { element = * $(this); generateHidden(element); element.attr("disabled", "disabled"); }); *  // fix per i checkbox read-only jQuery.each($("input[type=checkbox]"), * function() { element = $(this); // IE non supporta (stupiti?) * [readonly=readonly] con jQuery if (!element.attr("readonly")) return; if * (element.filter(":checked").length > 0) generateHidden(element); * element.attr("disabled", "disabled"); }); *  }; *  * generateHidden = function (element) { element.after("<input type='hidden' * name='" + element.attr("name") + "' value='" + element.attr("value") + * "'/>"); }; *  } )(jQuery); */
