<?php 
	
	include_once("../view/header-footer/header.php");    
	include_once("../all-ajax/inner-header.php");    
?>   

<script src="<?php echo ROOTPATH;?>/view/js/tab/search_candidate.js"></script>      
<script>
var last; 
$(document).ready(function(){      

	site_id = '<?php echo $_REQUEST['site_id']; ?>';
	job_city_id = '<?php echo $job_city_id; ?>';
	job_id = '<?php echo $job_id; ?>';
	
	//alert(apply_city_id);
	$(".comboText").click(function(){
		$(this).next().slideDown();
	});

	$("#clear_searchcandidate_locality").click(function(){ 
	
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/search_candidate.php", 
		data: {clear_searchcandidate_locality:1},
		beforeSend: function(){ 
		},
		success: function(data)
		{   
			$("#MyIframeDivs").load("searchcandidateLoad.php");  
			$("#locality_placed").html('');  
			location.reload();
		}
		}); 
	});	
	
	$("#clear_all_job_filers").click(function(){ 
	
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/search_candidate.php", 
		data: {clear_all_job_filers:1},
		beforeSend: function(){ 
		},
		success: function(data)
		{   
			$("#MyIframeDivs").load("searchcandidateLoad.php"); 
			location.reload();
		}
		}); 
	});	
	
	$("#clear_gender_filter").click(function(){ 
	
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/search_candidate.php", 
		data: {clear_gender_filter:1},
		beforeSend: function(){ 
		},
		success: function(data)
		{   
			$("#MyIframeDivs").load("searchcandidateLoad.php");
			location.reload();
		}
		}); 
	});
	
	$("#clear_profile_search").click(function(){ 
	
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/search_candidate.php", 
		data: {clear_profile_searchcandidate:1},
		beforeSend: function(){ 
		},
		success: function(data)
		{   
			$("#MyIframeDivs").load("searchcandidateLoad.php");
			location.reload();
		}
		}); 
	});
	
	$("body").click(function(e) 
	{    
		
		if ( e.target.id == "job-locality" || $(e.target).parents("#suggesstion_comboText").size() ) 
		{ 
             //alert("Inside div");   
        } else 
		{   
			 
			 
			$("#job-locality").val('');
			$("#suggesstion_comboText").slideUp(500);
        }   
    });	
    
    $("#search_roles_").keyup(function() 
	{
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/search_candidate.php", 
			data: {select_searchcandidate_category:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{  
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{  
					 
					$("#suggesstion_search_roles_").hide();
				}else
				{  	
					source_first_name = obj[0].name; 
					source_list = '<ul class="sug-box">'; 
					
					for(i=0;i<obj.length;i++)			  
					source_list +='<li id=searchcandidate-category><input type=radio name=searchcandidate-category onclick=searchcandidate_by_category("'+i+'","'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'")>'+obj[i].name+'</li>'
					
					
					source_list +='</ul>';   
					$("#suggesstion_search_roles_").show();
					$("#suggesstion_search_roles_").html(source_list); 
				}   
				
			}
		}); 
	});
	
	$("#job-locality").keyup(function() 
	{  
		city_id = '<?php echo $_REQUEST['city_id']; ?>';   
		$.ajax({	
			type: "POST",
			//url: URL+"/all-ajax/job.php", 
			//data: {job_locality:1,keyword:$(this).val(),city_id:$("#search_city_id_hidden").val()},
			url: URL+"/all-ajax/search_candidate.php", 
			data: {search_locality:1,keyword:$(this).val(),city_id:city_id},
			beforeSend: function(){ 
			},
			success: function(data)
			{  
				$("#job-locality-ul").hide();
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{  
					$("#suggesstion_comboText").hide();
					//$("#job-locality-ul").show();
					//$("#job-locality").val("entire city");
					$("#job-locality-ul").hide();
					
				}else
				{  	
					source_first_name = obj[0].location_name; 
					source_list = '<ul>'; 
					
					for(i=0;i<obj.length;i++)			
						source_list +='<li><a onClick=searchcandidate_by_locality("'+obj[i].id+'","'+encodeURIComponent(obj[i].location_name)+'") href="javascript:void(0)">'+obj[i].location_name+'</a></li>';   
					
					source_list +='</ul>';   
					$("#suggesstion_comboText").show();
					$("#suggesstion_comboText").html(source_list);    
				}    
			
			}
		}); 
	});
    
    
    // send sms
	$("#send_sms_frm").submit(function( event )  
	{ 	 
		if($('#send_sms_frm').valid())  
		{ 
			var formData=$('#send_sms_frm').serialize();  
			$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/search_candidate.php", 
			data: {send_sms_emp:1,formData:formData},	
					beforeSend: function(){
						
					},
					success: function(data){  					  
					$('#emp_send_sms').modal('hide');	
					alert("SMS Sent Successfully!!!");
					location.reload();
				}  
			});  
			return false; 			
	    }
		//event.preventDefault();  
	});
    
    // send email
	$("#send_email_frm").submit(function( event )  
	{ 	 
		if($('#send_email_frm').valid())  
		{ 
			var formData=$('#send_email_frm').serialize();  
			$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/search_candidate.php", 
			data: {send_email_emp:1,formData:formData},	
					beforeSend: function(){
						
					},
					success: function(data){  					  
					$('#emp_send_email').modal('hide');	
					alert("Email Sent Successfully!!!");
					location.reload();
				}  
			});  
			return false; 			
	    }
		//event.preventDefault();  
	});

    
});      

function searchcandidate_by_category(val,name,id)
{ 
    alert(id);
	var new_name = name.split(' ');	 
	new_name1 =   new_name[0].replace(new RegExp("%20", "g"), '_');        
	//new_name1 =   new_name1.replace(new RegExp("%2F", "g"), '_'); 
	new_name1 =   new_name1.replace(new RegExp("%2F", "g"), '_');    
	$.ajax({	
	type: "POST",
	url: URL+"/all-ajax/search_candidate.php", 
	data: {set_searchcandidate_filter:1,val:id,type:1},
	beforeSend: function(){ 
	},
	success: function(data)
	{  
    	$("#MyIframeDivs").load("searchcandidateLoad.php?site_id="+site_id+"&job_city_id="+job_city_id+"&job_id="+job_id);
	}
	});
	
}   


function searchcandidate_by_profile(val)
{
    $.ajax({	
	type: "POST",
	url: URL+"/all-ajax/search_candidate.php", 
	data: {searchcandidate_by_profile:1,val:val,remove:$('#profile_search'+val).is(':checked')},
	beforeSend: function(){ 
	},
	success: function(data)
	{  
		$("#MyIframeDivs").load("searchcandidateLoad.php?site_id="+site_id+"&job_city_id="+job_city_id+"&job_id="+job_id); 
	}
	});
	
}


function searchcandidate_by_gender(val)
{ 	 
	$.ajax({	
	type: "POST",
	url: URL+"/all-ajax/search_candidate.php", 
	data: {searchcandidate_by_gender:1,val:val,remove:$('#gender'+val).is(':checked')},
	beforeSend: function(){ 
	},
	success: function(data)
	{  
		$("#MyIframeDivs").load("searchcandidateLoad.php?site_id="+site_id+"&job_city_id="+job_city_id+"&job_id="+job_id); 
	}
	});	
}   

function searchcandidate_by_locality(val,name)
{
	new_name =   name.replace(new RegExp("%20", "g"), ' ');  
	$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/search_candidate.php", 
		data: {searchcandidate_by_locality:1,val:val,name:new_name},
		beforeSend: function(){ 
		},
		success: function(data)
		{  
            if(data=='false')
               alert("Location already added!"); 
			else {
    			$("#job-locality").val(''); 
    		    $("#suggesstion_comboText").hide();
    			$("#job-locality-ul").hide();
    			$("#locality_placed").html(data);  
    			
    			$("#MyIframeDivs").load("searchcandidateLoad.php?site_id="+site_id+"&job_city_id="+job_city_id+"&job_id="+job_id); 
			}
		}
	}); 
}

	
function searchcandidate_remove_locality(loc)
{ 
	new_name = loc.replace(new RegExp("%20", "g"), ' ');   
	$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/search_candidate.php", 
		data: {searchcandidate_remove_locality:1,name:new_name},
		beforeSend: function(){ 
		},
		success: function(data)
		{     
			$("#locality_placed").html(data);  
			$("#MyIframeDivs").load("searchcandidateLoad.php?site_id="+site_id+"&job_city_id="+job_city_id+"&job_id="+job_id); 
		}
	});  
	 
}



function send_sms(id)
{
    $("#emp_id").val(id);
    $("#emp_send_sms").modal({
		show: 'true',
		backdrop: 'static',
		keyboard:false
	});
} 

function send_email(id)
{
    $("#emp_id").val(id);
    $("#emp_send_email").modal({
		show: 'true',
		backdrop: 'static',
		keyboard:false
	});
}    


function view_emp_contact(id)
{
    $("#emp_view_contact").modal({
		show: 'true',
		backdrop: 'static',
		keyboard:false
	});
	
	$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/search_candidate.php", 
		data: {view_emp_contact:1,val:id},
		beforeSend: function(){ 
		},
		success: function(data)
		{
		    var obj = jQuery.parseJSON(data);  
			if(obj!=null || obj!='')
			{
			    $("#emp_name").val(obj['name']);
			    $("#emp_email").val(obj['email']);
			    $("#emp_phone").val(obj['phone']);
			}    
		}
	}); 
}


</script> 
<?php include_once("../all-ajax/inner-header.php");  ?> 
<div id="body" class="grey-bg">
<div class="wrapper">
<div class="bradeCrubs">
<!--<a href="<?php echo ROOTPATH;?>/MyDetails/ads.php">Home</a>
<a href="javascript:void(0);">Job</a>-->
<!--<a href="<?php echo ROOTPATH;?>/MyDetails/search_candidate.php?id=<?php echo $applyjobid;?>&city_id=<?php echo $applycityid;?>" class="current"><b>Search Candidates</b></a><br><br>-->
<a href="javascript:void(0);" class="current"><b>Search Candidates</b></a><br><br>
<a href="javascript:void(0);" class="current"><b><?php echo $jobs_result->heading ?> in <?php echo $city_name_result->name;?></b></a><br><br>

</div>
<div class="col-md-3 plr">
	<div id="dataLeft" class="job-filter">
    <div class="filterHead">Filter jobs 
    <a class="clearAll" href="javascript:void(0)" id="clear_all_job_filers">Clear All</a>
    </div>
    <div class="panel-group" id="accordion">
    
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 data-toggle="collapse" data-parent="#accordion" href="#collapse1"  class="panel-title expand collapsed">
           <div class="right-arrow pull-right">+</div>
          <a href="javascript:void(0);" class="big-head">Roles</a>
        </h4>
        <div class="col-md-8">
			<span id="categorylocality_placed" class="local-tabs-2">
				<?php 
					$val .= $jobcat_result->name.'<a href=javascript:void(0) onclick=searchcandidate_remove_category("'.str_replace(" ","%20",$jobs_result->category_id).'")> X</a> <br>';
					echo $val;
				?> 
			</span>	
		</div>
      </div>
	  
      <div id="collapse1" class="panel-collapse">
	  <input type="text" class="filterInput" id="search_roles_" name="search_roles_" placeholder="Search Role E.q. Marketing">  
	  <div id="suggesstion_search_roles_">  </div> 
        <div class="panel-body color-box" id="role-collapse"> 
            <ul class="innUl list-width" > <!-- id="job-role-ul"-->
				<?php
				$stmt=$conn->prepare("select name,id,priority from job_categories");          
            	$stmt->execute();   
            	$rw_count = $stmt->rowCount();  
            	if($rw_count > 0)
            	{
                	$alljob_categories=$stmt->fetchAll(PDO::FETCH_OBJ);
    				foreach($alljob_categories as $keys=>$dtt)
    				{
				?>
            	<li id="searchcandidate-category<?php echo $keys;?>" >
					<input type="radio" <?php if($dtt->id==$jobcat_result->id) echo 'checked=checked'; ?>  name="searchcandidate-category" onclick="searchcandidate_by_category(<?php echo $keys;?>,'<?php echo $dtt->name;?>',<?php echo $dtt->id;?>)" />&nbsp;<?php echo $dtt->name;?>
				</li> 
				<?php 
					} }
				?>
            </ul>
        </div>
      </div>
    </div>
	
    <div class="panel panel-default" id="locality">
      <div class="panel-heading">
        <h4 data-toggle="collapse" data-parent="#accordion" href="#collapse2" class="panel-title expand">
            <div class="right-arrow pull-right">+</div>
          <a href="#">Locality</a>
	    </h4>
      </div>
      <div id="collapse2" class="panel-collapse collapse">   
        <div class="panel-body">  
			 <!-- combo-box  -->
			 <a href="javascript:void(0)" class="cleFilter" id="clear_searchcandidate_locality">Clear Filter</a> 
			<div class="">
				<input type="text" class="location-name local-input" placeholder="E.q. Shalimar" id="job-locality" > 
				<ul id="job-locality-ul">
				<?php 
				$stmt =  $conn->prepare("select id,location_name from city_lacations  where city_id=:city_id");	  
				$stmt->bindValue(':city_id', $_REQUEST['city_id'] , PDO::PARAM_INT); 
				$stmt->execute();   
				$city_locations = $stmt->fetchAll(PDO::FETCH_OBJ); 
				foreach($city_locations as $dt) 
				{
				?> 
					<li><a href="javascript:void(0)" onClick="searchcandidate_by_locality(<?php echo $dt->id;?>,'<?php echo $dt->location_name;?>')"><?php echo $dt->location_name;?></a></li> 
				<?php } ?>
				</ul>
				
			</div>
			<div class="col-md-8">
				<span id="locality_placed" class="local-tabs-2">
					<?php 
					$test_array = explode(",",$_SESSION['searchcandidate_by_locality_name']);
					array_pop($test_array); 
					foreach($test_array as $dt) 
						$loc_val .= $dt.'<a href=javascript:void(0) onclick=searchcandidate_remove_locality("'.str_replace(" ","%20",$dt).'")> X</a> <br>';
						
					echo $loc_val;
					?> 
				</span>	
			</div>
			<div  id="suggesstion_comboText" class="locality-list"></div>
        </div>
      </div>
    </div>
	
	
	<div class="panel panel-default">
      <div class="panel-heading">
        <h4 data-toggle="collapse" data-parent="#accordion" href="#collapse5" class="panel-title expand">
            <div class="right-arrow pull-right">+</div>
          <a href="#">Gender</a>
        </h4>
      </div>
      <div id="collapse5" class="panel-collapse collapse">
        <div class="panel-body pad">
			<a href="javascript:void(0)"class="cleFilter" id="clear_gender_filter">Clear Filter</a> 
        	<ul class="innUl job-filter list-gender">   
				<li><input type="radio" name="gender" id="gender1" onclick="searchcandidate_by_gender(1)" <?php if($_SESSION['searchcandidate_by_gender']==1) echo 'checked=checked'; ?> /> &nbsp;Male </li>
				
				<li> <input type="radio" name="gender" id="gender2" onclick="searchcandidate_by_gender(2)" <?php if($_SESSION['searchcandidate_by_gender']==2) echo 'checked=checked'; ?>  /> &nbsp;Female </li>
				
				<li><input type="radio" name="gender" id="gender3" onclick="searchcandidate_by_gender(3)" <?php if($_SESSION['searchcandidate_by_gender']==3) echo 'checked=checked'; ?>  /> &nbsp;Transgender </li>
            </ul>
        </div>
      </div>
    </div>
    
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 data-toggle="collapse" data-parent="#accordion" href="#collapse6" class="panel-title expand">
            <div class="right-arrow pull-right">+</div>
          <a href="javascript:void(0);">Profile Freshness</a>
        </h4>
      </div>
      <div id="collapse6" class="panel-collapse collapse">
        <div class="panel-body pad">
			<a href="javascript:void(0)"class="cleFilter" id="clear_profile_search">Clear Filter</a>
			<?php
			$profile_val_array = explode(",",$_SESSION['searchcandidate_by_profile_val']); 
		    array_pop($profile_val_array);
			?>
        	<ul class="innUl job-filter list-gender">   
				<li><input type="checkbox" name="profile_search" id="profile_search1" onclick="searchcandidate_by_profile(1)" <?php if(in_array(1,$profile_val_array)) echo 'checked=checked'; ?> /> &nbsp;With mobile verified only </li>
				<li><input type="checkbox" name="profile_search" id="profile_search2" onclick="searchcandidate_by_profile(2)" <?php if(in_array(2,$profile_val_array)) echo 'checked=checked'; ?>  /> &nbsp;With email verified only </li>
				<!--<li><input type="checkbox" name="profile_search" id="profile_search3" onclick="searchcandidate_by_profile(3)" <?php if(in_array(3,$profile_val_array)) echo 'checked=checked'; ?>  /> &nbsp;with resume only </li>-->
            </ul>
        </div>
      </div>
    </div>
	
	
	
   
  </div> 
    
    </div>
    </div>
    
   <div id="MyIframeDivs"> <?php //include_once 'searchcandidateLoad.php';	?></div>   
   
<div class="clear"></div>
</div>
<br>

    
 <input type="hidden" value="<?php echo  $_REQUEST['city_id'];//$_COOKIE['search_city_id'];?>" id="search_city_id_hidden" name="search_city_id_hidden" />

</div>



<?php include_once("../view/header-footer/footer.php");  