You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
6.5 KiB
JavaScript

// JavaScript Document
//表单默认
$(document).ready(function(e) {
$( "#departureAirport" ).autocomplete({source: "/intlflights/searchairport.php",minLength: 1,});
$( "#destinationAirport" ).autocomplete({source: "/intlflights/searchairport.php",minLength: 1,});
$( "#returnFromAirport" ).autocomplete({source: "/intlflights/searchairport.php",minLength: 1,});
$( "#returnToAirport" ).autocomplete({source: "/intlflights/searchairport.php",minLength: 1,});
$( "#departureDate" ).datepicker({numberOfMonths: 2,showButtonPanel: true,minDate: 0, maxDate: "+12M"});
$( "#returnDate" ).datepicker({numberOfMonths: 2,showButtonPanel: true,minDate: 0, maxDate: "+12M"});
$( "#mreturnDate" ).datepicker({numberOfMonths: 2,showButtonPanel: true,minDate: 0, maxDate: "+12M"});
$( "#bradio" ).buttonset();
$( "#hotcity" ).tabs();
//$.get('/community/template/flight/Tmp2013/footer-bottompromo.htm',function(data){$("#bottomPromo").html(data)});
});
//格式化时间
function ForTime(mins)
{
var temp=mins;
//分钟
var mtemp=temp%60;
//小时
var htemp=parseInt(temp/60);
if(htemp<10)
{
htemp='0'+htemp;
}
if (htemp==24){htemp='00';}
if(mtemp<10){
mtemp='0'+mtemp;
}
return htemp+':'+mtemp;
}
//切换查询条件
function changeSearch(sval){
if(sval=="oneway"){
$(".MultiCities").hide();
$(".roundtrip").show();
$('.ReturnDate').hide();
$("#flytypetext").html('oneway')
}else if(sval=="roundtrip"){
$('.ReturnDate').show();
$(".MultiCities").hide();
$(".roundtrip").show();
$("#flytypetext").html('roundtrip')
}else if(sval=="MultiCities"){
$(".MultiCities").show();
$(".roundtrip").hide();
$("#flytypetext").html('Multicities');
}
}
//城市默认值
function clearinputcity(obj)
{
$(document).click(function(){
var aid=document.activeElement.id;
//alert(aid);
if($('#hotcity').css("display")!="none"){
if(aid!='departureAirport' && aid!='destinationAirport' && aid!='returnFromAirport' && aid!='returnToAirport' && aid!='hcity'){$("#hotcity").css("display","none");}
}
//if($('#'+obj).val()==''){$('#'+obj).val('enter a city name');}
});
if($('#'+obj).val()=='enter a city name'){$('#'+obj).val('');}
{
var h_input=parseInt($('#'+obj).height())+15;
var top=(parseInt($('#'+obj).offset().top)+h_input);
var left=$('#'+obj).offset().left;
//var screenw=$(window).width()
$("#hotcity").css("top",top);
$("#hotcity").css("left",left);
$("#hotcity").css("display","block");
//$("#hotcity a").attr("onclick","sairport(this,'"+obj+"')");
$("#hotcity .hota a").attr("pid",obj);
$("#hotcity .hota a").bind("click",function(){
obj=$(this).attr("pid");
var code=$(this).attr("data");
$("#"+obj).val(code);
$("#hotcity").hide();
});
$("#tabhead a").attr("onclick","tabclear('"+obj+"')");
}
}
function airportunblud(o)
{
if($(o).val()=='')
{
//hideairport();
$(o).val('enter a city name');
}else if($(o).val()=='enter a city name'){hideairport();}
}
//清除选项卡切换时输入框提示
function tabclear(obj)
{
if($("#"+obj).val()=='enter a city name'){$("#"+obj).val('');}
}
//选择热门城市
function sairport(o,par)
{
var code=$(o).attr("data");
$("#"+par).val(code);
$("#hotcity").hide();
//$("#nearby").val('yes');
}
function hideairport()
{
//$("#hotcity").hide();
$("#hotcity").css("display","none");
}
function keyairport(o)
{
if($(o).val()==''){
var h_input=parseInt($(o).height())+15;
var top=(parseInt($(o).offset().top)+h_input);
var left=$(o).offset().left;
$("#hotcity").css("top",top);
$("#hotcity").css("left",left);
$("#hotcity").css("display","block");
}else{hideairport()}
}
//时间转换mm/dd/yyyy to yyyy/mm/dd
function formatfTime(str)
{
if(str.indexOf("/")>0){
str=str.split("/");
str=str[2]+'/'+str[0]+'/'+str[1]
str=parseInt(str.replace(/(\/)/g,""));
return str;
}
}
//验证表单
function chkform()
{
var thisdate=new Date;
thisyear=thisdate.getFullYear();
thismonth=thisdate.getMonth()+1;
if(thismonth<10){thismonth='0'+thismonth}
thisday=thisdate.getDate();
if(thisday<10){thisday='0'+thisday}
thisdate=thisyear+'/'+thismonth+'/'+thisday;
thisdate=parseInt(thisdate.replace(/(\/)/g,""));
var departuredate=formatfTime($("#departureDate").val());
var returndate=formatfTime($("#returnDate").val());
var mreturndate=formatfTime($("#mreturnDate").val());
//判断出发时间是否大于当天
if (thisdate>departuredate)
{
$("#departureDate").focus();
alert('Departure date can not be earlier than today!!');
return false;
}
//双程验证返程时间
if($('#flytypetext').html()=='roundtrip')
{
//判断返回时间是否大于当天
if (thisdate>returndate)
{
$("#returnDate").focus();
alert('Return date can not be earlier than today!');
return false;
}
//判断出发日期是否小于或等于返回日期
if(departuredate>returndate)
{
$("#returnDate").focus();
alert('Departure date can not be earlier than return date');
return false;
}
}
if($("#departureAirport").val()=='enter a city name' || $("#departureAirport").val()=='') {
$("#departureAirport").focus();
alert("Please enter departure city");
return false;
}
if($("#destinationAirport").val()=='enter a city name' || $("#destinationAirport")=='') {
$("#destinationAirport").focus();
alert("Please enter destination city");
return false;
}
//验证两地是否相等
if($("#departureAirport").val()==$("#destinationAirport").val())
{
$("#destinationAirport").focus();
alert("Departure airport can not be equal to the destination airport");
return false;
}
//多地验证
if($('#flytypetext').html()=='Multicities'){
//alert(mreturndate);
if($("#returnFromAirport").val()=='enter a city name' || $("#returnFromAirport").val()=='') {
$("#returnFromAirport").focus();
alert("Please enter return from city");
return false;
}
if($("#returnToAirport").val()=='enter a city name' || $("#returnToAirport").val()=='') {
$("#returnToAirport").focus();
alert("Please enter return to city");
return false;
}
//验证两地是否相等
if($("#returnToAirport").val()==$("#returnFromAirport").val())
{
$("#destinationAirport").focus();
alert("Flight 2 Departure airport can not be equal to the destination airport");
return false;
}
//判断出发时间是否大于当天(第二程)
if (thisdate>mreturndate)
{
$("#mreturnDate").focus();
alert('Return date can not be earlier than today');
return false;
}
//判断第一程出发日期是否小于或等于第二程出发日期
if(departuredate>mreturndate)
{
$("#mreturnDate").focus();
alert('Flight 1 departure date can not be earlier than flight 2 departure date!');
return false;
}
}
}