<?php
wp_enqueue_style('wp-iv_directories-style-11', wp_iv_directories_URLPATH . 'admin/files/css/iv-bootstrap.css');
wp_enqueue_style('wp-iv_directories-style-12', wp_iv_directories_URLPATH . 'admin/files/css/login.css');

?>

<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,600italic,400,700' rel='stylesheet' type='text/css'>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<div id="login-2" class="bootstrap-wrapper login-main">
  <div class="menu-toggler sidebar-toggler"> </div>
  <div class="content"> 
    <!-- BEGIN LOGIN FORM -->
    <form id="login_form" class="login-form" action="" method="post">
      <h3 class="form-title">
        <?php  _e('Sign In','ivdirectories');?>
      </h3>
      <div class="display-hide" id="error_message"> </div>
      <div class="form-group"> 
        <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
        <label class="control-label visible-ie8 visible-ie9">
          <?php  _e('Username','ivdirectories');?>
        </label>
        <input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="<?php  _e('Username','ivdirectories');?>" name="username" id="username"/>
      </div>
      <div class="form-group">
        <label class="control-label visible-ie8 visible-ie9">
          <?php  _e('Password','ivdirectories');?>
        </label>
        <input class="form-control form-control-solid placeholder-no-fix" type="password" autocomplete="off" placeholder="<?php  _e('Password','ivdirectories');?>" name="password" id="password"/>
      </div>
      <div class="form-actions row">
        <div class="col-md-6">
          <button type="button" class="btn uppercase pull-left" onclick="return chack_login();" >
          <?php  _e('Login','ivdirectories');?>
          </button>
        </div>
        
        <!--
        <p class="pull-left  margin-20 para col-md-6 text-right">
          <input type="checkbox" id="test2" checked="checked" />
          <label for="test2">
            <?php  _e('Remember','ivdirectories');?>
          </label>
        </p>
        -->
        <div class="col-md-6 pull-right">
			<p class="pull-right para  text-right"> <a href="javascript:;" class="forgot-link">
			  <?php  _e('Forgot Password?','ivdirectories');?>
			  </a> 
			</p>
          </div>
      </div>
      <div class="create-account">
        <p>
          <?php
			$iv_redirect = get_option( '_iv_directories_price_table');
			$reg_page= get_permalink( $iv_redirect); 
			?>
          <a  href="<?php echo $reg_page;?>" id="register-btn" class="uppercase">
          <?php  _e('Create an account','ivdirectories');?>
          </a> </p>
      </div>
    </form>
    <!-- END LOGIN FORM --> 
    <!-- BEGIN FORGOT PASSWORD FORM -->
    <form id="forget-password" name="forget-password" class="forget-form" action="" method="post" >
      <h3>
        <?php  _e('Forget Password ?','ivdirectories');?>
      </h3>
      <div id="forget_message">
        <p>
          <?php  _e('Enter your e-mail address','ivdirectories');?>
        </p>
      </div>
      <div class="form-group">
        <input class="form-control form-control-solid placeholder-no-fix" type="text"  placeholder="<?php  _e('Email','ivdirectories');?>" name="forget_email" id="forget_email"/>
      </div>
      <div class="">
        <button type="button" id="back-btn" class="btn btn-default uppercase margin-b-30">
        <?php  _e('Back','ivdirectories');?>
        </button>
        <button type="button" onclick="return forget_pass();"  class="btn btn-success uppercase pull-right margin-b-30">
        <?php  _e('Submit','ivdirectories');?>
        </button>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
		function  forget_pass(){
				
			var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
			var loader_image = "<img src='<?php echo wp_iv_directories_URLPATH. 'admin/files/images/loader.gif'; ?>'/>";
				jQuery('#forget_message').html(loader_image);
				var search_params={
					"action"  : 	"iv_directories_forget_password",	
					"form_data":	jQuery("#forget-password").serialize(), 
				};
				var femail = jQuery('#forget_email').val();
				
				if( femail!="" ){
				jQuery.ajax({					
					url : ajaxurl,					 
					dataType : "json",
					type : "post",
					data : search_params,
					success : function(response){
						if(response.code=='success'){
							// redirect							
							jQuery('#forget_message').html('<div class="alert alert-success alert-dismissable"><a class="panel-close close" data-dismiss="alert">x</a>Password Sent. Please check your email. </div>' );
						}else{
							jQuery('#forget_message').html('<div class="alert alert-info alert-dismissable"><a class="panel-close close" data-dismiss="alert">x</a>'+response.msg+'</div>' );
						}
						
						
					}
				});
			}else{
				jQuery('#forget_message').html('<div class="alert alert-info alert-dismissable"><a class="panel-close close" data-dismiss="alert">x</a><?php  _e('Enter Email Address','ivdirectories');?></div>' );
			}	
	}
	function  chack_login(){
				
			var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
			var loader_image = "<img src='<?php echo wp_iv_directories_URLPATH. 'admin/files/images/loader.gif'; ?>'/>";
				jQuery('#error_message').html(loader_image);
				var search_params={
					"action"  : 	"iv_directories_check_login",	
					"form_data":	jQuery("#login_form").serialize(), 
				};
				var username = jQuery('#username').val();
				var password = jQuery('#password').val();
				if( password!="" && username!=""){
				jQuery.ajax({					
					url : ajaxurl,					 
					dataType : "json",
					type : "post",
					data : search_params,
					success : function(response){
						if(response.code=='success'){
							// redirect							
							window.location.href = response.msg;
						}else{
							jQuery('#error_message').html('<div class="alert alert-info alert-dismissable"><a class="panel-close close" data-dismiss="alert">x</a><?php  _e('Invalid Username & Password','ivdirectories');?> </div>' );
						}
						
						
					}
				});
			}else{
				jQuery('#error_message').html('<div class="alert alert-info alert-dismissable"><a class="panel-close close" data-dismiss="alert">x</a><?php  _e('Enter Username & Password','ivdirectories');?> </div>' );
			}	
	}	
    (function($){
        $(document).ready(function(){
            $('.forgot-link').on('click',function(){
                $("#login_form").hide();
                $("#forget-password").show();
            });
             $('#back-btn').on('click',function(){
                $("#login_form").show();
                $("#forget-password").hide();
            });
        });
    }(jQuery));
    
	
	jQuery("#password").keypress(function(e) {
		if(e.which == 13) {
			chack_login();
		
		}
	});
    jQuery("#forget_email").keypress(function(e) {
		if(e.which == 13) { 
		forget_pass();
		
		}
	});
	jQuery(document).ready(function () {
		jQuery("#forget-password").submit(function(e){
			e.preventDefault();
		});
	});	
	
    </script> 
