var hkey='';
var lhotels='';
var hspot='';
var hstar='';
var regions='';
var hsplit='';
var hcond=''+hsplit ;
var gcond='';

function ChangeOrderStr()
{
orderstr=$("hotel_Select").value;
ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
}

function ChangeListPage(pagenum)
{
switch (pagenum)
{
case 10:
$("List_Page10").className="List_Page c10";
$("List_Page20").className="List_Page p20";
$("List_Page40").className="List_Page p40";
break;
case 20:
$("List_Page10").className="List_Page p10";
$("List_Page20").className="List_Page c20";
$("List_Page40").className="List_Page p40";
break;
case 40:
$("List_Page10").className="List_Page p10";
$("List_Page20").className="List_Page p20";
$("List_Page40").className="List_Page c40";
break;
}
hotel_pagesize=pagenum;
ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
}

function filterCancel()
{
 hcond='';
 gcond='';
ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
}

function isPlus(number) {
    if(parseInt(number)<=0 || !parseInt(number)) {
        return false;
    }
    return true;
}
function ChangePrice()
{
         var lp=$("lprice").value;
       if($("lprice" ).value != "" && !isPlus($("lprice" ).value)) 
       {
		alert('对不起，价格必须为有效数字！');
		$("lprice").focus();
		return false;
       }
       if (lp=="")
       {
       lp=lprice;
       } 
       if (lp>tprice)
       {
       lp=tprice;
       }
      var hp=$("tprice").value;
       if($("tprice" ).value != "" && !isPlus($("tprice" ).value)) 
       {
		alert('对不起，价格必须为有效数字！');
		$("tprice").focus();
		return false;
       }
       if (hp=="" || hp>tprice)
       {
       hp=tprice;
       } 
       if (hp<lp)
       {
       lp=hp;
       }
         gcond =' and price BETWEEN '+lp+' AND '+hp+' '; 
         ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
}
function ChangeSpot()
{
         hspot='';
         var selectspot=$("hspot").value;
         if (selectspot!="0")
         {
         hspot =' and spotsid='+selectspot; 
         }
         hcond=hspot+hstar+hkey +regions +lhotels+hsplit ;
         ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
}
function ChangeStar()
{
         hstar='';
         var ls=$("lstar").value;
         var hs=$("hstar").value;
         if (parseInt(hs)<parseInt(ls))
         {
         ls=hs;
         }
         hstar =' and itemtype BETWEEN '+ls+' AND '+hs+' '; 
         hcond=hspot+hstar+hkey +regions +lhotels+hsplit ;
         ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
}
function ChangeItem()
{
         hsplit='';
         var item=$("itemtype").value;
            switch (parseInt(item))
            {
                case 1:
                    hsplit = " ";
                    hspot='';
                    $('Star_content').style.display = '';
                    $('Spot_content').style.display = 'none';
                  break;
                case 2:
                    hsplit = " and linkhotel <> \'\'";
                    hstar='';
                    hspot='';
                    $('Star_content').style.display = 'none';
                    $('Spot_content').style.display = 'none';
                    break;
                case 3:
                    hsplit = " and spotsid<>0 ";
                    hstar='';
                    $('Star_content').style.display = 'none';
                    $('Spot_content').style.display = '';
                    break;
                case 4:
                    hsplit = " and itemtype=3 ";
                     $('Star_content').style.display = 'none';
                    $('Spot_content').style.display = 'none';
                   break;
                case 5:
                    hsplit = " and itemtype=2 ";
                    hstar='';
                    hspot='';
                     $('Star_content').style.display = 'none';
                    $('Spot_content').style.display = 'none';
                   break;
                case 6:
                    hsplit = " and itemtype=1 ";
                    hstar='';
                    hspot='';
                    $('Star_content').style.display = 'none';
                    $('Spot_content').style.display = 'none';
                    break;
            }
         hcond=hspot+hstar+hkey +regions +lhotels+hsplit ;
         ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
}
function ChangeKey()
{
          hkey='';
　　	var hkeys=encodeURI($("hotelName") .value);　	
          if (hkeys!="")
          {
          hkey="and title like '%"+hkeys+"%' ";
          }
          hcond="";
          hcond=hspot+hstar+hkey +regions +lhotels +hsplit;
          ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
}
function ChangeRegion()
{
 　　	  var length =0;
          regions='';
          for(var i=1;i<=regioncount;i++)
　　		{
　　			if($("_region"+i).checked)
　　			{
　　			       regions+="'"+encodeURI($("_region"+i) .value)+"',";　	
　　			}
            }
            if (regions!="")
            {
            regions="and region in ("+regions.substring(0,regions.length-1)+")";
            hcond="";
            hcond=hspot+hstar+hkey +regions +lhotels+hsplit ;
            ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
            }
            else
            {
            hcond="";
            hcond=hspot+hstar+hkey +regions +lhotels+hsplit ;
            ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
            }
}
function ChangeHlink()
{
 　　	  var length =0;
          lhotels='';
          for(var i=1;i<=linkcount;i++)
　　		{
　　			if($("_hlink"+i).checked)
　　			{
　　			       lhotels+="'"+encodeURI($("_hlink"+i) .value)+"',";　	
　　			}
            }
            if (lhotels!="")
            {
            lhotels="and linkhotel in ("+lhotels.substring(0,lhotels.length-1)+")";
            hcond="";
            hcond=hspot+hstar+hkey +regions +lhotels+hsplit ;
            ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
            }
            else
            {
            hcond="";
            hcond=hspot+hstar+hkey +regions +lhotels+hsplit ;
            ajaxgethotellist(lid,hdate, hotel_pagesize, 1,orderstr);
            }

}
/*************************************************分页函数****************************************************/	

function  ajaxpagination(ajaxfunction, recordcount, pagesize, currentpage, divname) {
    
	var allcurrentpage = 0;
	var next = 0;
	var pre = 0;
	var currentpagestr = '';

	if (currentpage < 1) { 
        currentpage = 1; 
    }

	//计算总页数
	if (pagesize != 0) {
		allcurrentpage = parseInt((recordcount / pagesize));
		allcurrentpage = ((recordcount % pagesize) != 0 ? allcurrentpage + 1 : allcurrentpage);
		allcurrentpage = (allcurrentpage == 0 ? 1 : allcurrentpage);
	}
	next = currentpage + 1;
	pre = currentpage - 1;


    //产生最终输出序号大于总页码，那么就要将其控制在页码数之内
	if (allcurrentpage < currentpage) { 
        currentpage = allcurrentpage; 
    }
	
         if (allcurrentpage < 9)						
		     {
				if (currentpage > 1)
				  {
				    currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +pre +', ' +orderstr +');" >上一页</a>';
				  }
				for (var i=1;i<allcurrentpage+1;i++)
				  {
					  if (i==currentpage)
						{
							currentpagestr +='<a   class="pagination_current"  href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +i +', ' +orderstr +');" >'+i+'</a>';
					    }
					  else 
					    {
							currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +i +', ' +orderstr +');" >'+i+'</a>';
					    }
				   }
				if (currentpage < allcurrentpage)
				  {
				    currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +next +', ' +orderstr +');" >下一页</a>';
				  }
			 }
         if (allcurrentpage > 8)						
			{
				if (currentpage > 1)
				  {
				    currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +pre +', ' +orderstr +');" >上一页</a>';
				  }
				if (currentpage <5)
				  {
				     for (var i=1;i<5;i++)
						 {
						  if (i==currentpage)
							{
							currentpagestr +='<a   class="pagination_current"  href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +i +', ' +orderstr +');" >'+i+'</a>';
						    }
						  else 
						    {
							currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +i +', ' +orderstr +');" >'+i+'</a>';
						    }
						  }
				     currentpagestr +='<a>...</a>';
				      for (var i=allcurrentpage-2;i<allcurrentpage+1;i++)
						{
							currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +i +', ' +orderstr +');" >'+i+'</a>';
						}
				  }
				if (currentpage >4)
				  {
					 currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', 1, ' +orderstr +');" >1</a>';
				     currentpagestr +='<a>...</a>';
				     for (var i=currentpage-2;i<currentpage+3;i++)
						 {
						  if (i==currentpage)
							{
							currentpagestr +='<a   class="pagination_current"  href="###"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +i +', ' +orderstr +');" >'+i+'</a>';
						    }
						  else 
						    {
							currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +i +', ' +orderstr +');" >'+i+'</a>';
						    }
						  }
				     currentpagestr +='<a>...</a>';
	    			 currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +allcurrentpage +', ' +orderstr +');" >'+allcurrentpage+'</a>';
				  }
				if (currentpage < allcurrentpage)
				  {
				    currentpagestr +='<a href="#"  onclick="javascript:'+ajaxfunction+'(' + lid + ',\'' + hdate + '\',' + pagesize + ', ' +next +', ' +orderstr +');" >下一页</a>';
				  }
			}

	$(divname).innerHTML = (recordcount==0) ? '': currentpagestr;
}

/*************************************************AJAX加载酒店列表****************************************************/	

function ajaxgethotellist(lid,hdate, pagesize, pageindex,orderstr)
{
    $('loading').style.display = '';
    hotel_pageindex=pageindex;
    _sendRequest('/tools/ajax.aspx?t=getallhotelslist&lid=' + lid + '&hcond=' + hcond  + '&hdate=' + hdate + '&pagesize=' + pagesize + '&pageindex=' + pageindex + '&gcond=' + gcond  + '&orderstr=' + orderstr , function(d){
		try{
		eval('hotellist_callback(' + d + ')');}catch(e){};
	});
}



function hotellist_callback(data) {
    $('loading').style.display = 'none';
	hotel_recordcount=data[0].hcount;
	ajaxpagination('ajaxgethotellist', hotel_recordcount, hotel_pagesize, hotel_pageindex, "topPageListDisplay");
    var hotellist_html = '';
	for(var  i = 0;i<data.length;i++) {
    hotellist_html += data[i].hotelslist;
}
	//alert(hotellist_html);

    $('hotel_stastic_result').innerHTML = hotellist_html;
    correctPNG() ;
	ajaxpagination('ajaxgethotellist', hotel_recordcount, hotel_pagesize, hotel_pageindex, "botPageListDisplay");
}


function CityHotels()
{
    var webcity_html ='';
    var locus_1 = '';//省市
    var locus_2 = '';//城市
    if(webcity != null && webcity != '') {
        locus_1 = webcity.split(',')[0];
        locus_2 = webcity.split(',')[1];
    }
    
    for(var i=1;i<=states.length;i++) {        
        //当有选中的省市信息时
        if(locus_1 != '' && states[i-1].state == locus_1) 
        {
    webcity_html = '<span><a href=\"http://'+states[i-1].scode+'.xxjq.com/hotels/\">'+states[i-1].state+'酒店：</a></span>';
        }
    }
    //当有选中的城市信息时
    if(locus_2 != '') {
        k=0;
        for(var j=0;j<locations.length;j++) 
        {
            if(locations[j].state == locus_1) 
            {
                if(locations[j].city == locus_2) 
                {
    webcity_html += '<a href=\"http://'+locations[j].lcode+'.xxjq.com/hotels/\" class=\"cur\">'+locations[j].city+'</a>';
                }
                else
                {
     webcity_html += '<a href=\"http://'+locations[j].lcode+'.xxjq.com/hotels/\">'+locations[j].city+'</a>';
               }
               k++;
           }
        }
    }
    $('city_subject').innerHTML = webcity_html;
}

