 	var cookie_js = new Array() 
	var decodedCookie = decodeURIComponent(document.cookie);	
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) 
	{
        var c = ca[i];
        while (c.charAt(0) == ' ') 
		{	
            c = c.substring(1);
        } 
		 
        if (c.indexOf(name) == 0) 
		{
            var1 = c.substring(name);		
			var keyValuePair = var1.replace(/ /g,'').split('=');
			cookie_js[ keyValuePair[0] ] = keyValuePair[1];
        } 
    }   
  
	
$(document).ready(function(){  	  

	$("body").click(function(e) 
	{ 
		
		if ( e.target.id == "suggesstion-main-suggetion" || $(e.target).parents("#suggesstion-main-suggetion").size() ) 
		{ 
             //alert("Inside div");
			 
			
        } else 
		{  	 
			$("#main-suggetion").val('');
			$("#suggesstion-main-suggetion").hide(500);
			$("#recent_search_job").hide(500);
        }
		
		 
		
    });  
    
    $("#main-suggetion-category").change(function()
    {
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/job.php", 
		data: {recent_search_job_display:1,type:$("#main-suggetion-category").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')
			{  
				$("#recent_search_job").hide();
				
			}else
			{  	
				source_first_name = obj[0].keyword; 
				source_list = '<ul class="searchCityList"><div class="recSearch"><span class="recLeft">Recent Searches</span><span id="clear_recent_search" class="recRight" onClick=clear_recent_search(1)>Clear</span></div>'; 
				
				for(i=0;i<obj.length;i++)	
				{
					source_list +='<a href="javascript:void(0)"><li>'+obj[i].keyword+'</li></a>';
				}				
				source_list +='</ul>';   
				$("#recent_search_job").show();
				$("#recent_search_job").html(source_list);
			}			
	    }
      });		
	});
	
	$("#main-suggetion").click(function()
	{ 
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/job.php", 
		data: {recent_search_job_display:1,type:$("#main-suggetion-category").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')
			{  
				$("#recent_search_job").hide();
				
			}else
			{  
			    var MyUrl;
				source_first_name = obj[0].keyword1;
				Type = obj[0].type;
				//source_list = '<ul class="searchCityList"><span>Recent Searches</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="clear_recent_search" style=" float:right; padding-right:10px;" onClick=clear_recent_search(1)>Clear</span>'; 
                source_list = '<ul class="searchCityList"><div class="recSearch"><span class="recLeft">Recent Searches</span><span id="clear_recent_search" class="recRight" onClick=clear_recent_search(1)>Clear</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);
					     
					//charX1 +=obj[i].type_id; 
				////	MyUrl = URL+'/jobs/'+Globalcity_name+'/'+charX1; 
				
					
					if((obj[i].type)==0) 
					    MyUrl = URL+'/jobs/'+Globalcity_name+'/'+charX1;  
					else  if((obj[i].type)==1)
					 MyUrl = URL+'/cars/'+Globalcity_name+'/'+charX1+'_'+obj[i].type_id+'_'+obj[i].ModelId+'_'+obj[i].VarientId;
			    	else  if((obj[i].type)==2)
					 MyUrl = URL+'/laptop/'+Globalcity_name+'/'+charX1+'_'+obj[i].type_id+'_'+obj[i].ModelId+'_'+obj[i].VarientId;  
					    
					    
					source_list +='<a href="javascript:void(0)"><li onClick=selectCategorySource("'+encodeURIComponent(obj[i].keyword1)+'","'+obj[i].type_id+'","'+MyUrl+'")>'+obj[i].keyword1+'</li></a>'; 
				}

				source_list +='</ul>';   
				$("#recent_search_job").show();
				$("#recent_search_job").html(source_list);
			}		
	    }
      });		
    }); 		
	
	$("#main-suggetion").keyup(function()
	{      
	    $("#recent_search_job").hide();
		sorce_set=0; 
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/general-ajax.php", 
		data: {main_role_sugession:1,keyword:$(this).val(),category_id:$("#main-suggetion-category").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
			{  	
			    var MyUrl;
				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);
					
					//charX1 +=obj[i].type_id; 
					if((obj[i].type)==0)
					 MyUrl = URL+'/jobs/'+Globalcity_name+'/'+charX1;
					else  if((obj[i].type)==1)
					 MyUrl = URL+'/cars/'+Globalcity_name+'/'+charX1+'_'+obj[i].type_id+'_'+obj[i].ModelId+'_'+obj[i].VarientId;
			    	else  if((obj[i].type)==2)
					 MyUrl = URL+'/laptop/'+Globalcity_name+'/'+charX1+'_'+obj[i].type_id+'_'+obj[i].ModelId+'_'+obj[i].VarientId;
					  
					 
					 
					source_list +='<a href="javascript:void(0)"><li onClick=selectCategorySource("'+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-suggetion").show();
				$("#suggesstion-main-suggetion").html(source_list);
				$("#main-suggetion").css("background","#FFF");
			} 
		}
		});
	}); 	
	
	
	$("#role_main_suggetion").keyup(function()
	{
		sorce_set=0; 
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/general-ajax.php", 
		data: {job_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-role").slideUp();
				
			}else
			{
    			source_list = '<ul class="searchCityList">'; 
    			
    			for(i=0;i<obj.length;i++)			
    				source_list +='<li onClick=selectRoleSource("'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'")>'+obj[i].name+'<div class=mapIcon><span aria-hidden="true" class="glyphicon glyphicon-map-marker"></span></div></li>'; 
    			
    			source_list +='</ul>';   
    			$("#suggesstion-main-role").slideDown();
    			$("#suggesstion-main-role").html(source_list);
    			$("#role_main_suggetion").css("background","#FFF");
			}
		}
		});
	});
	
	$("#searchJob").click(function()
	{
	    $.ajax({	
    	type: "POST",
    	url: URL+"/all-ajax/job.php", 
    	data: {search_new_job:1,val:$("#main-suggetion").val()},
    	beforeSend: function(){
    	},
    	success: function(data){  
    		
    		var obj = jQuery.parseJSON(data); 
    		if((obj!=null) && (obj['job_url']!=''))
    		{
    		   //var job_role=obj['job_role'];
    		   //$("#role_main_suggetion").val(job_role);
    		   var jobUrl=URL+'/jobs/'+obj['job_city']+'/'+obj['job_url'];
    		   location.href=jobUrl;
    		}
    	  }
    	});
	});
	
	$("#car_role_sugession").keyup(function()
	{
		sorce_set=0; 
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/general-ajax.php", 
		///data: {car_role_sugession:1,keyword:$(this).val()},
		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+'/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"), '&');
	$("#car_role_sugession").val(new_name);
	$("#suggesstion-main-role").hide(); 
	
	window.location.href = MyUrl;
	
}

function selectRoleSource(name,val) 
{   
	new_name =   name.replace(new RegExp("%20", "g"), ' ');  
	//$("#role_main_suggetion").val('');
	$("#suggesstion-main-role").slideUp(); 
	
	$.ajax({	
	type: "POST",
	url: URL+"/all-ajax/job.php", 
	data: {set_job_role:1,val:val},
	beforeSend: function(){
	},
	success: function(data){  
		
		var obj = jQuery.parseJSON(data); 
		if(obj!=null)
		{
		   var job_role=obj['job_role'];
		   $("#role_main_suggetion").val(job_role);
		   var jobUrl=URL+'/jobs/'+obj['job_city']+'/'+obj['job_url'];
		   location.href=jobUrl;
		}
	}
	});  
	
}  

function selectCategorySource(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"), '&');
	$("#main-suggetion").val(new_name);
	$("#suggesstion-main-suggetion").hide(); 
	
	if(MyUrl!="undefined")
	{
    	$.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; 
    		}
    	});
	}
}    

function clear_recent_search(val)
{    
    $.ajax({	
		type: "POST",
        url: URL+"/login_logout.php",		
		data: {clear_recent_search:1},
		beforeSend: function(){
			//$("#main-suggetion").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
		},
		success: function(data)
		{     
		    $("#recent_search_job").slideUp();
		}
    });
}


