var record_id;
var rec_city_id;
var apply_recordsKy;
var apply_searchval;
function apply_records(id,ky,val)
{
    apply_recordsKy = ky;
    apply_searchval=val; //1= search page, 2=details page
    $("#submit_job").show();
	$("#job_heading_detail").show();
	$("#apply_job_details").show();
	$("#apply_job_msg").html("");
	$("#location_id").val('');
	$("#waiting_img").hide();
	record_id = id;	
	
	$("label.error").hide();
	$(".error").removeClass("error");	

	if(site_custom_id!='')
	{
        $("#apply").modal({
        show: 'true',
        backdrop: 'static',
        keyboard:false
        }); 
        
    	$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/job.php", 
			data: {apply_records_heading:1,record_id:record_id},	
				beforeSend: function(){
					
				},
				success: function(data){  					  
				var obj = jQuery.parseJSON(data);
				$('#job_heading').html(obj['job_heading']);
			}  
		});
	}		
	
	if(!(site_custom_id))
	{  
		user=1;
		setCookie(user,30);
		url = URL+"/login/login-modals.php";
		$("#LoginModalLoad").load(url); 
		$("#login").modal({
			show: 'true',
			backdrop: 'static',
			keyboard:false
		});   		
		removeCookie(); 
		
		
		
		$("#apply_job").closest('form').find("input[type=text], textarea,input[type=password]").val("");		
	}
}

function back_window(loaing_val)
{
    if(loaing_val==1)
    {
	  location.href = URL;
    }
	else if(loaing_val==2)
	{
	    location.reload();
	}
}

function recruiter_back_window(loaing_val)
{
	location.href = URL;
}

function recruiter_records(id,city_id)
{
    $('#contact-modal-body').hide(); 
    //$('#modal-header').hide();					  
    $('#submit_info').hide();    
    $("#recruiter_location_id").val('');
	$("#recruiter_msg").html("");
	$("#recruiter_waiting_img").hide();
	$("#recruiter_close1").hide();
	$("#recruiter_closebtn1").hide();
	
	record_id = id;	    
	rec_city_id = city_id;
	
	$("label.error").hide();
	$(".error").removeClass("error");	
	
	if(site_custom_id!='')
	{
    	$.ajax({	
    		type: "POST",
    		url: URL+"/all-ajax/job.php", 
    		data: {recruiter_records_heading:1,record_id:record_id,rec_city_id:rec_city_id},	
    			beforeSend: function(){
    				
    			},
    			success: function(data){  					  
        			var obj = jQuery.parseJSON(data);
        			if(obj['user_applied']==0)
        			{
        			  $('#job_heading_location').html(obj['job_heading']);
        			  $('#contact-modal-body').show(); 
                      $('#modal-header').show();					  
                      $('#submit_info').show();    
        			}
        		    else if(obj['user_applied']==1)
        		    {
                        $('#recruiter_no').val(obj['contact_mobile']);
                        $('#contact-modal-body-next').show();  
        		    }
    		    }  
    	}); 
    	
    	$("#recruiterno").modal({
    		show: 'true',
    		backdrop: 'static',
    		keyboard:false
    	}); 
	}
	
	if(!(site_custom_id))
	{  
		user=1;
		setCookie(user,30);
		url = URL+"/login/login-modals.php";
		$("#LoginModalLoad").load(url); 
		$("#login").modal({
			show: 'true',
			backdrop: 'static',
			keyboard:false
		});   		
		removeCookie(); 
		
		
		$("#recruiterno_form").closest('form').find("input[type=text], textarea,input[type=password]").val("");			
	}
}

function myFunction()
{
	$("label.error").hide();
    $(".error").removeClass("error");	
	$("#apply_job").closest('form').find("input[type=text], textarea,input[type=password]").val("");	
}

function myFunction1()
{
	$("label.error").hide();
    $(".error").removeClass("error");	
	/*$("#recruiterno_form").closest('form').find("input[type=text], textarea,input[type=password]").val("");	
	
	$('#contact-modal-body').show(); 
	$('#contact-modal-body-next').hide();
	$('#modal-header').show();					  
	$('#submit_info').show();  */
}

$(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.php", 
		data: {clear_all_mobile_filers:1},
		beforeSend: function(){ 
		},
		success: function(data)
		{  	  
			window.location.href = URL+'/mobile/'+Globalcity_name+'/All-'+Globalcity_name;///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();
        }    
		
    });  
	
	 
	
	
	
	
	$("#search_roles_").keyup(function() 
	{ 
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/computer-laptop.php", 
			data: {select_job_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 class="sug-box">'; 
					
					for(i=0;i<obj.length;i++)			  
					source_list +='<li id=job-category><input type=radio name=job-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); 
				}   
				
			}
		}); 
	});
	
	
	 jQuery.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-z\-_\s]+$/i.test(value);
      }, "Use letters & (_,-) only"); 
      
      
     
		$("#Lapcustomer").validate({ 
			
			rules:{ 
		     buyerName:{
				 required:true, 
				 number:true,
				 minlength:10,
				 maxlength:10,
				},	
 		
			},
			messages:{	

				buyerName:{					
                  required:"Please enter mobile no",
                  minlength:"10 digits needed",
                  minlength:"Max 10 digits allow",
				   		
				} 			   
            } 			  
		});	 
		
	
	$("#apply_job").validate({ 
			
			rules:{ 
		     apply_name:{
				 required:true,
				 minlength:3,
				 maxlength:35,
				 lettersonly:true
				},	

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

		     apply_ph:{
                    required:true,
				    number:true,
				    minlength:10,
				    maxlength:10	             			 
                },
				
			location_id: {
                 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"				
			   },

               location_id:{
				 required:"Please select location"					 						
				}			   
            } 			  
		});	
	
	//apply for job
	$("#apply_job").submit(function(event)  
	{ 	 
		if ($('#apply_job').valid())  
		{ 
	        $("#submit_job").hide();			
            $("#waiting_img").show(300);
			var formData = $('#apply_job').serialize();  
			$.ajax({	
			type: "POST",
			url: URL+"/custom_function/EmailConfigure.php", 
			data: {apply_records:1,formData:formData,record_id:record_id},	
					beforeSend: function(){
						
					},
					success: function(val)
					{
					    if(apply_searchval==1) // search job
					    {
    					    if(val==1) 
    					    {
    					      $("#apply_job_msg").html("You already applied for the job");
    					    }
    					    else
    					    {
    					        $("#applyrecords"+record_id).html("Applied");
    					        $("#applyrecords"+record_id).css({"opacity":"0.5","pointer-events":"none"});
    					        
                                //$("#applyrecords"+apply_recordsKy).html("Applied");
                                //$("#applyrecords"+apply_recordsKy).css({"opacity":"0.5","pointer-events":"none"});      
                                $("#apply_job_msg").html("You have successfully applied for the job");    
    					    }
    					    
                            $("#waiting_img").hide();	
        					$("#submit_job").hide();
        					$("#job_heading_detail").hide();
        					$("#apply_job_details").hide();
					    }
					    else if(apply_searchval==2) // job detail page
					    {
					        if(val==1) 
    					    {
    					       $(".applyrecords").html("Applied");
                               $(".applyrecords").addClass("disableloginbtn"); 
    					       $('#apply').modal('hide');	     
    					       alert("You already applied for the job");
    					       location.reload();
    					    }
    					    else
    					    {
    					       $(".applyrecords").html("Applied");
                               $(".applyrecords").addClass("disableloginbtn"); 
    					       $('#apply').modal('hide');	
        					   alert("You have successfully applied for the job"); 
        					   location.reload();
    					    }
					    }
				  }  
			});  
			return false; 			
	   }
		event.preventDefault();  
	});
		
	 $("#recruiterno_form").validate({ 
			
			rules:{ 
		     name:{
				 required:true,
				 minlength:3,
				 maxlength:35,
				 lettersonly:true
				},	

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

		     ph:{
                    required:true,
				    number:true,
				    minlength:10,
				    maxlength:10	             			 
                },
				
			location_id: {
                 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"				
			   },

               location_id:{
				 required:"Please select location"					 						
				}			   
            } 			  
		});
	
     //see recruiter mobile no	
	 $("#recruiterno_form").submit(function( event )  
		{ 	 
		   	if ($('#recruiterno_form').valid())  
			{ 
			var formData = $('#recruiterno_form').serialize();  
			$.ajax({	
			type: "POST",
			url: URL+"/custom_function/EmailConfigure.php", 
			data: {recruiter_records:1,formData:formData,record_id:record_id,rec_city_id:rec_city_id},	
					beforeSend: function(){
						
					},
					success: function(data){ 		
                      
					  var obj = jQuery.parseJSON(data);
					  $('#submit_info').addClass("disableloginbtn");
					  $("#recruiter_closebtn2").hide();
					  $("#recruiter_closebtn1").show();
					  $("#recruiter_close2").hide();
					  $("#recruiter_close1").show();
					  $('#submit_info').hide(200); 
					  $('#contact-modal-body').hide(); 
					  $('#contact-modal-body-next').show();  
					  $('#recruiter_no').val(obj['contact_mobile']);
                      //$('#modal-header').hide();					  
					  $('#submit_info').hide();                  					  
					}  
			  }); 
               return false;               
			}
			//event.preventDefault();            						 			
		});
		
	    
    
       
	
}); 
	 
 
 
 $("#city_search").keyup(function() 
	{   
     	$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/computer-laptop.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/computer-laptop.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);   
}



$(document).ready(function()
{
     
    $("#role_main_suggetionCar").keyup(function()
    { 	    
    	    sorce_set=0; 
    		$.ajax({	
    		type: "POST",
    		url: URL+"/all-ajax/general-ajax.php", 
    		data: {Inner_role_sugession:1,keyword:$(this).val()},
    		beforeSend: function(){
    			//$("#main-suggetion").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
    		},
    		success: function(data)
    		{     		 
    		    var obj = jQuery.parseJSON(data);
    			if(obj==null || obj=='null')
    			{  
    				$("#suggesstion-main-suggetion").slideUp();
    				
    			}else
    			{
    			    source_first_name = obj[0].keyword1; 
    				Type = obj[0].type; 
    				source_list = '<ul class="searchCityList"><div class="recSearch"><span class="recLeft">Search Results</span></div>'; 
    				  
    				for(i=0;i<obj.length;i++)	
    				{				  
    				 
    				    charX1 = '';
    					charY = obj[i].keyword1.split('/');   
    					for(var i1 = 0; i1 <charY.length; i1++) 
    					charX1 += charY[i1]+'_';
    					charX1 = charX1.substring(0, charX1.length - 1);
    					
    					charY = charX1.split(' ');
    					charX1='';
    					for(var i1 = 0; i1 <charY.length; i1++) 
    					charX1 += charY[i1]+'-';   
    					charX1 = charX1.substring(0, charX1.length - 1);
    					
    					charY = charX1.split('.');
    					charX1='';
    					for(var i1 = 0; i1 <charY.length; i1++) 
    					charX1 += charY[i1]+'-';   
    					charX1 = charX1.substring(0, charX1.length - 1);
    					    
    				  
    					if(Type==0)
    					 MyUrl = URL+'/jobs/'+Globalcity_name+'/'+charX1;
    					else if(Type==1)
    					 MyUrl = URL+'/cars/'+Globalcity_name+'/'+charX1+'_'+obj[i].type_id+'_'+obj[i].ModelId+'_'+obj[i].VarientId;
    					else if(Type==2)
    					 MyUrl = URL+'/computer-laptop/'+Globalcity_name+'/'+charX1+'_'+obj[i].type_id+'_'+obj[i].ModelId+'_'+obj[i].VarientId;
    					 
    					 
    					source_list +='<a href="javascript:void(0)"><li onClick=selectSourceRediecrt("'+encodeURIComponent(obj[i].keyword1)+'","'+obj[i].type_id+'","'+MyUrl+'")>'+obj[i].keyword1+'<div class=mapIcon><span aria-hidden="true" class="glyphicon glyphicon-search"></span></div></li></a>'; 
    				}
    				
    				source_list +='</ul>';   
    				$("#suggesstion-main-role").show();
    				$("#suggesstion-main-role").html(source_list);
    				$("#main-suggetion").css("background","#FFF");			
    			}
    		  }
    		});
    });  
    
});


function selectSourceRediecrt(name,val,MyUrl) 
{  
	new_name =   name.replace(new RegExp("%20", "g"), ' ');   
	new_name =   new_name.replace(new RegExp("%2F", "g"), '/');
	//new_name =   new_name.replace(new RegExp("%26", "g"), '&');
	$("#role_main_suggetionCar").val(new_name);
	$("#suggesstion-main-role").hide(); 
	
	$.ajax({	
		type: "POST",
		url: URL+"/login_logout.php",  
		data: {recent_search_job:1,keyword:new_name},
		beforeSend: function(){
			//$("#main-suggetion").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
		},
		success: function(data)
		{ 
		    window.location.href = MyUrl; 
		}
	});
}     
	