	var isset = false;
	var show_location_tip = false;
	var default_loc = '';
	function fetch_location(obj,_type,_id)
	{
		

		if(isset == true)
		{
			isset = false;
			return;
		}
		
		if(obj.value != "")
		{
			
			if(isDigit(obj.value))
			{
				fetch_zip(obj.value,obj,_type,_id);
			}else
			{	
				fetch_city(obj.value,obj,_type,_id);
			}
		}else
		{
			$("#location-tip").hide();
		}
		
	}

	function set_location(str,_id)
	{
		isset = true;
		$("#"+_id).val(str);
		//$("#"+_id).focus();		
		close_tip();
	}

	function fetch_city(_name,obj,_type,_id)
	{
		var _html = "";

		$("#location-tip").hide();
		$("#location-tip").html("");
		$.ajax({
			url : "includes/ajax.php",
			type : "get",
			data : "op=search&type="+ _type +"&action=res_city&keyword="+_name,
			cache : false,
			dataType : "json",
			success : function(msg){
				json = msg
				if(json != null)
				{
					default_loc = json[0].city;
					for(var i = 0;i<json.length; i++){
						if(json[i]!= null){
						_html += "<a href=\"javascript:set_location('"+json[i].city+"','"+_id+"');\">" + json[i].city + "</a>";
						}
					}
				}
				//alert(_html);
				if(_html.length<1){
					$("#location-tip").hide();
				}else{
					$("#location-tip").html(_html);
					show_tip(obj);
				}

			}
		})
	}

	function fetch_zip(_code,obj,_type,_id)
	{
		var _html = "";
		
		$("#location-tip").hide();
		$("#location-tip").html("");
		
		$.ajax({
			url : "includes/ajax.php",
			type : "get",
			data : "op=search&type="+ _type +"&action=res_zip&keyword="+_code,
			cache : false,
			dataType : "json",
			success : function(msg){
				json = msg				
				if(json != null)
				{
					default_loc = json[0].city;
					for(var i = 0;i<json.length; i++){
						if(json[i]!= null){
						_html += "<a href=\"javascript:set_location('"+json[i].city+"','"+_id+"');\">" + json[i].city + "</a>";
						}
					}
				}
				if(_html.length<1){
					$("#location-tip").hide();
				}else{
					$("#location-tip").html(_html);
					show_tip(obj);
				}

			}
		})
	}

	function show_tip(obj)
	{
		show_location_tip = false;
		var tip = document.getElementById("location-tip");
		var x = obj.offsetLeft;
		var y = obj.offsetTop;
		var url = window.location + "";
		while(obj=obj.offsetParent)
		{
			x += obj.offsetLeft;
			y += obj.offsetTop;
		}

		tip.style.left = x + "px";
		tip.style.top = y + 20 + "px";

		$("#location-tip").show();
	}

	function close_tip(){		
		$("#location-tip").hide();
	}

    function isDigit(str) {
         var patrn=/^\d+$/;
         return patrn.test(str);
    }

	function loc_blur(){
		if(!show_location_tip){
			close_tip();
		}
	}

	function tip_mousemove(){
		show_location_tip=true;
	}

	function tip_mouseout(){
		show_location_tip=false;
	}

	function key_enter(event,_id){
		 if (event.keyCode==13 && !isset && default_loc!=''){
			$("#"+_id).val(default_loc);
		 }
	}
/*$("#location-tip").mousemove( function() { alert('test'); } );
$("#location-tip").mouseout( function() { show_location_tip=false; } ); */

