<?php
$NotAvailable = "Not Available";

if ($this -> profile["Avator"] == "") {
	$pic = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAKMAowMBIgACEQEDEQH/xAAaAAEBAAMBAQAAAAAAAAAAAAAAAQIDBAUH/8QAKRABAAICAQEHBAMBAAAAAAAAAAECAxEEIRIiMUFCUXETMmGBBVKRI//EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwD7iIAogCiAKIAogCiAKIAogCiAKIAogCCAKIAogCiAKJsBRNgKIAogCiAKIAogCAAAAAAA5eXyfpR2aTHbnx/ANufkY8Md6dz/AFhx35+Sd9mIrHk5JmZnczufcB0RzM0eqJ/Tbj58+ukfMOIB6uPl4sk9mN1ny23vDjpL0OLy4trHknVvKfcHYGwAAAAAEBNm0AXZtAF2bQBMmSMdLWt4RDyLWm9ptbxl3fyFtY619524AAAAAAAepxMv1cPWe9HSW7bj/jp6X+YdYLs2gC7NoAuxAAQBRAFEAcf8jHSk/Ljd/OtX6UVn7t7hwAAAAAAa8wd/Br2cU2/tLqYYoiuOIj2ZAogCiAKIAggCiAKIA5efHdpLjejyMf1cUxH3R4PPmsxMxPTQIAAAAVjdtT5jbgxWveJ13Y8ZB6MdIjSoAogCiAKIAgAAAAADh5sf9txHTTuc3MrukTHjAOMAAACHocSNYK/l5+t6iPHb06RqlY9oBkAAAAAACADEBkMQGQxY3yUpHetr4BsaORlrWmvGZ8mrJybT0pGvzLnmZmdyAAAADLHaK3i0xuIejWYtG4ncS8xnjy3p9s9PYHojRj5FLfdHZlt2DIYgMhiAyRABNgBPTrLRk5MeiIn8tefLNp7NelYaQZ2zXt6tMOvnOwAAAAAAAAAWLW95/wBQBnGbJHWLTPy34uRFul+kuU+AejCuTBl13bT8OrYKIAm2vPbs45956M48XPyp61j9g0AAAAAAAAAAAAAAAAO3DbtY4nzcTo4s9LQDoEAHNyfur8IA1AAAAAAAAAAAAAAAAN3G9X6AG8AH/9k=';
} else {
	$pic = $this -> profile["Avator"];
}
function age($birthday) {
	if (!empty($birthday)) {
		$birthday = date("Y-m-d", strtotime($birthday));
		list($year, $month, $day) = explode("-", $birthday);
		$year_diff = date("Y") - $year;
		$month_diff = date("m") - $month;
		$day_diff = date("d") - $day;
		if ($day_diff < 0 && $month_diff == 0) {$year_diff--;
		}
		if ($day_diff < 0 && $month_diff < 0) {$year_diff--;
		}
		return ', ' . $year_diff . ' ' . 'years old';
	} else {
		return "";
	}
}

$edit = 0;
if (isset($this -> AccessRoles["members"]["Actions"]["active"])) {
	$edit = 1;
}
if ($this -> profile["UserID"] == $this -> UserDetails["UserID"]) {
	$edit = 1;
}

if ($this -> UserDetails["Administrator"] == 1) {
	$edit = 1;
}

$Email = 0;
if (filter_var($this -> profile["Email"], FILTER_VALIDATE_EMAIL)) {
	$Email = 1;
}
?>
<div class="page-header">
    	 
        <h1>Profile <small> for 
        	<?php
	        	
	        		echo $this->profile["FullName"];
	        	$UserIcon =  "fa fa-".  strtolower($this->profile["Sex"]);        	
        	?>
    </div>  
    <div class="row-fluid" id="showTables">
        
        	<div class="span3">
                    <div class="row-fluid" style="margin-bottom:20px">
	        	<div class="span12" style="background: #FFF;">
	        		<div class="head clearfix">
	                    
	                    <h1> <span class="<?=$UserIcon?>" style="color:#fff;font-size: 18px;"></span> Profile</h1>                     
	                </div>
                            <div class="block-fluid">
                                <div style="text-align:center" >
                                    <img src=<?=$pic?> class="img-thumbnail"  onclick="ChangePic(this)" style="max-height: 100px; cursor: pointer; margin:auto; margin-top: 10px; margin-bottom: 10px;" />
                                </div>
                                <div class="sidebar">
                                    <div class="item" style=" text-align: center" >
                                        <div class="btn-group" data-toggle="buttons-radio" style="margin:auto">
                                            <button type="button" class="btn tipb" onclick="ChangePic(this)"  pid="<?=$this->profile["UserID"]?>"  data-original-title="Upload Picture"><span class="fa fa-picture-o"></span></button>
                                            
                                            <?php
                                                if($this->profile["CID"] >0 && $edit==1){
                                             ?>
                                            <button type="button" class="btn tipb" title="" data-original-title="Change Password"  onclick="ChangePassword()" ><span class="fa fa-key "></span></button>
                                           <?php } ?>
                                            
                                            
                                            
                                            <?php
                                                if($this->profile["CID"] >0 && $this->profile["Active"] ==1  && $edit==1){
                                             ?>
                                            <button type="button" class="btn tipb" title="" data-original-title="Reset Logn"  onclick="ResetAccount()"> <span class="fa fa-undo "></span></button>
                                            <button type="button" class="btn tipb btn-danger" title="" data-original-title="De-activate Login"  onclick="DetactiveAccount(this)"><span class="fa fa-lock "></span></button>
            								<?php } ?>   
                                             <?php
										            if($this->profile["CID"] ==0  &&  $edit==1){
										            ?>
										                                            <button type="button" class="btn tipb btn-danger" title="" data-original-title="Allow Login"  onclick="ActivateLogin(this)" ><span class="fa fa-unlock-alt "></span></button>
										               <?php } ?>  
										                                            <?php
										            if($this->profile["CID"] >0 && $this->profile["Active"] ==0 && $this->profile["Status"]>0){
										            
            										?>
                                            <button type="button" class="btn tipb btn-danger" title="" data-original-title="Active Account"  onclick="ActivateAccount(this)" ><span class="fa fa-unlock-alt "></span></button>
               <?php } ?>  
                                        </div>
                                    </div>
                                    <div class="item" >
                                       <span class="fa fa-sitemap"></span> <?=$this->profile["UnionName"]?>
                                    </div>
                                    <div class="item">
                                        <span class="<?=$UserIcon?>"></span> <?=$this->profile["Ethnicity"]?>, <?=$this->profile["Sex"]?> <?=age($this->profile["DateOfBirth"] )?>
                                        
                                    </div>  
                                    <div class="item" >
                                       <span class="fa fa-map-marker"></span> 
                                        <?php 
                                        if($this->profile["JobType"]==2){
                                            echo $this->profile["CategoryName"].",  Pos: ".$this->POS;
                                        }else{
                                             echo $this->profile["CategoryName"].", Role: ".$this->profile["TypeName"];;
                                        }
                                        ?>
                                    </div>
                                
                                </div>
                            </div>
	        	</div>
	        	</div>
                   
        	 <?php
                                    if($this->profile["CID"]>0){
                                        
?>
                <div class="row-fluid" style="margin-bottom:20px">
	        	<div class="span12" style="background: #FFF;">
	        		<div class="head clearfix">
                                    
	                    <h1><div class="fa fa-info-circle" style="color:#fff;font-size: 18px;"></div> Quick Information</h1>                     
	                </div>
                            <div class="block-fluid">
                               
                                <div class="sidebar">
                                    <div class="item" >
                                        <div class="span6">Account Active</div><div class="span6">
                                            <?php
                                            if($this->profile["Active"]==1){
                                                echo "Yes";
                                            }else{
                                            	if($this->profile["Status"] ==1 && $this->profile["CID"] >0){
                                            		 echo "Pending"; 
												}else{
													 echo "No"; 
												}
                                              
                                            }
                                            ?>
                                        </div>
                                        <div style="clear:both"></div>
                                    </div>
                                    <div class="item" >
                                        <div class="span6">First Login</div><div class="span6">
                                            <?php
                                            if($this->profile["Status"] >0){
                                                echo "Yes";
                                            }else{
                                              if($this->profile["Status"] ==0 && $this->profile["CID"] >0){
                                            		 echo "Pending"; 
												}else{
													 echo "No"; 
												}
                                            }
                                            ?>
                                        </div>
                                        <div style="clear:both"></div>
                                    </div>
                                    <?php 
                                    if($this->profile["Active"] ==1 && $this->profile["Status"]==1){
                                    ?>
                                    <div class="item" >
                                        <div class="span6">Last visit</div><div class="span6">
                                            <?php
                                            if($this->profile["LastLogin"]=="0000-00-00 00:00:00"){
                                                echo "Never";
                                            }else{
                                              echo date("j F Y H:i",  strtotime($this->profile["LastLogin"]));  
                                            }
                                            ?>
                                        </div>
                                        <div style="clear:both"></div>
                                    </div>
                                    <?php
                                    }
                                    if($this->profile["JobType"]==2){
                                        echo '<div class="item" >';
                                        echo '<div class="span6">Scouted: </div>';
                        if($this->profile["ScoutID"] >0 && $this->profile["Scouted"] !=0){
                        echo '<div class="span6">Yes</div>';
                            
                        } else{
                           echo '<div class="span6">No</div>'; 
                        }
                                    echo '<div style="clear:both"></div>
                                    </div>';}?> 
                                    <?php 
                                    if($this->profile["Active"] ==1  && $this->profile["Status"]==0){
                                    ?>
                                <div class="item" >
                                        <div class="span6">First Login</div><div class="span6">No</div>
                                        <div style="clear:both"></div>
                                    </div>
                                    <?php
                                    }?>
                                    <div class="item" >
                                        <div class="span6">Details Verified</div><div class="span6">
                                            <?php
                                            if($this->profile["Verified"]==1){
                                                echo "Yes";
                                            }else{
                                              echo "No";  
                                            }
                                            ?>
                                        </div>
                                        <div style="clear:both"></div>
                                    </div>
                                    
                                </div>
                            </div>
	        	</div>
	        	</div>
                    <?php }
                                    if($this->profile["JobType"]==2){
                                        
?>
                <div class="row-fluid" style="margin-bottom:20px">
	        	<div class="span12" style="background: #FFF;">
	        		<div class="head clearfix">
                                    
	                    <h1><div class="fa fa-info-circle" style="color:#fff;font-size: 18px;"></div> Squads This Season</h1>                     
	                </div>
                            <div class="block-fluid">
                               
                                <div class="sidebar">
                                    <?php
                                    $no = '<div class="item" >
                                        <div class="span12">No Squads This Season</div>
                                        <div style="clear:both"></div>
                                    </div>';
                                    if(count($this->Participations)>0){
                                    	$count =0;
                                        foreach($this->Participations as $Squad){
                                        	if(date("Y",strtotime($Squad["FormDate"])) == date("Y")){
                                        		$count++;
                                    ?>
                                    <div class="item" >
                                        <div class="span8"><?=ucfirst($Squad["SquadName"])?></div><div class="span4"><?=date("d/m/Y",  strtotime($Squad["FormDate"]))?></div>
                                        <div style="clear:both"></div>
                                    </div>
                                    <?php }} 
									if($count==0){
										echo $no;
									}
									
									}else{
                                       echo $no; 
                                    }
?>
                                    
                                </div>
                            </div>
	        	</div>
	        	</div>
                                    <?php } ?>
                </div><!-- End span4 -->
                
                <div class="span9">
                	
                	<div class="span12" style="margin: 0px; margin-bottom:20px ">
                        <div class="head clearfix">
                            <div class="isw-cloud"></div>
                            <h1>Profile information</h1>
                            <ul class="buttons">        
                                
                                <li class="toggle active"><a href="#"></a></li>
                            </ul> 
                            
                        </div>
                        <div class="block  " style="padding: 0px; margin: 0px">
                    <div class=" tabs " data-cookie="widget_1" style="padding:0px; ">                        
                            

                            <ul class="profileTabs" style="display: none">
                                <li><a href="#PersonalDetails-tab"><span class="hidden-desktop hidden-tablet">PD</span> <span class="visible-desktop visible-tablet">Personal Details</span></a></li>
                                <li><a href="#Contacts-tab"><span class="hidden-desktop hidden-tablet">CD</span> <span class="visible-desktop visible-tablet">Contacts Details</span></a></li>
                                <li><a href="#Organisation-tab"><span class="hidden-desktop hidden-tablet">ORG</span> <span class="visible-desktop visible-tablet">Organisation</span></a></li>
                                <?php if($this->ShowTabs["Parent"]==0) {
                                ?>
                                <li ><a href="#Parent-tab"><span class="hidden-desktop hidden-tablet">Parent</span> <span class="visible-desktop visible-tablet">Parent/Guardian</span></a></li>
                                <? }?>
                                <li><a href="#Medical-tab"><span class="hidden-desktop hidden-tablet">MED</span> <span class="visible-desktop visible-tablet">Medical Aid</span></a></li>
                                <li><a href="#Apparel-tab"><span class="hidden-desktop hidden-tablet">APP</span> <span class="visible-desktop visible-tablet">Apparel (Kit)</span></a></li>
                                <li><a href="#Social-tab"><span class="hidden-desktop hidden-tablet">SN</span> <span class="visible-desktop visible-tablet">Social Networks</span></a></li>
                                 <?php
                                                if($this->profile["CID"] >0 && $this->profile["Active"] ==1  && $this->UserDetails["UnionType"]<3){
                                             ?>
                                <li><a href="#AccessRights-tab"><span class="hidden-desktop hidden-tablet">AR</span> <span class="visible-desktop visible-tablet">Access Rights</span></a></li>
                                                <?php }?>
                            </ul>                        

                        <div id="PersonalDetails-tab" class="form-parent">
                        	<div class="clearfix loadingPage" style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>
                        	<div class="DetailsContent" style="display: none" pid="PersonalDetails-tab">
                           <?=$this->partial('/members/profile/personaldetails.phtml',array(
                           "profile"=>$this->profile
                           )) ?>
                          </div>  
                          <div class="DetailsContent_Edit" style="display: none">
                             	<div class="clearfix " style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>
                        	
                             </div>        
                          </div>              

                            <div id="Contacts-tab" class="form-parent">
                            <div class="DetailsContent" pid="Contacts-tab" style="display: none">
                        		
                             <?=$this->partial('/members/profile/contactsdetails.phtml',array(
                             "profile"=>$this->profile
							 )) ?>
                             </div>
                             <div class="DetailsContent_Edit" style="display: none">
                             	<div class="clearfix " style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>
                        	
                             </div>
                             </div>

                            <div id="Organisation-tab" class="form-parent ">
                            	<div class="DetailsContent" pid="Organisation-tab" style="display: none">
                        		
                                <?=$this->partial('/members/profile/organisationdetails.phtml',array(
                                "profile"=>$this->profile
                           
								)) ?>
								</div>
								<div class="DetailsContent_Edit" style="display: none">
									<div class="clearfix " style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>
                        	
                             </div>
                                 </div>
                        <?php if($this->ShowTabs["Parent"]==0) {
                                ?>
                        <div id="Parent-tab" class="form-parent">
                        	<div class="DetailsContent" pid="Parent-tab" style="display: none">
                        		
                        	<?=$this->partial('/members/profile/guardian.phtml',array(
                        	 "profile"=>$this->profile
							)) ?>
							</div>
							<div class="DetailsContent_Edit" style="display: none">
								<div class="clearfix " style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>
                        	
                             </div>
                            </div>
                        <? }?>
                            <div id="Medical-tab" class="form-parent">
                            	<div class="DetailsContent" pid="Medical-tab" style="display: none">
                        		
                               <?=$this->partial('/members/profile/medicalaid.phtml',array("profile"=>$this->profile)) ?>
                               </div>
                               <div class="DetailsContent_Edit" style="display: none">
                               	<div class="clearfix " style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>
                        	
                             </div>
                               </div>              
                        <div id="Apparel-tab" class="form-parent">
                        	<div class="DetailsContent" pid="Apparel-tab" style="display: none">
                        		
                                <?=$this->partial('/members/profile/apparel.phtml',array("profile"=>$this->profile)) ?>
                                </div>
                                <div class="DetailsContent_Edit" style="display: none">
                                	<div class="clearfix " style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>
                        	
                             </div>
                            </div>
                        <div id="Social-tab" class="form-parent">
                        	<div class="DetailsContent" pid="Social-tab" style="display: none">
                                <?=$this->partial('/members/profile/socialnetwork.phtml',array("profile"=>$this->profile)) ?>
                                </div>
                                <div class="DetailsContent_Edit" style="display: none">
                                	<div class="clearfix " style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>
                        	
                             </div>
                            </div>
                       
                        
                       
                        
                        
                        <?php
					if($this->profile["CID"] >0 && $this->profile["Active"] ==1  && $this->UserDetails["UnionType"]<3){
									            ?>
                        <div id="AccessRights-tab">
                               
                         <form id="AcssRole">
                        	
                    <table class=" table">
                    	<tr>
                    		<th class="span2">Models</th>
                    		<th class="span9">Actions</th>
                    		<th class="span1">#</th>
                    	</tr>
                        <?php if($this->profile["UnionType"] > 2){?>
                    <tr>
                                <td>Union Access:</td>
                                <td>
                    			<label class="btn btn-gray tipb" title ="Administrator">
                                        <input type="checkbox" name="data[Administrator]" <?php if($this->profile["Administrator"]==1){ echo 'checked="true"' ;}?> value="1" class="selectRow"/> Administrator
                                    </label>
                                </td>
                                <td>
                                	<input type="checkbox"  class="parentLine"/>
                                </td>
                     </tr> 
                        <?php } ?>
                  <tr>
                                <td>User Login:</td>
                                <td>
                    			<label class="btn btn-gray tipb" title ="FPLogin">
                                        <input type="checkbox" name="data[FPLogin]"  
                                        <?php if($this->profile["FPLogin"] == 1){ echo 'checked="true"' ;}?>
                                        value="1" class="selectRow"/> FP Login
                                    </label>
                                    <label class="btn btn-gray tipb" title ="EFLogin">
                                        <input type="checkbox" name="data[EFLogin]"  
                                        <?php if($this->profile["EFLogin"] == 1){ echo 'checked="true"' ;}?>
                                        value="1" class="selectRow"/> EF Login
                                    </label>
                                   
                                </td>
                                <td>
                                	<input type="checkbox"  class="parentLine"/>
                                </td>
                     </tr> 
                    <?php foreach($this->Models as $Model){
                    	$ModelDB = new Model_DbTable_Models;
			$Actions = $ModelDB->getActions($Model["MID"]);
                    	?>
                    <tr>
                                <td><?=$Model["Model_Name"]?>:</td>
                                <td>
                                	<?php foreach($Actions as $Action){
                    								?>
                    							<label class="btn btn-gray tipb" title ="<?=$Action["Info"]?>">
                                        <input type="checkbox" name="model[][MID]" <?php if(isset($this->role[$Model["Model"]]["Actions"][$Action["Action"]])){ echo 'checked="true"' ;}?> 
                                        <?php if($Action["Action"] =="FPLogin" && $this->profile["FPLogin"] == 1){ echo 'checked="true"' ;}?>
                                         
                                         <?php if($Action["Action"] =="EFLogin" && $this->profile["EFLogin"] == 1){ echo 'checked="true"' ;}?>
                                        value="<?=$Model["Model"]?>|<?=$Action["Action"]?>" class="selectRow"/> <?=$Action["Action_Name"]?>
                                    </label>
                                    <?php } ?>
                                </td>
                                <td>
                                	<input type="checkbox"  class="parentLine"/>
                                </td>
                     </tr> 
                    <?php } ?>
                   
                  </table>
                <div class="footer tal" style=" text-align: right">
                	<input type="button" class="btn " onclick="SubmitRole()" value="Submit" />
                	</div>  
                 </form>
                            
               
                     
                         
                        </div>
                        <?php } ?>
                          </div>                
                        </div>       
                    </div>
                    
                    
                    
                    <div id="SquadParticipation">
                    	
                    </div>
                    
                    <div id="FixtureParticipation">
                    	
                    </div>
                    
                    
                </div>





</div>


   <script>
       var checkID = "";
       var listcities ="";
       
       $(function(){
       	$(".profileTabs").show();
       	$("#SquadParticipation").load("/members/squads/id/<?=$this->profile["UserID"] ?>");
       	$("#FixtureParticipation").load("/members/fixturesplaid/id/<?=$this->profile["UserID"] ?>");
       	
            $(".loadingPage").hide();
            $(".DetailsContent").show();
            // MySquadsList(); 
            $('#DateOfBirthInPut').mask('00-00-0000');
           $("#DateOfBirthInPut").datepicker({ dateFormat: 'dd-mm-yy' });
          // loadpage("personaldetails","PersonalDetails-tab");
          // loadpage("contactsdetails","Contacts-tab");
          // loadpage("organisationdetails","Organisation-tab");
          // loadpage("guardian","Parent-tab");
          // loadpage("medicalaid","Medical-tab");
         //  loadpage("apparel","Apparel-tab");
         //  loadpage("socialnetwork","Social-tab");
           
           
           $("#submitChange").click(function(){
			$("#errorBox").html("");
			if($("#Password").val() == $("#cPassword").val() && $("#Password").val() !=""){
			$.post("/members/password/id/<?=$this->profile["UserID"]?>/pass/"+$("#Password").val(),function(r){
                            $("#PaassWord").modal("hide");
                             notify_s('Success','Password successfully changed!');
				});
			}else if($("#Password").val() =="" ){
                            notify_e('Error','Password can not be emapty!');
			}else{
                            notify_e('Warning','Password does not match!');
			}
		});
		
               $("#pictureUploaded").change(function(){
               	 var selected_file = $(this).get(0).files[0];
             	 		handleFilesProfilePic(selected_file) ;
               });
               
               
               
               
               
             var bar = $('#picBar');
							var percent = $('#picPercent');
							var status = $('#picstatus');  
               ///UPLOAD PROFILE PIC
               $('#uploadProfilePicForm').ajaxForm({
    beforeSend: function() {
        status.empty();
        var percentVal = '0%';
        percent.width(percentVal)
         percent.html(percentVal);
        var filename = /([^\\]+)$/.exec($("#videoFile").val())[1];
        bar.show();
    },
    uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        percent.width(percentVal)
         percent.html(percentVal);
    },
    success: function() {
        var percentVal = '100%';
        percent.width(percentVal)
        percent.html("Completed ... "+percentVal);
    },
error: function (jqXHR, textStatus, errorThrown) {
	alert("there was an error");
	bar.hide();
	percent.width(0);
},
	complete: function(xhr) {
		location.reload();
		var json = jQuery.parseJSON(xhr.responseText);
		if(json.Message =="Error"){
				alert("there was an error");  	
				  
		}else{
			location.reload();
			
		}
	
		
	
		
	}
}); 
          
       });
       
       $(document).ready(function() {
    $('#applicantsTable').DataTable();
} );
       
	function showEdit(e){
            var form = $(e).parents(".form-parent").attr("id");
            
            $("#"+form+" .DetailsContent").hide();
            $("#"+form+" .DetailsContent_Edit").show();
            var page = $(e).attr("page");
            var id = $(e).attr("pageid");
           editpage(page,"#"+form+" .DetailsContent_Edit");
        
           
            
        }
         function CancelEdit(e){
            var form = $(e).parents(".form-parent").attr("id");
            
            $("#"+form+" .DetailsContent").show();
            $("#"+form+" .DetailsContent_Edit").hide();
           }
           
           
    function submitEdit(e){
    	var Formid = $(e).parents(".form-parent").attr("id");
            var form = $(e).parents(".form-profile").attr("id");
            
            var data = $("#"+form).serialize();
        
            $.post("/members/saveaccount/id/<?=$this->profile["UserID"]?>",data,function(r){
                if(r.OK==0){
                    notify_s('Success','Data was saved successfully!');
                    var page = $(e).attr("page");
                  //  var id = $(e).attr("pageid");
                    loadpage(page,"#"+Formid+" .DetailsContent");
                    $("#"+Formid+" .DetailsContent").show();
            $("#"+Formid+" .DetailsContent_Edit").hide();
          
                }else{
                    notify_e('Warning','Data could not be save please contact administration');
                }
                
            },"json");
            
        }       
           
  var loading ='<div class="clearfix" style="background: #FAFAFA url(/img/ajax-loader.gif) no-repeat center; min-height: 500px"></div>';         
  function loadpage(page,eml){
      $(eml).html(loading);
            $.post("/members/loadprofile/id/<?=$this->profile["UserID"]?>/page/"+page,function(html){
               $(eml).html(html);
            });
        }         
           
function editpage(page,elm)
{
     $(elm).html(loading);
            $.post("/members/editprofile/id/<?=$this->profile["UserID"]?>/page/"+page,function(html){
               $(elm).html(html);
            });
}            
           
function DiettryType(e)
{
    var type = $(e).val();
    if(type==3){
        $("#otherSpecify").show();
        $("#otherSpecifyText").val('<?=$this -> profile["DiettryOther"]?>');
    }else{
        $("#otherSpecify").hide();
        $("#otherSpecifyText").val();
    }
 }
 
  var DID;
   var btn;
 function deleteFile(e)
 {
     btn = e;
     DID= $(e).attr("pid");
    
     $("#AlertMessage").modal("show");
 }
 
function ConfirmDeleteFile()
{
	
   $.post("/union/members/deletefile/did/"+DID+"/id/<?=$this->profile["UserID"] ?>",function(img){
       notify_s("File Delete Sucessfully!");
                	location.reload();
                });
   
}


function checkid(e){
    var SAID = $(e).val();
    $(e).css({"border":"1px solid #ccc"})
    var IDType = $("#IDType").val();
    
    
    if(IDType !=2){
    if(SAID.length==13){
        
        var validate = validateSAID(SAID) ;
        if(validate==false){
            $(e).css({"border":"1px solid #f00"});
            $("#IDNumber2").val("");
        }else{
            
            $(e).css({"border":"1px solid #ccc"})
            var data = new Object();
            data.id ='<?= $this->profile["UserID"] ?>';
            data.idNum =SAID;
            $.post("/members/checkid/",data,function(resp){
                if(resp.found==0){
                    var tempDate = new Date(SAID.substring(0, 2), SAID.substring(2, 4) - 1, SAID.substring(4, 6));
                    var id_date = tempDate.getDate();
                    var id_month = tempDate.getMonth();
                    var id_year = tempDate.getFullYear();
                    $("#birthyear").val(id_year);
                    $("#birthmonth").val(("0" + (id_month + 1)).slice(-2));
                    $("#birthday").val(("0" + id_date).slice(-2));
                    notify_s('Success','The ID number was validated successfully!');
                    $("#IDNumber2").val(SAID).focus();
                }else{
                    notify_e('Warning','The ID number was found with other user on the system!');
                    
                    $("#IDNumber2").val("");
                    $(e).css({"border":"1px solid #f00"});
                }
            },"json");
        }
    }else{$("#IDNumber2").val("");}
    }else{
    $("#IDNumber2").val("");
    }
    
}
function Validate(idNumber) {
    
    // get first 6 digits as a valid date
    var tempDate = new Date(idNumber.substring(0, 2), idNumber.substring(2, 4) - 1, idNumber.substring(4, 6));

    var id_date = tempDate.getDate();
    var id_month = tempDate.getMonth();
    var id_year = tempDate.getFullYear();
    $("#birthyear").val(id_year);
    $("#birthmonth").val(("0" + (id_month + 1)).slice(-2));
    $("#birthday").val(("0" + id_date).slice(-2));
    var fullDate = id_date + "-" + (id_month + 1) + "-" + id_year;

    // get the gender
    var genderCode = idNumber.substring(6, 10);
    var gender = parseInt(genderCode) < 5000 ? "Female" : "Male";

    // get country ID for citzenship
    var citzenship = parseInt(idNumber.substring(10, 11)) == 0 ? "Yes" : "No";

}

function isNumber(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}

function ValidateEmail(mail)   
    {  
     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))  
      {  
        return (true)  
      }  

        return (false)  
    }
    
    function validateSAID(id){
       try {
           if (id.length != 13) {
     
     return false;
     }
           var y1o = id.substring(0, 1)
           var y2e = id.substring(1, 2)
           var m1o = id.substring(2, 3)
           var m2e = id.substring(3, 4)
           var d1o = id.substring(4, 5)
           var d2e = id.substring(5, 6)
           var go = id.substring(6, 7)
           var s1e = id.substring(7, 8)
           var s2o = id.substring(8, 9)
           var s3e = id.substring(9, 10)
           var co = id.substring(10, 11)
           var ae = id.substring(11, 12)
           var z = id.substring(12, 13)

           var A = 0;
           A = parseInt(A) + parseInt(y1o) + parseInt(m1o) + parseInt(d1o) + parseInt(go) + parseInt(s2o) + parseInt(co);
           var B1 = y2e + m2e + d2e + s1e + s3e + ae;
           var B2 = B1 * 2;
           var i = 0;
           var B3 = 0;
           var B2string = B2.toString();
           while (B2string.length > i) {
               var x = B2string.substring(i, i + 1);
               B3 = B3 + parseInt(x);
               i = i + 1;
           }

           var C = A + B3;
           var Cstring = C.toString();
           var secNo = Cstring.substring(1, 2);
           var D = 10 - parseInt(secNo);
           while (D >= 10) D = D - 10;
           if (D == z) {
               //test for valid date in 1900
               var valid = true;
               var bd = new Date('19' + y1o + y2e, parseInt(m1o + m2e) - 1, d1o + d2e);
               if ((bd == 'NaN') | (bd == 'Invalid Date')){ valid = false;}
               else if (bd.getFullYear() != parseInt('19' + y1o + y2e)) {valid = false;}
               else if (bd.getMonth() + 1 != parseInt(m1o + m2e)) {valid = false;}
               else if (bd.getDate() != parseInt(d1o + d2e)) {valid = false;}
               if (valid==true){ 
                   
                    //alert('19' + y1o + y2e);
                    return valid;
               }
               
               //if invalid test again in 2000
               
               bd = new Date('20' + y1o + y2e, parseInt(m1o + m2e) - 1, d1o + d2e);
               if ((bd == 'NaN') | (bd == 'Invalid Date')){ valid = false;}
               else if (bd.getFullYear() != parseInt('20' + y1o + y2e)){ valid = false;}
               else if (bd.getMonth() + 1 != parseInt(m1o + m2e)){ valid = false;}
               else if (bd.getDate() != parseInt(d1o + d2e)) {valid = false;}
                if (valid==true){ 
                   
                    //alert('19' + y1o + y2e);
                    return valid;
               }
           }
           else {
     
               return false;
           }
       }
       catch (e) {
   
           return false;
       }
   }
   
   function ChangePassword(e){
		$("#PaassWord").modal("show");
	}
        
    
	function ActivateAccount(){
		$("#AlertPopActivate").modal("show");
	}
	function ActiveNow(){
		$.post("/members/activate/id/<?=$this->profile["UserID"]?>/login/1",function(r){
                    notify_s('Success','Account was actived successfully!');
					location.reload();
				});
	}
	function ActiveNowAccount(){
		$.post("/members/activate/id/<?=$this->profile["UserID"]?>",function(r){
                    notify_s('Success','Account was actived successfully!');
					location.reload();
				});
	}
	
	function ActivateLogin(e){
            var email = parseInt('<?=$Email?>');
            
            if(email==1){
		$("#AlertPopActivateLogin").modal("show");
            }else{
                $(e).checked = false; 
                
                notify_e('Warning','Account can not be activated, please complete primary email on the profile');
            }
	}
        function ResetAccount(){
		$("#ResetPopActivate").modal("show");
	}
	
	
	function DetactiveAccount(){
		$("#AlertPopDeactivate").modal("show");
	}
	function DetactiveNow(){
		$.post("/members/deactivate/id/<?=$this->profile["UserID"]?>",function(r){
                    notify_s('Success','Account was deactived successfully!');
					location.reload();
				});
	}
        
        function ResetNowAccount(){
		$.post("/members/resetaccount/id/<?=$this->profile["UserID"]?>/reset/1/",function(r){
                    notify_s('Success','Account was reset successfully!');
					location.reload();
				});
	}
        
function handleFilesProfilePic(file){
  
    
    var imageType = /image.*/;
     
    if (!file.type.match(imageType)) {
      $(".file-input-wrapper span").text("Select file");
      //alert("Please upload an image file");
        }else{
            $("#cp_acceptWrapa").show()
        // $("#PictureCropArea").html("<tr style=''><td colspan='4' style='height:300px'></td></tr>").addClass("loadingPage");   
            var filetype = file.type.split("/");
            $("#ImgType").val(filetype[1]);
           
         var img = document.createElement("img");
   		 img.classList.add("obj");
    	img.file = file;
   // $("body").append(img);
    
            var reader = new FileReader();
            reader.onload =function(e) {
                
              $("#PictureCropArea").html('<div class="col-md-12 "><div class="img-container" style="height: 250px"><img id="image" src="'+e.target.result+'" alt="Picture"></div></div>');
                pictureCrop();
                };
            reader.readAsDataURL(file);
    }
     
} 
function SubmitRole(){
		var data = $("#AcssRole").serialize()
		 $.post("/members/submitroles/id/<?=$this->profile["UserID"]?>",data,function(){
		 	$("#AlertPopSaved").modal("show");
		 	setTimeout(function (){

  	$("#AlertPopSaved").modal("hide");

}, 5000);
		 });
	}
    
function UploadPic(e){
      $("#ProfilePicUpload").modal("show"); 
        
     $("#PictureCropArea").html('<div class="clearfix cropperwrapa-bg " style="  no-repeat center; min-height: 250px; line-height:250px; font-size:18px; text-align:center">Select your picture, please note, JPEG only</div>');
        
   }   
   
   
   
   
   
   
   function ChangePic(e){
       $("#avatar-modal").modal();
       $("#PictureCropArea").html('<div class="clearfix cropperwrapa-bg " style="  no-repeat center; min-height: 250px; line-height:250px; font-size:18px; text-align:center">Click the Button below to upload file, Please note jpg files only.</div>');
     
   }
   
   function BrowserForImage(){
       $("#pictureUploaded").click();
   }
   function pictureCrop(){
       'use strict';
//16 / 9
  var console = window.console || { log: function () {} };
  var $image = $('#image');
  var $download = $('#download');
  var $dataX = $('#dataX');
  var $dataY = $('#dataY');
  var $dataHeight = $('#dataHeight');
  var $dataWidth = $('#dataWidth');
  var $dataRotate = $('#dataRotate');
  var $dataScaleX = $('#dataScaleX');
  var $dataScaleY = $('#dataScaleY');
  var options = {
        aspectRatio: 1 / 1,
        preview: '.img-preview',
        crop: function (e) {
          $dataX.val(Math.round(e.x));
          $dataY.val(Math.round(e.y));
          $dataHeight.val(Math.round(e.height));
          $dataWidth.val(Math.round(e.width));
          $dataRotate.val(e.rotate);
          $dataScaleX.val(e.scaleX);
          $dataScaleY.val(e.scaleY);
        }
      };


  // Cropper
  $image.on({
    'build.cropper': function (e) {
      console.log(e.type);
    },
    'built.cropper': function (e) {
      console.log(e.type);
    },
    'cropstart.cropper': function (e) {
      console.log(e.type, e.action);
    },
    'cropmove.cropper': function (e) {
      console.log(e.type, e.action);
    },
    'cropend.cropper': function (e) {
      console.log(e.type, e.action);
    },
    'crop.cropper': function (e) {
      console.log(e.type, e.x, e.y, e.width, e.height, e.rotate, e.scaleX, e.scaleY);
    },
    'zoom.cropper': function (e) {
      console.log(e.type, e.ratio);
    }
  }).cropper(options);

 // Methods
  $('.docs-buttons').on('click', '[data-method]', function () {
    var $this = $(this);
    var data = $this.data();
    var $target;
    var result;

    if ($image.data('cropper') && data.method) {
      data = $.extend({}, data); // Clone a new one

      if (typeof data.target !== 'undefined') {
        $target = $(data.target);

        if (typeof data.option === 'undefined') {
          try {
            data.option = JSON.parse($target.val());
          } catch (e) {
            console.log(e.message);
          }
        }
      }

      result = $image.cropper(data.method, data.option, data.secondOption);
        $("#PictureCropArea").html('<div class="clearfix cropperwrapa-bg" style=" no-repeat center; min-height: 250px; line-height:250px; font-size:18px; text-align:center">uploading, please wait....</div>'); 
        $(".file-input-wrapper span").text("Uploading please wait..");
        $("#cp_acceptWrapa").hide()
        $("#imageFile1").val(result.toDataURL('image/jpeg'))
        $("#SubmitProfilePicBtn").click();
    var data = "Avatar="+result.toDataURL('image/jpeg');
  
     /*
    $.post("/members/uploadimage/id/<?=$this->profile["UserID"]?>",data,function(){
                	location.reload();
        })
       */
       // CurrentSID 
                ;

    }
  });
       
    }
    
    function UploadDocuments(){
	$("#DocumentsUpload").modal();
	$.get("/members/uploads/id/<?=$this->profile["UserID"]?>",function(data){
		$("#DocumentsUploadWrapa").html(data);
	});
	
}
function MySquadsList(){
    //MySquadsList
    $.get("/members/mysquads/id/<?=$this->profile["UserID"]?>",function(data){
		
	});
}
</script>




<div id="DocumentsUpload" class="modal hide fade" style="width: 350px">
	<div class="modal-header">
		<button type="button" class="close DoNotCraeteGrant" data-dismiss="modal" aria-hidden="true">×</button>
		<h3 id="myModalLabel">Document Upload</h3>
	</div >
	<div id="DocumentsUploadWrapa">
	<p>Loading please wait....</p>
	<div>
		
	</div>
	
</div>
</div>
        
  <div  id="avatar-modal" class="modal hide fade">
	<div class="modal-header">
		<button type="button" class="close DoNotCraeteGrant" data-dismiss="modal" aria-hidden="true">×</button>
		<h3 id="myModalLabel">Upload Avator</h3>
	</div >
	<div class="modal-content docs-buttons">
      <div id="PictureCropArea" style=" min-height: 250px" >
              
              <div style=" line-height: 250px; " >
               <div class="text-center" id="cp_target">Click the Button below to upload file, Please note jpg files only.</div>
                                     
            </div>
         </div>
         
            <div class="modal-body form-horizontal form-group-separated">
               <div class="form-group">
                  <label class="span4 control-label">New Photo</label>
                  <div class="span3">
                      <a class="btn " onclick="BrowserForImage()" style="  max-width: 364px; overflow: hidden">Select file</a>
                  </div>
               </div>
            </div>
         <div id="picBar" style="height: 20px; border: 1px solid #ccc; display: none; margin: 5px 10px">
  	<div id="picPercent"  style="background: green;height: 18px; margin-top: 1px; text-align: center"></div>
  </div>
         <div class="modal-footer">
             <div  id="cp_acceptWrapa" style=" display: none" class=" pull-right">
                 <button type="button" class="btn btn-success " id="cp_accept"  data-method="getCroppedCanvas">Accept</button>
             </div>  
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
         </div>
        </div>     
        
  </div>
        
        
 <!-- Cropping modal -->
 
 
 
 
 
 

    <div id="UploadMyImg"  class="modal hide fade" >
        <div class="modal-header">
		<button type="button" class="close "   data-dismiss="modal"   aria-hidden="true">×</button>
		<h3 id="myModalLabel">Upload Picture</h3>
	</div>
        
    </div><!-- /.modal -->
  
    
    <input id="pictureUploaded"  class="fileinput btn-info" style="display: none" type="file" title="Select file" data-filename-placement="inside" name="file">
    
    
    
    
    
    
     <div  id="AlertMessage" class="modal hide fade">
	<div class="modal-header">
		<button type="button" class="close DoNotCraeteGrant" data-dismiss="modal" aria-hidden="true">×</button>
		<h3 id="myModalLabel"><span style="color: #fff"> <span class="fa fa-exclamation-triangle" ></span> Confirm Delete </span></h3>
	</div >
	<div class="modal-content">
      
            <div class="modal-body form-horizontal form-group-separated">
               <p>
               <span class=""  style="color: #999; font-size: 12px; margin: 5px" id="AlertContent">Are you sure you want to delete this file?</span>  
            </p
            </div>
        
         <div class="modal-footer">
             <button type="button" class="btn btn-danger  pull-right " data-dismiss="modal" onclick="ConfirmDeleteFile()">Delete <i class="fa fa-angle-double-right"></i></button>
            <button type="button" class="btn btn-default  pull-left"  data-dismiss="modal">Cancel</button>
         </div>
        </div>     
        
  </div>