// JavaScript Document
$(document).ready(function(){
	// Get Paramiter from select List
	$('#from_cat').change(function(){
		var cat = '';
		$('#fromAddress').empty(); 
		$('#from_cat option:selected').each(function () {
			cat += $(this).val();
		});
	
		var post_url = 'ajax_getList.php';
		var data_set = { todo_detail: cat}
		$.post(
			post_url ,
			data_set,
			function(resp){
				//alert(resp);
				p = resp.split(",");
				for(var i = 0; i<p.length; i++)
				{
					q = p[i].split("|");
					if(q[0]){
						$('#fromAddress').append("<option value='" + q[0] + "'>" + q[1] + "</option>").show();
					}
				}
			}
					 
		);
		
		
		//alert($('#from_cat') option:selected)							  							  
	});
	
	// Destination
	
		$('#d_cat').change(function(){
		var cat = '';
		$('#myInput').empty(); 
		$('#d_cat option:selected').each(function () {
			cat += $(this).val();
		});
	
		var post_url = 'ajax_getList.php';
		var data_set = { todo_detail: cat}
		$.post(
			post_url ,
			data_set,
			function(resp){
				//alert(resp);
				p = resp.split(",");
				for(var i = 0; i<p.length; i++)
				{
					q = p[i].split("|");
					if(q[0]){
						$('#myInput').append("<option value='" + q[0] + "'>" + q[1] + "</option>").show();
					}
				}
			}
					 
		);
		
		
		//alert($('#from_cat') option:selected)							  							  
	});
		

	$('#fromAddress').change(function(){
			$('#fromAddress option:selected').each(function () {
				$('#select_f_bus').val($(this).val());
			});
	});
	
	$('#myInput').change(function(){
			$('#myInput option:selected').each(function () {
				$('#select_t_bus').val($(this).val());
			});
	});
	
	$('#locale').change(function(){
			$('#locale option:selected').each(function () {
				$('#select_l').val($(this).val());
			});
	});
	
	
	$('#form1').submit(
		function(){
			var b1 = $('#select_f_bus').val();
			var b2 = $('#select_t_bus').val();
			var l = $('#select_l').val();
			var wurl = 'printDirection.php?b1='+b1+'&b2='+b2+'&l='+l;
			$('#burl').val(wurl);
			//alert(wurl);
			
			$('.example4demo').popupWindow({ 
			windowURL: $('#burl').val(), 
			windowName:'swip',
			height:800, 
			width:1000, 
			top:50, 
			left:50,
			scrollbars:1
		}); 
			
			
		}						 
	);
	
	$('.example4demo').popupWindow({ 
			windowURL: $('#burl').val(), 
			windowName:'swip',
			height:800, 
			width:1000, 
			top:50, 
			left:50,
			scrollbars:1
		}); 
});
