﻿function BorrarComentario(elem)
{
    var CapaBorrado = document.getElementById('CapaBorrado');

    if (event.button==2)
    {    
        if (event.srcElement.tagName == 'A')
        {
            if ((event.srcElement.innerText != 'OSI') && (event.srcElement.innerText != 'INT') && (event.srcElement.innerText != 'SSR'))
            {
                CapaBorrado.style.display = 'block';
                CapaBorrado.style.pixelTop = window.event.y + document.body.parentElement.scrollTop + 4;
                CapaBorrado.style.pixelLeft = window.event.x + document.body.parentElement.scrollLeft;
                
                var HidenSeleccionado = $get('ctl00_MainContentPlaceHolder_UC_Datos_PaxContactoInfoAdicional1_UC_Info_Servicios1_HidSelecNode');
                
                if (HidenSeleccionado == null)
                {
                    HidenSeleccionado = $get('ctl00_MainContentPlaceHolder_ctl07_UC_Info_Servicios1_HidSelecNode');
                }
                
                HidenSeleccionado.value = event.srcElement.innerText;
            }
            else
            {
                CapaBorrado.style.display = 'none';
            }
        }
        else
        {
            CapaBorrado.style.display = 'none';
        }                
    }
    else
    {
        CapaBorrado.style.display = 'none';
    }
}

function MostrarErroresInfoServicios(elem)
{
    var TxtAux = elem.id.substring(0, elem.id.length - 6) + 'Txt' + elem.id.substring(elem.id.length - 3);
    var TxtElem = $get(TxtAux);
    
    var RequiredFAux = elem.id.substring(0, elem.id.length - 6) + 'RequiredField' + elem.id.substring(elem.id.length - 3);
    var RequiredFElem = $get(RequiredFAux);
    
    var RegularExpressionAux = elem.id.substring(0, elem.id.length - 6) + 'RegularExpression' + elem.id.substring(elem.id.length - 3);
    var RegularExpressionElem = $get(RegularExpressionAux);
    
    if (TxtElem.value == '')
    {        
        RequiredFElem.style.visibility = 'visible';
        RegularExpressionElem.style.visibility = 'hidden';
    }
    else
    {
        RequiredFElem.style.visibility = 'hidden';
                    
        if (!(/^([A-Z]|[a-z]|ñ|Ñ|ç|Ç|á|é|í|ó|ú|Á|É|Í|Ó|Ú|ü|Ü|-|\s){6,50}$/.test(TxtElem.value)))
        {            
            RegularExpressionElem.style.visibility = 'visible';            
        }
        else
        {
            RegularExpressionElem.style.visibility = 'hidden';
        }
    }
}

function ValidarTextosSE(elem)
{
    var DatosValidos = false;
        
    var IdGrid = ConstruirId(elem.id, 'GridServiSelec', 1);
    
    var FilasGrid = $get(IdGrid);

    if (FilasGrid != null)
    {
        for (var i = 0; i < FilasGrid.children[0].children.length; i++)
        {
            var Indice = i + 2;
            
            if (Indice < 10)
            {
                Indice = '0' + Indice;
            }
            
            ValidarTextoSE($get(IdGrid + '_ctl' + Indice + '_TxtTextoAdt'));        
        }
        
        var BtnSel = $get(ConstruirId(elem.id, 'BtnHiddenPopup', 1));
        
        if (BtnSel.value == '')
        {
            DatosValidos = true;
        }
    }
    else
    {
        DatosValidos = true;
    }
        
    return DatosValidos;
}

function ValidarTextoSE(elem)
{
    var Error = false;

    if (elem.value != '')
    {
        elem.value = elem.value.toUpperCase();
        
        Error = ValidarTextoAsoc(elem.value);
    }
    else
    {
        if (!elem.disabled)
        {
            Error = true;
        }
    }
    
    var ListId = elem.id.split('_');
    var indice = ListId[ListId.length - 2].substring(3);
    
    if (Error)
    {
        GuardarIdErrorSE(elem.id, indice);
        
        elem.style['background'] = '#FFFFCC';
        
        if (event.type == 'blur')
        {
            elem.focus();
        }
    }
    else
    {
        EliminarIdErrorSE(elem.id, indice);
        
        elem.style['background'] = '#FFFFFF';
        
        if (event.type == 'blur')
        {
            $get(ConstruirId(elem.id, 'BtnAceptar', 3)).focus();
        }
    }
}

function ValidarTextoAsoc(texto)
{
    var Error = true;

    if (/^([A-Z]|[0-9]){1,50}$/.test(jsTrimAll(texto)))
    {
        Error = false;
    }
    
    return Error;
}

function GuardarIdErrorSE(parentId, indice)
{
    var BtnSel = $get(ConstruirId(parentId, 'BtnHiddenPopup', 3));
    
    if (BtnSel.value == '')
    {
        BtnSel.value = indice;
        
        var DvError = $get('DvErrorTextoSE');
        DvError.style['display'] = 'block';
    }
    else
    {
        var NoExiste = true;
        var ValoresSel = BtnSel.value.split(';');
        
        for (var i = 0; i < ValoresSel.length && NoExiste; i++)
        {
            if (ValoresSel[i] == indice)
            {
                NoExiste = false;
            }
        }
        
        if (NoExiste)
        {
            BtnSel.value += ';' + indice;
        }
    }
}

function EliminarIdErrorSE(parentId, indice)
{
    var BtnSel = $get(ConstruirId(parentId, 'BtnHiddenPopup', 3));

    if (BtnSel.value != '')
    {
        var ValoresSel = BtnSel.value.split(';');
        
        if (ValoresSel.length == 1)
        {
            if (ValoresSel[0] == indice)
            {
                BtnSel.value = '';
                
                var DvError = $get('DvErrorTextoSE');
                DvError.style['display'] = 'none';
            }
        }
        else
        {
            var ListIndices = '';
        
            for (var i = 0; i < ValoresSel.length; i++)
            {
                if (ValoresSel[i] != indice)
                {
                    ListIndices += ';' + ValoresSel[i];
                }
            }
            
            BtnSel.value = ListIndices.substring(1);
        }
    }   
}