﻿
///
//  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=770, 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 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;
    }
}
