<?php
if($this->dx_auth->is_logged_in()){
    redirect("ctMain");
    die();
}

$form_attributes = array('class' => 'form', 'id' => 'frm_login', 'name' => 'frm_login');

$username = array(
    'name' => 'username',
    'id' => 'username',
    'size' => 25,
    'value' => set_value('username'),
    'autocomplete' => 'off',
    'onfocus' => 'nextfield =\'password\''  
);

$password = array(
    'name' => 'password',
    'id' => 'password',
    'size' => 25,
    'onfocus' => 'nextfield =\'submitBtn\''
);

$confirmation_code = array(
    'name' => 'captcha',
    'id' => 'captcha',
    'maxlength' => 8,
    'class' => "inputField",
    'autocomplete' => "off"
);

?>
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>

    <title>Login :: PT EDS MANUFACTURING INDONESIA</title>
    
    <!--[if lte IE 7]>

		<style type="text/css"> body { font-size: 85%; } </style>

	<![endif]-->

    <link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url(); ?>assets/3rdParty/jquery.ui.1.8.0/themes/redmond/jquery-ui.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/default.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/form.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/jquery.inputlimiter.1.0.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/no-script.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/queryLoader.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/3rdParty/fancybox/jquery.fancybox-1.3.4.css"/>
    <link rel="icon" type="image/png" href="<?php echo base_url(); ?>assets/images/favicon.png" />
    <!--[if IE]>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/excanvas.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href='<?php echo base_url(); ?>assets/css/jquery.messi.min.css' />
    
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery-1.6.2.min.js"></script>
    
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery-ui-latest.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jQuery-noConflict.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery.inputlimiter.1.2.1.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery.queryloader2.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/on_keypress.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/no-script.js"></script>
    
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/3rdParty/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery.messi.min.js"></script>
    
    <script type="text/javascript">

        var nextfield = "username";
        var baseUrl = "<?php echo base_url(); ?>";
        var frm = "frm_login";
        var loading = '<img src="<?php echo base_url(); ?>assets/images/loading.gif" alt="." title="."  style="vertical-align: middle;"/>&nbsp;<span> loading</span>';
        var defaultText = '<span style="font-weight: bold; font-style: italic;"> Authorize User Only!</span>';
        var baseUrl = "<?php echo base_url(); ?>"; 
        function checkResolution(reload){
            if(jQuery(window).width() < 975 && jQuery(window).height() < 600){
                new Messi("<br /> Monitor resolution doesn't meet application requirement <strong>(please use monitor with minimum 1024x768px resolution or more)</strong>.<br /><br /> Application will stop for now!.<br /><br />", {title: 'ERROR!',titleClass: 'anim error', modal: true });
                
                jQuery('.messi-closebtn').remove();
                if(reload != 1){
                    jQuery(".ui-dialog").hide();
                } else {
                    setTimeout(function(){ jQuery(".ui-dialog").hide(); }, 500);
                }
                jQuery("body").css("overflow","hidden");
                return false;
            } else {
                jQuery(".messi,.messi-modal").remove();
                jQuery(".ui-dialog").show();
                jQuery("#login-frm").dialog("option", "position", "center");
                return false;
            }
        }
        jQuery(document).ready(function () {
            checkResolution(1);
            jQuery(window).bind('resize', function () { checkResolution(0); });
            
            <?php if($this->session->flashdata('sess_expired') != '' ){ echo " new Messi('<br /> Please (re)Login to continue!', {title: 'SESSION EXPIRE',titleClass: 'anim info', modal: true, buttons: [{id: 0, label: 'Ok', val: 'Y'}], callback: function(val) {   }});"; } ?>
            jQuery("body").queryLoader2();
            jQuery("#username").inputlimiter({limit:12, limitTextShow:false});

            jQuery("#captchaTrigger").fancybox({
                'width':600,
                'height':400,
                'titleShow':true,
                'enableEscapeButton':false,
                'titlePosition':'inside',
                'showCloseButton':false,
                'hideOnOverlayClick':false
            });
            
            
            jQuery("#login-frm").dialog({ 
    			title:		'Login'
    		,	width:		500
    		,	height:		252
    		,	autoOpen:	true   
            ,   closeOnEscape:	false 		
    		,	modal:		true
            ,   open:       function(event, ui) {
                    jQuery(this).parent().children().children(".ui-dialog-titlebar-close").hide();
                    jQuery(this).parent().css('opacity', 0.6);
                    jQuery(this).parent().children().children(".ui-dialog-titlebar-close").hide();
                    jQuery(this).parent().hover( function () {
                        jQuery(this).css('opacity', 0.9);
                    }, function (event) {
                        jQuery(this).css('opacity', 0.6);
                    });
            }
    		});
            jQuery("#login-frm").dialog({ resizable: false });

            <?php if($show_captcha){ ?>
            jQuery("#captcha-container").html('<?php echo $this->dx_auth->get_captcha_image();?>');
            jQuery('#captchaTrigger').trigger('click');
            jQuery('#captcha').val('');
            
            <?php } ?>


            jQuery("#username, #password").bind("keypress", function (evt) {
                var charCode = evt.which;

                if (charCode <= 13) {
                    return true;
                }
                else {
                    var keyChar = String.fromCharCode(charCode);
                    var re = /[0-9a-zA-Z_-]/;  
                    return re.test(keyChar);
                }
            });


            jQuery("#submitBtn").click(function () {

                jQuery("#status").html('');
                jQuery("#status").html(loading);

                if (jQuery('input[name=username]').val() == '' || jQuery('input[name=password]').val() == '') {
                    alert("Please Fill In Username and Password");
                    jQuery("#status").html('');
                    jQuery("#status").html(defaultText);
                    return false;
                } else {
                    jQuery.ajax({
                        type:"POST",
                        dataType:'json',
                        url:"<?= base_url() ?>ctAuth/login",
                        data:"username=" + jQuery('#username').val() + '&password=' + jQuery('#password').val()
                    }).done(function (res) {


                            if (res.error == 0) {
                                //alert("Login Success");
                                window.location= baseUrl + "ctMain";
                            } else if (res.type > 0) {

                                if (res.type == 1) {
                                    alert(res.msg);
                                    
                                } else if (res.type == 2) {
                                    jQuery("#captcha-container").html(res.data.image);
                                    jQuery('#captcha').val('');
                                    jQuery('#captchaTrigger').trigger('click');

                                } else {
                                    alert("505");
                                }
                            } else {
                                alert("505.");
                            }
                            jQuery("#status").html('');
                            jQuery("#status").html(defaultText);

                        });
                    return false;
                }
                return false;
            });

            jQuery("#captchaBtn").click(function () {
                    jQuery("#captcha-button-container").addClass("hidden-1px");
                    jQuery("#captcha-loader").removeClass("hidden-1px");

                    jQuery.ajax({
                        type:"POST",
                        dataType:'json',
                        url:baseUrl + "ctAuth/captchaCheck",
                        data:"captcha=" + jQuery('#captcha').val()
                    }).done(function (res) {
    
                            if (res.error == 0) {
                                jQuery.fancybox.close();
                            } else if (res.type > 0) {

                                if (res.type == 1) {
                                    alert(res.msg);
                                    jQuery("#captcha-container").html(res.data.image);
                                    jQuery('#captcha').val('');
                                    jQuery('#captchaTrigger').trigger('click');
                                } else if (res.type == 2) {
                                    alert(res.msg);
                                    jQuery("#captcha-container").html(res.data.image);
                                    jQuery('#captcha').val('');
                                    jQuery('#captchaTrigger').trigger('click');

                                } else {
                                    alert("505");
                                }
                            } else {
                                alert("505.");
                            }
                            jQuery("#captcha-loader").addClass("hidden-1px");
                            jQuery("#captcha-button-container").removeClass("hidden-1px");

                    });
                return false;
            });
        });

        
    </script>

</head>
<body>
<div id='isScript'><p class="alert">Javascript is currently not supported/disabled by this browser. Please enable
    JavaScript for full functionality.</p></div>
<div id='content'>
    <a href="#inline1" id="captchaTrigger" style="visibility: hidden;"></a>

    <div id='noscript' class="remAlert">
        <div id="login-frm" class="hidden">
            <div>
                  
                <div id="status" class="visible"><span style="font-weight: bold; font-style: italic;"> Authorize User Only!</span></div>

				 <div  style="position:absolute;left:220px" > 
					<br /><img  src="<?php echo base_url(); ?>assets/images/yazaki_logo1.png" height="120" width="200" />
				</div>
                <?php echo form_open('ctAuth/login', $form_attributes);?>


                    
                            <?php echo form_label('Username', $username['id']);?><br />
                            <?php echo form_input($username)?>
                            <?php echo form_error($username['name']); ?>
                            <br />        
                            <?php echo form_label('Password', $password['id']);?><br />
                            <?php echo form_password($password)?>
                            <?php echo form_error($password['name']); ?>
                            <br />
                            <br />
                            <br />
                    
                <input type="button" id="submitBtn" name="submitBtn" value="Login" onfocus="nextfield ='done'"/> &nbsp;
                <input type="reset" id="resetBtn" name="resetBtn" value="Reset"/>


                <div id="result"></div>
                <div style="display: none;">
                    <div id="inline1" style="overflow:auto;">
                        <span id="captcha-title" class="alert">You have exceeded maximum login failure!</span>
                        <hr />
                        <span id="captcha-container"></span>
                        <hr/>
                        <?php echo form_label('Please Enter The Code', $confirmation_code['id']);?>
                        <?php echo form_input($confirmation_code)?>
                        <span id="captcha-button-container"><input type="button" id="captchaBtn" name="captchaBtn" value="submit" /></span>
                        <span id="captcha-loader" class="hidden-1px" style="border:1px solid #ffd324; padding: 5px;"><img src="<?php echo base_url(); ?>assets/images/load.gif" alt="Loading..." title="Loading" style="vertical-align: middle;" />&nbsp;<span> loading</span></span>
                    </div>
                </div>
                <?php echo form_close()?>
            </div>

        </div>
    </div>
</div>

<script>

    jQuery(document).ready(function () {
        jQuery('#isScript').addClass('remAlert');
        jQuery('#noscript').addClass('noAlert');
        setTimeout("jQuery('#username').focus();jQuery('#login-frm').attr('class', 'visible');", 1000);

    });
</script>

</body>
</html>