<?php

/*
* @category    Vista Consulta Resultados
* @package     OfiClinic Web
* @author      Jorge Ancizar Galeano Ruiz<desarrollo@ofisalud.com>
* @copyright   2010 Jorge Ancizar Galeano Ruiz
* @version     OfiClinic Web 1.0
* @license     COMERCIAL
* @link        http://www.desarrollo@ofisalud.com
* @country     Colombia
* @telephone   3016398114
*/
?>
<!DOCTYPE html>
<html lang="es" class="no-js">
    <head>
        <meta charset="utf-8">
        <title>.:: MODULO DIGITAL ::.</title>
        <meta name="description" content="Planificador">
        <meta name="author" content="Green TICS">
        <meta name="robots" content="noindex, nofollow">
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0">
        <meta name="robots" content="noindex, nofollow">
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0">
        <link rel="shortcut icon" href="images/favicon-32x32.png">
        <link rel="stylesheet" href="libjq/css/bootstrap.min.css">
        <link rel="stylesheet" href="libjq/css/plugins.css">
        <link rel="stylesheet" href="libjq/css/jquery.gritter.css" >
        <link rel="stylesheet" href="libjq/css/main.css">
        <link rel="stylesheet" href="libjq/chosen/bootstrap-chosen.css">
        <link rel="stylesheet" href="libjq/css/themes/agropartners.css">
        <script src="libjq/js/vendor/modernizr-respond.min.js"></script>
    </head>
    <body style="background-color: rgb(10,73,116); -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;">
    <center>
        <table border="0">
            <tr>
                <td style="background:url(images/bg.png) no-repeat; background-size: 100% 100%;">
                    <table border="0">
                        <tr>
                            <td width="450" height="650"></td>
                            <td width="400" height="650" align="center">
                                <br><br>
                                <form method="post" id="form-login" class="form-horizontal ">
                                    <div class="login-title text-center" style="background: rgb(10,73,116);">
                                        <h1 style="color: whitesmoke;"><strong>MODULO DIGITAL</strong></h1>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-xs-12">
                                            <div class="input-group">
                                                <span class="input-group-addon"><i class="fa fa-user"></i></span>
                                                <input type="text" id="login-codusuario" name="login-codusuario" class="form-control input-lg" placeholder="Por favor ingrese su numero de identificacion">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-xs-12">
                                            <div class="input-group">
                                                <span class="input-group-addon"><i class="gi gi-asterisk"></i></span>
                                                <input type="password" id="login-password" name="login-password" class="form-control input-lg" placeholder="Por favor ingrese su fecha nacimiento AAAAMMDD">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group form-actions">
                                        <div class="col-xs-4">
                                            <input type="hidden" id="task-form" value="login">
                                            </label>
                                        </div>
                                        <div class="col-xs-8 text-right">
                                            <button type="submit" id="btnLogInt" class="btn btn-sm btn-primary"><i class="fa fa-angle-right"></i> Ingresar</button>
                                            <button class="btn btn-sm btn-danger" onclick="window.open('http://www.medicareips.com.co', '_self');"><i class="fa fa-angle-right"></i> Salir</button>
                                        </div>
                                    </div>
                                </form>
                            </td>
                            <td width="100" height="650" align="center"></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </center>
        <script src="libjq/js/vendor/jquery-2.2.1.js"></script>
        <script src="libjq/js/vendor/jquery.gritter.min.js"></script>
        <script src="libjq/js/vendor/bootstrap.min.js"></script>
        <script src="libjq/js/plugins.js"></script>
        <script src="libjq/chosen/chosen.jquery.js"></script>
        <script src="libjq/js/vendor/easy-numbers/autoNumeric-min.js"></script>
        <link href="libjq/js/vendor/jsgrid/jsgrid.min.css" rel="stylesheet" />
        <link href="libjq/js/vendor/jsgrid/jsgrid-theme.min.css" rel="stylesheet" />
        <script src="libjq/js/vendor/jsgrid/jsgrid.min.js"></script>
        <link href="libjq/js/vendor/dropzone/dropzone.min.css" rel="stylesheet" />
        <script src="libjq/js/vendor/dropzone/dropzone.min.js"></script>
        <script src="libjq/js/app.js"></script>
        <script src="libjq/js/tools.js"></script>
        <script>
            $(function(){ 
                sessionStorage.clear();
                sessionStorage.setItem("0","0");
                var Login = function() {
                    var switchView = function(viewHide, viewShow, viewHash){
                        viewHide.slideUp(250);
                        viewShow.slideDown(250, function(){
                            $('input').placeholder();
                        });
                        if ( viewHash ) {
                            window.location = '#' + viewHash;
                        } else {
                            window.location = '#';
                        }
                    };
                    return {
                        init: function() {
                            var formLogin       = $('#form-login'),
                                formReminder    = $('#form-reminder');
                            $('#link-reminder-login').click(function(){
                                switchView(formLogin, formReminder, 'reminder');
                            });
                            $('#link-reminder').click(function(){
                                switchView(formReminder, formLogin, '');
                            });
                            if (window.location.hash === '#reminder') {
                                formLogin.hide();
                                formReminder.show();
                            }
                            jQuery.validator.setDefaults({
                                debug: true,
                                success: "valid"
                            });
                            $('#form-login').validate({
                                debug: true,
                                errorClass: 'help-block animation-slideDown', 
                                errorElement: 'div',
                                errorPlacement: function(error, e) {
                                    e.parents('.form-group > div').append(error);
                                },
                                highlight: function(e) {
                                    $(e).closest('.form-group').removeClass('has-success has-error').addClass('has-error');
                                    $(e).closest('.help-block').remove();
                                },
                                success: function(e) {
                                    e.closest('.form-group').removeClass('has-success has-error');
                                    e.closest('.help-block').remove();
                                },
                                rules: {
                                    'login-codusuario': {
                                        required: true,
                                        maxlength: 20,
                                        minlength: 5
                                    },
                                    'login-password': {
                                        required: true,
                                        number: true,
                                        maxlength: 8,
                                        minlength: 8
                                    }
                                },
                                messages: {
                                    'login-codusuario': {
                                        required: 'Por favor ingrese su numero de identificacion',
                                        minlength: 'Debe tener mínimo 5 caracteres',
                                        maxlength: 'Debe tener máximo 20 caracteres'
                                    },
                                    'login-password': {
                                        required: 'Por favor ingrese su codigo de paciente',
                                        number: 'La fecha de nacimiento debe ser en formato AAAAMMDD',
                                        minlength: 'Debe tener mínimo 8 caracteres',
                                        maxlength: 'Debe tener máximo 8 caracteres'
                                    }
                                }
                            });
                        }
                    };
                }();

                $("#btnLogInt").click(function() {
                    if($('#form-login').valid()){
                        $.ajax({
                            type: "POST",
                            url: "function/controller.php",
                            data: {
                                task: 'login',
                                user: $("#login-codusuario").val(),
                                pass: $("#login-password").val()
                            }, 
                            success: function(data){
                                var response = JSON.parse(data);
                                if(response['success'] === "true"){
                                    sessionStorage.setItem("pPaciente",response['pPaciente']);
                                    sessionStorage.setItem("pCodUsuario",response['pCodUsuario']);
                                    sessionStorage.setItem("pClaveUsuario",response['pClaveUsuario']);
                                    window.open("moduloweb.php", "_self");
                                }else{
                                    jQuery.gritter.add({
                                        title: 'MEDICARE IPS..!',
                                        text: 'El documento y/o fecha de nacimiento son incorrectos, intenta nuevamente.',
                                        class_name: 'growl-danger',
                                        //image: '../../images/logo/hoja.png',
                                        sticky: false,
                                        time: ''
                                    });
                                }
                            }
                        });
                    }
                });
                Login.init();
            });
        </script>
        
    </body>
</html>