﻿      function pageLoad() {
            var cc = document.URL.split('#');
            var myUrl = cc[0].toLowerCase();
            var url = myUrl.split('/');
            var idCursos = url[url.length - 1];
            
            if (IsNumeric(idCursos) == false) {
                idCursos = null;
            }

            if (myUrl.indexOf('/cursos/') > -1) {
                document.getElementById('ctl00_CP_UCLMBL_pnlControl').style.display = 'none';
                document.getElementById('ctl00_CP_UCLMBL_pnlCargando').style.display = '';
                Sys.Net.WebServiceProxy.invoke(ApplicationUrlBase + '/UserControlHome/WSExtranetLocal.asmx', 'spCursosBusquedas', false, { 'IDCursos': idCursos }, ResultLoMasBuscado, OnFailed, 'User Context', 1000000);
                if (document.getElementById('controlCursosSimilares') != null) {
                    document.getElementById('controlCursosSimilares').style.display = 'none';
                    document.getElementById('ctl00_CP_UCTFC_DataListTop5Cursos_pnlCargandoCS').style.display = '';
                    Sys.Net.WebServiceProxy.invoke(ApplicationUrlBase + '/UserControlHome/WSExtranetLocal.asmx', 'spCursosRel', false, { 'idCursos': idCursos }, ResultCursosSimilares, OnFailed, 'User Context', 1000000);
                }
                document.getElementById('ControlTematicasRelacionadas').style.display = 'none';
                document.getElementById('ctl00_CP_UCTR_pnlCargandoTR').style.display = '';
                Sys.Net.WebServiceProxy.invoke(ApplicationUrlBase + '/UserControlHome/WSExtranetLocal.asmx', 'spCursosTematicasRel', false, { 'IdCursos': idCursos }, ResultTematicasSimilares, OnFailed, 'User Context', 1000000);
            }


        }

        function ResultLoMasBuscado(result) {
            document.getElementById('ctl00_CP_UCLMBL_pnlControl').style.display = '';
            document.getElementById('ctl00_CP_UCLMBL_pnlCargando').style.display = 'none';
            bndData(result);

        }

        function bndData(result) {
            var constanteNombre = 'busqueda';
            for (var i = 0; i < result.length; i++) {

                var nombre = constanteNombre + i;
                var myLink = document.getElementById(nombre);
                myLink.setAttribute('href', result[i].Url);
                myLink.setAttribute('title', 'Busqueda de ' + result[i].Terminos);
                myLink.innerHTML = result[i].Terminos;
            }

        }


        function ResultCursosSimilares(result) {
            document.getElementById('controlCursosSimilares').style.display = '';
            document.getElementById('ctl00_CP_UCTFC_DataListTop5Cursos_pnlCargandoCS').style.display = 'none';
            if (result.length > 0) {
                bindCursosSimilares(result);
            }
            else {
                document.getElementById('controlCursosSimilares').style.display = 'none';
            }


        }

        function bindCursosSimilares(result) {
            var constanteNombre = 'ctl00_CP_UCTFC_DataListTop5Cursos_hhIdCursos';
            for (var i = 0; i < result.length; i++) {
                var z = i + 1;
                var nombrehh = constanteNombre + z;
                var nombreLinkTitulo = 'lnkIdCursos' + z;
                var nombreTitulo = 'lblTituloIdCursos' + z;
                var nombrePrecioHoras = 'lblPrecioIdCursos' + z;
                var nombreLinkMas = 'lnkMasIdCursos' + z;
                var myHH = document.getElementById(nombrehh);
                var myLinkTitulo = document.getElementById(nombreLinkTitulo);
                var myTitulo = document.getElementById(nombreTitulo);
                var myPrecioHoras = document.getElementById(nombrePrecioHoras);
                var myLinkMas = document.getElementById(nombreLinkMas);
                myHH.setAttribute('value', result[i].IdCursos);
                myLinkTitulo.setAttribute('title', result[i].Titulo);
                myLinkTitulo.setAttribute('href', ApplicationRutaCurso + result[i].UrlCurso);
                myTitulo.innerHTML = result[i].Titulo;
                var horas = result[i].Horas;
                var precio = result[i].Precio;
                if ((isdefined(horas) == true) || (horas == null)) {
                    horas = '';
                }
                if ((isdefined(precio) == true) || (precio == null)) {
                    precio = '';
                }
                if ((precio.length > 0) && (IsNumeric(precio) == true)) {
                    precio = formatDecimal(precio) + ' &#8364;';
                }
                if ((horas.length > 0) && (IsNumeric(horas) == true)) {
                    horas = formatDecimal(horas) + ' h';
                }
                if ((precio.length > 0) && (precio != '0')) {
                    if (horas.length > 0) {
                        myPrecioHoras.innerHTML = horas + ' | ' + precio;
                    }
                    else {
                        myPrecioHoras.innerHTML = precio;
                    }

                }
                else {
                    myPrecioHoras.innerHTML = horas;
                }
                myLinkMas.setAttribute('title', result[i].Titulo);
                myLinkMas.setAttribute('href', ApplicationRutaCurso + result[i].UrlCurso);
            }

        }

        function ResultTematicasSimilares(result) {

            document.getElementById('ControlTematicasRelacionadas').style.display = '';
            document.getElementById('ctl00_CP_UCTR_pnlCargandoTR').style.display = 'none';
            bindTematicasRelacionadas(result);
        }

        function bindTematicasRelacionadas(result) {
            var constanteNombre = 'tematica';
            for (var i = 0; i < result.length; i++) {
                var name = constanteNombre + i;
                var myLink = document.getElementById(name);
                myLink.setAttribute('href', result[i].Url);
                myLink.setAttribute('title', 'Tematica ' + result[i].Terminos);
                myLink.innerHTML = result[i].Terminos;

            }
        }


        function OnFailed(Errores) {

        }


        function IsNumeric(sText) {
            var ValidChars = "0123456789.";
            var IsNumber = true;
            var Char;


            for (i = 0; i < sText.length && IsNumber == true; i++) {
                Char = sText.charAt(i);
                if (ValidChars.indexOf(Char) == -1) {
                    IsNumber = false;
                }
            }
            return IsNumber;

        }

        function formatDecimal(text) {
            var cc = text.split('.');
            return cc[0];
        }

        function isdefined(variable) {
            return (typeof (window[variable]) == "undefined") ? false : true;
        }
      
       
       
  
         Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);

         Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);

         Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, args) {

             if (args.get_error() != null) {

                 if (args.get_error().name === 'Sys.WebForms.PageRequestManagerParserErrorException') {
                     args.set_errorHandled(true);
                     //window.location = ApplicationUrlBase + '/HelpTCG.aspx';
                 }
             }
         });

         function redirect(url) {

             window.location = url;

         }


         Sys.Application.add_init(appl_init);
         var controlId;
         var PaisID = EstaticPaisID;
         function InitializeRequest(sender, args) {
             controlId = args.get_postBackElement().id;
         }

         function appl_init() {
             var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();
             pgRegMgr.add_endRequest(EndHandler);

         }

         function validarHtml(origen, args) {

             var cc = args.Value;
             if (cc.indexOf('<') > -1) {
                 args.IsValid = false;
             }
             else if (cc.indexOf('>') > -1) {
                 args.IsValid = false;
             }
             else if (cc.indexOf('http://') > -1) {
                 args.IsValid = false;
             }
             else { args.IsValid = true };
         }

         function EndHandler() {
             afterAsyncPostBack();
         }

         function afterAsyncPostBack() {
             if (controlId == 'ctl00_CP_UCTFC_UCTabFormulario1_btnMatricula') {
                 $find('ModalProcessingSolicitud').hide();
                 //window.open(ApplicationUrlBase + '/Matriculacion.aspx?Matricula=' + IdMatricula, 'Matriculación', 'width=650, height=500, menubar=1, resizable=0');
             }
         }

         var retValueMatricula; var retValue; function showProcessPanel() { var check = $get('ctl00_CP_UCTFC_UCTabFormulario1_chkAcepto').checked; if (Page_ClientValidate('Solicitudes') && check == true) { return $find('ModalProcessingSolicitud').show() } else if (check == false) { alert('Debe aceptar el Aviso Legal y la Política de Protección de Datos') } return false }
         function showProcessPanelMatricula() {
             var check = $get('ctl00_CP_UCTFC_UCTabFormulario1_chkAceptoMatricula').checked;
             if (Page_ClientValidate('Matriculas') && check == true) {
                 $find('ModalProcessingSolicitud').show();
                 return true;
             }
             else if (check == false) {
                 alert('Debe aceptar el Aviso Legal y la Política de Protección de Datos');
                 return false;
             }

         }

         function CargarMultiSolicitudes(idcurso, valor, visible) {
             if (visible == 'True') {
                 Sys.Net.WebServiceProxy.invoke(ApplicationUrlBase + '/UserControlHome/WSExtranetLocal.asmx', 'spgetCursosMultisolicitudes', false, { 'IdCursos': idcurso, 'NumCursos': 3, 'IdPaise': PaisID, 'IdProvincia': valor }, resultMultiSolicitud, OnFailedProvincia, 'User Context', 1000000)
                 document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_UCCursosSolicitudesMultiples_PnlMulti').style.display = 'none';
                 document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_UCCursosSolicitudesMultiples_PnlCargandoMulti').style.display = '';
                 document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_btnSolicitud').disabled = true;
             }
         }

         function resultMultiSolicitud(result) {
             if (result.length > 0) {
                 var myConst = 'ctl00_CP_UCTFC_UCTabFormulario1_UCCursosSolicitudesMultiples_rptCursos_ctl0';
                 for (var i = 0; i < result.length; i++) {
                     var label = myConst + i + '_lblIdCursos';
                     document.getElementById(label).value = result[i].IdCursos;
                     var title = myConst + i + '_HlkTitle';
                     document.getElementById(title).innerHTML = result[i].TituloCurso;
                     document.getElementById(title).href = ApplicationRutaCurso + result[i].UrlCurso;
                     var descripcion = myConst + i + '_descripcion';
                     document.getElementById(descripcion).innerHTML = result[i].Descripcion;
                 }
             }
             document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_UCCursosSolicitudesMultiples_PnlMulti').style.display = '';
             document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_UCCursosSolicitudesMultiples_PnlCargandoMulti').style.display = 'none';
             document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_btnSolicitud').disabled = false;
         }

         function CargaProvincia(valor) {
             PaisID = valor;
             Sys.Net.WebServiceProxy.invoke(ApplicationUrlBase + '/UserControlHome/WSExtranetLocal.asmx', 'GetProvinciaByPaisId', false, { 'id': valor }, resultProvincia, OnFailedProvincia, 'User Context', 1000000)
         }


         function OnFailedProvincia(error) { }
         function resultProvincia(result, eventArgs) {
             var myList = document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_Provincia_id');
             if (myList.type == 'select-one') {
                 myList.options.length = 0;
                 if (result.length > 0) {
                     myList.options.add(new Option('Seleccionar', 0)); for (i = 0; i < result.length; i++) { myList.options.add(new Option(result[i].Provincia, result[i].IdProvincias)) }
                 } else { myList.options.add(new Option('Seleccionar', 1)) }
             }
         }

         function CargarActividades(valor) {
             Sys.Net.WebServiceProxy.invoke(ApplicationUrlBase + '/UserControlHome/WSExtranetLocal.asmx', 'getactividadesByPixel', false, { 'SecorId': valor }, resultActividades, OnFailedActividades, 'User Context', 1000000)
         }

         function OnFailedActividades(error) { }
         function resultActividades(result, eventArgs) {
             var myList = document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_Actividades_id');
             if (myList.type == 'select-one') {
                 myList.options.length = 0;
                 if (result.length > 0) {
                     myList.options.add(new Option('Seleccionar Actividad', 0));
                     for (i = 0; i < result.length; i++) {
                         myList.options.add(new Option(result[i].Descripcion, result[i].IdActividadesTCG))
                     }
                 }
                 else {
                     myList.options.add(new Option('Seleccionar Actividad', 1))
                 }
             }
         }


         function CargaProvinciaMatricula(valor) { Sys.Net.WebServiceProxy.invoke(ApplicationUrlBase + '/UserControlHome/WSExtranetLocal.asmx', 'GetProvinciaByPaisId', false, { 'id': valor }, resultProvinciaMatricula, OnFailedProvinciaMatricula, 'User Context', 1000000) }
         function OnFailedProvinciaMatricula(error) { }
         function resultProvinciaMatricula(result, eventArgs) { var myList = document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_Provincia_matricula_id'); if (myList.type == 'select-one') { myList.options.length = 0; if (result.length > 0) { myList.options.add(new Option('Selecíonar una Provincia', 0)); for (i = 0; i < result.length; i++) { myList.options.add(new Option(result[i].Provincia, result[i].IdProvincias)) } } else { myList.options.add(new Option('Selecíonar una Provincia', 1)) } } }
         function validateCheckBox(controlName) { var control = document.getElementById(controlName); if (control.checked == true) { control.style.borderColor = '#000000'; control.style.borderStyle = 'solid'; control.style.borderWidth = '2px'; control.style.outline = 'solid 2px #000000'; return true } else { control.style.borderColor = '#FF0000'; control.style.borderStyle = 'solid'; control.style.borderWidth = '2px'; control.style.outline = 'solid 2px #FF0000'; return false } }


         function verTemario() {
             var miLabel = document.getElementById('ctl00_CP_UCTFC_UCTemario');
             var miPnl = document.getElementById('ctl00_CP_UCTFC_pnlTemario');
             var lnk = document.getElementById('ctl00_CP_UCTFC_lnkVerMasTemario');
             var lnkOcu = document.getElementById('ctl00_CP_UCTFC_lnkOcultarTemario');
             lnkOcu.style.display = '';
             lnk.style.display = 'none';
             if (miLabel.offsetHeight != null) {
                 miPnl.style.height = (miLabel.offsetHeight + 30) + 'px';
             }
             else {
                 miPnl.style.height = (miLabel.clientHeight + 30) + 'px';
             }
         }

         function OcultarTemario() {
             var miLabel = document.getElementById('ctl00_CP_UCTFC_UCTemario');
             var miPnl = document.getElementById('ctl00_CP_UCTFC_pnlTemario');
             var lnk = document.getElementById('ctl00_CP_UCTFC_lnkVerMasTemario');
             var lnkOcu = document.getElementById('ctl00_CP_UCTFC_lnkOcultarTemario');
             lnkOcu.style.display = 'none';
             lnk.style.display = '';
             miPnl.style.height = '148px';

         }

         function verObjectivos() {
             var miLabel = document.getElementById('ctl00_CP_UCTFC_UCObjectivos');
             var miPnl = document.getElementById('ctl00_CP_UCTFC_pnlObjectivos');
             var lnk = document.getElementById('ctl00_CP_UCTFC_lnkVerMasObjectivos');
             var lnkOcu = document.getElementById('ctl00_CP_UCTFC_lnkOcultarObjectivos');
             lnk.style.display = 'none';
             lnkOcu.style.display = '';
             if (miLabel.offsetHeight != null) {
                 miPnl.style.height = (miLabel.offsetHeight + 30) + 'px';
             }
             else {
                 miPnl.style.height = (miLabel.clientHeight + 30) + 'px';
             }
         }

         function OcultarObjectivos() {
             var miLabel = document.getElementById('ctl00_CP_UCTFC_UCObjectivos');
             var miPnl = document.getElementById('ctl00_CP_UCTFC_pnlObjectivos');
             var lnk = document.getElementById('ctl00_CP_UCTFC_lnkVerMasObjectivos');
             var lnkOcu = document.getElementById('ctl00_CP_UCTFC_lnkOcultarObjectivos');
             lnk.style.display = '';
             lnkOcu.style.display = 'none';
             miPnl.style.height = '148px';

         }

         function disableEnterKey(e) {
             var key;
             var eve = e || window.event;

             if (window.event)
                 key = window.event.keyCode;     //IE
             else
                 key = e.which;     //firefox

             if (key == 13) {
                 eve.cancelBubble = true;
                 eve.returnValue = false;

                 if (eve.stopPropagation) {
                     eve.stopPropagation();
                     eve.preventDefault();
                 }

                 return false;
             }
             else
                 return true;
         }


         function CambiarMatricula() {
             var solicitud = document.getElementById('TablaSolicitud');
             var matricula = document.getElementById('TablaMatricula');
             var Tabsolicitud = document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_tabSolicitud');
             var Tabmatricula = document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_tabMatricula');
             var texto = document.getElementById('TextoLogo');
             texto.innerHTML = 'Matricúlate en este curso';
             solicitud.style.display = 'none';
             matricula.style.display = '';
             Tabmatricula.className = 'tabActivo';
             Tabsolicitud.className = 'tabInactivo';
         }
         function CambiarSolicitud() {
             var solicitud = document.getElementById('TablaSolicitud');
             var matricula = document.getElementById('TablaMatricula');
             var Tabsolicitud = document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_tabSolicitud');
             var Tabmatricula = document.getElementById('ctl00_CP_UCTFC_UCTabFormulario1_tabMatricula');
             var texto = document.getElementById('TextoLogo');
             texto.innerHTML = 'Solicita información gratis al centro';
             solicitud.style.display = '';
             if (matricula != null) {
                 matricula.style.display = 'none';
             }
             if (Tabmatricula != null) {
                 Tabmatricula.className = 'tabInactivo';
             }
             Tabsolicitud.className = 'tabActivo';
         }
