$resmcountt=$cn->countrow("select c.ct_id,p.parent_reg_id,r.type from tbl_parent p, tbl_child c,tbl_register r where p.parent_reg_id=r.reg_id and p.pt_id=c.pt_id and c.down_reg_id='D' and c.d_status='N' and r.rpack_id='$pack' and r.type='user' and p.priority='H' order by c.ct_id asc  limit 1");
				if($resmcountt>0)
				{
					$res122=$cn->getrows("select c.ct_id,p.parent_reg_id,r.type from tbl_parent p, tbl_child c,tbl_register r where p.parent_reg_id=r.reg_id and p.pt_id=c.pt_id and c.down_reg_id='D' and c.d_status='N' and r.rpack_id='$pack' and r.type='user' and p.priority='H' order by c.ct_id asc  limit 1");
					while($rw=mysqli_fetch_array($res122))
					{
						$pid=$rw["parent_reg_id"];
						$ctid=$rw["ct_id"];
						$stdate=date("Y-m-d H:i:s");
						$enddate=date("Y-m-d H:i:s",strtotime('+'.$hrs.' hours'));
						$data1=array("parent_reg_id"=> $pid, "reg_id"=> $id, "pack_id"=> $pack, "p_status"=>"NV","start_date"=>$stdate,"end_date"=>$enddate);
						$user_pack=$cn->insertRec($data1,"tbl_user_package");
						$child_status=$cn->updatedeleterows("update tbl_child set d_status='Y', d_p_id='$id' where ct_id=$ctid ");
						//mailsend($email);
						header("Location:login.php?msg=regsuccess");
						/*echo "<script>";
						echo "alert('You are registerd successfully, Please Your Account Will be paired Right away..');";
						echo "window.location.href='login.php';";
						echo "</script>";*/
					}
				 }
				 else
				 {
				 	$resmcount=$cn->countrow("select c.ct_id,p.parent_reg_id,r.type from tbl_parent p, tbl_child c,tbl_register r where p.parent_reg_id=r.reg_id and p.pt_id=c.pt_id and c.down_reg_id='D' and c.d_status='N' and r.rpack_id='$pack' and r.type='userm' order by c.ct_id asc  limit 1");
				  	if($resmcount>0)
				  	{
						$res12=$cn->getrows("select c.ct_id,p.parent_reg_id,r.type from tbl_parent p, tbl_child c,tbl_register r where p.parent_reg_id=r.reg_id and p.pt_id=c.pt_id and c.down_reg_id='D' and c.d_status='N' and r.rpack_id='$pack' and r.type='userm' order by c.ct_id asc  limit 1");
						while($rw=mysqli_fetch_array($res12))
						{
							$pid=$rw["parent_reg_id"];
							$ctid=$rw["ct_id"];
							$stdate=date("Y-m-d H:i:s");
							$enddate=date("Y-m-d H:i:s",strtotime('+'.$hrs.' hours'));
							$data1=array("parent_reg_id"=> $pid, "reg_id"=> $id, "pack_id"=> $pack, "p_status"=>"NV","start_date"=>$stdate,"end_date"=>$enddate);
							$user_pack=$cn->insertRec($data1,"tbl_user_package");
							$child_status=$cn->updatedeleterows("update tbl_child set d_status='Y', d_p_id='$id' where ct_id=$ctid ");
							//mailsend($email);
							header("Location:login.php?msg=regsuccess");
							/*echo "<script>";
							echo "alert('You are registerd successfully, Please login and make payment..');";
							echo "window.location.href='login.php';";
							echo "</script>";*/
						}
				  	}
				  	else
				  	{
						$rescount=$cn->countrow("select c.ct_id,p.parent_reg_id,r.type from tbl_parent p, tbl_child c,tbl_register r where p.parent_reg_id=r.reg_id and p.pt_id=c.pt_id and c.down_reg_id='D' and c.d_status='N' and r.rpack_id='$pack' and r.type='super' order by c.ct_id asc  limit 1");
						if($rescount>0)
						{
							//join super user
							$res1=$cn->getrows("select c.ct_id,p.parent_reg_id,r.type from tbl_parent p, tbl_child c,tbl_register r where p.parent_reg_id=r.reg_id and p.pt_id=c.pt_id and c.down_reg_id='D' and c.d_status='N' and r.rpack_id='$pack' and r.type='super' order by c.ct_id asc  limit 1");
							while($rw=mysqli_fetch_array($res1))
							{
								$pid=$rw["parent_reg_id"];
								$ctid=$rw["ct_id"];
								$stdate=date("Y-m-d H:i:s");
								$enddate=date("Y-m-d H:i:s",strtotime('+'.$hrs.' hours'));
								$data1=array("parent_reg_id"=> $pid, "reg_id"=> $id, "pack_id"=> $pack, "p_status"=>"NV","start_date"=>$stdate,"end_date"=>$enddate);
								$user_pack=$cn->insertRec($data1,"tbl_user_package");
								$child_status=$cn->updatedeleterows("update tbl_child set d_status='Y', d_p_id='$id' where ct_id=$ctid ");
								//mailsend($email);
							}
							header("Location:login.php?msg=regsuccess");
							/*echo "<script>";
							echo "alert('You are registerd successfully, Please login and make payment..');";
							echo "window.location.href='login.php';";
							echo "</script>";*/
						}
						else
						{
							//join normal user
							$rescount1=$cn->countrow("select c.ct_id,p.parent_reg_id,r.type from tbl_parent p, tbl_child c,tbl_register r where p.parent_reg_id=r.reg_id and p.pt_id=c.pt_id and c.down_reg_id='D' and c.d_status='N' and r.rpack_id='$pack' order by c.ct_id asc  limit 1");
							if($rescount1>0)
							{
								$res11=$cn->getrows("select c.ct_id,p.parent_reg_id,r.type from tbl_parent p, tbl_child c,tbl_register r where p.parent_reg_id=r.reg_id and p.pt_id=c.pt_id and c.down_reg_id='D' and c.d_status='N' and r.rpack_id='$pack' order by c.ct_id asc  limit 1");
								while($rw=mysqli_fetch_array($res11))
								{
									$pid=$rw["parent_reg_id"];
									$ctid=$rw["ct_id"];
									$stdate=date("Y-m-d H:i:s");
									$enddate=date("Y-m-d H:i:s",strtotime('+'.$hrs.' hours'));
										$data1=array("parent_reg_id"=> $pid, "reg_id"=> $id, "pack_id"=> $pack, "p_status"=>"NV","start_date"=>$stdate,"end_date"=>$enddate);
									$user_pack=$cn->insertRec($data1,"tbl_user_package");
									$child_status=$cn->updatedeleterows("update tbl_child set d_status='Y', d_p_id='$id' where ct_id=$ctid ");
									//mailsend($email);
								}
								header("Location:login.php?msg=regsuccess");
								/*echo "<script>";
								echo "alert('You are registerd successfully, Please login and make payment..');";
								echo "window.location.href='login.php';";
								echo "</script>";*/
							}
							else
							{
								$resupdate=$cn->updatedeleterows("update tbl_register set user_status='N' where reg_id='$id'");
								header("Location:login.php?msg=regsuccess");
								//mailsend($email);
								/*echo "<script>";
								echo "alert('You are registerd successfully, You will be paired shortly..');";
								echo "window.location.href='login.php';";
								echo "</script>";*/
							}
							
						}
				  	}
				}