﻿
/*********************************  CUGenerales.js ********************************/
var DenInicio = 'MasterPagina_CPHContenido_'

function ValidarLogon()
{  
    var TxtNombre = document.getElementById(DenInicio + 'Logon_TxtNombre')
    var TxtApellidoUno = document.getElementById(DenInicio + 'Logon_TxtApellidoUno')
    var TxtApellidoDos = document.getElementById(DenInicio + 'Logon_TxtApellidoDos')
    var TxtEmail = document.getElementById(DenInicio + 'Logon_TxtEmail')
    
    var ContenidoTxtNombre = trim(TxtNombre.value)
    var ContenidoTxtApellidoUno = trim(TxtApellidoUno.value)
    var ContenidoTxtApellidoDos = trim(TxtApellidoDos.value)
    var ContenidoTxtEmail = trim(TxtEmail.value)
   
    var lblAsteriscoNombre = document.getElementById(DenInicio + 'Logon_AstNombre')
    var lblAsteriscoApellidoUno = document.getElementById(DenInicio + 'Logon_AstApellidoUno')
    var lblAsteriscoApellidoDos = document.getElementById(DenInicio + 'Logon_AstApellidoDos')
    var lblAsteriscoEmail = document.getElementById(DenInicio + 'Logon_AstEmail')
    
    var VacioNombre=false
    var VacioApellidoUno=false
    var VacioApellidoDos=false
    var ErrorEmail = false
    
    lblAsteriscoNombre.style.display='none'
    lblAsteriscoApellidoUno.style.display='none'
    lblAsteriscoApellidoDos.style.display='none'
    lblAsteriscoEmail.style.display='none' 
 
    if(ContenidoTxtNombre==''){
        lblAsteriscoNombre.style.display='inline'
        VacioNombre=true
        TxtNombre.style.backgroundColor = '#FF7777'
    }
    if(ContenidoTxtApellidoUno==''){
        lblAsteriscoApellidoUno.style.display='inline'
        VacioApellidoUno=true
        TxtApellidoUno.style.backgroundColor = '#FF7777'
    }
    if(ContenidoTxtApellidoDos==''){
        lblAsteriscoApellidoDos.style.display='inline'
        VacioApellidoDos=true
        TxtApellidoDos.style.backgroundColor = '#FF7777'
    }
    
    if ((VacioNombre==true) || (VacioApellidoUno==true) || (VacioApellidoDos==true)){
        document.getElementById(DenInicio + 'Logon_LblError').innerHTML='<span style="color: #333;">Izen Abizenak bete behar dira</span> Se deben rellenar Nombre y Apellidos'
        return false
    }
    
    if(ComprobarEmail(ContenidoTxtEmail)==false){
        lblAsteriscoEmail.style.display='inline'
        document.getElementById(DenInicio + 'Logon_LblError').innerHTML='<span style="color: #333;">Emaila ez da zuzena</span> Email no es correcto'
        return false
    }
  
    return true
}
function ComprobarEmail(valor)
{
    var s = valor;
    var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    var filter2=/^[A-Za-z][A-Za-z0-9_]*.[A-Za-z][A-Za-z0-9_]+@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    if (s.length == 0 ){
        return true;
    } 
    if (filter.test(s)){
        return true;
    } 
    if (filter2.test(s)){
        return true;
    }  
    return false
}

function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}


function AbrirMenu(NumMenu)
{
    var PnlMensajeAdheridos = document.getElementById(DenInicio + 'PnlMensajeAdheridos')
    PnlMensajeAdheridos.style.display = 'none'
    
    var PnlContenidoInicio = document.getElementById(DenInicio + 'PnlContenidoInicio')
    PnlContenidoInicio.style.display = 'none'
    
    var PnlContenedorLogon = document.getElementById(DenInicio + 'PnlContenedorLogon')
    PnlContenedorLogon.style.display = 'none'
    
    var PnlAdheridos= document.getElementById(DenInicio + 'PnlAdheridos')
    PnlAdheridos.style.display = 'none'
    
    var PnlGaleriaImagenes = document.getElementById(DenInicio + 'PnlGaleriaImagenes')
    PnlGaleriaImagenes.style.display = 'none'
    
    
    var ImgManifiesto = document.getElementById('MasterPagina_EncabezadoSuperior_ImgManifiesto')
    ImgManifiesto.style.visibility = 'hidden'
    var ImgUnete = document.getElementById('MasterPagina_EncabezadoSuperior_ImgUnete')
    ImgUnete.style.visibility = 'hidden'
    var ImgAdheridos = document.getElementById('MasterPagina_EncabezadoSuperior_ImgAdheridos')
    ImgAdheridos.style.visibility = 'hidden'
    var ImgGaleria = document.getElementById('MasterPagina_EncabezadoSuperior_ImgGaleria')
    ImgGaleria.style.visibility = 'hidden'
    
    switch(NumMenu)
        {
            case 0:
                PnlContenidoInicio.style.display = 'block'
                ImgManifiesto.style.visibility = 'visible'
            break
            
            case 1:
                PnlContenedorLogon.style.display = 'block'
                ImgUnete.style.visibility = 'visible'
            break
            
            case 2:
                PnlAdheridos.style.display = 'block'  
                ImgAdheridos.style.visibility = 'visible'          
            break
            
            case 3:            
                PnlGaleriaImagenes.style.display = 'block'
                ImgGaleria.style.visibility = 'visible'
            break

        }   
    return false 
}

/*************************************Empieza ListadoPaginado.ascx***************************************************/

  function MostrarCalendarioPaginacion(txtboxID,textbox)
    {
        var DenInicio = textbox.id.substring(0, textbox.id.lastIndexOf("_")+1)
        
        XCalendario = event.clientX - event.offsetX
        YCalendario = event.clientY - event.offsetY + textbox.offsetHeight
      
        document.getElementById(DenInicio + "pnlCalendarioBuscador").style.left = XCalendario
        document.getElementById(DenInicio + "pnlCalendarioBuscador").style.top = YCalendario
        document.getElementById(DenInicio + "pnlCalendarioBuscador").style.position ='absolute'
        
        calendario = document.getElementById(DenInicio + "pnlCalendarioBuscador")
       
        if ((calendario.style.display=='none')||(txtboxID!=txtboxAnterior)) 
        {
            calendario.style.display ='block'
        }
        else if (calendario.style.display=='block')
        {
            calendario.style.display ='none'
        }
        txtboxAnterior=txtboxID
        document.getElementById(DenInicio + "cTxtCalendario").value=txtboxID
        document.getElementById(DenInicio + "cPosicionAbsolutaCalendario").value = XCalendario + "#" + YCalendario
    }
    
    function CambioEstiloLinkPanel(ObjetoSeleccionado, Accion)
    {
        var EstiloPanelLinkTxt
        if (Accion == 0)
        {
            EstiloPanelLinkTxt = 'EstiloPanelLinkTxt'
        }
        else if (Accion == 1)
        {
            EstiloPanelLinkTxt = 'EstiloPanelLinkTxtSel'
        }
        //Buscar el 'PanelLinkTxt' para asignarle el Estilo
        document.getElementById(ObjetoSeleccionado.id.replace('LinkPanelNivelUno', 'PanelLinkTxt')).className = EstiloPanelLinkTxt        
    }
    
    function VisualizarBotonConfirmar(ObjetoPulsado, Confirmacion, Publicar)
    {
        var ObjetoBtnConfirmar
        var cConfirmar
        var IdcInicio = ObjetoPulsado.id.substring(0, ObjetoPulsado.id.lastIndexOf("_") + 1)
        var IdcConfirmar = IdcInicio + 'cConfirmar'
        cConfirmar = document.getElementById(IdcConfirmar)            
        cConfirmar.value = Confirmacion
        
        var cPublicar
        var IdcPublicar = IdcInicio + 'cPublicar'
        cPublicar = document.getElementById(IdcPublicar)            
        cPublicar.value = Publicar
        
        switch(Confirmacion)
        {
            case 0:
                //Boton Confirmar para Publicar
                ObjetoBtnConfirmar = document.getElementById(ObjetoPulsado.id.replace('BtnPublicar','BtnConfirmar'))
                switch(Publicar)
                {
                    case 0:
                        ObjetoBtnConfirmar.innerText = 'Confirmar Despublicar'
                    break
                    case 1:
                        ObjetoBtnConfirmar.innerText = 'Confirmar Publicar'
                    break
                }
                    
            break
            
            case 1:
                //Boton Confirmar para Eliminar
                ObjetoBtnConfirmar = document.getElementById(ObjetoPulsado.id.replace('BtnEliminar','BtnConfirmar'))
                ObjetoBtnConfirmar.innerText = 'Confirmar Eliminar'          
            break
        }  
        
        VisibilidaBtnConfirmar = ObjetoBtnConfirmar.style.visibility  
       
        if (VisibilidaBtnConfirmar == 'hidden')
        {
            ObjetoBtnConfirmar.style.visibility = 'visible'
        }
        else if (VisibilidaBtnConfirmar == 'visible')
        {
            ObjetoBtnConfirmar.style.visibility = 'hidden'
        }
        return false
    }
/*************************************Finaliza ListadoPaginado.ascx***************************************************/
