﻿    //Required
	$(
		function(){
			fromMarkchange();
			$(document).bind("click",hidefrommarks);
	});
	//from
	function showfrommarks(){
		var offset = $("#mark_from").offset();
		$("#mark_from_div").css("top",offset.top+22);
		$("#mark_from_div").css("left",offset.left);
		$("div[id*='_div']").hide();
		$("#mark_from_div").show();
		 $("#mark_from_options").load("MarkList.aspx?fromorto=from&mark=" + $("#mark_from").val()+"&cityId="+$("#city_from_hide").val()+"&regionId="+$("#hidRegion").val()+"&rndmath="+Math.floor(Math.random()*10));
	}
	var fromtext = "null";
	function fromMarkchange(){	   
	    if($("#mark_from").val() != fromtext){
	        fromtext = $("#mark_from").val();
		    $("#mark_from_options").load("MarkList.aspx?fromorto=from&mark=" + $("#mark_from").val()+"&cityId="+$("#city_from_hide").val()+"&regionId="+$("#hidRegion").val()+"&rndmath="+Math.floor(Math.random()*10));
		}
	}
	function hidefrommarks(){
		$("#mark_from_div").hide();
	}
	function fromMarkSelect(markCN,code){
	    $("#mark_from").val(markCN);
	    $("#mark_from_hide").val(code);
	}
	//from to
	function Markoption(){
		$("#mark_from_options tr").mousemove(function(){$(this).css('background','#e5f3dc');});
		$("#mark_from_options tr").mouseout(function(){$(this).css('background','#ffffff');});		
		
		keyevent();
	}
	//key event
	function keyevent(){
	    //取消重复绑定
	    $(document).unbind("keydown");
	    //
	    $("td[id*='_options'] tr:first").css('background','#e5f3dc');
	    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','#e5f3dc');
						        }
					        }
				        );
			        }
			        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();
						        }
					        }
				        );
			        }
			    }
		    }
	    );
}


