﻿// JScript 文件
 var provinceList;
var cityList;
var startProvince = 0;
var endProvince = 0;
var inputAreaItem;
var isStartInput;
var startCity=0,endCity=0;
var area_loaded = false;
var mode=0;
var type_name;

/***************************************地点选择器*****************************************/
    function ShowAreaSelect() {
        BOX_show("divArea");
        
        if( area_loaded ) {  
            if (isStartInput)
            {
                $("#divArea").find(".level1").hide();
                UpdateArea();
                return false;
            }
            else
            {
                $("#divArea").find(".level1").show();
                UpdateArea(endProvince);
                return false;
            }
        }
        area_loaded = true;
        $("#divArea").find(".area").empty();
        IIITripAJAX({
            service : AreaService().LoadCitys,
            params  : {mode:mode},
            resultHanle : function(result) {
                cityList = result.Data;             
                IIITripAJAX({
                    service : AreaService().LoadProvinces,
                    params  : {},
                    resultHanle : function(result) {
                        var region_area = $("#divArea").find(".level1");
                        $.each( result.Data, function(i,n){
                            var item = $("<span/>");
                            item.text( n.AreaName );
                            item.css({"cursor":"pointer"});
                            item.bind("click", function(){
                                UpdateArea(n.Id);
                                return false;
                            });
                            item.appendTo( region_area );
                        });
                        //UpdateSchoolArea( $("#usertype").val(), null );
                        
                        var schoolsArea = $("#divArea").find(".mainContent");
                        var loading = schoolsArea.find(".loading");
                        var areas = schoolsArea.find(".area");
                        loading.hide();
                        if (isStartInput) 
                        {
                            $("#divArea").find(".level1").hide();
                            UpdateArea();
                        }
                        else
                        {
                             $("#divArea").find(".level1").show();
                        }
                        areas.show();       
                    }
                }).execRequest_Json();  
            }
        }).execRequest_Json();        
    }  
document.onclick   =function   aa()   
  {   
  var   parentID=window.event.srcElement.parentElement.id;   
  var myid=window.event.srcElement.id;
  if (myid!= "hotelType" && myid!="hotelClass" && parentID!="mySelect") HideSelect();
  }     
    function UpdateArea(areaId) {
        $("#divArea").find(".area").empty();
        var citysArea = $("#divArea").find(".mainContent");
        //var loading = citysArea.find(".loading");
        var citys = citysArea.find(".area");
        if (isStartInput)
        {
            $.each( cityList, function(i,n){
                if(n.IfStart == 1){
                    var city_item = $("<li></li>").text( n.AreaName );
                    city_item.css( {"cursor":"pointer"} );
                    city_item.text( n.Name );
                    city_item.bind("click", function(){
                        BOX_remove( "divArea" );
                        inputAreaItem.val( n.AreaName );
                        startCity = n.Id;   
                        return false;
                    });
                    citys.append( city_item ); 
                } 
            });
        }
        else
        {
            $.each( cityList, function(i,n){
                if(n.ParentId == areaId){
                    var city_item = $("<li></li>").text( n.AreaName );
                    city_item.css( {"cursor":"pointer"} );
                    city_item.text( n.Name );
                    city_item.bind("click", function(){
                        BOX_remove( "divArea" );
                        inputAreaItem.val( n.AreaName );
                        endCity = n.Id;
                        endProvince = n.ParentId;
                        return false;
                    });
                    citys.append( city_item ); 
                } 
            });
        }
    }
    
 /*****************************************************************地点选择器******************************************************/ 
 
/***************************************************************列表选择******************************************************************/
var hotel_class=0;
var hotel_type=0;
	var selectedItem;
	var nSelectedFlag = 0;
	var mytmp;
	function mOvr(a,nflag)
	{
		if (nflag == 1)
		{
			a.className = 'selected_item';
		}else{
			a.className = 'normal_item';
		}
	}
	function ShowMySelect(a,nContent)
	{
		HideSelect();
		selectedItem = a;
		nSelectedFlag = 1;
    	
    	var pos = [a.offsetLeft, a.offsetTop]; //首先获得该元素相对第一个非流布局父元素的位置    
    	var parentNode = a.offsetParent; //获得该元素的第一个非流布局父元素    
    	if (parentNode != a) {         
    		while (parentNode) {             
    			pos[0] += parentNode.offsetLeft;             
    			pos[1] += parentNode.offsetTop;            
    			parentNode = parentNode.offsetParent; //循环定义非流布局父元素        
    		}    
    	}		
		var b = document.getElementById('mySelect');
		//b.style.left = a.offsetLeft;
		//b.style.top = a.offsetTop + a.offsetHeight + 1;
		b.style.left = String(pos[0]) + 'px';
		b.style.top = String(pos[1] + a.offsetHeight + 1) + 'px';
		b.style.width = String(a.offsetWidth) + 'px';
		//if (nContent == 1) b.innerHTML = getProvince();
		if (nContent == 2) b.innerHTML = getHotelClass();
		if (nContent == 3) b.innerHTML = getHotelType();
		b.style.display = 'block';
	}
	function HideMySelect()
	{
		//document.getElementById('mySelect').style.display = 'none';
	}
	function getSelectedValue(a)
	{
		selectedItem.value = a.innerHTML;		
		HideSelect();
	}
	function HideSelect()
	{
		document.getElementById('mySelect').style.display = 'none';
	}
	function BodyClick()
	{
		if (nSelectedFlag == 0)
		{
			HideSelect();
		}
		nSelectedFlag = 0;
	}
	function getHotelClass()
	{
		var cstr1 = '';
		cstr1 = cstr1 + '<p class="normal_item" onmouseover="mOvr(this,1)" onmouseout="mOvr(this,0)" onclick="getSelectedValue(this);hotel_class=0;" >不限</p>\n';
		cstr1 = cstr1 + '<p class="normal_item" onmouseover="mOvr(this,1)" onmouseout="mOvr(this,0)" onclick="getSelectedValue(this);hotel_class=1;" >五星级/豪华</p>\n';
		cstr1 = cstr1 + '<p class="normal_item" onmouseover="mOvr(this,1)" onmouseout="mOvr(this,0)" onclick="getSelectedValue(this);hotel_class=2;" >四星级/高档</p>\n';
		cstr1 = cstr1 + '<p class="normal_item" onmouseover="mOvr(this,1)" onmouseout="mOvr(this,0)" onclick="getSelectedValue(this);hotel_class=3;" >三星级/舒适</p>\n';
		cstr1 = cstr1 + '<p class="normal_item" onmouseover="mOvr(this,1)" onmouseout="mOvr(this,0)" onclick="getSelectedValue(this);hotel_class=4;" >二星级及以下/经济</p>\n';
		return cstr1;
	}
	function getHotelType()
	{
		var cstr1 = '';
		cstr1 = cstr1 + '<p class="normal_item" onmouseover="mOvr(this,1)" onmouseout="mOvr(this,0)" onclick="getSelectedValue(this);hotel_type=0;" >不限</p>\n';
		cstr1 = cstr1 + '<p class="normal_item" onmouseover="mOvr(this,1)" onmouseout="mOvr(this,0)" onclick="getSelectedValue(this);hotel_type=1;" >酒店式公寓</p>\n';
		cstr1 = cstr1 + '<p class="normal_item" onmouseover="mOvr(this,1)" onmouseout="mOvr(this,0)" onclick="getSelectedValue(this);hotel_type=2;" >度假型酒店</p>\n';
		return cstr1;
	}
/***************************************************************列表选择******************************************************************/
function getTrafficType(){
    var n=0;
    n=$("#trafficType").attr("checked")+$("#trafficType1").attr("checked")*2+$("#trafficType2").attr("checked")*4+$("#trafficType3").attr("checked")*8;
    return n;
}	
function getSightspotType(){
    var n=0;
    n=$("#sightspotType").attr("checked")
        +$("#sightspotType1").attr("checked")*2+$("#sightspotType2").attr("checked")*4;
    return n;
} 

$(document).ready(function ()
{
   $("#mainNav").find("#index_menu").find("a").attr("class","current");
     //加载推荐路线
   /*  IIITripAJAX({
        service : CircuitryService().GetPaiXuCircuitry,
        params  : {num:1},
        resultHanle : function(result) {
            var oData = result.Data;
            var firstContainer = $("#firstRecommandContainer");
            var item;
            $.each(oData,function(i,n) {
                        item=$("#recommand_temp").clone();
                        item.attr("id","recommand_"+i);
                        item.find("#left").find("a").attr("href","Search/Route/Route_view.aspx?id="+n.Id);
                        item.find("#left").find("a").text(n.CircuitryName);
                        item.find("#left").attr("id","left"+i);
                        item.find("#leftprice").text(n.ReferencePrice);
                        item.find("#leftprice").attr("id","leftprice"+i);
                        item.attr("style",null);
                        item.appendTo(firstContainer);
            })
        }
    }).execRequest_Json(null);
    //加载其他类别的线路
    IIITripAJAX({
        service : CircuitryService().GetPaiXuCircuitry,  //换成相应的线路数据源
        params  : {num:2},
        resultHanle : function(result) {
            var oData = result.Data;
            var firstContainer = $("#Table1");
            var item;
            $.each(oData,function(i,n) {
                        item=$("#recommand_temp").clone();
                        item.attr("id","recommand_"+i);
                        item.find("#left").find("a").attr("href","Search/Route/Route_view.aspx?id="+n.Id);
                        item.find("#left").find("a").text(n.CircuitryName);
                        item.find("#left").attr("id","left"+i);
                        item.find("#leftprice").text(n.ReferencePrice);
                        item.find("#leftprice").attr("id","leftprice"+i);
                        item.attr("style",null);
                        item.appendTo(firstContainer);
            })
        }
    }).execRequest_Json(null);
    IIITripAJAX({
        service : CircuitryService().GetPaiXuCircuitry,
        params  : {num:3},
        resultHanle : function(result) {
            var oData = result.Data;
            var secondContainer = $("#Table2");
            var item;
            $.each(oData,function(i,n) {
                        item=$("#recommand_temp").clone();
                       item.attr("id","recommand_"+i);
                        item.find("#left").find("a").attr("href","Search/Route/Route_view.aspx?id="+n.Id);
                        item.find("#left").find("a").text(n.CircuitryName);
                        item.find("#left").attr("id","left"+i);
                        item.find("#leftprice").text(n.ReferencePrice);
                        item.find("#leftprice").attr("id","leftprice"+i);
                        item.attr("style",null);
                        item.appendTo(secondContainer);
            })
        }
    }).execRequest_Json(null);
    IIITripAJAX({
        service : CircuitryService().GetPaiXuCircuitry,
        params  : {num:4},
        resultHanle : function(result) {
            var oData = result.Data;
            var secondContainer = $("#Table3");
            var item;
            $.each(oData,function(i,n) {
                        item=$("#recommand_temp").clone();
                        item.attr("id","recommand_"+i);
                        item.find("#left").find("a").attr("href","Search/Route/Route_view.aspx?id="+n.Id);
                        item.find("#left").find("a").text(n.CircuitryName);
                        item.find("#left").attr("id","left"+i);
                        item.find("#leftprice").text(n.ReferencePrice);
                        item.find("#leftprice").attr("id","leftprice"+i);
                        item.attr("style",null);
                        item.appendTo(secondContainer);
            })
        }
    }).execRequest_Json(null);*/
    
    //线路绑定
      $("#route_startCity").bind("focus", function() {
            inputAreaItem = $("#route_startCity");
            isStartInput = true;
            mode=6;
            ShowAreaSelect();
      });
/*    $("#route_endCity").bind("focus",function() {
            inputAreaItem = $("#route_endCity");
            isStartInput = false;
            mode=2;
            ShowAreaSelect();
      });*/
      
      $("#route_startDate").bind("focus",function () {
        WdatePicker();
      });
      
      $("#route_btnSearch").bind("click",function() {
                   if (!IsNum($.trim($("#route_travelDays").val())) || $.trim($("#route_travelDays").val()).length>2){
                alert("旅行天数不合法");
                return;
            }
            var travelType = 0,travelDays=0;
            var sRouteEndCity= '';
            $("input[@name='seneryType']").each(function () {
                if ($(this).attr("checked") == true)
                {
                    travelType = travelType + parseInt($(this).attr("value"));
                }
            });            
            if ($.trim($("#route_endCity").val()) != "")
            {
                sRouteEndCity = $.trim($("#route_endCity").val());
            }
            if ($.trim($("#route_travelDays").val()) != "")
            {
                travelDays = $.trim($("#route_travelDays").val());
            }
            
            if ($.trim($("#route_startDate").val()) != "")
            {
                startDate = $.trim($("#route_startDate").val());
            }
            
            if(!QueryStringCheck(sRouteEndCity,travelDays)) alert("输入含有非法字符");
            window.location.href =  "Search/Route/Route_search_list.aspx?sc=" + startCity + "&ec=" + sRouteEndCity + "&sd=" + startDate + "&tt=" + travelType + "&td=" + travelDays;
      });
    //自助游绑定
        var trafficType ="";
        var hotelStar = "";
        var startDate ="";
        var backDate ="";
          $("#selfplay_startCity").bind("focus", function() {
            inputAreaItem = $("#selfplay_startCity");
            isStartInput = true;
            mode=6;
            ShowAreaSelect();
      });
      
 /*     $("#selfplay_endCity").bind("focus",function() {
            inputAreaItem = $("#selfplay_endCity");
            isStartInput = false;mode=2;
            ShowAreaSelect();
      });*/
      
      $("#selfplay_startDate").bind("focus",function () {
        WdatePicker();
      });
      
      $("#selfplay_endDate").bind("focus", function () {
        WdatePicker();
      });
      
      $("#selfplay_btnSearch").bind("click", function() {
         trafficType = "";
         hotelStar = "";
        
        $("input[@name='selfplay_trafficType']").each(function () {
            if ($(this).attr("checked") == true)
            {
                if (trafficType != "")
                {
                    trafficType += ",";
                }
                trafficType = trafficType + Math.pow(2,$(this).attr("value")-1);
            }
        });
             if ($.trim($("#selfplay_endCity").val()) != "")
            {
                var sDIYEndCity = $.trim($("#selfplay_endCity").val());
            }       
        $("input[@name='hotelStar']").each(function () {
            if ($(this).attr("checked") == true)
            {
                if (hotelStar != "")
                {
                    hotelStar += ",";
                }
                hotelStar = hotelStar + $(this).attr("value");
            }
        });
        
        if ($.trim($("#selfplay_startDate").val()) != "")
        {
            startDate = $.trim($("#selfplay_startDate").val());
        }
        
        if ($.trim($("#selfplay_endDate").val()) != "")
        {
            backDate = $.trim($("#selfplay_endDate").val());
        }
        
        if(!QueryStringCheck(sDIYEndCity)) alert("输入含有非法字符");
        window.location.href =  "Search/SelfPlay/Search.aspx?sc=" + startCity + "&ec=" + sDIYEndCity + "&sd=" + startDate + "&bd=" + backDate + "&tt=" + trafficType + "&hs=" + hotelStar;
      });
    //酒店绑定
    $("#hotel_startDate").bind("focus",function () {
        WdatePicker();
      });
    $("#hotel_endDate").bind("focus",function () {
        WdatePicker();
      });
      $("#hotel_city").bind("focus", function() {
            inputAreaItem = $("#hotel_city");
            isStartInput = false;
            mode=5;
            ShowAreaSelect();
      });
    $("#hotel_btnSearch").bind("click",function() {
            if ($("#hotel_city").val()=="") {
                alert("所在地不能为空");
                return;
            }
            else if ($("#hotel_startDate").val()==""){
                alert("入住时间不能为空");
                return;
            }
            else if ($("#hotel_endDate").val()==""){
                alert("离店时间不能为空");
                return;
            }
            else if (!DateCheck($("#hotel_startDate").val(),$("#hotel_endDate").val())){
                alert("入住时间不能在离店时间之后！");
                return;
            }
            else if (!IsNum($("#priceStart").val()) || !IsNum($("#priceEnd").val())){
                alert("房价必须输入数字");
                return;
            }
            else if (!($("#priceStart").val()<=$("#priceEnd").val())){
                alert("房价范围错误");
                return;
            }
            else if($("#hotelName").val().length>50){
                alert("酒店名称太长");
                return;
            }
            
            
            var querystring="";
            
            querystring+="city="+endCity;
            querystring+="&startDate="+$("#hotel_startDate").val();
            querystring+="&endDate="+$("#hotel_endDate").val();
            querystring+="&hotelName="+$("#hotelName").val();  
            querystring+="&hotelType="+hotel_type;
            querystring+="&hotelLevel="+hotel_class;          
             if($("#priceStart").val()=="")
            {
                querystring+="&priceStart=0";
            }
            else
            {
                querystring+="&priceStart="+$("#priceStart").val();
            }
            if($("#priceEnd").val()=="")
            {
                querystring+="&priceEnd=100000000";
            }
            else
            {
                querystring+="&priceEnd="+$("#priceEnd").val();
            }
            querystring+="&num=0";
             if(!QueryStringCheck($("#hotelName").val(),$("#priceStart").val(),$("#priceEnd").val())) alert("输入含有非法字符");               
            window.location.href="Search/Hotel/Hotel_search_list.aspx?"+querystring;

      });

   //交通绑定
       $("#traffic_startDate").bind("focus",function () {
        WdatePicker();
      });
      $("#traffic_startArea").bind("focus", function() {
            inputAreaItem = $("#traffic_startArea");
            isStartInput = true;
            mode=6;
            ShowAreaSelect();
      });
      $("#traffic_targetArea").bind("focus",function() {
            inputAreaItem = $("#traffic_targetArea");
            isStartInput = false;
            mode=2;
            ShowAreaSelect();
      });
    $("#traffic_btnSearch").bind("click",function() {
            if ($("#traffic_startArea").val()=="") {
                alert("出发地不能为空");
                return;
            }
            else if ($("#traffic_targetArea").val()==""){
                alert("目的地不能为空");
                return;
            }
            else if ($("#traffic_startDate").val()==""){
                alert("出发日期不能为空");
                return;
            }
            var querystring="";
            
            var trafficType=0;
            trafficType=getTrafficType();
            querystring+="startArea="+startCity;
            querystring+="&targetArea="+endCity;
            querystring+="&startDate="+$("#traffic_startDate").val();
            querystring+="&trafficType="+trafficType;                 
            window.location.href="Search/Traffic/Traffic_search_list.aspx?"+querystring;

      });
      
      //景点绑定
      $("#location").bind("focus", function() {
        inputAreaItem = $("#location");
        isStartInput = false;
        mode=3;
        ShowAreaSelect();
      });
       $("#startDate").bind("focus",function () {
        WdatePicker();
      });
       $("#keyword").bind("click", function() {
            $("#keyword").attr("value","");
      });
    $("#sightspot_btnSearch").bind("click",function() {
            if($("#keyword").attr("value").length>100){
                alert("关键词太长，请重新输入");
                return;
            }
            if($("#keyword").attr("value").length==0 || $("#keyword").attr("value")=="请输入关键字"){
                alert("关键词不能为空");
                return;
            }
            var querystring="";
            querystring+="location="+endCity;
            querystring+="&startDate="+$("#startDate").val();  
            if($("#keyword").attr("value")=="请输入关键字") querystring+="&keyword=";
            else querystring+="&keyword="+$("#keyword").attr("value");
             querystring+="&sightSpotType="+getSightspotType();               
             querystring+="&num=0";
             if(!QueryStringCheck($("#keyword").val())) alert("输入含有非法字符");  
            window.location.href="Search/sightspot/sightspot_search_list.aspx?"+querystring;

      });
      
});
/* var m=0;var n=0;
function selectTag(showContent,selfObj){
	    // 操作标签 
	    var tag = document.getElementById("tags").getElementsByTagName("li");
	    var taglength = tag.length;
	    for(i=0; i<taglength; i++){
		    tag[i].className = "";
	    }
	    selfObj.parentNode.className = "selectTag";
	    type_name=selfObj.innerText;
	    // 操作内容
	    for(i=0; j=document.getElementById("tagContent"+i); i++){
		    j.style.display = "none";
	    }  
	    document.getElementById(showContent).style.display = "block";
	    if(m==0 && type_name=="网站公告")
	    {
	        dongtaixinwen();
	        m++;
	    }
	    if(n==0 && type_name=="旅游动态")
	    {
	        dongtaixinwen();
	        n++;
	    }  
 }
function dongtaixinwen()
{
    if(type_name == "网站公告")
    {
      type_name="网站公告";
    }
    if(type_name == "旅游动态")
    {
      type_name = "首页新闻动态";
    }  
    IIITripAJAX
    ({
         service: MemberService().GetDongtai,
         params:{type_name:type_name},
         resultHanle :function(result)
         {
               if(type_name == "网站公告")
                {
                   $.each(result.Data,function(i,n)
                    {   
                       var item=$("#gonggao").clone();
                       item.attr("id","title"+i);
                          if(i<10)
                           {
                               if(i == 0)
                               {
                                   item.find("#title1").find("#title2").attr("style","width:95%;height:20px;line-height:20px;font-size:9pt;font-weight:600;overflow:hidden;color:#496501;");
                                   item.find("#title1").find("#title2").find("a").text(n.NewsTitle);
                                   item.find("#title1").find("#title2").find("a").click( function(){window.location.href="BULLETIN.html?id="+n.Id;return false;}); //.attr("href","BULLETIN.html?id="+n.Id);
                                   item.find("#content1").find("#content2").attr("style","width:95%;height:100px;font-size:9pt;font-weight:400;overflow:hidden;color:#bbbbbb;display:block;line-height:16px;");
                                   item.find("#content1").find("#content2").html((n.NewsContent).replace(new RegExp("\n","gm"),"<br>").replace(/ /g,"&nbsp;"));
                                   item.find("#line1").find("#line2").attr("style","width:95%;height:10px;font-size:9pt;font-weight:400;overflow:hidden;color:#bbbbbb;display:block;");
                               }
                               else
                               {
                                   item.find("#title1").find("#title2").attr("style","width:95%;height:20px;line-height:20px;font-size:9pt;font-weight:600;overflow:hidden;color:#496501;");
                                   item.find("#title1").find("#title2").find("a").text(n.NewsTitle);
                                   item.find("#title1").find("#title2").find("a").click( function(){window.location.href="BULLETIN.html?id="+n.Id;return false;});//attr("href","BULLETIN.html?id="+n.Id);
                               }
                               item.attr("style",null);
                               item.appendTo("#tagContent1");
                           }          
                     })
                 }
                if(type_name == "首页新闻动态")
                {
                    
                    $.each(result.Data,function(i,n)
                    {  
                       var item=$("#dongtaixinwen").clone();
                       item.attr("id","title"+i);
                       
                       if(i<10)
                       {
                           if(i == 0)
                           {
                               item.find("#title3").find("#title4").attr("style","width:95%;height:20px;line-height:20px;font-size:9pt;font-weight:600;overflow:hidden;color:#496501;");
                               item.find("#title3").find("#title4").find("a").text(n.NewsTitle);
                               item.find("#title3").find("#title4").find("a").attr("href","news.html?id="+n.Id);
                               item.find("#content3").find("#content4").attr("style","width:95%;height:100px;font-size:9pt;font-weight:400;overflow:hidden;color:#bbbbbb;display:block;line-height:16px;");
                               item.find("#content3").find("#content4").html((n.NewsContent).replace(new RegExp("\n","gm"),"<br>").replace(/ /g,"&nbsp;"));
                               item.find("#line3").find("#line4").attr("style","width:95%;height:10px;font-size:9pt;font-weight:400;overflow:hidden;color:#bbbbbb;display:block;");
                           }
                           else
                           {
                               item.find("#title3").find("#title4").attr("style","width:95%;height:20px;line-height:20px;font-size:9pt;font-weight:600;overflow:hidden;color:#496501;");
                              item.find("#title3").find("#title4").find("a").text(n.NewsTitle);
                               item.find("#title3").find("#title4").find("a").attr("href","news.html?id="+n.Id);
                           }
                           item.attr("style",null);
                           item.appendTo("#tagContent2");
                       }
                    })
                 }
         }
    }).execRequest_Json(null);

}*/



