﻿
///
//  parDesc             = nome del textBox che contiene la descrizione da ricercare.
//  parDescMinLength    = numero minimo dei caratteri permessi nel campo parDesc per efettuare la ricerca.
//  parIdentifier       = identificatore unique che deve correspondere ad un GridViewNode nel file GenericPopupConfig.xml.
//
//  Description:        Javascript utility to open the generic popup when clicked on the search button.
//  Author:             Sachin Chopra.
///

function OpenInfoPopup(nomeFile)
{
    var url = 'Info.aspx?nomeFile=' + nomeFile;
    window.open(url,'co','width=800, height=600,scrollbars=yes,left=0,top=0');
}

function OpenGenericPopupCodice(parCod,parCodMinLength,parDesc,parDescMinLength,parIdentifier,nomeCampo)
{	
    var txtCod     =   window.document.getElementById(parCod);
    var txtDesc    =   window.document.getElementById(parDesc);
    
    var strCodValue    = txtCod.value;
    var strDescValue   = txtDesc.value;
    
    if( (strDescValue != "" || strCodValue != "") && (strCodValue.length >= parCodMinLength || strDescValue.length >= parDescMinLength) )
    {
        var url = 'GenericPopup.aspx?parIdentifier=' + parIdentifier;
        if(strCodValue != "")
            url += '&parCod=' + strCodValue;
        if(strDescValue != "")
            url += '&parDesc=' + strDescValue;

        window.open(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0');
    }
    
    else
    {
        alert('Attenzione: per effettuare la ricerca nel campo ' + nomeCampo +'\ninserire almeno ' + parCodMinLength +' caratteri.')
        txtDesc.focus;
    }
}

function OpenGenericPopupTitolo(parCod,parCodMinLength,parDesc,parDescMinLength,parIdentifier,nomeCampo,parTipoLinea)
{	
    var txtCod     =   window.document.getElementById(parCod);
    var txtDesc    =   window.document.getElementById(parDesc);
    var txtTipoLinea = window.document.getElementById(parTipoLinea);
    var strTipoLinea = txtTipoLinea.value;
    
    var strCodValue    = txtCod.value;
    var strDescValue   = txtDesc.value;
    if(strDescValue.length < parDescMinLength && strCodValue.length < parCodMinLength)
    {
        if(strDescValue == "" && strCodValue == "" || strDescValue.length == strCodValue.length) {
            if(strDescValue.length == 0 && strDescValue.length == 0){
                alert('Attenzione per eseguire la ricerca è necessario compilare uno dei campi: Codice percorso o Titolo')
            } else {
                alert('Attenzione: per effettuare la ricerca nel campo ' + nomeCampo +'\ninserire almeno ' + parDescMinLength +' caratteri.')
                txtDesc.focus;
            }            
            txtDesc.focus;
        } else if (strCodValue != "") {
            alert('Attenzione: per effettuare la ricerca nel campo codice \ninserire almeno ' + parCodMinLength +' caratteri.')
            txtCod.focus;
        }
        else if (strDescValue != "") {
            alert('Attenzione: per effettuare la ricerca nel campo ' + nomeCampo +'\ninserire almeno ' + parDescMinLength +' caratteri.')
            txtDesc.focus;
        }
    } else if( strDescValue.length >= parDescMinLength || strCodValue != "" && strCodValue.length >= parCodMinLength)
    {
        var url = 'GenericPopup.aspx?parIdentifier=' + parIdentifier;
        if(strCodValue != "")
            url += '&parCod=' + strCodValue;
        if(strDescValue != "")
            url += '&parDesc=' + strDescValue;
            url += '&parTipoLinea=' + strTipoLinea;
        window.open(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0');
    }    
}

function OpenGenericPopup(parDesc,parDescMinLength,parIdentifier,nomeCampo)
{	
    var txtDesc    =   window.document.getElementById(parDesc);
    
    var strDescValue   = txtDesc.value;
    
    if( (strDescValue != "") && (strDescValue.length >= parDescMinLength) )
    {
        var url = 'GenericPopup.aspx?parIdentifier=' + parIdentifier;
        if(strDescValue != "")
            url += '&parDesc=' + strDescValue;
            
        // NOTE - SACHIN: TO DO
       //Se non lo facciamo MODAL, va in errore quando
                // - 1. Si apre il popup.
                // - 2. Cambia la pagina sottostante.
                // - 3. Clicca su qualsiasi cosa linkabile nel popup (che va a scrivere nei campi della pagina sottostante)

//       if (window.showModalDialog)
//       {
//            // IE(ShowModalDialog)
//            window.showModalDialog(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0');
//       }
//       else
//       {
//            // FIREFOX (modal = yes)
//            window.open(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0,modal=yes');
//       }
       
        window.open(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0');
    }
    
    else
    {
        alert('Attenzione: per effettuare la ricerca nel campo ' + nomeCampo +'\ninserire almeno ' + parDescMinLength +' caratteri.')
        txtDesc.focus;
    }
}

///
//  parDesc             = nome del textBox che contiene la descrizione da ricercare.
//  parDescMinLength    = numero minimo dei caratteri permessi nel campo parDesc per efettuare la ricerca.
//  parIdentifier       = identificatore unique che deve correspondere ad un GridViewNode nel file GenericPopupConfig.xml.
//
//  Description:        Javascript utility to open the generic popup when the ENTER key is pressed.
//  Author:             Sachin Chopra.
///
function TrapKeyDown(parDesc,parDescMinLength,parIdentifier)
{
    if(event.keyCode == 13)
    {
        OpenGenericPopup(parDesc,parDescMinLength,parIdentifier);
        event.returnValue=false; 
        event.cancel = true;
    }   
    else
        return false;
}

function EnableParentFields() //richiamata al click di Inserisci nuova sede operativa, dalla popup sedi operative
{
    
//    if (window.opener.document.getElementById("panelInserimentoCampi") != null)
//    {
//        panelInserimentoCampi.visible = true;
//        window.opener.document.getElementById("panelModificaCampi").visible = false;
//    }
//    if (window.opener.document.getElementById("txtDescComuneSedeLavoro") != null)
//    {
//        window.opener.document.getElementById("txtDescComuneSedeLavoro").value = "";
//        window.opener.document.getElementById("txtDescComuneSedeLavoro").readOnly = false;
//        window.opener.document.getElementById("txtDescComuneSedeLavoro").disabled = false;
//    }
//    if (window.opener.document.getElementById("txtCodComuneSedeLavoro") != null)
//    {
//        window.opener.document.getElementById("txtCodComuneSedeLavoro").value = "";
//        window.opener.document.getElementById("txtCodComuneSedeLavoro").readOnly = false;
//        window.opener.document.getElementById("txtCodComuneSedeLavoro").disabled = false;
//    }
//    if (window.opener.document.getElementById("txtCAPSedeLavoro") != null)
//    {
//        window.opener.document.getElementById("txtCAPSedeLavoro").value = "";
//        window.opener.document.getElementById("txtCAPSedeLavoro").readOnly = false;
//        window.opener.document.getElementById("txtCAPSedeLavoro").disabled = false;
//    }
//    if (window.opener.document.getElementById("txtIndirizzoSedeLavoro") != null)
//    {
//        window.opener.document.getElementById("txtIndirizzoSedeLavoro").value = "";
//        window.opener.document.getElementById("txtIndirizzoSedeLavoro").readOnly = false;
//        window.opener.document.getElementById("txtIndirizzoSedeLavoro").disabled = false;
//    }
//    window.opener.document.getElementById("txtTelefonoSedeLavoro").value = "";
//    window.opener.document.getElementById("txtEmailSedeLavoro").value = "";
//    window.opener.document.getElementById("txtFaxSedeLavoro").value = "";
//    window.opener.document.getElementById("txtTelefonoSedeLavoro").readOnly = false;
//    window.opener.document.getElementById("txtTelefonoSedeLavoro").disabled = false;
//    window.opener.document.getElementById("txtEmailSedeLavoro").readOnly = false;
//    window.opener.document.getElementById("txtEmailSedeLavoro").disabled = false;
//    window.opener.document.getElementById("txtFaxSedeLavoro").readOnly = false;
//    window.opener.document.getElementById("txtFaxSedeLavoro").disabled = false;
    if (window.opener.document.getElementById("btnSalvaSede") != null)
    {
        window.opener.document.getElementById("btnSalvaSede").readOnly = false;
        window.opener.document.getElementById("btnSalvaSede").disabled = false;
    }
    window.opener.document.getElementById("idPopup").value = "abilita";
    window.opener.document.getElementById("txtIdSedeImpresa").value = "Nuova";
    window.close();
    window.opener.document.forms[0].submit();
}

function DisableParentFields() //richiamata alla selezione di una sede dalla popup
{
//    window.opener.document.getElementById("txtDescComuneSedeLavoro").readOnly = true;
//    window.opener.document.getElementById("txtCodComuneSedeLavoro").readOnly = true;
//    window.opener.document.getElementById("txtCAPSedeLavoro").readOnly = true;
//    window.opener.document.getElementById("txtIndirizzoSedeLavoro").readOnly = true;
//    window.opener.document.getElementById("txtTelefonoSedeLavoro").readOnly = false;
//    window.opener.document.getElementById("txtTelefonoSedeLavoro").disabled = false;
//    window.opener.document.getElementById("txtEmailSedeLavoro").readOnly = false;
//    window.opener.document.getElementById("txtEmailSedeLavoro").disabled = false;
//    window.opener.document.getElementById("txtFaxSedeLavoro").readOnly = false;
//    window.opener.document.getElementById("txtFaxSedeLavoro").disabled = false;
//    window.opener.document.getElementById("btnSalvaSede").readOnly = false;
//    window.opener.document.getElementById("btnSalvaSede").disabled = false;
//    window.opener.document.getElementById("idPopup").value = "";
//    window.opener.document.getElementById("txtModifica").value = "";
    window.close();
    window.opener.document.forms[0].submit();
}


function DisableParentFieldsByBody() //richiamata all'onload delle pagine che contengono i campi della sede operativa
{
    if(document.getElementById("idPopup").value == "")
    {
        //Disabilito i campi della pagina in primo inserimento.
        document.getElementById("txtCodiceFiscale").readOnly = true;
        document.getElementById("txtDenomDatlav").readOnly = true;
        document.getElementById("txtDescComuneSedeLavoro").readOnly = true;
        document.getElementById("txtCodComuneSedeLavoro").readOnly = true;
        document.getElementById("txtCAPSedeLavoro").readOnly = true;
        document.getElementById("txtIndirizzoSedeLavoro").readOnly = true;
        document.getElementById("txtTelefonoSedeLavoro").readOnly = true;
        document.getElementById("txtEmailSedeLavoro").readOnly = true;
        document.getElementById("txtFaxSedeLavoro").readOnly = true;
    }
}

///
//  parIdentifier       = identificatore unique che deve correspondere ad un GridViewNode nel file GenericPopupConfig.xml.
//
//  Description:        Javascript utility to open PopupSedeOperativa.
//  Author:             Sachin Chopra.o
///
function OpenPopupSedeOperative(parIdentifier)
{	
//        if (document.getElementById("txtDescComuneSedeLavoro") != null)
//            document.getElementById("txtDescComuneSedeLavoro").value = "";
//        if (document.getElementById("txtCodComuneSedeLavoro") != null)    
//            document.getElementById("txtCodComuneSedeLavoro").value = "";
//        if (document.getElementById("txtCAPSedeLavoro") != null)
//            document.getElementById("txtCAPSedeLavoro").value = "";
//        if (document.getElementById("txtIndirizzoSedeLavoro") != null)
//            document.getElementById("txtIndirizzoSedeLavoro").value = "";
//        document.getElementById("txtTelefonoSedeLavoro").value = "";
//        document.getElementById("txtEmailSedeLavoro").value = "";
//        document.getElementById("txtFaxSedeLavoro").value = "";
//        document.getElementById("txtIdComuneSedeLavoro").value = "";
//        document.getElementById("txtDescComuneSedeLavoroBck").value = "";
//        document.getElementById("txtCodComuneSedeLavoroBck").value = "";
        document.getElementById("txtIdSedeImpresa").value = "";
        document.getElementById("txtIdSedeCO").value = "";
        document.getElementById("txtModifica").value = "";
        
        var url = 'PopupSedeOperativa.aspx?parIdentifier=' + parIdentifier;
          
       // NOTE - SACHIN: TO DO
       //Se non lo facciamo MODAL, va in errore quando
                // - 1. Si apre il popup.
                // - 2. Cambia la pagina sottostante.
                // - 3. Clicca su qualsiasi cosa linkabile nel popup (che va a scrivere nei campi della pagina sottostante)
        
//       if (window.showModalDialog)
//       {
//            // IE (ShowModalDialog)
//            window.showModalDialog(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0');
//       }
//       else
//       {
//            // FIREFOX (modal = yes)
//            window.open(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0,modal=yes');
//       }
        
        window.open(url,'','width=970, height=600,scrollbars=yes,left=0,top=0');
}

//Ariana
function Refresh(txtReady)
{
    if (txtReady.value != "")
    {
        window.close();
        window.opener.document.forms[0].isReentry.value='true';
        window.opener.document.forms[0].submit();
    }
     
}

//Ariana -> utilizzata per effettuare la ricerca libera dei titoli di studio: parametri: descrizione e idLivello
function ShowGenericPopupParametrizzataTitStudio(descrizione,idLivello,sField, path)
{
    //
    fields = sField.split("_");
	var tempStr = "";
	for(i=0; i<fields.length; i++){
		tempStr = tempStr + "&tn" + i + "=" + fields[i];
	}
		
     txt1=window.document.getElementById(descrizione);
     stringValue1=txt1.value;
     
     txt2=window.document.getElementById(idLivello);
     stringValue2=txt2.value;
     
     
     if (stringValue1!="" && stringValue2!="" && stringValue1.length>=3)
     {
        url =  path+"?parPage=1&descrizione="+stringValue1+"&idLivello="+stringValue2+ tempStr;
        
        window.open(url,'','width=800, height=600,scrollbars=yes,left=0,top=0');
     }
      else if (stringValue1=="" || stringValue1.length<3)
     {
        alert('Compilare almeno tre caratteri per effettuare la ricerca.');
        txt1.focus();
     }
    //
   
}
//Ariana -> utilizzata per effettuare la ricerca libera dei titoli di studio: parametri: descrizione e idLivello
function TrapGenericKeyDownParametrizzataTitStudio(descrizione,idLivello,sField, path)
{
    if(event.keyCode == 13)
    {
        ShowGenericPopupParametrizzataTitStudio(descrizione,idLivello,sField, path);
        event.returnValue=false; 
        event.cancel = true;

    }   
    else
        return false;  
}
//
function OpenGenericPopupSettore(parCod,parCodMinLength,parDesc,parDescMinLength,parIdentifier,nomeCampo)
{	
    var txtCod     =   window.document.getElementById(parCod);
    var txtDesc    =   window.document.getElementById(parDesc);
    
    var strCodValue    = txtCod.value;
    var strDescValue   = txtDesc.value;
    
    if( (strDescValue != "" || strCodValue != "") && (strCodValue.length >= parCodMinLength || strDescValue.length >= parDescMinLength) )
    {
        var url = 'GenericPopup.aspx?parIdentifier=' + parIdentifier;
        if(strCodValue != "")
            url += '&parCod=' + strCodValue;
        if(strDescValue != "")
            url += '&parDesc=' + strDescValue;
            
        // NOTE - SACHIN: TO DO
       //Se non lo facciamo MODAL, va in errore quando
                // - 1. Si apre il popup.
                // - 2. Cambia la pagina sottostante.
                // - 3. Clicca su qualsiasi cosa linkabile nel popup (che va a scrivere nei campi della pagina sottostante)

//       if (window.showModalDialog)
//       {
//            // IE(ShowModalDialog)
//            window.showModalDialog(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0');
//       }
//       else
//       {
//            // FIREFOX (modal = yes)
//            window.open(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0,modal=yes');
//       }
       
        window.open(url,'co','width=770, height=600,scrollbars=yes,left=0,top=0');
    }
    
    else
    {
        alert('Attenzione: per effettuare la ricerca nel campo ' + nomeCampo +'\ninserire almeno ' + parCodMinLength +' caratteri.')
        txtDesc.focus;
    }
}

//Ariana -> popup modifica generica
function OpenPopupModifica(url, idRecord)
{
    window.open(url + "?idRecord=" +idRecord,'PopupMod','width=800, height=600,scrollbars=yes,left=0,top=0');
}

//Ariana
function RichiestaConfermaEliminaRecord(message) 
{ 
    message=formatText(message); 
    if (confirm(message)==true)
        return true;
    else
        return false;
}

function formatText (text)
{
    text=text.replace(/§/gi,"\n");
    return text;
}

function OpenPopupTitoliStudio(idLivello, codice, descrizione,sField)
{
    fields = sField.split("_");
	var tempStr = "";
	for(i=0; i<fields.length; i++)
	{
		tempStr = tempStr + "&tn" + i + "=" + fields[i];
	}
	
	txt1=window.document.getElementById(idLivello);
    stringValue1=txt1.value;
     
	txt2 = window.document.getElementById(codice);
    stringValue2=txt2.value;
		
    txt3=window.document.getElementById(descrizione);
    stringValue3=txt3.value;
        
     if (stringValue1!="" && (stringValue2!="" || stringValue3!="") && (stringValue2.length>=2 || stringValue3.length>=2))
     {
        var url = 'OF_Candidatura_Popup_TitoliStudio.aspx?idLivello=' + stringValue1 + "&codice=" + stringValue2 + "&descrizione=" + stringValue3+ tempStr;
        window.open(url,'','width=970, height=600,scrollbars=yes,left=0,top=0');
     }
      else if (stringValue1=="" || (stringValue2.length<2 && stringValue3.length<2))
     {
        alert('Compilare almeno due caratteri per effettuare la ricerca.');
        txt2.focus();
     }    
}

function ConfirmAction (msg, link)
{
    msg=msg.replace("&amp","'");
    var conferma = confirm(msg);
    if (conferma)
    {
        location.href = link;
    }
}

//Ariana
function OpenPopupSchedeProgettuali(codice,descrizione,sField)
{
    fields = sField.split("_");
	var tempStr = "";
	for(i=0; i<fields.length; i++)
	{
		tempStr = tempStr + "&tn" + i + "=" + fields[i];
	}
		
     txt1=window.document.getElementById(codice);
     stringValue1=txt1.value;
     
     txt2=window.document.getElementById(descrizione);
     stringValue2=txt2.value;
     
     if((stringValue1 != "" || stringValue2 != "") && (stringValue1.length >= 2 || stringValue2.length >= 2) )
     {
        url =  "OF_Candidatura_Popup_ElencoSchedeProgettuali.aspx?&codice="+stringValue1+"&descrizione="+stringValue2+ tempStr;
        
        window.open(url,'schedeProg','width=800, height=600,scrollbars=yes,left=0,top=0');
     }
     else 
     {
        if ((stringValue1 != "" || stringValue2 != "") && (stringValue1.length < 2 || stringValue2.length < 2)) 
        {
            alert('Compilare almeno due caratteri per effettuare la ricerca.');
            txt1.focus();
        } else
        {
            alert('Attenzione per seguire la ricerca della scheda progettuale è necessario compilare uno dei campi:\n- Codice percorso\n- Titolo percorso');
            txt1.focus();
        }
     }
}

function VisualizzaSchedeProgettuali(sField)
{
    fields = sField.split("_");
	var tempStr = "";
	for(i=0; i<fields.length; i++)
	{
		tempStr = tempStr + "&tn" + i + "=" + fields[i];
	}
    url =  "OF_Candidatura_Popup_ElencoSchedeProgettuali.aspx?schede=true" + tempStr;        
    window.open(url,'schedeProg','width=800, height=600,scrollbars=yes,left=0,top=0');          
}

//funzione per limitare il numero di caratteri da inserire nelle txtArea
function textCounter(field,  maxlimit) 
{
    if (field.value.length > maxlimit) 
        field.value = field.value.substring(0, maxlimit);
    
}

function ShowGenericPopupTitoloPercorsoFormativoPeriodo(nomeCampoDescrizione, nomeCampoCodice, nomeCampoIdTitoloPercorso, idBando, mese, anno, tipoPercorso, path, fieldLengthDescrizione, fieldLengthCodice)
{
    txtCodice = window.document.getElementById(nomeCampoCodice);
    stringValueCodice = txtCodice.value;
    txtDescrizione = window.document.getElementById(nomeCampoDescrizione);
    stringValueDescrizione = txtDescrizione.value;
    txtIdBando = window.document.getElementById(idBando);
    stringValueIdBando = txtIdBando.value;
    
    txtMese = window.document.getElementById(mese);
    stringValueMese = txtMese.value;
    txtAnno = window.document.getElementById(anno);
    stringValueAnno = txtAnno.value;
    txtTipoPercorso = window.document.getElementById(tipoPercorso);
    stringValueTipoPercorso = txtTipoPercorso.value;
          
    if (stringValueMese == "" || stringValueAnno == "" || stringValueIdBando == "" || stringValueTipoPercorso == "")
    {
        alert('Attenzione per ricerca l\'edizione del percorso di interesse è necessario compilare i campi, codice avviso, mese anno e tipo percorso.')
        txtDescrizione.focus();
    }
    else
    {
      if((stringValueCodice != "" && stringValueCodice.length >= fieldLengthCodice)
          ||(stringValueDescrizione != "" && stringValueDescrizione.length >= fieldLengthDescrizione))
      {
          url = path+"?nomeCampoDescrizione="+nomeCampoDescrizione+"&valueCampoDescrizione="+stringValueDescrizione+"&nomeCampoCodice="+nomeCampoCodice+"&valueCampoCodice="+stringValueCodice +"&idBando="+stringValueIdBando+"&nomeCampoIdTitoloPercorso="+nomeCampoIdTitoloPercorso+"&mese="+stringValueMese+"&anno="+stringValueAnno;
          window.open(url,'Popup','width=700, height=600,scrollbars=yes,left=0,top=0');
      }
      else
      {
          alert('Attenzione inserire almeno 2 caratteri per effettuare la ricerca.')
          txtDescrizione.focus();
      }
    }  
}

function ShowGenericPopupTitoloPercorsoFormativo(nomeCampoDescrizione, nomeCampoCodice, nomeCampoIdTitoloPercorso, idBando, path, fieldLengthDescrizione, fieldLengthCodice)
{
    txtCodice = window.document.getElementById(nomeCampoCodice);
    stringValueCodice = txtCodice.value;
    txtDescrizione = window.document.getElementById(nomeCampoDescrizione);
    stringValueDescrizione = txtDescrizione.value;
    txtIdBando = window.document.getElementById(idBando);
    stringValueIdBando = txtIdBando.value;
          
    if((stringValueCodice != "" && stringValueCodice.length >= fieldLengthCodice)
        ||(stringValueDescrizione != "" && stringValueDescrizione.length >= fieldLengthDescrizione))
    {
        url = path+"?nomeCampoDescrizione="+nomeCampoDescrizione+"&valueCampoDescrizione="+stringValueDescrizione+"&nomeCampoCodice="+nomeCampoCodice+"&valueCampoCodice="+stringValueCodice +"&idBando="+stringValueIdBando+"&nomeCampoIdTitoloPercorso="+nomeCampoIdTitoloPercorso+"&mese="+"&anno=";
        window.open(url,'Popup','width=700, height=600,scrollbars=yes,left=0,top=0');
    }
    else
    {
        alert('Attenzione inserire almeno 2 caratteri per effettuare la ricerca.')
        txtDescrizione.focus();
    }  
}
