﻿// JScript 文件
    //Required
	$(
		function(){
			H_frominputchange();
			H_toinputchange();
			$(document).bind("click",H_hidefromcitys);
			$(document).bind("click",H_hidetocitys);
	});
	var fromtext = "null";
	//from
	function H_showfromcitys(){
		var offset = $("#city_from").offset();
		$("#city_from_div").css("top",offset.top+22);
		$("#city_from_div").css("left",offset.left);
		$("div[id*='_div']").hide();
		$("#city_from_div").show();
		$("#city_from_options").load("Hotel/HotelCityData.aspx?fromorto=from&input=" + $("#city_from").val());
		
	}
	
	function H_frominputchange(){	   
	    if($("#city_from").val() != fromtext){
	        fromtext = $("#city_from").val();
		    $("#city_from_options").load("Hotel/HotelCityData.aspx?fromorto=from&input=" + $("#city_from").val());
//		    var cityli = $("#city_from_options").html();
//		    $("#city_from_options").html(cityli.substring(cityli.indexOf("<SPAN"),cityli.indexOf("</SPAN>")+7));
//		    alert($("#city_from_options").html());
		}
	}
	function H_hidefromcitys(){
		$("#city_from_div").hide();
	}
	function H_fromSelect(cityCN,code){
	    $("#city_from").val(cityCN);
	    $("#city_from_hide").val(code);
	}
	//to
	function H_showtocitys(){
		var offset = $("#city_to").offset();
		$("#city_to_div").css("top",offset.top+20);
		$("#city_to_div").css("left",offset.left-3);
		$("div[id*='_div']").hide();
		$("#city_to_div").show();
		$("#city_to_options").load("Hotel/HotelCityData.aspx?fromorto=to&input=" + $("#city_to").val());
	}
	var totext = "null";
	function H_toinputchange(){
	    if($("#city_to").val() != totext){
            totext = $("#city_to").val();
		    $("#city_to_options").load("Hotel/HotelCityData.aspx?fromorto=to&input=" + $("#city_to").val());
		}
	}
	function H_hidetocitys(){
		$("#city_to_div").hide();
	}
	function H_toSelect(cityCN,code){
	    $("#city_to").val(cityCN);
	    $("#city_to_hide").val(code);
	}
	//from to
	function H_option(){
		$("#city_from_options tr").mousemove(function(){$(this).css('background','#ffeea9');});
		$("#city_from_options tr").mouseout(function(){$(this).css('background','#ffffff');});		
		$("#city_to_options tr").mousemove(function(){$(this).css('background','#ffeea9');});
		$("#city_to_options tr").mouseout(function(){$(this).css('background','#ffffff');});
		
		keyeventHotel();
	}
	//key event
	function keyeventHotel(){
	    //取消重复绑定
	    $(document).unbind("keydown");
	    //
	    $("td[id*='_options'] tr:first").css('background','#ffeea9');
	    var i;
	    i = 0;
	    $(document).keydown(
		    function(){
	            var objs = $("div[id*='_div']:visible tr:lt(16):gt(0)");
	            
	            if(objs != null){
			        if(event.keyCode == 40)
			        {

				        i = i + 1;
			        }else if(event.keyCode == 38){
				        i = i - 1;
			        }
			        var count = objs.length;
			        if(i >= count){i = count - 1;};
			        if(i < 0){i = 0;}
			        if(event.keyCode == 38 || event.keyCode == 40){
				        objs.each(
					        function(){
					        			        //alert(objs.index($(this)));
						        if(objs.index($(this)) == i){
							        objs.css('background','#ffffff');
							        $(this).css('background','#ffeea9');
						        }
					        }
				        );
			        }
			        if(event.keyCode==13)
			        {
			          objs.each(
					        function(){
						        if(objs.index($(this)) == i){
							         $(this).click();
						        }
					        }
				        );
			               return false;
			        }
			        if(event.keyCode == 39 || event.keyCode == 37){
				        objs.each(
					        function(){
						        if($("div[id*='_div']:visible tr:lt(16):gt(0)").index($(this)) == i){
							        $(this).click();
							        $("div[id*='_div']:visible").hide();
						        }
					        }
				        );
			        }
			    }
		    }
	    );
}
