﻿//是否有目的地
function selectSubject(temp){
    if(temp==0){
        $("#hasDest").show();
        $("#NoDest").hide()
    }
    else{
        $("#hasDest").hide()
        $("#NoDest").show();
    }
}
//显示主题或者目的地
function showCondition(temp){
    if(temp==0){
        $("#tr_dest").show();
        $("#tr_zhuti").hide()
    }
    else{
        $("#tr_dest").hide()
        $("#tr_zhuti").show();
    }
}
//搜索
function searchTrip(){
    var begionCity=$("#txt_begionCity")[0];
    var endCity=$("#txt_endCity")[0];
    var begionDate=$("#txt_begiondate")[0];
    var rb_endCity=$("#rb_endCity")[0];
    var rb_shi=$("#shi")[0];
    var rb_fou=$("#fou")[0];
    var dual=0; //0表示目的 1表示主题 2表示天数价格的查询
    var str="";
    var selectTitle=$("#ctl00_Left1_ddl_zhuti").val();//主题标题ID
    var day=$("#ctl00_Left1_ddl_day").val();//期待天数
    var price=$("#ctl00_Left1_ddl_price").val();//价格
    var begionCity1=$("#txt_begionCity1")[0];
    var begionDate1=$("#txt_begiondate1")[0];
    if(rb_fou.checked==true) {//否
        dual=2;
        if(begionDate1.value=="") {
            alert("请输入出发日期");
            begionDate1.focus();
            return false;
        } 
        if(begionCity1.value==""){
            alert("请输入出发地");
            begionCity1.focus();
            return false;
        }
        setCookie("trip_xp_dual",dual,0);
        setCookie("trip_xp_begioncity",XP_Get3Code(begionCity1.value),0);
        setCookie("trip_begiondate",begionDate1.value,0);
        str = "/SearchTrip.aspx?dual=" + dual + "&begionCity=" + XP_Get3Code(begionCity1.value) + "&day=" + day + "&price=" + price + "&begionDate=" + begionDate1.value + "";
    }
    if(rb_shi.checked==true){ //是
        if(rb_endCity.checked==true)//目的地
        {
            if(endCity.value==""||endCity.value=="输入中文/拼音/三字码")
            {
                alert("请输入目的地城市");
                endCity.focus();
                return false;
            }
            setCookie("trip_xp_dual",dual,0);
            setCookie("trip_xp_begioncity",XP_Get3Code(begionCity.value),0);
            setCookie("trip_begiondate",begionDate.value,0);
            str = "/SearchTrip.aspx?dual=" + dual + "&begionCity=" + XP_Get3Code(begionCity.value) + "&endCity=" + XP_Get3Code(endCity.value) + "&selectTitle=0&begionDate=" + begionDate.value + "";
        }
        else//主题
        {   
            dual=1;
            setCookie("trip_xp_dual",dual,0);
            setCookie("trip_xp_begioncity",XP_Get3Code(begionCity.value),0);
            setCookie("trip_begiondate",begionDate.value,0);
            str = "/SearchTrip.aspx?dual=" + dual + "&begionCity=" + XP_Get3Code(begionCity.value) + "&endCity=" + XP_Get3Code(endCity.value) + "&selectTitle=" + selectTitle + "&begionDate=" + begionDate.value + "";
        }
        if(begionDate.value=="")
        {
            alert("请输入出发日期");
            begionDate.focus();
            return false;
        } 
    }
    setCookie("trip_xp_day",day,0);
    setCookie("trip_xp_price",price,0);
    setCookie("trip_xp_selectTitle",selectTitle,0);
    setCookie("trip_xp_endcity", XP_Get3Code(endCity.value), 0);
    window.location.href=str;
}
//绑定搜索的信息
function bindSearchInfo(dual, begionCityName, endCityName, begiondate, selectTitle, Price, Day) {
    if(dual==0)//目的地
    {
        $("#rb_endCity")[0].checked=true;
        selectSubject(dual);
        showCondition(dual);
        $("#txt_begionCity").val(begionCityName);
        $("#txt_begionCity")[0].style.color="#000";
        $("#txt_endCity").val(endCityName);
        $("#txt_endCity")[0].style.color="#000";
        $("#txt_begiondate").val(begiondate);
    }
    if(dual==1)//主题
    {
        $("#rb_zhuti")[0].checked=true;
        selectSubject(0);
        showCondition(dual);
        $("#txt_begionCity").val(begionCityName);
        $("#txt_begionCity")[0].style.color="#000";
        $("#txt_begiondate").val(begiondate);
        $("#ctl00_Left1_ddl_zhuti").val(selectTitle);
    }
    if (dual == 2) {
        $("#fou")[0].checked=true;
        selectSubject(dual);
        $("#txt_begionCity1").val(begionCityName);
        $("#txt_begiondate1").val(begiondate);
        $("#ctl00_Left1_ddl_price").val(Price);
        $("#ctl00_Left1_ddl_day").val(Day); 
    }    

}
// 获取三字代码
function XP_Get3Code(str)
{
    var regExp=/\(([A-Z]{3})\)/;
    if(regExp.exec(str)!=null){var author=RegExp.$1;return author}    
    else{if(str.length==3){if (isEnglish(str)){return str;}else{return "";}}return "";}
}
function isEnglish(str){var re = /[a-zA-Z]/;if(re.test(str)){return true;}else{return false;}}
//查看不同城市的信息
function changeSelect(obj)
{
    $(".selaction_li_selected").attr("className","selaction_li");
    obj.className="selaction_li_selected";
}
//游轮
function youlun(id)
{
    $("#ctl00_ContentPlaceHolder1_youlun").val(id);
    $(".order_loaddings").show();
    $(".orderDatas").html('');
    $.ajax({        
        url:"/Default.aspx",
        data:"ajax=true&id="+id+"",
        cache:false,
        success:function(html)
        {   
            if(html.length>0)
            {   
                $("#rpdata").show();               
                $("#rpdata").html(html);
                $(".order_loaddings").hide();
                $(".orderDatas").hide();
                
            }
            else{
                $("#rpdata").hide();
                $(".orderDatas").show();
                $(".orderDatas").html('没有相关数据');
                $(".order_loaddings").hide();
            }
            
        },
        error:function(html)
        {
            $(".orderDatas").html('获取数据发生错误！');
            $(".order_loaddings").hide();
        }
    })
}
//区域
function CallTheServer1(id){
   $("#ctl00_ContentPlaceHolder1_hid").val(id);
    $(".order_loaddings").show();
    $(".orderDatas").html('');
    $.ajax({        
        url:"/Default.aspx",
        data:"ajax=true&AreaID="+id+"",
        cache:false,
        success:function(html){   
            if(html.length>0){   
                $("#rpdata").show();               
                $("#rpdata").html(html);
                $(".order_loaddings").hide();
                $(".orderDatas").hide();
            }
            else{
                $("#rpdata").hide();
                $(".orderDatas").show();
                $(".orderDatas").html('没有相关数据');
                $(".order_loaddings").hide();
            } 
        },
        error:function(html){
            $(".orderDatas").html('获取数据发生错误！');
            $(".order_loaddings").hide();
        }
    })
}
//更多
function returnMore(){
    //游轮
    if($("#ctl00_ContentPlaceHolder1_youlun").val().length>0){
        var subjectid=$("#ctl00_ContentPlaceHolder1_youlun").val();
        window.location.href="/"+subjectid+"/1/SearchTrip.html";
    }
    else{
        var id= $("#ctl00_ContentPlaceHolder1_hid").val();//区域ID
        window.location.href="/SearchTrip.aspx?moreid="+id+"";
    }
}

/*出发城市*/
function showbox(obj) {
    var showmsg = $(".departbox");
    if (showmsg[0].style.display == "block") {
        showmsg.hide();
        $(obj).css("background-image", "url('/images/ico/r_cfa.gif')");
    }
    else {
        $(obj).css("background-image", "url('/images/ico/shang.gif')");
        showmsg[0].style.zIndex = 99999;
        showmsg[0].style.top = XP_getPoint(obj).y + 25 + "px";
        showmsg[0].style.left = XP_getPoint(obj).x - 78 + "px";
        showmsg.show();
    }
}
function hidebox(obj)
{
     $(".departbox").hide();
}

//根据区域ID获取行程
function loading(citycode,cityName) {
    var url = "ajax=true&flag=true";
    cityName = encodeURI(cityName);
      if (citycode != "") { url = "ajax=true&flag=true&citycode=" + citycode + "&cityName="+cityName+""; }
        $("#loadingData").show();
        $("#trip1").html('');
        $(".departbox").hide();
        $.ajax({
            url: "/Default.aspx",
            data: url,
            cache: false,
            success: function(html) {
            var datas = html.split('|');
            $("#trip1").html(datas[0]);
//            $("#trip2").html(datas[1]);
//            $("#trip3").html(datas[2]);
//            $("#trip4").html(datas[3]);
            $("#clumeb").html(datas[1]);
            $("#loadingData").hide();
            },
            error: function(html) {
                $("#trip1").html('获取数据发生错误！');
                $("#loadingData").hide();
            }
        })
}
function tripcity(citycode,obj) {
    $(".trip_depart").html($(obj).html() + "出发");
    loading(citycode, encodeURI($(obj).html()));
}
