﻿// JScript 文件

function disp()
    {
        document.getElementById("city").style.display="none";
        document.getElementById("hotel").style.display="none";
        document.getElementById("flights").style.display="none"
        document.getElementById("tours").style.display="block";
        document.getElementById("single_city").style.display="none";
        document.getElementById("muti_dest").style.display="block";
        document.getElementById("toursSearch").style.backgroundColor="#d00d00";
        document.getElementById("toursSearch").style.color="White";
        document.getElementById("cruiseSearch").style.backgroundColor="";
        document.getElementById("cruiseSearch").style.color="#c8652c";
        document.getElementById("hotelSearch").style.backgroundColor="";
        document.getElementById("hotelSearch").style.color="#c8652c";
        document.getElementById("flightSearch").style.backgroundColor="";
        document.getElementById("flightSearch").style.color="#c8652c";
        document.getElementById("mulSearch").style.backgroundColor="#d00d00";
        document.getElementById("mulSearch").style.color="White";
        document.getElementById("singleSearch").style.backgroundColor="";
        document.getElementById("singleSearch").style.color="#c8652c";
    }
    function disp_city()
    {
        document.getElementById("tours").style.display="none";
        document.getElementById("hotel").style.display="none";
        document.getElementById("flights").style.display="none";
        document.getElementById("city").style.display="block";
        document.getElementById("toursSearch").style.backgroundColor="";
        document.getElementById("toursSearch").style.color="#c8652c";
        document.getElementById("cruiseSearch").style.backgroundColor="#d00d00";
        document.getElementById("cruiseSearch").style.color="White";
        document.getElementById("hotelSearch").style.backgroundColor="";
        document.getElementById("hotelSearch").style.color="#c8652c";
        document.getElementById("flightSearch").style.backgroundColor="";
        document.getElementById("flightSearch").style.color="#c8652c";
    }
    function disp_hotel()
    {
        document.getElementById("tours").style.display="none";
        document.getElementById("city").style.display="none";
        document.getElementById("flights").style.display="none";
        document.getElementById("hotel").style.display="block";
        document.getElementById("toursSearch").style.backgroundColor="";
        document.getElementById("toursSearch").style.color="#c8652c";
        document.getElementById("cruiseSearch").style.backgroundColor="";
        document.getElementById("cruiseSearch").style.color="#c8652c";
        document.getElementById("hotelSearch").style.backgroundColor="#d00d00";
        document.getElementById("hotelSearch").style.color="White";
        document.getElementById("flightSearch").style.backgroundColor="";
        document.getElementById("flightSearch").style.color="#c8652c";

    }
    function disp_flights()
    {
        document.getElementById("tours").style.display="none";
        document.getElementById("city").style.display="none";
        document.getElementById("hotel").style.display="none";
        document.getElementById("flights").style.display="block";
        document.getElementById("toursSearch").style.backgroundColor="";
        document.getElementById("toursSearch").style.color="#c8652c";
        document.getElementById("cruiseSearch").style.backgroundColor="";
        document.getElementById("cruiseSearch").style.color="#c8652c";
        document.getElementById("hotelSearch").style.backgroundColor="";
        document.getElementById("hotelSearch").style.color="#c8652c";
        document.getElementById("flightSearch").style.backgroundColor="#d00d00";
        document.getElementById("flightSearch").style.color="White";
    }
    function disp_muti()
    {
        document.getElementById("single_city").style.display="none";
        document.getElementById("muti_dest").style.display="block";
        document.getElementById("toursSearch").style.backgroundColor="#d00d00";
        document.getElementById("toursSearch").style.color="White";
        document.getElementById("cruiseSearch").style.backgroundColor="";
        document.getElementById("cruiseSearch").style.color="#c8652c";
        document.getElementById("hotelSearch").style.backgroundColor="";
        document.getElementById("hotelSearch").style.color="#c8652c";
        document.getElementById("flightSearch").style.backgroundColor="";
        document.getElementById("flightSearch").style.color="#c8652c";
        document.getElementById("mulSearch").style.backgroundColor="#d00d00";
        document.getElementById("mulSearch").style.color="White";
        document.getElementById("singleSearch").style.backgroundColor="";
        document.getElementById("singleSearch").style.color="#c8652c";
    }
    function disp_single()
    {
        document.getElementById("muti_dest").style.display="none";
        document.getElementById("single_city").style.display="block";
        document.getElementById("toursSearch").style.backgroundColor="#d00d00";
        document.getElementById("toursSearch").style.color="White";
        document.getElementById("cruiseSearch").style.backgroundColor="";
        document.getElementById("cruiseSearch").style.color="#c8652c";
        document.getElementById("hotelSearch").style.backgroundColor="";
        document.getElementById("hotelSearch").style.color="#c8652c";
        document.getElementById("flightSearch").style.backgroundColor="";
        document.getElementById("flightSearch").style.color="#c8652c";
        document.getElementById("mulSearch").style.backgroundColor="";
        document.getElementById("mulSearch").style.color="#c8652c";
        document.getElementById("singleSearch").style.backgroundColor="#d00d00";
        document.getElementById("singleSearch").style.color="White";
    }
    function setDivDisp()
    {
        var dType=document.getElementById("UserSearch1$hfDivType").value;
        if(dType=="1")//China Tours
        {
            disp();
        }
        else if(dType=="2")//Yangtze Cruise;
        {
            disp_city();
        }
        else if(dType=="3")//China Hotels
        {
            disp_hotel();
        }
        else if(dType=="4")//China Flight
        {
            disp_flights();
        }
        else if(dType=="5")//Single city tours
        {
            disp_single();
        }
    }
    function flightSearch()
    {
        //alert("OK");
        //return;
        //document.getElementById("flightTemp").style.display="block"
        //document.getElementById("flightbtn").style.display="none";
        //获取各个参数
        var cityFromCode=document.getElementById("ddlFrom").value;//出发城市编号    
        var cityFromName=document.getElementById("ddlFrom").options[document.getElementById("ddlFrom").selectedIndex].innerText;//出发城市英文名
        var cityToCode=document.getElementById("ddlTo").value;//到达城市编号
        var cityToName=document.getElementById("ddlTo").options[document.getElementById("ddlTo").selectedIndex].innerText;//到达城市英文名
        var ipFrom = document.getElementById("txtFlightDate").value; //出发时间;
        if (ipFrom == "") {
            alert("Please select the flight date!");
            return;
        }
        var flightClass="E";//document.getElementById("ddlClass").value;//飞机舱位类型
        var airLine=document.getElementById("ddlAirline").value;//飞机航线        
        var adult=document.getElementById("adult").value;//成人数量
        var children=document.getElementById("children").value;//孩童数量
        var infant = document.getElementById("infant").value; //婴儿数量;
        var reqStr = "result.aspx?fromCity=" + cityFromCode + "&toCity=" + cityToCode;
        reqStr += "&date=" + ipFrom + "&flightClass=" + flightClass + "&airline=" + airLine + "&adult=" + adult + "&child=" + children + "&infant=" + infant;
        //var search=document.getElementById("UserSearch1$hfFlag").value;
//        if(search=="2")//The web is under the root.
//        {
//            window.location.href="flight/"+reqStr;
//        }
//        else
//        {
//            window.location.href="../flight/"+reqStr;
        //        }
        window.location.href = "flight/" + reqStr;
    }
    function cityClickrbtn()
    {
        var ddl = document.getElementById("UserSearch1$ddlCity");                                                                                
        for(i=0;i<ddl.length-1;i++)
        {
            ddl[i].selected=false;
        }
        ddl[0].selected=true;
    }
    function tourck()//check the cities that user has clicked the checkbox.
    {
        //get original cities by selecting more destination.
        var city=document.getElementById("txtCkCity").value;
        var obj=document.getElementsByName("tour");
        var tourlen=obj.length;
        if(city!="")
        {
            for(var ci=0;ci<tourlen;ci++)
            {
                if(city.indexOf(obj[ci].value)!=-1)
                    city=city.replace(obj[ci].value+",","");
            }
        }
        var cities="";
        for(var ii=0;ii<tourlen;ii++)
        {
            if(obj[ii].checked)
            cities=cities+obj[ii].value+",";
        }
        document.getElementById("txtCkCity").value=cities+city;
    }
    function searchTour()//search the tours for user request.
    {
        var tourType=document.getElementById("ddlTourType").value;
        var tourLen=document.getElementById("ddlTourLength").value;
        var budget=document.getElementById("ddlBudget").value;
        var destination=document.getElementById("txtCkCity").value;
        destination=destination.substring(0,destination.lastIndexOf(","));
        destination=escape(destination);
        var keyword=document.getElementById("txtKeyWord").value;
        keyword=escape(keyword);
        window.location.href="/tour/userSearch.aspx?type="+tourType+"&len="+tourLen+"&price="+budget+"&dest="+destination+"&keyword="+keyword;
        //alert("OK");
    }
    function wopen()//open a new window to select more destination.
    {
        window.open("../city.htm", "cities", "width=630px,height=600px,top=120,left=500,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no");
    }
    function selectCity()
    {
        var obj=document.getElementsByName("scity");
        var olen=obj.length;
        for(var ci=0;ci<olen;ci++)
            if(obj[ci].checked)
                obj[ci].checked=false;
    }
    function singleCity()
    {
        document.getElementById("ddlCity").selectedIndex=0;
    }
    function searchSingleCity()
    {
        var obj=document.getElementsByName("scity");
        var olen=obj.length;
        var cityName="";
        for(var ci=0;ci<olen;ci++)
            if(obj[ci].checked)
            cityName=obj[ci].value;
        if(document.getElementById("ddlCity").selectedIndex==0&&cityName=="")
        {
            alert("You must select a city!");
            return;
        }
        if(cityName=="")
            cityName=document.getElementById("ddlCity").value;
        window.location.href="../city/userSearch.aspx?cityID="+cityName;
    }
    function searchShip()
    {
        //document.getElementById("btnShipSearch").disabled=true;
        var shipID=document.getElementById("ddlShipName").value;
        var star=document.getElementById("shipStar").value;
        var itinerary=document.getElementById("shipItinerary").value;
        var bDate=document.getElementById("begindate").value;
        var eDate = document.getElementById("enddate").value;
        if (bDate == "") {
            alert("Please Select the sailing beginning date!");
            return false;
        }
        if (eDate == "") {
            alert("Please Select the sailing ending date!");
            return false;
        }
        window.location.href="../yangtze/userSearch.aspx?shipID="+shipID+"&star="+star+"&beginDate="+bDate+"&endDate="+eDate+"&route="+itinerary;
        
    }
    function searchHotel() {
        //document.getElementById("btnSearchHotel").disabled=true;
        var cityID = document.getElementById("ddlHotelCity").value;
        //        if(cityID=="0")
        //        {
        //            alert("Please select a city!");
        //            document.getElementById("btnSearchHotel").disabled=false;
        //            return;
        //        }
        var hotelName = document.getElementById("txtHotelName").value;
        var starRate = document.getElementById("hotelRating").value;
        window.location.href = "../hotel/userSearch.aspx?cityID=" + cityID + "&hotel=" + hotelName + "&star=" + starRate;
    }
    //New Search
    function Init_Search(search_type) {
        var des_mul = GetObj("st_mul_tour");
        var des_single = GetObj("st_sin_city");
        var des_tour = GetObj("s_tour_pal");
        var t_tour = GetObj("st_tours");
        var t_cruise = GetObj("st_cruise");
        var t_hotel = GetObj("st_hotel");
        var t_flight = GetObj("st_flight");

        //Panel Title
        t_tour.onclick = function() {
            des_tour.className = "s_tour_pal";
            DisplaySearchPanel("tours");
        };
        t_cruise.onclick = function() {
            DisplaySearchPanel("cruise");
        };
        t_hotel.onclick = function() {
            DisplaySearchPanel("hotel");
        };
        t_flight.onclick = function() {
            DisplaySearchPanel("flight");
        };
        
        //Multi-Destination And Single City Trip Search
        des_mul.onclick = function() {
            des_tour.className = "s_tour_pal";
            DisplaySearchPanel("tours");
        };
        des_single.onclick = function() {
            des_tour.className = "s_tour_pal_city";
            DisplaySearchPanel("city");
        };
        DisplaySearchPanel(search_type);

        //Initialize the searching action
        GetObj("search_tour").onclick = function() {
            searchTour();
        };
        GetObj("search_city").onclick = function() {
            searchSingleCity();
        };
        GetObj("search_cruise").onclick = function() {
            searchShip();
        };
        GetObj("search_hotel").onclick = function() {
            searchHotel();
        };
        GetObj("search_flight").onclick = function() {
            var date = GetObj("txtDepartDate");
            if (date.value == "") {
                alert("Please input your date.");
                return;
            }
            var fromCity = GetObj("ddlFromCity").value;
            var toCity = GetObj("ddlToCity").value;
            window.location.href = "../flight/search.htm?fromCity=" + fromCity + "&toCity=" + toCity + "&date=" + date.value;
        };
    }
    //display the specified search panel
    function DisplaySearchPanel(search_type) {
        var t_tour = GetObj("s_tour_pal");
        var t_cruise = GetObj("s_cruise_pal");
        var t_hotel = GetObj("s_hotel_pal");
        var t_flight = GetObj("s_flight_pal");
        var tour = GetObj("nsc_tour");
        var city = GetObj("nsc_city");
        var cruise = GetObj("nsc_cruise");
        var hotel = GetObj("nsc_hotel");
        var flight = GetObj("nsc_flight");
        //title
        t_tour.style.display = "none";
        t_cruise.style.display = "none";
        t_hotel.style.display = "none";
        t_flight.style.display = "none";
        //panel
        tour.style.display = "none";
        city.style.display = "none";
        cruise.style.display = "none";
        hotel.style.display = "none";
        flight.style.display = "none";
        switch (search_type) {
            case "tours":
                t_tour.style.display = "block";
                tour.style.display = "block";
                break;
            case "city":
                t_tour.style.display = "block";
                city.style.display = "block";
                GetObj("s_tour_pal").className = "s_tour_pal_city";
                break;
            case "cruise":
                t_cruise.style.display = "block";
                cruise.style.display = "block";
                break;
            case "hotel":
                t_hotel.style.display = "block";
                hotel.style.display = "block";
                break;
            case "flight":
                t_flight.style.display = "block";
                flight.style.display = "block";
                break;
        }
    }
    
    function GetObj(objName) {
        if (document.getElementById) { return eval('document.getElementById("' + objName + '")') }
        else
        { return eval('document.all.' + objName) }
    }
