$(document).ready(function(){  
   
   $("#city_search").click(function(){
		
	   $(this).next().slideDown();    
	});
	
	$("#city_name_search").click(function(){
		
		$(this).next().slideDown();    
	});
	
	$('#contact-modal-body-next').hide();  
	
	
	$("#search_roles_").click(function(){ 
			$(this).next().slideDown();    
	}); 	
	
	$("#clear_all_job_filers").click(function(){  
	
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/job.php", 
		data: {clear_all_job_filers:1},
		beforeSend: function(){ 
		},
		success: function(data)
		{  
			 
			window.location.href = window.location.href;  	 
		}
		}); 
	
		
	});
	
	$("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").hide(400); 
			$("#job-locality-ul").hide(400);
        }   
		
		
		if ( e.target.id == "search_roles_" || $(e.target).parents("#suggesstion_search_roles_").size() ) 
		{ 
             //alert("Inside div");   
        } else 
		{    
			 
			$("#search_roles_").val('');   
			$("#suggesstion_search_roles_").hide(); 
			//$("#job-role-ul").show();
        }    
		
    });  
	
	
	// send email start 
	$("#send_email_frm").validate({ 
			
		rules:{ 
	     emp_subject:{
			 required:true,
			 minlength:3
			},	

		email_type:{
			required: true
			}		
		},
		messages:{	

			emp_subject:{					
              required:"Please enter subject",
			  minlength : "Please enter minimum 3 characters subject"			
			},   
			
			email_type:{
			 required:"Please enter your email description"					 						
			}		   
        } 			  
	});
    // send email end
    
    // send sms start 
	$("#send_sms_frm").validate({ 
			
		rules:{ 
	     
		emp_sms:{
			required: true
			}		
		},
		messages:{	

			emp_sms:{
			 required:"Please enter message"					 						
			}		   
        } 			  
	});
    // send sms end

	
}); 
	 
 
 
 $("#city_search").keyup(function() 
	{   
     	$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/job.php", 
			data: {search_city:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{   
					$("#citysearch-ajax").hide(); 
				}else
				{  	 
					source_list = '<ul>';  
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"  ><li onclick=select_sub_locs("'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'") >'+obj[i].name+'</li></a>' 
					
					source_list +='</ul>';  
					$("#citysearch-ajax").show();
					$("#citysearch-ajax").html(source_list); 
				}   
				
			}
		}); 
	});

	
	$("body").click(function(e) 
	{  
		if ( e.target.id == "city_search" || $(e.target).parents("#citysearch-ajax").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			$("#city_search").next().slideUp();
			$("#citysearch-ajax").hide(400); 
		} 	
		
		if ( e.target.id == "search_roles_" || $(e.target).parents("#suggesstion_search_roles_").size() ) 
		{ 
             //alert("Inside div");   
        } else 
		{     
			 
			$("#search_roles_").next().slideUp();     
			$("#suggesstion_search_roles_").hide(); 
			 
        }   	
	});
 


function select_sub_locs(name,val)
{  
	
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#city_search_id_hidden").val(new_name);  
	$("#apply_city_search").val(new_name);    
	$("#city_search").val(new_name);    
	$("#city_search").next().slideUp(); 
	$("#citysearch-ajax").hide(400);   
}


$("#city_name_search").keyup(function() 
	{   
     	$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/job.php", 
			data: {search_city:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{   
					$("#citynamesearch-ajax").hide(); 
				}else
				{  	 
					source_list = '<ul>';  
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"  ><li onclick=select_sub_location("'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'") >'+obj[i].name+'</li></a>' 
					
					source_list +='</ul>';  
					$("#citynamesearch-ajax").show();
					$("#citynamesearch-ajax").html(source_list); 
				}   
				
			}
		}); 
	});

	
	$("body").click(function(e) 
	{  
		if ( e.target.id == "city_name_search" || $(e.target).parents("#citynamesearch-ajax").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			$("#city_name_search").next().slideUp();
			$("#citynamesearch-ajax").hide(400); 
		} 	
		
		if ( e.target.id == "search_roles_" || $(e.target).parents("#suggesstion_search_roles_").size() ) 
		{ 
             //alert("Inside div");   
        } else 
		{     
			 
			$("#search_roles_").next().slideUp();     
			$("#suggesstion_search_roles_").hide(); 
			 
        }   	
	});
 


function select_sub_location(name,val)
{  
	
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#city_search_name_hidden").val(new_name);  
	$("#apply_city_name_search").val(new_name);    
	$("#city_name_search").val(new_name);    
	$("#city_name_search").next().slideUp(); 
	$("#citynamesearch-ajax").hide(400);   
}
