jQuery("#AntInfoNavLink_Help").hover(function(){
	jQuery("#AntInfo-menu_Help").show();
	jQuery("#AntInfoNavLink_Helpa").removeClass();
	jQuery("#AntInfoNavLink_Helpa").addClass('AntInfoHelpCurrent');
},function(){
	jQuery("#AntInfo-menu_Help").hide();
	jQuery("#AntInfoNavLink_Helpa").removeClass();
	jQuery("#AntInfoNavLink_Helpa").addClass('AntInfoHelp');
});
jQuery("#AntInfoNavLink_Company").hover(function(){
	jQuery("#AntInfo-menu_Company").show();
	jQuery("#AntInfoNavLink_Companya").removeClass();
	jQuery("#AntInfoNavLink_Companya").addClass('AntInfoHelpCurrent');
},function(){
	jQuery("#AntInfo-menu_Company").hide();
	jQuery("#AntInfoNavLink_Companya").removeClass();
	jQuery("#AntInfoNavLink_Companya").addClass('AntInfoHelp');
});
jQuery("#AntInfoNavLink_daohang").hover(function(){
	jQuery("#AntInfo-menu_daohang").show();
	jQuery("#AntInfoNavLink_daohanga").removeClass();
	jQuery("#AntInfoNavLink_daohanga").addClass('AntInfoHelpCurrent');
},function(){
	jQuery("#AntInfo-menu_daohang").hide();
	jQuery("#AntInfoNavLink_daohanga").removeClass();
	jQuery("#AntInfoNavLink_daohanga").addClass('AntInfoHelp');
});

// JavaScript Document
var keyword = document.getElementById('keyword');
var suggestion = document.getElementById('Suggestion');
suggestion.style.width = keyword.offsetWidth + 'px';
suggestion.style.top="60px";
keyword.onfocus = function()
{
	if (this.value == "请输入地域名或小区全称")
	{
		this.value = '';
		this.style.color = '#000000';
		suggestion.style.display = '';
	}
}
keyword.onblur = function()
{
	if (this.value == '')
	{
		this.value="请输入地域名或小区全称";
        this.style.color="gray";
		suggestion.style.display = 'none';
	}
}
var text = ''; //临时保存文本值, 值变化了才去请求接口
var index = 0; //提示层被选中的项
keyword.onkeypress = function(ev)
{
	ev = ev || window.event;
	if (suggestion.style.display == '' && ev.keyCode == 13 )
	{
		return false;
	}
}
keyword.onkeyup = function(ev)
{
	ev = ev || window.event;
	if (__IsInput(ev))
	{
		if (suggestion.style.display == '')
		{
			if (ev.keyCode == 13)
			{
				//enter
				if(index > 0)	 
				{
				    if(suggestion.rows.length<=1)
				    {
				        index=0;
				    }
				    else
				    {
				        this.value = suggestion.rows[index].cells[0].innerHTML;			
				            				    
				    }			    
				}
				suggestion.style.display = 'none';
				try{getByKey()}catch(e){};	
				//return false;
			}
			else if (ev.keyCode == 40)
			{
				//down
				if (suggestion.rows.length > 1)
				{
					suggestion.rows[index].className = 'item';					
					index ++;
					if (index == suggestion.rows.length) index = 1;					
					suggestion.rows[index].className = 'itemFocus';
				}	
			}
			else if (ev.keyCode == 38)
			{
				//up
				if (suggestion.rows.length > 1)
				{				
					suggestion.rows[index].className = 'item';
					index --;
					if (index < 1) index = suggestion.rows.length - 1;					
					suggestion.rows[index].className = 'itemFocus';
				}
			}
			else if (ev.keyCode == 27)
			{
				//esc
				suggestion.style.display = 'none';
			}			
		}
		else
		{
		 	if (ev.keyCode == 40)
			{
				//down
				suggestion.style.display = '';
			}	
		}
	}
	else
	{
		if (this.value != text)
		{
			text = this.value;
			if (text != '')
			{
			//debugger;
				Xml.Request('/public/Xml.aspx?action=showsale&q=' + escape(this.value), null, ShowHint);
			}
			else
			{
				for (var i=suggestion.rows.length-1; i>0; i--)
				{
					suggestion.tBodies[0].removeChild(suggestion.rows[i]);
				}
			}
		}
	}
}

function GetSubString(string,length)
{
    var l = 0;
    var tmp="";
	for(var i=0; i<string.length; i++)
	{   
		var c = string.charCodeAt(i);		
		l += (c < 256 || (c >= 0xff61 && c <= 0xff9f))? 1:2;
		if(l<=length)
		{
		    tmp+=string.charAt(i);
		}
	}
	return tmp;
}
function GetStringLength(string)
{		
	var l = 0;
	for(var i=0; i<string.length; i++)
	{
		var c = string.charCodeAt(i);		
		l += (c < 256 || (c >= 0xff61 && c <= 0xff9f))? 1:2;
	}
	return l;
}
function AddRow(text, type)
{
	var tr = document.createElement('TR');
	tr.setAttribute('index', suggestion.rows.length);
	tr.onmouseover = function()
	{
		var i = parseInt(this.getAttribute('index'));
		if (i != index)
		{
			if (index != -1) suggestion.rows[index].className = 'item';
			this.className = 'itemFocus';
			index = i;
		}
	}
	var td = document.createElement('TD');
	if(GetStringLength(text)>26)
	{
	    text=GetSubString(text,26);
	}
	td.innerHTML = text;
	td.style.paddingLeft='3px';
	tr.appendChild(td);
	td = document.createElement('TD');
	td.innerHTML = "<font>约有"+type+"条房源</font>";
	td.align = 'right';
	td.style.textAlign="right";
	td.style.paddingRight='3px';
	tr.appendChild(td);
	tr.className="item";
	suggestion.tBodies[0].appendChild(tr);
}
function ShowHint()
{	
	for (var i=suggestion.rows.length-1; i>0; i--)
	{
		suggestion.tBodies[0].removeChild(suggestion.rows[i]);
	}
	var xml = new XmlSource(this, 'CommunityName', 'SaleCountTotal');
	for (var i=0; i<xml.CommunityName.length; i++)
	{
		AddRow(xml.CommunityName[i].data, xml.SaleCountTotal[i].data);
	}
	if (suggestion.rows.length > 1)
	{
		suggestion.style.display = '';
		index = 0;
		//suggestion.rows[1].className = 'itemFocus';
	}
}

suggestion.onclick = function(ev)
{
	ev = ev || window.event;
	var target = ev.target || ev.srcElement;
	index = parseInt(target.parentNode.getAttribute('index'));
	if (index > 0)
	{
		keyword.value = target.parentNode.cells[0].innerHTML;
		try{getByKey()}catch(e){};	
	}
	suggestion.style.display = 'none';
}

var bodies = [document, document.body, document.documentElement];
for (var i=0; i<bodies.length; i++)
{
	if (bodies[i].onclick == null)
	{
		bodies[i].onclick = function(ev)
		{
			ev = ev || window.event;
			var target = ev.target || ev.srcElement;
			if (suggestion.style.display == '' && target != keyword)
			{				
				suggestion.style.display = 'none';
			}
		}
		break;
	}
}
function TextFocus(obj)
{
	if (obj.value == obj.defaultValue)
	{
		obj.value = '';
		obj.style.color = '#000000';
	}
	else if(obj.value == '请输入经纪公司名称关键字')
	{
	    obj.value = '';
		obj.style.color = '#000000';
	}
}
function TextBlur(obj)
{
	if (obj.value == '')
	{
		obj.value = obj.defaultValue;
		obj.style.color = '#999999';
	}
}
__IsSelect = function(ev)
{
	if (ev.shiftKey || (ev.ctrlKey && ev.shiftKey))
	{
		return (ev.keyCode >=35 && ev.keyCode <=40);
	}
	else if (ev.ctrlKey && !ev.shiftKey)
	{
		return ev.keyCode == 65;
	}
	else
	{
		return false;
	}
}
__IsMove = function(ev)
{
	return (ev.keyCode >=35 && ev.keyCode <=40);	
}
__IsDelete = function(ev)
{
	if (ev.ctrlKey)
	{
		return ev.keyCode == 8;
	}
	else if (ev.shiftKey)
	{
		return ev.keyCode == 46;
	}
	else
	{
		return ev.keyCode == 8 || ev.keyCode == 45 || ev.keyCode == 46;
	}
}
__IsEdit = function(ev)
{
	return __IsSelect(ev) || __IsMove(ev) || __IsDelete(ev) || ev.keyCode == 9 || ev.keyCode == 13;
}

__IsInput = function(ev)
{
	return __IsSelect(ev) || __IsMove(ev) || ev.keyCode == 9 || ev.keyCode == 13;
}
__IsNumber = function(ev)
{
	return !ev.shiftKey && ((ev.keyCode >=48 && ev.keyCode <= 57) || (ev.keyCode >=96 && ev.keyCode <= 105));
}
function divdrag(obj,_Id)
 {
  var s = document.getElementById(_Id).style
  var b = document.body
  var x = event.clientX + b.scrollLeft - s.pixelLeft
  var y = event.clientY + b.scrollTop - s.pixelTop
     if(s.position == "")
     {
         s.position = "absolute"
     }
  var m = function()
  {
   if (event.button == 1)
   {
    s.pixelLeft = event.clientX + b.scrollLeft - x
    s.pixelTop = event.clientY + b.scrollTop - y
   }
   else document.detachEvent("onmousemove", m)
  }
  document.attachEvent("onmousemove", m)
  event.cancelBubble = true
 }
