<?php  
ob_start();
session_start();
ini_set('display_errors', 0); 



//echo"<pre>";print_r($_COOKIE);
$data = array();
$postvars = http_build_query($data) . "\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ytygroup.app/dms/getServerMaintenaceDetails.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);				
$server_output = curl_exec ($ch);
//echo"<pre>";print_r($server_output);die;
$message=json_decode($server_output);
curl_close ($ch);
$status=$message->data[0]->status;
if($status=='Active') // code for Maintenance page
{
	include '../../db/connection_prdcln.php';

	$li = "SELECT * FROM ytycustom.xxyty_dashboard WHERE dashboard_code IN ('090029', '089986')";
	$lin = oci_parse($dbcon , $li);
	oci_execute($lin);
	$linkArray = array();
	while($link = oci_fetch_array($lin)){
		$linkArray[$link['DASHBOARD_CODE']] = $link['DASHBOARD_LINK'];
	}
	if($_POST['txtUserid1'])
	{
		include '../../db/include-api.php';
		die;
	}
?>
	<!doctype html>
	<html class="no-js" lang="">
	<head>
		<title>YTY SSO  | Login</title>
		<link rel="shortcut icon" type="image/png" href="<?php echo $_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST'];?>/CommonLogo/favicon-icon.png"/>
		<?php include ("include_sso/headercss.php"); ?>

	<link rel="stylesheet" href="/var/www/html/Dashboard/css/bootstrap.min.css">

	<style type="text/css">
		.fxt-otp-layout1 .fxt-form .fxt-form-row .fxt-form-col {
		margin-right: 10px;
		flex-basis: 0;
		flex-grow: 1;

	}
	.fxt-otp-layout1 .fxt-form .form-control {
		text-align: center;
		font-size: 20px;
		min-height: 43px;
		-webkit-box-shadow: none;
		box-shadow: none;
		border: 1px solid #e7e7e7;
		padding: 10px 15px;
		color: #111;
	}
	.fxt-template-layout11 .fxt-form .form-control {
		min-height: 43px;
		-webkit-box-shadow: none;
		box-shadow: none;
		border: 1px solid #e7e7e7;
		padding: 10px 15px;
		color: #111;
	}
	</style>
	</head>

<body>
	<!--[if lt IE 8]>
        <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->
	<section class="fxt-template-animation fxt-template-layout11">
		<div class="container">
			<div class="row align-items-center justify-content-center">
				<div class="col-xl-5 col-lg-6 col-sm-10 col-12 fxt-bg-color">
					<div class="fxt-content">
						<div class="fxt-header">
							<a href="login.php" class="fxt-logo"><img src="img_sso/yty-fitness.png" alt="Logo"></a>
							<p>Welcome to YTY Single Sign On Dashboard  asd
							<?php  print_R($_SERVER)?>

							<!-- 
							<span> 
							<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Something Error
							</span> 
							-->

							<?php
						if($_SESSION['error']){?>
						<span> 
						<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> &nbsp; <?php echo $_SESSION['error'];?>
						</span> 
						  <?php
						}
						unset($_SESSION['error']);
						  ?>

							</p>
						</div>
						<div class="fxt-form">
						<?php  print_R($_SERVER)?>
							
						<!-- Form Start -->	
							<form name="form"  action="" id="form" method="POST" enctype="multipart/form-data">
								<div class="form-group">
									<div class="fxt-transformY-50 fxt-transition-delay-1">
										<input id="txtUserid1" type="text" name="txtUserid1" class="form-control"  placeholder="Employee Id" value="<?php if(isset($_SESSION["txtUserid1"])) { echo $_SESSION["txtUserid1"]; } ?>" onkeyup="return wating(this.value)"  autocomplete="off" onchange="return getEmployeeDetails(document.getElementById('txtUserid').value)" required>
									</div>
									<span id="empList"></span>
								</div>


								<div class="form-group">
									<div class="fxt-transformY-50 fxt-transition-delay-2">
										<input id="txtPassword" type="password" class="form-control" placeholder="Password" value="<?php if(isset($_SESSION["txtPassword"])) { echo $_SESSION["txtPassword"]; } ?>" name="txtPassword" onkeypress="empty()" required>
										
										<i toggle="#password" onclick="passWordShow()" class="fa fa-fw fa-eye toggle-password field-icon"></i>
									</div>

									<script>
									function passWordShow() {
									  var x = document.getElementById("txtPassword");
									  if (x.type === "password") {
									    x.type = "text";
									  } else {
									    x.type = "password";
									  }
									}
									</script>

						<!-- 		<?php
								//if($_SESSION['error']){?>
								<p class="errormsg" style=" color: red; font-size: 16px;"><?php // echo $_SESSION['error'];?></p>
								<?php
								//}
								//unset($_SESSION['error']);
								?>pdf_sso/password_reset_procedure.pdf -->

								</div>
								<div class="form-group">
									<div class="fxt-transformY-50 fxt-transition-delay-3">
										<div class="fxt-checkbox-area">
											<div class="checkbox">
												<input id="checkbox1" type="checkbox">
												<label for="checkbox1">Keep me logged in

											<input type="checkbox" name="remember_me" class="checkboxinput" <?php if(isset($_SESSION["txtUserid"])) { ?> checked <?php } ?>>

                         <span class="checkmark"></span>
												</label>
											</div>

											<a href="http://ytyportal.ytygroup.my/db/connection-maintenance.php"   class="switcher-text" >Forgot Password?</a>

										</div>
									</div>
								</div>
								<div class="form-group">
									

									<div class="fxt-transformY-50 fxt-transition-delay-4">
									<a href="http://ytyportal.ytygroup.my/db/connection-maintenance.php"><button type="submit" id="btnLogin" onclick="return window.location='http://ytyportal.ytygroup.my/db/connection-maintenance.php';" class="fxt-btn-fill"><i class="fas fa-sign-in-alt"></i> Log in</button></a>
									</div>


								</div>
											<!-- <div class="form-group">
											<div class="fxt-transformY-50 fxt-transition-delay-3">
											<div class="fxt-checkbox-area bottompart">
											
											<span style="display:none;" class="switcher-text" id="flip">Problems signing in ?</span>
											
											<span  style="display:none;"><a href="pdf_sso/password_reset_procedure.pdf"  class="switcher-text">Password reset procedure</a></span>
											
											<span>
											<a href="http://ytyportal.ytygroup.my/db/connection-maintenance.php"  class="switcher-text">Oracle Apps</a>
											</span>
											<span>
												<a href="<?php //echo $linkArray['090029'];?>"  target="_blank" class="switcher-text">OPM System</a>
											</span>
											</div>
											</div>
											</div> -->


									<input name="orgid" type="hidden" id="orgid" value="<?php if(isset($_SESSION["orgid"])) { echo $_SESSION["orgid"]; } ?>" />
									<input id="txtUserid" type="hidden" name="txtUserid" value="<?php if(isset($_SESSION["txtUserid"])) { echo $_SESSION["txtUserid"]; } ?>">
									<input type="hidden" name="email" id="email" value="<?php if(isset($_SESSION["email"])) { echo $_SESSION["email"]; } ?>" />
									<input type="hidden" name="InvalidCode" id="InvalidCode" />
									<input type="hidden" name="hidurl" id="hidurl" value="0" />
									<input type="hidden" name="hiduser" id="hiduser" value="0" />
									<input type="hidden" name="e_short_name" id="e_short_name" />

							</form>

							<!-- Form Ends -->
						</div>						
					</div>
				</div>
			</div>
		</div>
	</section>
<?php 
}
else
{
	include '../../db/connection.php';
	$li = "SELECT * FROM ytycustom.xxyty_dashboard WHERE dashboard_code IN ('090029', '089986')";
	$lin = oci_parse($dbcon , $li);
	oci_execute($lin);
	$linkArray = array();
	while($link = oci_fetch_array($lin)){
		$linkArray[$link['DASHBOARD_CODE']] = $link['DASHBOARD_LINK'];
	}
?>

<!doctype html>
<html class="no-js" lang="">
<head>
    <title>YTY SSO  | Login</title>
<link rel="shortcut icon" type="image/png" href="<?php echo $_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST'];?>/CommonLogo/favicon-icon.png"/>
    <?php include ("include_sso/headercss.php"); ?>

<link rel="stylesheet" href="/var/www/html/Dashboard/css/bootstrap.min.css">

<style type="text/css">
	.fxt-otp-layout1 .fxt-form .fxt-form-row .fxt-form-col {
    margin-right: 10px;
    flex-basis: 0;
    flex-grow: 1;

}
.fxt-otp-layout1 .fxt-form .form-control {
    text-align: center;
    font-size: 20px;
    min-height: 43px;
    -webkit-box-shadow: none;
    box-shadow: none;
    border: 1px solid #e7e7e7;
    padding: 10px 15px;
    color: #111;
}
.fxt-template-layout11 .fxt-form .form-control {
    min-height: 43px;
    -webkit-box-shadow: none;
    box-shadow: none;
    border: 1px solid #e7e7e7;
    padding: 10px 15px;
    color: #111;
}
</style>
</head>

<body>
	<!--[if lt IE 8]>
        <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->
	<section class="fxt-template-animation fxt-template-layout11">
		<div class="container">
			<div class="row align-items-center justify-content-center">
				<div class="col-xl-5 col-lg-6 col-sm-10 col-12 fxt-bg-color">
					<div class="fxt-content">
						<div class="fxt-header">
							<a href="login.php" class="fxt-logo"><img src="img_sso/yty-fitness.png" alt="Logo"></a>
							<p>Welcome to YTY Single Sign On Dashboard 
<?php   
$url="";
if(isset($_SERVER['HTTP_REFERER']) & $_SERVER['HTTP_REFERER']!='')
{
$strArr=explode('?',$_SERVER['HTTP_REFERER']);
$url=$strArr[1];
$url=explode('=',$url);
$url=base64_decode($url[1]);
}else{
	if($_GET['gotourl']!=''){
		$url=base64_decode($_GET['gotourl']);
	}else{
		$url="";
	}
}
?>
							<!-- 
							<span> 
							<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Something Error
							</span> 
							-->

							<?php
						if(isset($_SESSION['error'])){?>
						<span> 
						<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> &nbsp; <?php echo $_SESSION['error'];?>
						</span> 
						  <?php
						}
						unset($_SESSION['error']);
						  ?>

							</p>
						</div>
						<div class="fxt-form">
							
						<!-- Form Start -->	
							<form name="form"  action="logged.php" id="form" method="POST" enctype="multipart/form-data">
							<input type="hidden" value="<?php echo $url; ?>" name="gotourl"/>
								<div class="form-group">
									<div class="fxt-transformY-50 fxt-transition-delay-1">
										<input id="txtUserid1" type="text" name="txtUserid1" class="form-control"  placeholder="Employee Id" value="<?php if(isset($_SESSION["txtUserid1"])) { echo $_SESSION["txtUserid1"]; } ?>" onkeyup="return wating(this.value)"  autocomplete="off" onchange="return getEmployeeDetails(document.getElementById('txtUserid').value)" required>
									</div>
									<span id="empList"></span>
								</div>


								<div class="form-group">
									<div class="fxt-transformY-50 fxt-transition-delay-2">
										<input id="txtPassword" type="password" class="form-control" placeholder="Password" value="<?php if(isset($_SESSION["txtPassword"])) { echo $_SESSION["txtPassword"]; } ?>" name="txtPassword" onkeypress="empty()" required>
										
										<i toggle="#password" onclick="passWordShow()" class="fa fa-fw fa-eye toggle-password field-icon"></i>
									</div>

									<script>
									function passWordShow() {
									  var x = document.getElementById("txtPassword");
									  if (x.type === "password") {
									    x.type = "text";
									  } else {
									    x.type = "password";
									  }
									}
									</script>

						<!-- 		<?php
								//if($_SESSION['error']){?>
								<p class="errormsg" style=" color: red; font-size: 16px;"><?php // echo $_SESSION['error'];?></p>
								<?php
								//}
								//unset($_SESSION['error']);
								?>pdf_sso/password_reset_procedure.pdf -->

								</div>
								<div class="form-group">
									<div class="fxt-transformY-50 fxt-transition-delay-3">
										<div class="fxt-checkbox-area">
											<div class="checkbox">
												<input id="checkbox1" type="checkbox">
												<label for="checkbox1">Keep me logged in

											<input type="checkbox" name="remember_me" class="checkboxinput" <?php if(isset($_SESSION["txtUserid"])) { ?> checked <?php } ?>>

                         <span class="checkmark"></span>
												</label>
											</div>

											<a href="#"  class="switcher-text" onclick='return checkUserId()'>Forgot Password?</a>

										</div>
									</div>
								</div>
								<div class="form-group">
									

									<div class="fxt-transformY-50 fxt-transition-delay-4">
										<button type="submit" id="btnLogin" onclick="return validate();" class="fxt-btn-fill"><i class="fas fa-sign-in-alt"></i> Log in</button>
									</div>


								</div>
											<!-- <div class="form-group">
											<div class="fxt-transformY-50 fxt-transition-delay-3">
											<div class="fxt-checkbox-area bottompart">
											
											<span style="display:none;" class="switcher-text" id="flip">Problems signing in ?</span>
											
											<span  style="display:none;"><a href="pdf_sso/password_reset_procedure.pdf"  class="switcher-text">Password reset procedure</a></span>
											
											<span>
											<a href="<?php //echo $linkArray['089986'];?>" target="_blank" class="switcher-text">Oracle Apps</a>
											</span>
											<span>
												<a href="<?php //echo $linkArray['090029'];?>"  target="_blank" class="switcher-text">OPM System</a>
											</span>
											</div>
											</div>
											</div> -->


									<input name="orgid" type="hidden" id="orgid" value="<?php if(isset($_SESSION["orgid"])) { echo $_SESSION["orgid"]; } ?>" />
									<input id="txtUserid" type="hidden" name="txtUserid" value="<?php if(isset($_SESSION["txtUserid"])) { echo $_SESSION["txtUserid"]; } ?>">
									<input type="hidden" name="email" id="email" value="<?php if(isset($_SESSION["email"])) { echo $_SESSION["email"]; } ?>" />
									<input type="hidden" name="InvalidCode" id="InvalidCode" />
									<input type="hidden" name="hidurl" id="hidurl" value="0" />
									<input type="hidden" name="hiduser" id="hiduser" value="0" />
									<input type="hidden" name="e_short_name" id="e_short_name" />

							</form>

							<!-- Form Ends -->
						</div>						
					</div>
				</div>
			</div>
		</div>
	</section>
<?php
}
include ("include_sso/footerjs.php"); 
?>
<script> 
$(document).ready(function(){
  $("#flip").click(function(){
    $("#panel").slideToggle("slow");
  });
});
</script>
<style>


#panel { 
  display: none;
}
</style>
</body>
</html>


<!-- ALERT POP UP -->
<div class="modal fade" tabindex="-1" role="dialog" id="alertModel" style="z-index:99999">
  <div class="modal-dialog modal-md" style="margin: 130px auto;" role="document">
    <div class="modal-content">
      <div class="modal-header" style="border-radius:4px; color:#FFFFFF; background-color:#005baa">

      	<h4 class="modal-title" id="validationMsg" style="font-size:15px;font-size: 15px; text-align: center;position: relative;
      				top: 7px;"></h4>

        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>

      </div>
        <div class="modal-body">
         	<span id='error_msg' style="color: red;"></span></p>
         <p id="messagePara"></p>
        </div>
        <div class="modal-footer" id="footerMsg">
          <button type="button" class="btn btn-success" data-dismiss="modal">Ok</button>
        </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>


<!-- /.modal -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="/var/www/html/Dashboard/js/bootstrap.min.js"></script>
<script>
	function moveNextField(key) {
	var nextVal=Number(key)+1;
    if (nextVal<='4') {
    	 document.getElementById("otp_"+nextVal).value='';
	     document.getElementById("otp_"+nextVal).focus();
    	}
	}
	function wating(val)
	{
		if(val!="" && val.length=='6'){
			document.getElementById("empList").innerHTML='Loading please wait...';
			document.getElementById('btnLogin').disabled=true;
			$.ajax({
				url: "search_employee.php",
				type: 'get',
				data: { term:val,type:+1}, 
				dataType: 'json',
				success:function(response) {
					if(response!="")
					{
						//alert(response[1]);
						if(response[1]==1){
							$("#orgid").val(response[0][0].org_id);
							$("#email").val(response[0][0].email);
							$("#txtUserid").val(response[0][0].id);
							$("#txtUserid1").val(response[0][0].display_value);
							$("#e_short_name").val(response[0][0].e_short_name);						
							document.getElementById('btnLogin').disabled=false;
							document.getElementById("empList").innerHTML='';
						}

						else{
							document.getElementById('empList').innerHTML=response[0];
							document.getElementById('btnLogin').disabled=false;
						}
					}
				}
			  }); 
		}
		//else
			//document.getElementById("loading").innerHTML='';
	}
	function getEmployeeDetails(value)
	{
		document.getElementById('validationMsg').innerHTML='Alert !!';
		if(Number(document.getElementById("txtUserid1").value))
			val=document.getElementById("txtUserid1").value;
		else
			val=value;
			
		if(val!=""){
			$.ajax({
				url: "search_employee.php",
				type: 'get',
				data: { term:val,type:+1}, 
				dataType: 'json',
				success:function(response) {
					if(response[1]==0)
					{
						document.getElementById("messagePara").innerHTML='Invalid Employee ID.';
						$("#txtUserid").val('');
						$("#txtUserid1").val('');
						//document.getElementById("loading").innerHTML='';
						$("#alertModel").modal('show');
					}
				}
			  }); 
		}
	}
	function check() {
		var lTable = document.getElementById("ptag");
		lTable.style.display = (lTable.style.display == "table") ? "none" : "table";

	}
	function chekUserId()
	{
		var userId=document.getElementById("txtUserid").value;
		var orgid=document.getElementById("orgid").value;
		if(userId==""){
			var mailTo='mailto:Oraclesupport@ytygroup.com.my?Subject=Problems signing in for Emp ID&body=Please provide below information:%0DEmp ID: <Your Emp ID>%0DProblem: <describe the issue>%0DScreenshot: <Please paste the screenshot here>';
			var resMailTo = mailTo;
		}
		else
		{
			var mailTo='mailto:Oraclesupport@ytygroup.com.my?Subject=Problems signing in for Emp ID: EMP_ID&body=Please provide below information:%0DProblem: <describe the issue>%0DScreenshot: <Please paste the screenshot here>';
			var resMailTo = mailTo.replace("EMP_ID", orgid+''+userId);
		}
		document.getElementById('mailTo').href=resMailTo;
	}
	function checkUserId()
	{
		var strVal=document.getElementById("btnLogin").disabled;
		document.getElementById('footerMsg').style.display="block";
		if(strVal==true)
		{
			var userId=document.getElementById("txtUserid").value;
			if(userId==""){
				document.getElementById("messagePara").innerHTML='Please enter your Employee ID.';
			}
			else
			{
				document.getElementById("messagePara").innerHTML='Invalid Employee ID.';
			}
			document.getElementById('validationMsg').innerHTML='Alert !!';
			$("#alertModel").modal('show');
		}
		else{
				var userId=document.getElementById("txtUserid").value;
				var orgid=document.getElementById("orgid").value;
				if(userId==""){
					//window.location.href = "pdf_sso/password_reset_procedure.pdf";
					document.getElementById("messagePara").innerHTML='Please enter your Employee ID.';
					document.getElementById('validationMsg').innerHTML='Alert !!';
					//window.open('pdf_sso/password_reset_procedure.pdf');
					$("#alertModel").modal('show');
					
				}

				else if(document.getElementById('email').value==""){
					document.getElementById("messagePara").innerHTML='Email id is not Registered.';
					document.getElementById('validationMsg').innerHTML='Alert !!';
					$("#alertModel").modal('show');
				}
				else
				{	
					var txtUserid=	document.getElementById('txtUserid1').value;	
					if(txtUserid=="")
					{
						document.getElementById("email").value="";
						document.getElementById("messagePara").innerHTML='Please enter your Employee ID.';						
						document.getElementById('validationMsg').innerHTML='Alert !!';
						$("#alertModel").modal('show');
						return false;
					}				
					document.getElementById('validationMsg').innerHTML='We’ve sent an OTP code to your registered email address';
					document.getElementById('footerMsg').style.display="none";
					document.getElementById("messagePara").innerHTML='<table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="table"><tr><td><label for="message" style="margin-bottom: 10px;margin-left: 150px;">Enter OTP Code Here</label><br><div class="fxt-transformY-50 fxt-transition-delay-1"><div class="fxt-form-row" style="display: flex; justify-content: space-between; width:80%;margin-left:50px;"><input type="tel" name="otp_1" id="otp_1" class="fxt-form-col otp-input form-control" onkeyup="return moveNextField(1)" autocomplete="off" maxlength="1" required="required">&nbsp;&nbsp;<input type="tel" name="otp_2" id="otp_2" onkeyup="return moveNextField(2)" class="fxt-form-col otp-input form-control" autocomplete="off" maxlength="1" required="required">&nbsp;&nbsp;<input type="tel" name="otp_3" id="otp_3" onkeyup="return moveNextField(3)" class="fxt-form-col otp-input form-control" autocomplete="off" maxlength="1" required="required">&nbsp;&nbsp;<input type="tel" name="otp_4" id="otp_4" class="fxt-form-col otp-input form-control" onkeyup="return moveNextField(4)" autocomplete="off" maxlength="1" required="required"></div></div><span id="validateError" style="color:red;display: block;font-size: 13px;margin-top: 9px;"></span><strong style="font-size:11px;"><p style="position: relative;left:140px;">Not yet received your code?<button class="fxt-resend" disabled id="timer" type="submit" onclick="return resendOTP()" style="background-color: snow;border: none; border-block: none;text-decoration: underline;  color: red;font-size: 12px;cursor: pointer;">Resend code</button></p></td></tr><tr><td><input style="float: right; padding: 9px 20px;width:100%;transition: all 0.3s ease-in-out;font-weight: bold;" onMouseOver="style.backgroundColor=\'#005baa\'"  onMouseOut="style.backgroundColor=\'#17a2b8\'" name="Submit" type="submit" onclick="return checkBothOTP()" id="vrtoptbtn" value="Verify" class="btn btn-info"> <input name="generate_otp" type="hidden" id="generate_otp"  class="form-control"  /></td></tr></table>';
						$("#alertModel").modal('show');
						timer(60);
						var emailId=document.getElementById("email").value;
						var uName=document.getElementById("e_short_name").value;
							$.ajax({
								url: "forgotPasswordOTPEmail.php",
								type: 'post',
								data: { emailId:emailId,uName:uName}, 
								//dataType: 'json',
								success:function(response) {
									if(response!=1){
										document.getElementById("generate_otp").value=response;
									}							
									else
									{
										document.getElementById("messagePara").innerHTML='Error in database';
									}
								}
							 }); 
				}
		}
	}
	function checkBothOTP()
	{
	  $('#error_msg').html('');	
	  var otp_1=document.getElementById('otp_1').value;
	  var otp_2=document.getElementById('otp_2').value;
	  var otp_3=document.getElementById('otp_3').value;
	  var otp_4=document.getElementById('otp_4').value;
	  var combine_otp=otp_1+otp_2+otp_3+otp_4;
	  //alert(combine_otp);
	  if(combine_otp=="")
	  {
	    $('#error_msg').html('<i class="fa fa-exclamation-triangle" aria-hidden="true"> Please enter OTP.');
	    return false;
	  }
		
	  if(Number(document.getElementById('generate_otp').value)!=Number(combine_otp))
	  {
	    $('#error_msg').html('<i class="fa fa-exclamation-triangle" aria-hidden="true"> Invalid OTP.');
	    return false;
	  }
	    document.getElementById("vrtoptbtn").innerHTML="Please wait..."; 
	    $('#vrtoptbtn').prop('disabled',true);
	    confirmYourPassword(); 
	}	
	function checkBothPassword()
	{
	  $('#error_msg').html('');	
	  var new_password=document.getElementById('new_password').value;
	  var confirm_password=document.getElementById('confirm_password').value;
	  if(new_password=="")
	  {
	    $('#error_msg').html('<i class="fa fa-exclamation-triangle" aria-hidden="true"> Please enter new password.');
	    return false;
	  }
	  if(new_password.length < "8")
	  {
	    $('#error_msg').html('<i class="fa fa-exclamation-triangle" aria-hidden="true"> Password length should be 8 digit.');
	    return false;
	  }
	  if(confirm_password=="")
	  {
	    $('#error_msg').html('<i class="fa fa-exclamation-triangle" aria-hidden="true"> Please retype new password.');
	    return false;
	  }

	  if(new_password!=confirm_password)
	  {
	    $('#error_msg').html("<i class='fa fa-exclamation-triangle' aria-hidden='true'> New password and confirm password doesn't match.");
	    return false;
	  }
	    document.getElementById("passBtn").innerHTML="Please wait..."; 
	    $('#passBtn').prop('disabled',true);
	    sendRecoveryMail(new_password); 
	}
	function confirmYourPassword()
	{
		document.getElementById('validationMsg').innerHTML='Reset Your Password';
		document.getElementById("messagePara").innerHTML='<table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="table"><tr><td><label for="message" style="margin-bottom: 10px;">New Password</label><br><div class="fxt-transformY-50 fxt-transition-delay-1"><input type="password" name="new_password" id="new_password" class="fxt-form-col otp-input form-control" placeholder="New Password" autocomplete="off" required="required"></td></tr><tr><td><label for="message" style="margin-bottom: 10px;">Retype New Password</label><br><input type="password" name="confirm_password" id="confirm_password"  class="fxt-form-col otp-input form-control" placeholder="Retype New Password" autocomplete="off" required="required">&nbsp;&nbsp;</td></tr><tr><td><input style="float: right; padding: 9px 20px;width:100%;transition: all 0.3s ease-in-out;font-weight: bold;" onMouseOver="style.backgroundColor=\'#005baa\'"  onMouseOut="style.backgroundColor=\'#17a2b8\'" name="passBtn" type="submit" onclick="return checkBothPassword()" id="passBtn" value="Submit" class="btn btn-info"> <input name="password_emp_idr" type="hidden" id="password_emp_id"  class="form-control"  /></td></tr></table>';
			$("#alertModel").modal('show');		  
	}
	function sendRecoveryMail(new_password)
	{
		  var userId=document.getElementById("txtUserid").value;
		  var orgid=document.getElementById("orgid").value;
		  var emailId=document.getElementById("email").value;
		  var uName=document.getElementById("e_short_name").value;
		  $.ajax({
			url: "forgotPasswordEmail.php",
			type: 'post',
			data: { userId:orgid+''+userId+'@_@'+new_password+'@_@'+emailId+'@_@'+uName}, 
			//dataType: 'json',
			success:function(response) {
				if(response==1){
					document.getElementById('validationMsg').innerHTML='Thank You !!';
					document.getElementById("messagePara").innerHTML='Password for your SSO account has been reset successfully.';
				}
				else if(response==2){
					document.getElementById("validateError").innerHTML='Invalid captcha code.';
				}
				else
				{
					document.getElementById("messagePara").innerHTML='Error in database';
				}
			}
		  }); 
	}	// function refreshCaptcha(){
	// 	var img = document.images['captchaimg'];
	// 	img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
	// }
	function fillTextData(data)
	{
		var dataArr=data.split("_");
		$("#orgid").val(dataArr[1]);
		$("#txtUserid").val(dataArr[0]);
		$("#txtUserid1").val(dataArr[2]);
		$("#email").val(dataArr[3]);
		$("#e_short_name").val(dataArr[4]);						
		document.getElementById("empList").innerHTML='';
	}
	//----for otp------
	function resendOTP()
	{
		timer(60);
		var emailId=document.getElementById("email").value;
		var uName=document.getElementById("e_short_name").value;
			$.ajax({
				url: "forgotPasswordOTPEmail.php",
				type: 'post',
				data: { emailId:emailId,uName:uName}, 
				//dataType: 'json',
				success:function(response) {
					if(response!=1){
						document.getElementById("generate_otp").value=response;
					}							
					else
					{
						document.getElementById("messagePara").innerHTML='Error in database';
					}
				}
			 }); 
	}
	let timerOn = true;
	function timer(remaining) {
	  document.getElementById('timer').style.textDecoration='none';
	  var m = Math.floor(remaining / 60);
	  var s = remaining % 60;
	  
	  m = m < 10 ? '0' + m : m;
	  s = s < 10 ? '0' + s : s;
	  document.getElementById('timer').innerHTML = m + ':' + s;
	  remaining -= 1;
	  
	  if(remaining >= 0 && timerOn) {
	    setTimeout(function() {
	        timer(remaining);
	    }, 1000);
	    return;
	  }

	  if(!timerOn) {
	    // Do validate stuff here
	    return;
	  }
	  
	  // Do timeout stuff here
	  $('#timer').prop('disabled',false);
	  document.getElementById('timer').style.textDecoration='underline';
	  document.getElementById('timer').innerHTML ='Resend code';
	}
</script>


<!-- jQuery -->
<!-- <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
BS JavaScript
<script src="/var/www/html/Dashboard/js/bootstrap.min.js"></script> -->

<script src="/var/www/html/Dashboard/js/bootstrap.min.js"></script>


