 $j(document).ready(function(){
    // text mail
    $j('#txtEmail').live('focusin focusout', function(event) {
        if (event.type == 'focusin') {
            if($j(this).val() == 'E-mail'){$j(this).val('');}
        } else {
            if($j(this).val() == ''){$j(this).val('E-mail');}

        }
    });
    
    // passsword in
    $j("#txtPassword").live('focusin',function(){
        if($j(this).val() == 'Contraseña'){
            $j(this).val('');
        }
    });

    // password out
    $j("#txtPassword").live('focusout',function(){
        if($j(this).val() == ''){
            $j(this).val('Contraseña');
        }
    });

    // olvido contraseña
    // link
    $j('p.pass').live('click', function(){
        var none = $j(this).next().css('display');
        //alert(none);
        if(none == 'none'){
            $j(this).next().css('display','block');
            //alert('IGUAL');
        }else{
            $j(this).next().css('display','none');
           //alert('NO ES IGUAL');
        }
    });
    // text
    $j('.recuperar').live('focusin focusout', function(e){
       if(e.type == 'focusin'){
           if($j(this).val() == 'Escriba su dirección de correo electrónico.'){$j(this).val('');}
       }else{
           if($j(this).val() == ''){$j(this).val('Escriba su dirección de correo electrónico.');}
       }
    });
//
    // registro como empresa 
    $j('p.registro').live('click',function(){
        if($j(this).html() == 'Regístrese como empresa.'  || $j('#sNombre').html() == 'Nombres'){
            $j('#sNombre').html('Empresa');
            $j('#sApellido').html('Razón social');
            $j(this).html('Regístrese como persona natural.');
            $j('#hideTipo').val(3);
            /****/
            var fechaActual = new Date();
            var dia = fechaActual.getDate();
            var mes = fechaActual.getMonth() +1;
            var  anno = fechaActual.getFullYear();
            if (dia <10) dia = "0" + dia;
            if (mes <10) mes = "0" + mes;  
            var fechaHoy = dia + "/" + mes + "/" + anno;
            //alert(fechaHoy);
            /*****/
            $j('#from').val(fechaHoy);
            $j('.fecha_nac').hide();
            //$j('.espec').hide();
        }else{
            $j('#sNombre').html('Nombres');
            $j('#sApellido').html('Apellidos');
            $j(this).html('Regístrese como empresa ó institución.');
            $j('#hideTipo').val(1);
            $j('#from').val('');
            $j('.fecha_nac').show();
            //$j('.espec').show();
        }
    });
//
    // recuperar contraseña
    $j('.btn-recuperar').click(function(){
        var mail = $j('.recuperar').val();
        $j.ajax({
            type:   'POST',
            url:    'controller/recuperar_password.php',
            data:   'mail='+mail,
            success: function(datos){
                $j('.btn-recuperar').after(datos);
            }
        });
    });
    /*****************************************************************************************************************/
        $j( "#from" ).datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange: '1912:1995',
            numberOfMonths: 1,
            dateFormat: 'dd/mm/yy'
        });
        $j.datepicker.regional['es'] = {
                closeText: 'Cerrar',
                prevText: '&#x3c;Ant',
                nextText: 'Sig&#x3e;',
                currentText: 'Hoy',
                monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
                'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
                monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
                'Jul','Ago','Sep','Oct','Nov','Dic'],
                dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
                dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
                dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
                weekHeader: 'Sm',
                dateFormat: 'dd/mm/yy',
                firstDay: 1,
                isRTL: false,
                showMonthAfterYear: false,
                yearSuffix: ''};
        $j.datepicker.setDefaults($j.datepicker.regional['es']);
    /*****************************************************************************************************************/
    /*
     *  Otra Especialidad
     *  funciona cuando se selecciona otra en el combobox de especialidades
     *  mostrara un text para ingresar otra especialidad
     */
     var cboEspecialidad = $j('#cboEspecialidad');
     cboEspecialidad.change(function(){
        // borro campo otra especialidad si existe
        $j('.espe-otra').remove();
        // si especialidad es igual a 0 (otra)
        var html = null;
        if(cboEspecialidad.val() == 'Otra'){
            // html para el campo
            html = '<tr class="espe-otra"><td>Especifique especialidad:</td>';
            html+= '<td><input class=":required"  type="text" name="espe-otra" style="width: 210px;" /></td></tr>';
            // agreganco html
            cboEspecialidad.parent().parent().after(html);
        }
     });
     // end otra especialidad
 });
//
 function fnEnviar(){
     var val_fecha = $j('#from').val();
     if(val_fecha==''){
           alert('Fecha de Nacimiento es necesario');
           return false;
     }
     $j('#loading').css('display','block');
     $j.ajax({
         type: 'POST',
         url: 'view/seccion/terminos_condiciones2.php',
         success: function(datos){
             $j('#loading').css('display','none');
             $j.modal(datos);
         }
     });
     return false;
 }

 function fnSend(){
     $j('.register').submit();
 }
 
 function solonumeros(evt){
        var nav4 = window.Event ? true : false;
        var key = nav4 ? evt.which : evt.keyCode;
        return (key <= 13 || (key >= 48 && key <= 57) || key == 44);
 }
