<?php
session_start();
$username=$_SESSION['username'] ?? '';
$password=$_SESSION['password'] ?? '';
$deptt="3";
$chn=$_GET['chn'] ?? '';
$cyc_no=$_GET['cyc_no'] ?? '';
$don_no=$_GET['don_no'] ?? '';
$semen_id=sprintf("%06d", $_GET['semen_no'] ?? '');
//$semen_id=$_GET['semen_no'];

//$x_semen_id_x=$chn.".".$semen_id;
$x_semen_id_x=$chn;

$xnm=$_GET['xnm'] ?? '';
$chn = stripslashes($chn);
$cyc_no = stripslashes($cyc_no);
$xcyc_no=$chn.".".$cyc_no;
$username = stripslashes($username);
$password = stripslashes($password);
//$don_no = explode('.',stripslashes($don_no));
//$don_no_x=$don_no[0];

include 'dbcon.php'; 
$ptpass = md5($password);
$query  = "SELECT * FROM matcher_usermst WHERE nif_usr='$username' AND nif_pass='$ptpass' AND act_vate='1'";
$result = mysqli_query($conn, $query);
$login_check = mysqli_num_rows($result);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$clint_code = $row["clint_code"];
}
?>
<!DOCTYPE HTML>
<html>
	<head>
<style type="text/css">
INPUT { margin-right: 1em }
body {
background: #666666;
}
</style>
<link href="../style.css" rel="stylesheet" type="text/css" />
<link href="style_btn.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js_button.js"></script>
<link href="../style_btn.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js_button.js"></script>

<style>
  #foo {
    position: fixed;
    top: -1000000px;
  }
</style>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>
function focusOnMyInputBox(){                                 
    //document.getElementById("test").focus();
    document.getElementById("mixedcontent").focus();
}
</script>
<script>
function myFunction() {
	var eggdish = document.getElementById("test").value;
	var originchn = document.getElementById("orgin_chn").value;
	if(eggdish.length == 9){
	document.getElementById("test123").focus();
	 	if(eggdish.toUpperCase() === originchn.toUpperCase()){
			document.getElementById('abcdoocyt').innerHTML = 'Embryo dish matched';
			document.getElementById('efgoocyt').innerHTML = '';
				document.getElementById('oocytpic')
    			.innerHTML = '<img src="oocyt.gif" />';
			document.getElementById('abcd').innerHTML = 'Put the sperm tube';

		}else{
			document.getElementById('abcdoocyt').innerHTML = '';
			document.getElementById('abcd').innerHTML = '';
			document.getElementById('efgoocyt').innerHTML = 'Embryo dish not matched';
				document.getElementById('oocytpic')
    			.innerHTML = '<img src="wrongoocyt.gif" />';
					document.getElementById("filler").focus();
		}
	}

}
</script>


<script>
function myFunction123() {

	var secndpra = document.getElementById('test123').value;
 	if (secndpra.length == 16 ) {
		var spermtextbx = document.getElementById("test123").value;
		var testval = document.getElementById("test").value;
		var originchn = document.getElementById("orgin_chn").value;
		var donchn = document.getElementById("don_chn").value;
		var semnid = document.getElementById("semen_id").value;

			if (spermtextbx.toUpperCase() === semnid.toUpperCase()){
				document.getElementById('abcdsprm').innerHTML = 'Sperm tube matched';
				document.getElementById('efgsprm').innerHTML = '';

				document.getElementById('spermpic')
    			.innerHTML = '<img src="sperm.gif" />';

			}else{
				document.getElementById('abcdsprm').innerHTML = '';
				document.getElementById('efgsprm').innerHTML = 'Sperm tube not matched';
				document.getElementById('spermpic')
    			.innerHTML = '<img src="wrongsperm.gif" />';

			}

					if (testval.toUpperCase() === originchn.toUpperCase() && spermtextbx.toUpperCase() === semnid.toUpperCase()){
						document.getElementById('abcd').innerHTML = 'Congratulation !!!  Bilogical material matched';
						document.getElementById('efg').innerHTML = '';
							document.getElementById("filler").focus();
							document.getElementById('test123').disabled = true;
							document.getElementById('test').disabled = true;
					 }else{
						document.getElementById('abcd').innerHTML = '';
						document.getElementById('efg').innerHTML = 'Bilogical material not matched';
							document.getElementById("filler").focus();
							document.getElementById('test123').disabled = true;
							document.getElementById('test').disabled = true;
					}



	}
}
</script>
<script>
function splttxt() {
var mrgedtxt = document.getElementById("mixedcontent").value.toUpperCase();
var x_mrgedtxt = document.getElementById("mixedcontent").value;
//alert(x_mrgedtxt);
		if (x_mrgedtxt.length > 47 ) {
				document.getElementById("filler").focus();
				var result = mrgedtxt.split(".");
				var result1 = result[0].toUpperCase();
				var result2 = result[1].toUpperCase();
				var result3 = result[2].toUpperCase();
				var result4 = result[3].toUpperCase();
				var result5 = result[4].toUpperCase();
				var chnxxx = document.getElementById("orgin_chn").value.toUpperCase();
				var sprmxxx = document.getElementById("semen_id").value.toUpperCase();
				var donchnxxx = document.getElementById("don_chn").value.toUpperCase();
	
				//if(donchnxxx.length <1){
				//}else{
				//var chnxxx = document.getElementById("don_chn").value.toUpperCase();
				//}
	
					if ( (result1===chnxxx) && (result4===sprmxxx) || (result4===chnxxx) && (result1===sprmxxx)){
						document.getElementById('abcd').innerHTML = 'Biological material matched !!!!!!';
						document.getElementById('efg').innerHTML = '';
						//ajax call start
							$.ajax({
							type: 'POST',
							url: 'process_complet_test.php',
							//data: $('urfrm').serialize(),
							data: { 'chn': result1, 'chn_cycle': result2, 'witns_one': result3, 'witns_two': result5, 'chn_don': donchnxxx, 'chn_semen': sprmxxx, 'finalwtns': x_mrgedtxt, 'pmark':'1' },
							dataType: 'json',
							success: function ( data ) {
							}
							});
						//ajax call end
					} else {
						document.getElementById('abcd').innerHTML = '';
						document.getElementById('efg').innerHTML = 'Biological material not matched !!!!!!';
						//ajax call start
							$.ajax({
							type: 'POST',
							url: 'process_complet_test.php',
							//data: $('urfrm').serialize(),
							data: { 'chn': result1, 'chn_cycle': result2, 'witns_one': result3, 'witns_two': result5, 'chn_don': donchnxxx, 'chn_semen': sprmxxx, 'finalwtns': x_mrgedtxt, 'pmark':'2' },
							dataType: 'json',
							success: function ( data ) {
							}
							});
						//ajax call end
					}
	
					setTimeout(function(){
					 document.getElementById("mixedcontent").value="";
					},200);
		}

}
</script>
</head>
<body onLoad="focusOnMyInputBox();">
<div id="staticParent" align="center">
<h3><strong>FINAL PROCEDURE<br><br><?php echo $chn." ".$xnm;?></strong></h3><br>

<?php
//echo "<div style='color:#33CC00;font-size:16px;'>".date('d/m/Y',strtotime($row['reslt_dt']))." ".substr($row['reslt_dt'],-8)." by user ".$xentby."<br>"."<font color='$xclr'>".$xprocedure."  - ".$xproc_mainid_splt."</div><br>";
?>

<form name="urfrm" id="urfrm" method="post" action="#process_complet.php?chn=<?php echo $chn;?>&cyc_no=<?php echo $cyc_no;?>" target="_parent">

  <div id="foo">
    <input name="test123" id="test123" type="text" onKeyUp="myFunction123_tobeomit()">
    <input name="test" id="test" type="text" maxlength="80" onKeyUp="myFunction_tobeomit()">
    <input name="filler" id="filler" type="text"><br>
<input name="mixedcontent" class="name" type="text" size="80" onKeyUp="splttxt()"><br>
	
<input name="cyc_no" class="name" type="text" value="<?php echo $cyc_no;?>"><br>
<input name="orgin_chn" class="name" type="text" value="<?php echo $chn;?>">
<input name="don_chn" id="don_chn" class="name" type="text" value="<?php echo $don_no;?>">
<input name="semen_id" id="semen_id" class="name" type="text" value="<?php echo $x_semen_id_x;?>">
  </div>
<?php
$myfile = fopen("txan526a.txt", "w") or die("Unable to open file!");
$txt = "reset";
fwrite($myfile, $txt);
fclose($myfile);
?>

</form>
</br>
</br>
<table width="80%">
<tr><td colspan="2"><div id="abcd" style="color:#33CC00;font-size:36px;"></div><div id="efg" style="color:#FF0000;font-size:36px;"></div></td></tr>
<tr><td colspan="2"></td></tr>
<tr><td align="right" width="40%"><div id="spermpic"></div></td><td align="left"><div id="abcdsprm" style="color:#0066CC;font-size:26px;"></div><div id="efgsprm" style="color:#FF0000;font-size:26px;"></div></td></tr>
<tr><td colspan="2"></td></tr>
<tr><td align="right" width="40%"><div id="oocytpic"></div></td><td align="left"><div id="abcdoocyt" style="color:#FF6600;font-size:26px;"></div><div id="efgoocyt" style="color:#FF0000;font-size:26px;"></div><br></td></tr></table>
<a href="gend_cycle_select.php?chn=<?php echo $chn;?>" class="btn-two blue small">Back to patient listing</a>	
</div>
</body>
</html>
