﻿$(function() {

    $("#DateBegin").datepicker({minDate: 0, dateFormat: 'yy-mm-dd', showOtherMonths: true,onSelect: function(dateText, inst) {myDate = new Date(dateText.replace('-',','));myDate.setDate(myDate.getDate()+1);$('#datemustend').datepicker('option', 'minDate',myDate);}});
    $("#datemustend").datepicker({ minDate: 1,dateFormat: 'yy-mm-dd', showOtherMonths: true });
    //.datepicker({ dateFormat: 'yy-mm-dd', showOtherMonths: true });
    $('a.city_tip').cluetip({ local: true, cursor: 'pointer', width: 180, height: 200, positionBy: 'fixed', topOffset: -70, showTitle: false });
    //$('a.air_tip').cluetip({ local: true, cursor: 'pointer', width: 180, height: 200, positionBy: 'fixed', topOffset: -70, showTitle: false });
    $('a.air_tip').cluetip({ local: true, cursor: 'pointer', positionBy: 'fixed', topOffset: 0, leftOffset:25, showTitle: false });
    //选择城市 
    $(".t_cname").click(function() {
        if ($("#tr_" + $(this).attr("cid")).length == 0) {
            $.ajax
            ({
                type: "POST",
                url: "CAjax/CityAndSpot.ashx?a=1",
                dataType: 'text',
                data: { "cid": $(this).attr("cid") },
                success: function(data, status) {
                    if (data != "") {
                        $(".ban_list").append(data);
                        ShowHidTable();
                    }
                },
                error: function(data, status, e) {
                    alert("Error");
                }
            });
            $(this).addClass("select_city");
        }
        else {
            $(this).removeClass("select_city");
            $("#tr_" + $(this).attr("cid")).remove();
            ShowHidTable();
        }
    });

    //选择景区
    $(".t_sname").click(function(e) {
        //先判断表格是否已经存在这个景点
        var sign = false;
        var sname = $(this).text();
        var kk = $(this);

        $("#spot_list2 td a").each(function() {
            if ($(this).text() == sname) {
                sign = true;
                if ($.trim(kk.attr("class")) == "t_sname") {
                    $(this).addClass("select_city1");
                    kk.addClass("select_city");
                } else {
                    $(this).removeClass("select_city1");
                    kk.removeClass("select_city");
                }
            }
        });
        if (sign == false) {
            $.ajax
            ({
                type: "POST",
                url: "CAjax/CityAndSpot.ashx?a=1",
                dataType: 'text',
                data: { "cid": kk.attr("cid") },
                success: function(data, status) {
                    if (data != "") {
                        $(".ban_list").append(data);
                        $("#spot_list2 td a").each(function() {
                            if ($(this).text() == sname) {
                                $(this).addClass("select_city1");
                                kk.addClass("select_city");
                            }
                        });

                        $(".t_cname").each(function() {
                            if ($(this).attr("cid") == kk.attr("cid")) {
                                $(this).addClass("select_city");
                            }
                        });
                    }
                },
                error: function(data, status, e) {
                    alert("Error");
                }
            });
        }
        ShowHidTable();
    });

    $("#cbBeginEnd").change(function(){
        if($(this).attr("checked")==true){
            $(".whereBeginEnd").css("color","#555555");
            $("#BeginCity").removeAttr("disabled");
            $("#EndCity").removeAttr("disabled");
        }
        else{
            $(".whereBeginEnd").css("color","#999999");
            $("#BeginCity").attr("disabled","disabled");
            $("#EndCity").attr("disabled","disabled");
        }
    });
    

    //点击复选框
    $(".select_box").live("click", function() {
        var k = $(this).attr("cid");
        $("#Sceniclist a").each(function() {
            if ($(this).attr("cid") == k) {
                $(this).removeClass("select_city");
            }
        });
        $(".t_cname").each(function() {
            if ($(this).attr("cid") == k) {
                $(this).removeClass("select_city");
            }
        });
        $("#tr_" + k).remove();
        ShowHidTable();
    });
    //点击表格内景点名称
    $("#spot_list2 a").live("click", function() {
        var sname = $(this).text();
        //$(this).toggleClass("select_city1");
        if ($(this).attr("class") == "") {
            $(this).addClass("select_city1");
            $("#Sceniclist a").each(function() {
                if ($(this).text() == sname) {
                    $(this).addClass("select_city");
                }
            });
        } else {
            $(this).removeClass("select_city1");
            $("#Sceniclist a").each(function() {
                if ($(this).text() == sname) {
                    $(this).removeClass("select_city");
                }
            });
        }
        ShowHidTable();
    });
    
    function ShowHidTable(){
        var TrLength = $("#spot_list2 tr").length;
        if(TrLength==1){
            $("#spot_list2").hide();
        }
        else if(TrLength>1){
            $("#spot_list2").show();
        }
    }

    //    $("#views").click(function() {
    //        var gg = "";
    //        $(".select_box").each(function() {
    //            var cid = $(this).attr("cid");
    //            var k = "";
    //            $("#tr_" + cid + " a").each(function() {
    //                if ($(this).attr("class") != "") {
    //                    if (k == "") {
    //                        k = $(this).text();
    //                    } else {
    //                        k = k + "|" + $(this).text();
    //                    }
    //                }
    //            });
    //            if (gg == "") {
    //                gg = $(this).val() + "##" + k + "##" + $("#other_" + cid).val();
    //            } else {
    //                gg = gg + "%%%" + $(this).val() + "##" + k + "##" + $("#other_" + cid).val();
    //            }
    //        });
    //        $("#HiddenFieldWhere").val(gg);
    //    });


    //    $("#ButtonNext2,#ButtonPre1").click(function() {
    //        var gg = "";
    //        $(".select_box").each(function() {
    //            var cid = $(this).attr("cid");
    //            var k = "";
    //            $("#tr_" + cid + " a").each(function() {
    //                if ($(this).attr("class") != "") {
    //                    if (k == "") {
    //                        k = $(this).text();
    //                    } else {
    //                        k = k + "|" + $(this).text();
    //                    }
    //                }
    //            });
    //            if (gg == "") {
    //                gg = $(this).val() + "##" + k + "##" + $("#other_" + cid).val();
    //            } else {
    //                gg = gg + "%%%" + $(this).val() + "##" + k + "##" + $("#other_" + cid).val();
    //            }
    //        });
    //        $("#HiddenFieldWhere").val(gg);

    //    })

    $("#DateBeginFle1").click(function() {

        if ($(this).attr("checked") == true) {
            $("#DateBeginFle").attr("disabled", "");
            $(".spanDateBeginFle1").css("color","#555555");
        } else {
            $("#DateBeginFle").attr("disabled", "disabled");
            $(".spanDateBeginFle1").css("color","#999999");
        }
    })
    $("#DateDurationFle1").click(function() {

        if ($(this).attr("checked") == true) {
            $("#DateDurationFle").attr("disabled", "");
            $(".spanDateDurationFle1").css("color","#555555");
        } else {
            $("#DateDurationFle").attr("disabled", "disabled");
            $(".spanDateDurationFle1").css("color","#999999");
        }
    })
    /*
    $("#Changtu_tui").click(function() {
        $("#Changtu_huo").attr("disabled", "disabled").attr("checked", "");
        $("#Changtu_huo").parent().attr("disabled", "disabled");
        $("input[name='Air_pank']").attr("disabled", "disabled");
    });
    $("#Changtu_fei").click(function() {
        $("#Changtu_huo").attr("disabled", "").attr("checked", "checked");
        $("#Changtu_huo").parent().attr("disabled", "");
        $("input[name='Air_pank']").attr("disabled", "");
    });
    */
    
    $("input[name='Transportation']").change(function(){
        var myCheckID = ($(this).attr("id"));
        if(myCheckID=="Changtu_tui"){
            $("input[type='radio']",$("#WhatSeftUl")).attr("disabled", "disabled");
            $("#WhatSeftUl").css("color","#999999");
            $(".Changtu_feili").css("color","#999999");
            $(".Changtu_huoli").css("color","#999999");            
            $(".spanChangtu_fei").css("color","#999999");
            $(".spanChangtu_huo").css("color","#999999");
        }
        else if(myCheckID == "WhatSeft"){
            $("#Changtu_fei").removeAttr("disabled");
            $("#Changtu_fei").parent().removeAttr("disabled");
            $("#Changtu_huo").removeAttr("disabled");
            $("#Changtu_huo").parent().removeAttr("disabled");
            $(".spanChangtu_fei").css("color","#555555");
            $(".spanChangtu_huo").css("color","#555555");
                
            if($("#Changtu_huo").attr("checked") == true){
                $("input[type='radio']",$("#Changtu_huoUl")).removeAttr("disabled");
                $("input[type='radio']",$("#Changtu_feiUl")).attr("disabled", "disabled");
                $(".Changtu_huoli").css("color","#555555");
                $(".Changtu_feili").css("color","#999999");
            }
            else{
                $("#Changtu_fei").attr("checked",true);
                $("input[type='radio']",$("#Changtu_feiUl")).removeAttr("disabled");
                $("input[type='radio']",$("#Changtu_huoUl")).attr("disabled", "disabled");
                $(".Changtu_feili").css("color","#555555");
                $(".Changtu_huoli").css("color","#999999");
            }
        }
    })
    
    $("input[name='SelfWay']").change(function(){
        $("#Changtu_fei").removeAttr("disabled");
        $("#Changtu_fei").parent().removeAttr("disabled");
        var myCheckID = ($(this).attr("id"));
        if(myCheckID=="Changtu_fei"){
            $("input[type='radio']",$("#Changtu_feiUl")).removeAttr("disabled");
            $("input[type='radio']",$("#Changtu_huoUl")).attr("disabled", "disabled");
            $(".Changtu_feili").css("color","#555555");
            $(".Changtu_huoli").css("color","#999999");
        }
        else if(myCheckID == "Changtu_huo"){
            $("input[type='radio']",$("#Changtu_huoUl")).removeAttr("disabled");
            $("input[type='radio']",$("#Changtu_feiUl")).attr("disabled", "disabled");
            $(".Changtu_huoli").css("color","#555555");
            $(".Changtu_feili").css("color","#999999");
        }
    })
    
    $("input[name='Air_pank']").change(function() {

        if ($("#Air_pank3").attr("checked") == false) {
            $("#Changtu_shen").attr("disabled", "disabled");
            $("#Changtu_shen").parent().attr("disabled", "disabled");
        } else {
            $("#Changtu_shen").attr("disabled", "");
            $("#Changtu_shen").parent().attr("disabled", "");
        }

    });
    $("#ddlistSingleRooms").change(function() {
        var k = parseInt($(this).val());
        var old = $(".SingleRoomsList").size();
        //$("#tb_singleRooms").empty();
        if(k>0){
            if(k>old){
                for (var i = (old+1); i <= k; i++) {
                    $("#tb_singleRooms").append("<div id='ttr_" + i + "' class='SingleRoomsList'><span style=\"font-weight:bold;\">Room " + i + "</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >1 Rollaway</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >1 Crib</span><span class=\"spanpad\"><input type='checkbox' name='rooma'  iid=\"" + i + "\">Breakfast<a class='air_tip' href=\"#BreakfastNotes\" rel=\"#BreakfastNotes\"><img src=\"images/gif208.gif\" /></a>&nbsp;&nbsp;<span class=\"color999\"><input type='radio' name=\"s_r_" + i + "\"  value=\"1\" disabled=\"disabled\"><label for=\"s_r_" + i + "\">regular</label> <input id=\"s_r_" + i + "\"  type='radio' name=\"s_r_" + i + "\" value=\"2\" disabled=\"disabled\"><label for=\"s_r_" + i + "\">western</label></span></span><span class=\"spanpad\"><input type='checkbox' name='rooma' >nonsmoking</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >Wheelchair accessible</span></div>");
                    //cluetip;
                }
                $('a.air_tip').cluetip({ local: true, cursor: 'pointer', positionBy: 'fixed', topOffset: 0, leftOffset:5, showTitle: false });
            }
            else
            {
                $(".SingleRoomsList").each(function(index){
                    if(index>k-1){
                        $(this).remove();
                    }
                });
                //cluetip;
            }
        }
        else{
            $("#tb_singleRooms").empty();
        }
    });
    $("#twinrooms").change(function() {
        var k = parseInt($(this).val());
        var old = $(".TwinRoomsList").size();
        //$("#t_twinrooms").empty();
        if(k>0){
            if(k>old){
                for (var i = (old+1); i <= k; i++) {
                    $("#t_twinrooms").append("<div id='ttr_" + i + "' class='TwinRoomsList'><span style=\"font-weight:bold;\">Room " + i + "</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >1 Rollaway</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >1 Crib</span><span class=\"spanpad\"><input type='checkbox' name='rooma'  iid=\"" + i + "\">Breakfast<a class='air_tip' href='#BreakfastNotes' rel='#BreakfastNotes'><img src=\"images/gif208.gif\" /></a>&nbsp;&nbsp;<span class=\"color999\"><input type='radio' name=\"y_r_" + i + "\"  value=\"1\" disabled=\"disabled\"><label for=\"y_r_" + i + "\">regular</label> <input id=\"y_r_" + i + "\"  type='radio' name=\"y_r_" + i + "\" value=\"2\" disabled=\"disabled\"><label for=\"y_r_" + i + "\">western</label></span></span><span class=\"spanpad\"><input type='checkbox' name='rooma' >nonsmoking</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >Wheelchair accessible</span></div>");
                    //cluetip;
                }
                $('a.air_tip').cluetip({ local: true, cursor: 'pointer', positionBy: 'fixed', topOffset: 0, leftOffset:5, showTitle: false });
            }
            else
            {
                $(".TwinRoomsList").each(function(index){
                    if(index>k-1){
                        $(this).remove();
                    }
                });
                //cluetip;
            }
        }
        else{
            $("#t_twinrooms").empty();
        }
    });
    $("#doublerooms").change(function() {
        var k = parseInt($(this).val());
        var old = $(".DoubleRoomsList").size();
        //$("#t_doublerooms").empty();
        if(k>0){
            if(k>old){
                for (var i = (old+1); i <= k; i++) {
                    $("#t_doublerooms").append("<div id='ttr_" + i + "' class='DoubleRoomsList'><span style=\"font-weight:bold;\">Room " + i + "</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >1 Rollaway</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >1 Crib</span><span class=\"spanpad\"><input type='checkbox' name='rooma' iid=\"" + i + "\">Breakfast<a class=\"air_tip\" href=\"#BreakfastNotes\" rel=\"#BreakfastNotes\"><img src=\"images/gif208.gif\" /></a>&nbsp;&nbsp;<span class=\"color999\"><input type='radio' name=\"k_r_" + i + "\"value=\"1\" disabled=\"disabled\"><label for=\"k_r_" + i + "\">regular</label> <input id=\"k_r_" + i + "\"  type='radio' name=\"k_r_" + i + "\" value=\"2\" disabled=\"disabled\"><label for=\"k_r_" + i + "\">western</label></a></span></span><span class=\"spanpad\"><input type='checkbox' name='rooma' >nonsmoking</span><span class=\"spanpad\"><input type='checkbox' name='rooma' >Wheelchair accessible</span></div>");
                }
                $('a.air_tip').cluetip({ local: true, cursor: 'pointer', positionBy: 'fixed', topOffset: 0, leftOffset:5, showTitle: false });
            }
            else
            {
                $(".DoubleRoomsList").each(function(index){
                    if(index>k-1){
                        $(this).remove();
                    }
                });
                //cluetip;
            }
        }
        else{
            $("#t_doublerooms").empty();
        }
    });
    
    $("input[name='rooma']").live("click",function(){
        if($(this).attr("checked")){
            $(this).next().next().attr("class","color555");
            $("input",$(this).next().next()).removeAttr("disabled");
        }
        else{
            $(this).next().next().attr("class","color999");
            $("input",$(this).next().next()).attr("disabled","disabled");
        }
    });
    
    $("#foodtype2").click(function() {
        $("#gg_3").hide();
    });
    $("#foodtype1").click(function() {
        $("#gg_3").show();
    });    
    
    
    $("input[name='Guidelanguage']").change(function() {
        var selValue = $(this).val();
        if(selValue=="Other"){
            $("#tbOtherLan").removeAttr("disabled");
            $("#tbOtherLan").css("background-color","#FFFFFF");
        }
        else{
            $("#tbOtherLan").attr("disabled","disabled")
            $("#tbOtherLan").css("background-color","#E2E2E2");
        }
    });
    
    $("input[name='whostyle']").change(function() {
        var selValue = $(this).val();
        if(selValue=="Other"){
            $("#txtTravelFocus").removeAttr("disabled");
        }
        else{
            $("#txtTravelFocus").attr("disabled","disabled")
        }
    });
    
    $(".cbWhatTitle").click(function(){
        var cbID = $(this).attr("id");
        
        if(cbID=="cbLongDistance"){
            if($(this).attr("checked")==true){
                $("#oDivLongDistance").show();
            }
            else{
                $("#oDivLongDistance").hide();
            }
        }
        else if(cbID=="cbAccommodations"){
            if($(this).attr("checked")==true){
                $("#oDivAccommodations").show();
            }
            else{
                $("#oDivAccommodations").hide();
            }
            
        }
        else if(cbID=="cbTourGuide"){
            if($(this).attr("checked")==true){
                $("#oDivTourGuide").show();
            }
            else{
                $("#oDivTourGuide").hide();
            }
            
        }
        else if(cbID=="cbPrivateLocal"){
            if($(this).attr("checked")==true){
                $("#oDivPrivateLocal").show();
            }
            else{
                $("#oDivPrivateLocal").hide();
            }
            
        }
        else if(cbID=="cbSpotEntrance"){
            if($(this).attr("checked")==true){
                $("#oDivSpotEntrance").show();
            }
            else{
                $("#oDivSpotEntrance").hide();
            }
            
        }
        else if(cbID=="cbLocalMeals"){
            if($(this).attr("checked")==true){
                $("#oDivLocalMeals").show();
            }
            else{
                $("#oDivLocalMeals").hide();
            }
            
        }
    });
    
    //step Where
    $("#ButtonNext1").click(function() {
        
//        if ($("#BeginCity").val() == "") {
//            alert("Please enter Begin city!");
//            $("#BeginCity").focus();
//            return false;
//        }
//        if ($("#EndCity").val() == "") {
//            alert("Please enter End city!");
//            $("#EndCity").focus();
//            return false;
//        }
        
        if(CheckStepWhere())
        {
            $("#yu_1").hide();
            $("#yu_2").show();
            $("#yu_3").hide();
            $("#yu_4").hide();
            $("#yu_5").hide();
            returnTop();
        }
    });
    function CheckStepWhere(){
        var gg = "";
        $(".select_box").each(function() {
            var cid = $(this).attr("cid");
            var k = "";
            $("#tr_" + cid + " a").each(function() {
                if ($(this).attr("class") != "") {
                    if (k == "") {
                        k = $(this).text();
                    } else {
                        k = k + "|" + $(this).text();
                    }
                }
            });
            if (gg == "") {
                gg = $(this).val() + "##" + k;// + "##" + $("#other_" + cid).val();
            } else {
                gg = gg + "%%%" + $(this).val() + "##" + k;// + "##" + $("#other_" + cid).val();
            }
        });
        $("#HiddenFieldWhere").val(gg);

        if (gg == "") {
            alert("Please Select Scenic");
            returnTop("div_where");
            return false;
        }
        else
        {
            return true;
        }
    }
    
    //step When
    $("#ButtonNext2").click(function() {
        
        if(CheckStepWhen())
        {
            $("#yu_1").hide();
            $("#yu_2").hide();
            $("#yu_4").hide();
            $("#yu_5").hide();
            $("#yu_3").show();
            returnTop();
        }
    });
    function CheckStepWhen(){
        if ($("#DateBegin").val() == "") {
            alert("Please enter time");
            returnTop("div_when");
            $("#DateBegin").focus();
            return false;
        }
        if ($("#ddlDuration").val() == "") {
            alert("Please select Duratin Nights");
            returnTop("div_when");
            $("#ddlDuration").focus();
            return false;
        }
        return true;
    }
    $("#ButtonPre1").click(function() {
        $("#yu_2").hide();
        $("#yu_1").show();
        returnTop();
    });
    
    //step what
    $("#Button5").click(function() {
        //$("#HiddenRoom1")
        if(CheckStepWhat())
        {
            $("#yu_1").hide();
            $("#yu_2").hide();
            $("#yu_3").hide();
            $("#yu_5").hide();
            $("#yu_4").show();
            returnTop();
            CountRooms();
        }        
    });
    
    function CheckStepWhat(){
        if($("#cbAccommodations").attr("checked")==true){
            if ($("#ddlistSingleRooms").val() == "0" && $("#twinrooms").val() == "0" && $("#doublerooms").val() == "0") {
                alert("Please Select Hotel Room!");
                returnTop("what_hotels");
                $("#ddlistSingleRooms").focus();
                return false;
            }
        }
        if($("#cbTourGuide").attr("checked")==true){
            var selLan=$("input[name='Guidelanguage']:checked").val();
            if(selLan=="Other" && $.trim($("#tbOtherLan").val())=="")
            {
                alert("Please inter language");
                returnTop("cbTourGuide");
                $("#tbOtherLan").focus();
                return false;
            }
        }
        return true;
    }
    function CountRooms(){
        var k1 = "";
        $(".TwinRoomsList").each(function() {
            var kk1 = ""
            $(this).find("input[type=checkbox]").each(function() {

                if ($(this).attr("checked") == true) {
                    if ($(this).attr("iid") != "undefined" && $(this).attr("iid") != "") {
                        if ($("#y_r_" + $(this).attr("iid")).attr("checked") == true) {
                            if (kk1 == "") {
                                kk1 = "2";
                            } else {
                                kk1 = kk1 + ",2";
                            }
                        } else {
                            if (kk1 == "") {
                                kk1 = "1";
                            } else {
                                kk1 = kk1 + ",1";
                            }
                        }
                    } else {
                        if (kk1 == "") {
                            kk1 = "1";
                        } else {
                            kk1 = kk1 + ",1";
                        }
                    }
                } else {
                    if (kk1 == "") {
                        kk1 = "0";
                    } else {
                        kk1 = kk1 + ",0";
                    }
                }
            });
            if (k1 == "") {
                k1 = kk1;
            } else {
                k1 = k1 + "||" + kk1;
            }
        });
        $("#HiddenRoom1").val(k1);
        var k2 = "";
        $(".DoubleRoomsList").each(function() {
            var kk1 = ""
            $(this).find("input[type=checkbox]").each(function() {
                if ($(this).attr("checked") == true) {
                    if ($(this).attr("iid") != "undefined" && $(this).attr("iid") != "") {
                        if ($("#k_r_" + $(this).attr("iid")).attr("checked") == true) {
                            if (kk1 == "") {
                                kk1 = "2";
                            } else {
                                kk1 = kk1 + ",2";
                            }
                        } else {
                            if (kk1 == "") {
                                kk1 = "1";
                            } else {
                                kk1 = kk1 + ",1";
                            }
                        }
                    } else {
                        if (kk1 == "") {
                            kk1 = "1";
                        } else {
                            kk1 = kk1 + ",1";
                        }
                    }
                } else {
                    if (kk1 == "") {
                        kk1 = "0";
                    } else {
                        kk1 = kk1 + ",0";
                    }
                }
            });
            if (k2 == "") {
                k2 = kk1;
            } else {
                k2 = k2 + "||" + kk1;
            }
        });
        $("#HiddenRoom2").val(k2);
        
        var k3 = "";
        $(".SingleRoomsList").each(function() {
            var kk1 = ""
            $(this).find("input[type=checkbox]").each(function() {

                if ($(this).attr("checked") == true) {
                    if ($(this).attr("iid") != "undefined" && $(this).attr("iid") != "") {
                        if ($("#s_r_" + $(this).attr("iid")).attr("checked") == true) {
                            if (kk1 == "") {
                                kk1 = "2";
                            } else {
                                kk1 = kk1 + ",2";
                            }
                        } 
                        else {
                            if (kk1 == "") {
                                kk1 = "1";
                            } else {
                                kk1 = kk1 + ",1";
                            }
                        }
                    } 
                    else {
                        if (kk1 == "") {
                            kk1 = "1";
                        } else {
                            kk1 = kk1 + ",1";
                        }
                    }
                } else {
                    if (kk1 == "") {
                        kk1 = "0";
                    } else {
                        kk1 = kk1 + ",0";
                    }
                }
            });
            if (k3 == "") {
                k3 = kk1;
            } else {
                k3 = k3 + "||" + kk1;
            }
        });
        $("#HFSingleRooms").val(k3);
    }
    $("#ButtonPre2").click(function() {
        $("#yu_3").hide();
        $("#yu_2").show();
         returnTop();
    });
    
    
    //step Who
    $("#Button4").click(function() {
        if(checkWho()){
            $("#yu_4").hide();
            $("#yu_5").show();
            returnTop();
        }
    });
    
    function checkWho()
    {
        if($("#age2").val()==0 && $("#age12").val()==0 && $("#age16").val()==0 && $("#age30").val()==0 && $("#age40").val()==0 &&  $("#age55").val()==0){
            alert("Please select Member Age & Number.");
            returnTop("div_who");
            return false;
        }
        else{
            return true;
        }
    }
    
    $("#ButtonPre3").click(function() {
        $("#yu_4").hide();
        $("#yu_3").show();
         returnTop();
    });
    
    //step Your Contact Information
    $("#Button66").click(function(){
        
        if(CheckStepContact())
        {
            $("#yu_1").show();
            $("#yu_2").show();
            $("#yu_3").show();
            $("#yu_4").show();
            $("#yu_5").show();
            $("#ibtnSubmit").show();
            $(".finishHide").hide();
            returnTop();
        }
    });
    function CheckStepContact(){
        var clientTitle = $("#TSex").find("option:selected").val();  
        if(clientTitle=="" || clientTitle=="Title"){
            alert("Please select title");
            $("#TSex").focus();
            return false;
        }
    
        var firstName = $.trim($("#FirstName").val()).toLowerCase();
        var lastName = $.trim($("#txtLastName").val()).toLowerCase();
        if ((firstName == "" && lastName == "") || (firstName=="first name" && lastName=="last name")) {
            alert("Please enter the full name");
            $("#FirstName").focus();
            return false;
        }
        else{
            if (firstName == "" || firstName=="first name"){
                alert("Please enter the first name");
                $("#FirstName").focus();
                return false;
            }
            
            if (lastName == "" || lastName=="last name"){
                alert("Please enter the last name");
                $("#txtLastName").focus();
                return false;
            }
        }
        
        var emailHeader = $.trim($("#Email").val());
        var emailBody = $.trim($("#txtEmailBody").val());
        var emailAddress = emailHeader+"@"+emailBody;
        if (emailAddress=="@") {
            alert("Please enter E-mail Address");
            $("#Email").focus();
            return false;
        }

        if (!checkEmail(emailAddress)) {
            alert("Email format is incorrect");
            $("#txtEmailBody").focus();
            return false;
        }
        
        var AlterEmailHeader = $.trim($("#txtAlternative").val());
        var AlterEmailBody = $.trim($("#txtAlternativeBody").val());
        var AlterEmailAddress = AlterEmailHeader+"@"+AlterEmailBody;
        if (AlterEmailAddress != "@") {
            if (!checkEmail(AlterEmailAddress)) {
                alert("Alternative E-mail format is incorrect");
                $("#txtAlternative").focus();
                return false;
            }
        }

        var phoneCountry = $.trim($("#txtPhoneCountry").val()).toLowerCase();
        var phoneArea = $.trim($("#txtPhoneArea").val()).toLowerCase();
        var phoneNum = $.trim($("#Tel").val()).toLowerCase();
        var phoneExtension = $.trim($("#txtPhoneExtension").val()).toLowerCase();
        if((phoneCountry == "" && phoneArea == "" && phoneNum == "" && phoneExtension == "") || (phoneCountry == "country" && phoneArea == "area" && phoneNum == "number" && phoneExtension == "extension")){
            alert("Please enter Fixed-line phone");
            $("#txtPhoneCountry").focus();
            return false;
        }
        else{
            if(!(limitNum(phoneCountry))){
                alert("Fixed-line phone should numbers");
                $("#txtPhoneCountry").focus();
                return false;
            }
            if(!(limitNum(phoneArea))){
                alert("Fixed-line phone should numbers");
                $("#txtPhoneArea").focus();
                return false;
            }
            if(!(limitNum(phoneNum))){
                alert("Fixed-line phone should numbers");
                $("#Tel").focus();
                return false;
            }
            //if(phoneExtension!="" && phoneExtension == "extension" && !(limitNum(phoneExtension))){
            //    alert("Fixed-line phone should numbers");
            //    $("#txtPhoneExtension").focus();
            //    return false;
            //}
        }
        
        
        var mobileCountry = $.trim($("#txtMobileCountry").val()).toLowerCase();
        var mobileNum = $.trim($("#txtMobile").val()).toLowerCase();
        if((mobileCountry!="" && mobileCountry!="country") || (mobileNum!="" && mobileNum!="number")){
            if(!(limitNum(mobileCountry))){
                alert("Mobile should numbers");
                $("#txtMobileCountry").focus();
                return false;
            }
            if(!(limitNum(mobileNum))){
                alert("Mobile should numbers");
                $("#txtMobile").focus();
                return false;
            }
        }
        return true;
    }
    $("#ButtonPre5").click(function(){
        $("#yu_5").hide();
        $("#yu_1").hide();
        $("#yu_2").hide();
        $("#yu_3").hide();
        $("#yu_4").show();
        returnTop();
    });
    

    

    
    
    

    
    
    $("#ibtnSubmit").click(function(){
        if(checkSubmit())
        {
            $("#spanFinishLoading").show();
            $("#Button6").click();
        }
    });
    function returnTop(objID){
        if(objID==null || objID == "undefine" || objID==""){
            $("html,body").animate({scrollTop:'0px'}, 1000);
        }
        else{
            $("html,body").animate({scrollTop: $("#"+objID).offset().top}, 1000);
        }
    }
    
    
    function checkSubmit(){
        //step 1
        if(!CheckStepWhere()){
            return false;
        }
        
        //step 2
        if(!CheckStepWhen()){
            return false;
        }
        
        
        //step 3
        if(!CheckStepWhat()){
            return false;
        }
        CountRooms();
        
        //step 4
        if(!checkWho()){
            return false;
        }
        
        //step 5
        if(!CheckStepContact())
        {
            return false;
        }
        
        return true;
    }
    
    function checkEmail(strText){
        var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
        return pattern.test(strText);
    }
    function limitNum(strNum) {
        if(strNum.replace(/[\d+]/ig,"").length>0) {
            return false;
        }
        else{
            return true;
        }
    }

    //$(".displaynone").show();
})
