﻿
$(document).ready(function() {
    $.ajax({
        type: "GET",
        url: "xml/tourinfo" + surl + ".xml",
        dataType: "xml",
        success: function(xml) {
            var numberOfTour = 0;
            $(xml).find('tour').each(function() {
                var id = $(this).find('ID').text();
                var tcode = $(this).find('TCODE').text();
                var ttitle = $(this).find('TTITLE').text();
                var ccode = $(this).find('CCODE').text();
                var cname = $(this).find('CNAME').text();
                var theme = $(this).find('THEME').text();
                var spoint = $(this).find('SPOINT').text();
                var point = $(this).find('POINT').text();
                point = point.replace("<b>", "");
                point = point.replace("</b>", "");
                point = point.substr(0, 137);
                var duration = $(this).find('DURATION').text();
                var adult = $(this).find('ADULT').text();
                var aprice = $(this).find('ADULT').text();
                var dcity = $(this).find('DCITY').text();
                var dtype = $(this).find('TYPE').text();
                var ctitle = $(this).find('CTITLE').text();
                var check = 0;
                var lprice;
                var uprice;
                var camp;


                duration = duration.replace("H", "時間");
                duration = duration.replace("M", "分");
                duration = duration.replace("D", "日");
                duration = duration.replace("N", "泊");
                aprice = String.toInt(aprice);
                if (($.query.get("t") == "") && ($.query.get("k") == "") && ($.query.get("p") == "") && ($.query.get("c") == "")) {
                    check = 1;
                } else {
                    check = 0;
                    switch ($.query.get("p")) {
                        case 1:
                            lprice = 0;
                            uprice = 50;
                            break;
                        case 2:
                            lprice = 50;
                            uprice = 100;
                            break;
                        case 3:
                            lprice = 100;
                            uprice = 300;
                            break;
                        case 4:
                            lprice = 300;
                            uprice = 500;
                            break;
                        case 5:
                            lprice = 500;
                            uprice = 1000;
                            break;
                        case 6:
                            lprice = 1000;
                            uprice = 2000;
                            break;
                        case 7:
                            lprice = 2000;
                            uprice = 9999;
                            break;
                        default:
                            lprice = 0;
                            uprice = 9999;
                    }
                }

                var cimage = "";
                switch (dtype) {
                    case "$":
                        cimage = "img/s_btn_discount.gif";
                        camp = "t";
                        break;
                    case "G":
                        cimage = "img/s_btn_tokuten.gif";
                        camp = "t";
                        break;
                    case "S":
                        cimage = "img/s_btn_special.gif";
                        camp = "t";
                        break;
                    case "T":
                        cimage = "img/s_btn_webonly.gif";
                        camp = "t";
                        break;
                    default:
                        cimage = "img/Back.gif";
                        camp = "";
                        break;
                }
                var cd = $.query.get("cd");
                if ((check == 1) || (($.query.get("k") == ccode) || ($.query.get("t") == theme) || (($.query.get("p") != "") && (lprice <= aprice) && (aprice < uprice)) || (($.query.get("c") == 1) && (camp == "t")))) {
                    //var imageurl = "http://travelife.us/gl/tour_img/";
                    var imageurl = "../img/tour/";

                    if (cd == "JTBAME") {
                        $("<div/>").attr("id", id).attr("style", "height:190px;")
                        .append($("<div/>").addClass("gridr-3 bg-7 pt-5 pr-5 pb-5 pl-5")
                        .append($("<p/>").addClass("typo-10").text("価格US$(税込)"))
                        .append($("<p/>").addClass("typo-8 mb-5").append($("<span/>").attr("id", "price").text("$" + adult + ".00").append($("<span/>").addClass("typo-5").text("より"))))
                        .append($("<p/>").append($("<span/>").addClass("typo-9").text("時間:" + duration)).append($("<p/>").text("言語:日本語")).append($("<p/>").text("ツアーコード:" + tcode)))
                        .append($("<p/>").addClass("typo-10 mt-10").append($("<span/>").text("詳細はこちらから↓")))
                        .append($("<a href='tour/" + tcode + ".html?cd=JTBAME'><div class='bt-6' id='book" + id + "'/></a>"))
                        .append($("<div/>").addClass("clear"))
                        )
                        .append($("<div/>").addClass("gridl-14")
                        .append($("<img/>").addClass("floatleft mt-5 mr-5 mb-5").attr("src", imageurl + tcode + "1.jpg").attr("width", "175").attr("height", "131").attr("alt", "New-York" + tcode))
                        .append($("<p/>").addClass("typo-10 mt-5").text(spoint))
                        .append($("<h5/>").text(ttitle)).append($("<span/>").addClass("icon-1 mt-10").text("おすすめ"))
                        .append($("<p/>").addClass("mt-10").text(point))
                        )
                        .append($("<div/>").addClass("gridl-14").append($("<img/>").attr("style", "float:left;").attr("src", cimage)).append($("<p/>").attr("style", "margin-left:110px; margin-top:8px;").text(ctitle))
                        ).append($("<hr/>"))
                    .appendTo("#tourlists");
                        numberOfTour = numberOfTour + 1;
                    } else {
                        $("<div/>").attr("id", id).attr("style", "height:190px;")
                        .append($("<div/>").addClass("gridr-3 bg-7 pt-5 pr-5 pb-5 pl-5")
                        .append($("<p/>").addClass("typo-10").text("価格US$(税込)"))
                        .append($("<p/>").addClass("typo-8 mb-5").append($("<span/>").attr("id", "price").text("$" + adult + ".00").append($("<span/>").addClass("typo-5").text("より"))))
                        .append($("<p/>").append($("<span/>").addClass("typo-9").text("時間:" + duration)).append($("<p/>").text("言語:日本語")).append($("<p/>").text("ツアーコード:" + tcode)))
                        .append($("<p/>").addClass("typo-10 mt-10").append($("<span/>").text("詳細はこちらから↓")))
                        .append($("<a href='tour/" + tcode + ".html'><div class='bt-6' id='book" + id + "'/></a>"))
                        .append($("<div/>").addClass("clear"))
                        )
                        .append($("<div/>").addClass("gridl-14")
                        .append($("<img/>").addClass("floatleft mt-5 mr-5 mb-5").attr("src", imageurl + tcode + "1.jpg").attr("width", "175").attr("height", "131").attr("alt", "New-York" + tcode))
                        .append($("<p/>").addClass("typo-10 mt-5").text(spoint))
                        .append($("<h5/>").text(ttitle)).append($("<span/>").addClass("icon-1 mt-10").text("おすすめ"))
                        .append($("<p/>").addClass("mt-10").text(point))
                        )
                        .append($("<div/>").addClass("gridl-14").append($("<img/>").attr("style", "float:left;").attr("src", cimage)).append($("<p/>").attr("style", "margin-left:110px; margin-top:8px;").text(ctitle))
                        ).append($("<hr/>"))
                    .appendTo("#tourlists");
                        numberOfTour = numberOfTour + 1;
                    };
                }

                switch ($.query.get("k")) {
                    case 20:
                        $("#result").html(sCity + " マイバス オプショナルツアー");
                        $("body title").context.title = sCity + " マイバス オプショナルツアー";
                        break;
                    case 25:
                        $("#result").html(sCity + " マイバス パッケージツアー");
                        $("body title").context.title = sCity + " マイバス パッケージツアー";
                        break;
                    case 26:
                        $("#result").html(sCity + " マイバス ホテル宿泊プラン");
                        $("body title").context.title = sCity + " マイバス ホテル宿泊プラン";
                        break;
                    case 27:
                        $("#result").html(sCity + " マイバス クーポン");
                        $("body title").context.title = sCity + " マイバス クーポン";
                        break;
                    case 99:
                        $("#result").html(sCity + " マイバス 送迎/チャーター");
                        $("body title").context.title = sCity + " マイバス 送迎/チャーター";
                        break;
                    default:
                        break; // $("#result").html(title + " マイバス 全ツアー 一覧");
                }
                //価格
                switch ($.query.get("p")) {
                    case 1: case 2: case 3: case 4: case 5: case 6: case 7:
                        $("#result").html(sCity + " マイバス 価格別 一覧");
                        $("body title").context.title = sCity + " マイバス 価格別 一覧";
                        break;
                    default:
                        break; //   $("#result").html(title + " マイバス 全ツアー 一覧");
                } //価格終わり
                //キャンペーン
                switch ($.query.get("c")) {
                    case 1:
                        $("#result").html(sCity + " マイバス キャンペーン 一覧");
                        $("body title").context.title = sCity + " マイバス キャンペーン 一覧";
                        break;
                    default:
                        break; // $("#result").html(title + " マイバス 全ツアー 一覧");
                } //キャンペーン終わり
                $("p.loading").empty(); //loading delete;
            });
            if (numberOfTour == 0) {
                $("<div/>").attr("style", "padding:10px; background-color:#fff6dd; text-align:center;").append($("<p/>").attr("style", "font-size:16px; font-weight:bold;").text("申し訳ございません。検索条件に該当するご希望のツアーがありませんでした。"))
                 .append($("<p/>").attr("style", "font-size:14px;").text("条件を変えて再検索してください。")).appendTo("#tourlists");
                $("p.loading").empty(); //loading delete;
            }
        }

    });
    var cd = $.query.get("cd");
    if (cd == "JTBAME" || cd == "jtbame") {
        $("a").each(function() {
            var check = $(this).get()[0].href;
            if (check != "") {
                if (check.indexOf("?") >= 0) {
                    $(this).attr("href", $(this).get() + "&cd=JTBAME");
                } else {
                    $(this).attr("href", $(this).get() + "?cd=JTBAME");
                };
            };
        });
    };
});


