 $(document).ready(function(){  
	
	// Set default datepicker options     
	/*	$.datepicker.setDefaults({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd-mm-yy',
//		defaultDate: +2,
		
		minDate: 0,
		maxDate: '+2y',
		numberOfMonths: 2,
		showAnim: 'fadeIn',
		showButtonPanel: false,
		autoOpen: false
		}); 
		
	$("#flight_frm").validate({
		
		errorElement:'div',
		rules:{ 
			flight_from:{
				required:true				 
			},
			flight_to:{
				required:true				 
			},
			flight_main:{
				required:true				 
			}    
		},
		messages:{	

			flight_from:{
				required:"Enter source"				 
			},
			flight_to:{
				required:"Enter destination"			 
			},
			flight_main:{
				required:"Enter date of journey"				 
			} 	
			 
		}
	});
	
	$( "#flight_frm" ).submit(function( event ) 
	{
		if ($('#flight_frm').valid()) 
		{ 
			msg = "Searching flights..";
			flight_waiting_popup(msg);
			form.submit();
		}  
	});	 
	
	
	$("#flight-seats-cancel-form").validate({
		
		errorElement:'div',
		rules:{ 
		
			flightPNR:{
				required:true				 
			}   
		},
		messages:{	
			
			flightPNR:{
				required:"Enter PNR"				 
			} 	
			 
		}
	});   
	*/  
	 
	
	$("body").click(function(e) 
	{    		
		if ( e.target.id == "main-city-load" || $(e.target).parents("#suggesstion-main-city-load").size() ) 
		{ 
             //alert("Inside div");   
        } else 
		{   		 
			 
			$("#main-city-load").val('');
			$("#suggesstion-main-city-load").slideUp(500);
        }   
    });  
	 
 
 
	
	$("#main-city-load").keyup(function(){    
		sorce_set=0; 
		$.ajax({	
		type: "POST",
		url: URL+"/all-ajax/general-ajax.php", 
		data: {main_city_load:1,keyword:$(this).val()},
		beforeSend: function(){
			//$("#main-city-load").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
		},
		success: function(data){  
			//console.log(data); 
			var obj = jQuery.parseJSON(data);              			
			source_first_name = obj[0].name; 
			source_list = '<ul class="searchCityList">'; 
			
			for(i=0;i<obj.length;i++)			
				source_list +='<li onClick=selectCitySource("'+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-city-load").show();
			$("#suggesstion-main-city-load").html(source_list);
			$("#main-city-load").css("background","#FFF");
		}
		});
	});  
	 
	
});



function selectCitySource(name,val) 
{   
	new_name =   name.replace(new RegExp("%20", "g"), ' ');  
	$("#main-city-load").val('');
	$("#showCity").val(new_name);
	$("#suggesstion-main-city-load").hide();  
	$(".selectFullCat").hide();   
	
	$.ajax({	
	type: "POST",
	url: URL+"/login_logout.php", 
	data: {set_main_city_cookie:1,city_id:val,city_name:new_name},
	beforeSend: function(){
		//location.reload(); 
		//window.location.href = window.location.href;
	},
	success: function(data){     
		 res = window.location.href.split("/jobs"); 
		 if(res.length > 1)
		 {   
		    res1 = res[1].split("/");   
		    window.location.href = URL+"/jobs/"+new_name+"/"+res1[2];
		 }
		 else 
		  window.location.href = window.location.href;
	}
	});  
	
}  

 