var record_id;
function apply_records(id)
{
	  record_id = id;	 
}

function recruiter_records(id)
{
	record_id = id;	    
}

$(document).ready(function(){  
   
   $("#city_search").click(function(){
		
	   $(this).next().slideDown();    
	});
	
	$("#city_name_search").click(function(){
		
		$(this).next().slideDown();    
	});
	
	$('#contact-modal-body-next').hide();  
	
	
    $("#sub_role").click(function(){  
			$(this).next().slideDown();    
	});	
	
	$("#search_roles_").click(function(){ 
			$(this).next().slideDown();    
	}); 	
	
	$("#clear_all_mobile_filers").click(function(){  
	
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/mobile&tablets.php", 
		data: {clear_all_mobile_filers:1},
		beforeSend: function(){ 
		},
		success: function(data)
		{  
			 
			window.location.href = window.location.href;  	 
		}
		}); 
	
		
	});
	
	$("body").click(function(e) 
	{    
		
		if ( e.target.id == "mobile-locality" || $(e.target).parents("#suggesstion_comboText").size() ) 
		{ 
             //alert("Inside div");   
        } else 
		{   
			 
			$("#mobile-locality").val(''); 
			$("#suggesstion_comboText").hide(400); 
			$("#mobile-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();
        }    
		
    });  
	
	$("#mobile-locality").keyup(function() 
	{  
		  
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/mobile&tablets.php", 
			data: {mobile_locality:1,keyword:$(this).val(),city_id:$("#search_city_id_hidden").val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{  
				$("#mobile-locality-ul").hide();
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{  
					$("#suggesstion_comboText").hide();
					$("#mobile-locality-ul").show();
					$("#mobile-locality").val("entire city");
					
				}else
				{  	
					source_first_name = obj[0].location_name; 
					source_list = '<ul>'; 
					
					for(i=0;i<obj.length;i++)			
						source_list +='<li><a onClick=search_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);    
				}    
			
			}
		}); 
	});
	
	
	
	
	
	$("#search_roles_").keyup(function() 
	{  
		 
		//$("#job-role-ul").hide();
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/mobile&tablets.php", 
			data: {select_mobile_category:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{  
				
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{  
					 
					$("#suggesstion_search_roles_").hide();
					//$("#job-role-ul").show();
					
					
				}else
				{  	
					source_first_name = obj[0].name; 
					source_list = '<ul>'; 
					
					for(i=0;i<obj.length;i++)			  
					source_list +='<li id=mobile-category><input type=radio name=mobile-category onclick=search_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); 
				}   
				
			}
		}); 
	});
	
	$("#apply_job").validate({ 
			
			rules:{ 
		     apply_name:{
				 required:true,
				 minlength:3,
				 maxlength:35
				},	

			apply_email:{
				required: true,
				email: true				
				},

		     apply_ph:{
                    required:true,
				    number:true,
				    minlength:10,
				    maxlength:10	             			 
                },
				
			city_search: {
                 required:true								
                }				
			},
			messages:{	

				apply_name:{					
                  required:"Please enter name",
				  minlength : "Please enter minimum 3 characters name",
				  maxlength : "Max 35 characters are allowed"  					
				},   
				
				apply_email:{
				 required:"Please enter Email Id"					 						
				}, 
				
				apply_ph:{
				required:"Please enter an Mobile No",	
				minlength : "Please enter minimum 10 digits",
				maxlength : "Max 10 digits are allowed"				
			   },

               city_name:{
				 required:"Please select city"					 						
				}			   
            } 			  
		});	
	
	//apply for job
	$( "#apply_job" ).submit(function( event )  
		{ 	 
			if ($('#apply_job').valid())  
			{ 
			var formData = $('#apply_job').serialize();  
			$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/job.php", 
			data: {apply_records:1,formData:formData,record_id:record_id},	
					beforeSend: function(){
						
					},
					success: function(data){  					  
			        $('#apply').modal('hide');	
					alert("You have successfully applied for the job"); 
					}  
			});  
             return false; 			
			}
			//event.preventDefault();  
		});
		
	 $("#recruiterno_form").validate({ 
			
			rules:{ 
		     name:{
				 required:true,
				 minlength:3,
				 maxlength:35
				},	

			email:{
				required: true,
				email: true				
				},

		     ph:{
                    required:true,
				    number:true,
				    minlength:10,
				    maxlength:10	             			 
                },
				
			city_name_search: {
                 required:true								
                }				
			},
			messages:{	

				name:{					
                  required:"Please enter name",
				  minlength : "Please enter minimum 3 characters name",
				  maxlength : "Max 35 characters are allowed"  					
				},   
				
				email:{
				 required:"Please enter Email Id"					 						
				}, 
				
				ph:{
				required:"Please enter an Mobile No",	
				minlength : "Please enter minimum 10 digits",
				maxlength : "Max 10 digits are allowed"				
			   },

               city_name_search:{
				 required:"Please select city"					 						
				}			   
            } 			  
		});
	
     //see recruiter mobile no	
	 $( "#recruiterno_form" ).submit(function( event )  
		{ 	 
		   	if ($('#recruiterno_form').valid())  
			{ 
			var formData = $('#recruiterno_form').serialize();  
			$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/job.php", 
			data: {recruiter_records:1,formData:formData,record_id:record_id},	
					beforeSend: function(){
						
					},
					success: function(data){ 			         
					  $('#contact-modal-body').hide(); 
					  $('#contact-modal-body-next').show();  
					  $('#recruiter_no').val(data)
                      $('#modal-header').hide();					  
					  $('#submit_info').hide();                      					  
					}  
			  }); 
               return false;               
			}
			//event.preventDefault();            						 			
		});
	
}); 
	 
 
 
 $("#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/mobile&tablets.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);   
}
