var  mob_varify; 
var loc_val = new Array();
var loc_id = new Array();
var loc_ct = 0; 

$(document).ready(function(){       
	
	$("#city").click(function(){
		
			$(this).next().slideDown();    
	});

	$("#profile_city_search").click(function(){
		
			$(this).next().slideDown();    
	});
    	
	$("#sub_role").click(function(){  
			$(this).next().slideDown();    
	}); 
	
	
	$("#search_roles_").click(function(){ 
			$(this).next().slideDown();    
	});
	
	
	$("body").click(function(e) 
	{  
		if ( e.target.id == "city" || $(e.target).parents("#city-ajax").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			$("#city").next().slideUp();
			$("#city-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(); 
			 
        }   	
	});	
		
	
	$("#city").keyup(function() 
	{     
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.php", 
			data: {select_city:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{   
					$("#city-ajax").hide(); 
				}else
				{  	 
					source_list = '<ul>';  
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"  ><li onclick=select_sub_locns("'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'") >'+obj[i].name+'</li></a>' 
					
					source_list +='</ul>';  
					$("#city-ajax").show();
					$("#city-ajax").html(source_list); 
				}   
				
			}
		}); 
	});
	
	
	
	$("#select_city").click(function(){
			//$(this).next().slideDown();   
	});  
	
	$("body").click(function(e) 
	{  
		 	if ( e.target.id == "select_city" || $(e.target).parents("#city-id-ajax").size() ) 
			{ 
				 //alert("Inside div");   
			} else 
			{    
				$("#select_city").next().slideUp();
				$("#city-id-ajax").hide(400); 
			} 	 
	});
	
	$("#select_city").keyup(function() 
	{     
		/*$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.php", 
			data: {select_city:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{   
					$("#city-id-ajax").hide(); 
					$("#ul-city-id-ajax").hide();
                    $("#select_city").val('No record found');
				}else
				{  	 
					source_list = '<ul class="menu-box-3">';  
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"  ><li onclick=select_sub_loctns("'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'") >'+obj[i].name+'</li></a>' 
					
					source_list +='</ul>';  
					$("#city-id-ajax").show();
					$("#city-id-ajax").html(source_list); 
					$("#ul-city-id-ajax").hide();
				}   
				
			}
		}); */
	});
	
	$("#select-sub-locations").click(function(){ 
			$(this).next().slideDown(); 
	});	   
	
	
	$("body").click(function(e) 
		{    
			
			if ( e.target.id == "select-sub-locations" || $(e.target).parents("#job-loction-sugeetion-ajax").size() ) 
			{ 
				 //alert("Inside div");   
			} else 
			{    
				$("#select-sub-locations").next().slideUp();
				$("#job-loction-sugeetion-ajax").hide(400);
			} 
			
			if ( e.target.id == "ul-location-ajax" || $(e.target).parents("#select-sub-locations").size() ) 
			{ 
				 //alert("Inside div");   
			} else 
			{    
				
				//$("#select-sub-locations").next().slideUp();
				 
			}   
			
		});      
	
	$("#select-sub-locations").keyup(function() 
	{     
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/job.php", 
			data: {select_city_sub_location:1,keyword:$(this).val(),city_id:$("#search_city_hidden").val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{   
					$("#job-loction-sugeetion-ajax").hide(); 
					$("#ul-location-ajax").hide(); 
				}else
				{  	 
					source_list = '<ul class="menu-box-3">';  
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"><li onclick=select_location_post_job("'+encodeURIComponent(obj[i].location_name)+'","'+obj[i].id+'") >'+obj[i].location_name+'</li></a>' 
					
					source_list +='</ul>';  
					$("#job-loction-sugeetion-ajax").show();
					$("#job-loction-sugeetion-ajax").html(source_list); 
					$("#ul-location-ajax").hide(); 
				}   
				
			}
		}); 
	}); 
	
	
  $("#job-category").click(function(){
			$(this).next().slideDown();
			job_cat_set = 0;
	}); 
	
	
	$("body").click(function(e) 
	{  
		if ( e.target.id == "job-category" || $(e.target).parents("#job-category-sugeetion").size() ) 
			{ 
				 //alert("Inside div");   
			} else 
			{    
				$("#job-category-sugeetion-ajax").hide(400);
				$("#job-category-sugeetion").hide(400);
			} 	
	 });
	 
	 
	 	
	$("#job-category").keyup(function() 
	{  
		 
		//$("#job-role-ul").hide();
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.php", 
			data: {select_job_category:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{  
				
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{  
					 
					$("#job-category-sugeetion-ajax").hide();
					//$("#job-role-ul").show();
					
					
				}else
				{  	
					source_first_name = obj[0].name; 
					source_list = '<ul class="menu-box-3">'; 
					
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"  ><li onclick=select_role_post_job("'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'") >'+obj[i].name+'</li></a>' 
					
					source_list +='</ul>';   
					 
					$("#job-category-sugeetion-ajax").show();
					$("#job-category-sugeetion-ajax").html(source_list);
                    $("#job-category-sugeetion").hide();					
				}   
				
			}
		}); 
	});   
	
	 
	        
	$("#submit_password").click(function(e) 
	{   
		 $.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.php", 
			data: {submit_pwd:1,old_password:$("#old_password").val(),new_password:$("#new_password").val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
				if(data==0){
					alert("Invalid Old Password");
					$("#old_password").val('');
					$("#new_password").val('');
				}
				else
				{
					alert("Password Updated..!");
					window.location.href = window.location.href;  	   	  
				}
			}
		}); 
	});	
	
	 
	
	$("#search_roles_").keyup(function() 
	{  
		 
		//$("#job-role-ul").hide();
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.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>'; 
					
					for(i=0;i<obj.length;i++)			  
					source_list +='<li><a href="javascript:void(0)" onclick=search_by_category("'+i+'","'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'")>'+obj[i].name+'</a></li>'
					
					
					source_list +='</ul>';   
					$("#suggesstion_search_roles_").show();
					$("#suggesstion_search_roles_").html(source_list); 
				}   
				
			}
		}); 
	});    
	
	
	 
 

$("#profile_city_search").keyup(function() 
	{   
   		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.php", 
			data: {profile_city_search:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{   
					$("#citysearch-ajax").hide(); 
					$("#profile_city_search").val("Record not found");
				}else
				{  	 
					source_list = '<ul>';  
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"  ><li onclick=select_city_locs("'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'") >'+obj[i].name+'</li></a>' 
					
					source_list +='</ul>';  
					$("#profilecitysearch-ajax").show();
					$("#profilecitysearch-ajax").html(source_list); 
				}   
				
			}
		}); 
	});
	
	$("body").click(function(e) 
	{  
		if ( e.target.id == "profile_city_search" || $(e.target).parents("#profilecitysearch-ajax").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			$("#profile_city_search").next().slideUp();
			$("#profilecitysearch-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_loctns(name,val)
  { 
	$("#search_city_hidden").val(val);  
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#select_city").val(new_name);    
	$("#select_city").next().slideUp();
	$("#select-sub-locations").val('');
	$("#city-id-ajax").hide(400);
	$("#city_val").val(val);
	$("#locations_val").val('');  
	
	loc_val.splice(0, loc_val.length);     
    loc_id.splice(0, loc_id.length); 
	$("#locality_placed").html("");
	
	var source_list =''; 
	$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/MyDetails.php", 
		data: {select_city_sub_location:1,ajax_set:1,city_id:$("#search_city_hidden").val()},
		beforeSend: function(){ 
		},
		success: function(data)
		{   
			 
			var obj = jQuery.parseJSON(data);  
			if(obj==null || obj=='null')
			{   
				$("#select-sub-locations").val('Entire City');  
			}else
			{  	 
				//source_list = '<ul>';  
				for(i=0;i<obj.length;i++)			  
				source_list +='<a href="javascript:void(0)"  ><li onclick=select_location_post_job("'+encodeURIComponent(obj[i].location_name)+'","'+obj[i].id+'") >'+obj[i].location_name+'</li></a>'   
				//source_list +='</ul>';    
				$("#ul-location-ajax").html(source_list); 
			
			} 			
		}
	}); 
		
}

function select_location_post_job(name,val) 
{
	if(loc_ct < 5)
	{
		if(loc_id.indexOf(val) < 0)
		{
			var v='';
			new_name =   name.replace(new RegExp("%20", "g"), ' ');     
			new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
			$("#select-sub-locations").val(new_name);
			$("#job-loction-sugeetion-ajax").hide(400);    
			$("#select-sub-locations").next().slideUp();         
			 loc_val.push(new_name); 
			 loc_id.push(val);  
			var res = loc_id.join(",");
			$("#locations_val").val(res); 
					
			for (var i = 0, len = loc_val.length; i < len; i++) 
				v += '<a  href=javascript:void(0) onclick=select_loc_id("'+i+'")  >'+loc_val[i]+' X </a>';  
			$("#locality_placed").html(v);
			$("#select-sub-locations").next().slideUp(); 
			$("#select-sub-locations").val('');  
			loc_ct++;
		}
		else
			alert("Location is already added!");
		
	}else
		alert("You can't add more than 5 locations");
}

function select_loc_id(val) 
{      
	var v='';
	loc_val.splice(val, 1); 
	loc_id.splice(val, 1);   
	var res = loc_id.join(",");  
	$("#locations_val").val(res);  
		
	for (var i = 0, len = loc_val.length; i < len; i++) 
		v += '<a  href=javascript:void(0) onclick=select_loc_id("'+i+'") >'+loc_val[i]+' X </a><br>'; 
	
	$("#locality_placed").html(v); 
	loc_ct--;
}

function select_role_post_job(name,val) 
{   
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#job-category").val(new_name);
	$("#job-category-sugeetion-ajax").hide(400);    
	$("#job-category").next().slideUp();
	$("#job_cat_val").val(val);
	
	$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.php", 
			data: {select_sub_job_category:1,val:val},
			beforeSend: function(){ 
			},
			success: function(data)
			{  
					
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{  
					 
					$("#job-sub-category").hide();
					//$("#job-role-ul").show(); 
					
				}else
				{  	 
					source_list = '<ul>';  
					
					for(i=0;i<obj.length;i++)			  
					source_list += obj[i].name+'<input type=checkbox  name="sub-roles[]" value="'+obj[i].id+'" />';
				
					source_list +='</ul>';    
					$("#job-sub-category").show();
					$("#job-sub-category").html(source_list); 
				}   
				
			}
		}); 
}      





	
function select_sub_locns(name,val)
{  	
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#search_city_id_hidden").val(new_name);  
	$("#city").val(new_name);    
	$("#city").next().slideUp(); 
	$("#city-ajax").hide(400);   
} 
 
 

 
 


function select_city_locs(name,val)
{  	
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#city_search_cityid_hidden").val(new_name);  
	$("#profile_city_search").val(new_name);    
	$("#profile_city_search").next().slideUp(); 
	$("#profilecitysearch-ajax").hide(400);   
}  