function redirect(frm){
	var frmtest = frm;
	if(frmtest.journey_type[0].checked==true){
		frmtest.action="index.php";
		frmtest.act.value = "OneWaySearch";
		document.getElementsById('return_date').alt="";
		return true;
	}else if(frmtest.journey_type[1].checked==true){
		frmtest.action="index.php";
		frmtest.act.value = "TwoWaySearch";
		return true;
	}
}
function searchredirect(frm){
	var frmtest = frm;
	if(frmtest.journey_type[0].checked==true){
		frmtest.act.value = "OneWaySearch";
		document.getElementById('return_date').alt='';
	}else if(frmtest.journey_type[1].checked==true){
		frmtest.act.value = "TwoWaySearch";
		document.getElementById('return_date').alt='date|dd/mm/yyyy|/|4|journey_date';		
	}
}

jQuery(document).ready(function() {
	if(document.getElementById('return_travel') == undefined){
	}else{
		var return_travel_obj = document.getElementById('return_travel');
		var travels_obj = document.getElementById("travels");
		
		function getSelectOption(){
			rad = document.srch_frm.return_by_same[0].checked;
			if(rad){
				return 1;
			}else{
				return 0;
			}
		}
		
		function selectReturnTravels(){
			val = getSelectOption();
			if(val == 1){
				var chosenoption = travels_obj.options[travels_obj.selectedIndex].value;
				return_travel_obj.value = chosenoption;
			}else{
				return_travel_obj.value = 0;
			}
		}
		
		travels_obj.onchange=function(){
			selectReturnTravels();
			getBTypeSearch();
		}
		
		return_travel_obj.onchange=function(){
			document.srch_frm.return_by_same[1].checked = true;
		}
		
		document.srch_frm.return_by_same[0].onclick=function(){
			selectReturnTravels();
		}
		document.srch_frm.return_by_same[1].onclick=function(){
			selectReturnTravels();
		}
	}
});	

//new design script for search 
$(document).ready(function(){    
    
	//to on change drop down options for movies and dates
	$('#start_point').change(function(){
		var start_pointId = $("#start_point").val();
		getCitiesJquery(start_pointId,'');
		
	});
	$('.btnradio').click(function(){
		var val = $(this).val();
		if(val==1){
			$("#return_date").attr("disabled","");
			$("#return_date").val("Select Date");
			$("#return_date").attr("alt","date|dd/mm/yyyy|/|4|journey_date");
			$("#act").val("TwoWaySearch");
		}
		else{
			$("#return_date").attr("disabled","disabled");
			$("#return_date").val("");
			$("#return_date").attr("alt","");
			$("#act").val("OneWaySearch");
		}
	});
	
	
	
});

function getCitiesJquery(start_pointId,dest_pointId){
	
	if(start_pointId != '' && start_pointId != 0){
		$("select#destination_point option").remove();
		$("#destination_point").attr("disabled","disabled");
		var obj = document.getElementById('destination_point');
		obj.options[obj.options.length] = new Option('Loading...','',true,true);
		var post_string = "start_pointId=" + start_pointId+"&destinationId="+dest_pointId;
//alert(post_string);
		$.ajax({
			type: "POST",
	        data: post_string,
	        dataType: "text",
			cache: true,  
	        url: siteURL + 'scripts/GetCitiesSearch.php',
	        timeout: 60000,
	        error: function() {
//alert(data);	        	
//alert("Failed to submit");

	        },
	        success: function(data) {		         
		       $("select#destination_point option").remove();			       
		       $("#destination_point").attr("disabled","");
		       eval(data);
	        }
		});
	}// checking not null
}

//search form
function SearchSubmit(){
	if(validateForm(document.srch_frm,0,0,0,0)){
		var startpt=$('#start_point :selected').text();
		var destpt=$('#destination_point :selected').text();
		var jdate=$('#journey_date').val();
		
		
		//var search_load_text =' Please wait... <br />We are searching for all available buses on the route <br />'+startpt+' to '+destpt+' on '+jdate+' <br /> <br /> Please wait...<br /><br /> Shopping KE Pehle <a href="http://www.upto75.com" target="_blank"><img src=\"images/upto75-logo.jpg\" border=\"0\" title="upto75.com"/></a> Dekha Karo and save Rs.3000 per month';
		var search_load_text = 'Searching for all buses available on  the route <br /> <br style="line-height: 10px;"/><span class="searchdata">  <strong>'+startpt+' </strong>To  <strong>'+destpt+'</strong> On <strong>'+jdate+'</strong></span>';
		
		if($("input[@name='journey_type']:checked").val() == 1){
		var rt_jdate=$('#return_date').val();
		var search_load_text = search_load_text+'<br /><span class="searchdata">  <strong>'+destpt+' </strong>To  <strong>'+startpt+'</strong> On <strong>'+rt_jdate+'</strong></span>';
		}
		$('#searchtext').html(search_load_text);
		displayDiv();
		
	}
}
 function displayDiv(){
  var waitsearchdiv = document.getElementById('waitsearchdiv');
  waitsearchdiv.style.left = ( $(document).width()* parseFloat(0.25) )+"px";
  waitsearchdiv.style.top = ( $(window).height()* parseFloat(0.25) )+"px";
  
  waitsearchdiv.style.height = "290px";//( $('#loadingtext').height()+ parseInt(10) )+"px";
  
  waitsearchdiv.style.display = '';
  document.body.scrollTop = 0;
  
  showBackground();
  }

function showBackground() {
	document.srch_frm.submit();
	var backdiv = document.getElementById('backdiv');
	if (! document.body) {
		backdiv.style.height = 10000;
		backdiv.style.width = 800;
	} else {
		backdiv.style.height = $(document).height()+"px";
		backdiv.style.width = $(document).width()+"px";
	}
	backdiv.style.display = '';
	document.body.scrollTop = 0;
}

