<script>
function gotopage(u)
{
	document.searchfrm.action = u;
	document.searchfrm.act.value='search';
	document.searchfrm.submit();
}
function submitform(start,limit)
{
	document.searchfrm.act.value=document.location.href;
	document.getElementById("start").value=start;
	document.getElementById("limit").value=limit;
		
	//document.searchfrm.action = u;
	
	document.searchfrm.submit();
}
function gotolink(u,family_id)
{
	document.searchfrm.act.value=document.location.href;
	document.getElementById("family_id").value=family_id;
	document.searchfrm.action = u;
	
	document.searchfrm.submit();
}
function gotomsg(u,id,email,opt)
{
	
	if(opt=="family"){
		document.getElementById("family_id").value=id;
		
	}else{
		document.getElementById("member_id").value=id;
		
	}
	
	document.getElementById("email").value=email;
	
	document.searchfrm.action = u;
	
	document.searchfrm.submit();
}
</script>
<form name="searchfrm" id="searchfrm" action="<?php echo $page_name?>" method="post" target="_parent">
<input type="hidden" name="start" id="start" value="<?=$_REQUEST["start"]?>" />
<input type="hidden" name="limit" id="limit" value="<?=$_REQUEST["limit"]?>" />
<input type="hidden" name="act" id="act" value="" />
<input type="hidden" name="family_id" id="family_id" value="" />
<input type="hidden" name="member_id" id="member_id" value="<?php echo $_REQUEST["member_id"]?>" />
<input type="hidden" name="search" id="search" value="<?php echo $_REQUEST["search"]?>" />
<input type="hidden" name="fname" id="fname" value="<?php echo $_REQUEST["fname"]?>" />
<input type="hidden" name="gender" id="gender" value="<?php echo $_REQUEST["gender"]?>" />
<input type="hidden" name="email" id="email" value="<?php echo $_REQUEST["email"]?>" />
<input type="hidden" name="maritalstatus" id="maritalstatus" value="<?php echo $_REQUEST["maritalstatus"]?>" />
<div style="padding-top:40px;">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
             <tr>
                <td colspan="2" align="left" class="breadcrumb"><a href="index.php" class="bnav">Home</a> &raquo; <?php if($_REQUEST["member_id"]==''){?>My Family<?php }else{?>Family Member List<?php }?></td>
                </tr>
              <tr>
                <td colspan="2">&nbsp;</td>
                </tr>
              <tr>
                <td width="78%"><h3><?php if($_REQUEST["member_id"]==''){?>My Family<?php }else{?>Family Member List<?php }?></h3></td>
                <td width="22%"><table width="68%" border="0" align="right" cellpadding="0" cellspacing="0">
                  <tr>
                    <td align="center">
					<?php if($_REQUEST["member_id"]==''){?>
					<a href="addfamily" class="btn btn-primary">Add Family Member</a>
					<?php }else{?> <td align="right">
					<?php
					if($_REQUEST["search"]=="yes"){
					?>
					<a href="#" onclick="gotopage('searchmember')" class="btn-primary">Back to Search Result</a>
					<?php }else{
					?><a href="WelcomeMember" class="btn btn-primary">Back to Members</a>
					<?php
					}?>
					<?php }?></td>
					</td>
                  </tr>
                </table></td>
                </tr>
                <tr><td>&nbsp;</td></tr>
			 <tr>
                <td colspan="2">
				Total Members: <?php echo $_REQUEST["nume"];?></td>
                </tr>
              <tr>
                <td colspan="2">&nbsp;</td>
                </tr>
              <tr>
                <td colspan="2"><table width="98%" border="0" align="center" cellpadding="5" cellspacing="1" class="table table-bordered">
                  <tr>
				  	<td width="10%" height="28" align="center">&nbsp;</td>
                    <td width="25%"><strong>Name</strong></td>
                   <td width="8%"><strong>Gender</strong></td>
				   <td width="8%"><strong>Relation</strong></td>
				   <td width="8%"><strong>Marital Status</strong></td>
                    <td width="30%" align="center"><strong>Action</strong></td>
                  </tr>
				  <?php
				  foreach($memberlist as $member){
				  ?>
                  <tr>
                   <td align="center" valign="top"><?php if($member->fam_simage!='' and file_exists('./static/uploadfiles/members/'.$member->fam_simage)){?>
					<img src="./utility/processImage.php?imageName=<?php echo urlencode($member->fam_simage); ?>&w=80&h=80&mod=4&type=2&<?php echo date("HisdmY");?>" />
					<?php }else{
					?>
					<?php if($member->fam_gender=="Male"){?>
					<img src="images/boy-icon.jpg" width="80px" height="80px" />
					<?php }else{
					?><img src="images/girl-icon.jpg" width="80px" height="80px" /><?php
					}?>
					<?php
					}?></td>
                    <td valign="middle"><?php echo $member->fam_fullname?></td>
					<td valign="middle"><?php echo $member->fam_gender?></td>
                    <td valign="middle"><?php echo $member->fam_relationwithmember?></td>
					<td valign="middle"><?php echo $member->fam_maritalstatus?></td>
                    <td align="right" valign="middle">
					<?php
					if($_REQUEST["member_id"]==''){
					?>
					<a style="cursor:pointer" onclick="gotolink('editfamily','<?php echo $member->id;?>')" class="btn btn-primary">
                    <i class="fa fa-pencil-square-o" title="Edit"></i></a>
					&nbsp;
					<a style="cursor:pointer" onclick="gotolink('viewfamily','<?php echo $member->id;?>')" class="btn btn-primary">
                    <i class="fa fa-eye" title="view profile"></i></a>
					<?php
					}else{
					?>
					<a style="cursor:pointer" onclick="gotolink('viewfamily','<?php echo $member->id;?>')" class="btn btn-primary">
                    <i class="fa fa-eye" title="view profile"></i></a>&nbsp;
					<?php
					}
					?>
					<a style="cursor:pointer" onclick="gotomsg('sendmessage','<?php echo $member->id;?>','<?php echo $member->email;?>','family')" class="btn btn-primary">
                    <i class="fa fa-envelope-o" title="send email"></i></a>
					</td>
					
                  </tr>
                 <?php }?>
                </table></td>
              </tr>
			  <tr><td colspan="5">
	  <table width="98%" align="center" cellspacing="1">
			 <tr>
			  		<td height="32" align="center" valign="middle">
                    	<a href="#" onclick="submitform('0','<?php echo $_REQUEST['limit']?>')" >First</a>
                    </td>
                    <td  align="center" valign="middle">
						<?php //print_r($_POST);
                        if($_REQUEST["back"] >=0){
                        ?>
                        <a href="#" onclick="submitform('<?php echo $_REQUEST["back"]?>','<?php echo $_REQUEST['limit'] ?>')">Prev</a>
                        <?php
                        }
                        ?>
                    </td>
                    <td align="center" valign="middle"><strong>Pages </strong><?php //echo $_REQUEST["nume"];?>
                    <?php								  
						$l=1;
						$lastPage = ceil($_REQUEST["nume"]/($_REQUEST["limit"]));
						$k=0;
						$startNo=0;
						$endNo=10;
						$curPage = ceil($_REQUEST["next"]/$_REQUEST["limit"]);
						if($curPage==1){
								$_SESSION['startNo']  =0;
								$_SESSION['endNo']= 10;
							}
						if($curPage==$lastPage){
							$_SESSION['startNo']  =$lastPage-$endNo;
							$_SESSION['endNo']= $lastPage;
						}
						for($i=0;$i < $_REQUEST["nume"];$i=$i+$_REQUEST["limit"]){
						
							if($curPage%5 == 0){
								$startNo = $curPage-5;
								if($startNo < 0){
								 $startNo=0;	
								}
								$endNo = $curPage+5;
								if($endNo > $lastPage){
								 $endNo =$lastPage;
								}						
								$_SESSION['startNo'] = $startNo;
								$_SESSION['endNo']= $endNo;
							}else{
								if(isset($_SESSION['startNo']) && $_SESSION['startNo'] != ""){
									$startNo  =$_SESSION['startNo'];
								}
								if(isset($_SESSION['endNo']) && $_SESSION['endNo'] != ""){
									$endNo  =$_SESSION['endNo'];
								}
							}
							
							if($l >= $startNo && $l <= $endNo)							
							{
								
								if($startNo > 1 and $x==0){
									?><a class="onav" href="#" onclick="submitform('0','<?php echo $_REQUEST['limit']?>')" >1..</a><?php
									$x=1;
								}
								if($i <> $_REQUEST["eu"]){
									if($l == $lastPage){
										$lastPageLink = "'".$i."','".$_REQUEST['limit']."'";
									}
									
									
								?>
								<a class="onav" href="#" onclick="submitform('<?php echo $i?>','<?php echo $_REQUEST['limit']?>')"><?php echo $l; ?></a>
							<?php
								}
								else { 
										if($l == $lastPage){
											$lastPageLink = "#";
										}
								?>
									<span class="paging_pages_cur"><a href="#" class="selected" alt="<?php echo SEO_ENCHOR_ALT; ?>" title="<?php echo SEO_ENCHOR_TITLE; ?>"><?php echo $l; ?></a></span>
									<?php
										} 
										if($l==$endNo and $l!=$lastPage){
											?><a href="#" onclick="submitform('<?php echo ($lastPage*10)-10; ?>','<?php echo $_REQUEST['limit']?>')" >..<?php echo $lastPage; ?></a><?php
											$y=1;
										}    
							}
																				
							$l=$l+1;
						} 
					  ?>                  </td>
                    <td align="center" valign="middle">
						<?php  
						if($_REQUEST["th"] < $_REQUEST["nume"]) { 	
                        ?>
                      		<a href="#" onclick="submitform('<?php echo $_REQUEST["next"]?>','<?php echo $_REQUEST['limit']?>')">Next</a>
                        <?php
						}
						?>
                    </td>
                    <td align="center" valign="middle"><a href="#" onclick="submitform('<?php echo ($lastPage*10)-10; ?>')">Last</a></td>
                </tr>
			 </table>
			 </td></tr>
              
              </table>
</form>