var ismarkerSearchFocus = false;
var markersearchFocusTimer=null;
function markersearchFocus(_input) {
	ismarkerSearchFocus = true;
	if (_input.value == language.qsrbzm) {
		_input.value = "";
		_input.setAttribute("presearvalue", "?");
	}
	var search = function() {
		if (_input.getAttribute("presearvalue") != _input.value) {
			_input.setAttribute("presearvalue", _input.value);
			markersearchListOut(_input.value);
		}
		markersearchFocusTimer = setTimeout(search, 300);
	};
	search();
}
function markerviewSearchListAll() {
	ismarkerSearchFocus = true;
	markersearchListOut("");
}
function markertimeHiddenSearch() {
		var hidden = function() {
			if (!ismarkerSearchFocus) {
				document.getElementById("markersearchListOutCanvas").style.display = "none";
			}
	    };
	setTimeout(hidden, 200);
}
function markerviewSearchListAllBlur(){alert(ismarkerSearchFocus+",1");
ismarkerSearchFocus = false;alert(ismarkerSearchFocus+",2");
}
function markersearchBlur(_input) {
	ismarkerSearchFocus = false;
	window.clearTimeout(markersearchFocusTimer);
	if (_input.value == "") {
		_input.value = language.qsrbzm;
	}
}
function markersearchListOut(v) {
	markeroverindex = 0;
	var _canvas = document.getElementById("markersearchListOutCanvas");
	_canvas.innerHTML = "";
	_canvas.style.display = "block";
	_canvas.scrollTop = 0;
	var p = 0;
	var pvalue;
	var curmarkerObject=null;
		for(var i=0;i<markerObject.markerids.length;i++){
		    curmarkerObject=markerObject.markerArr[markerObject.markerids[i]];
		    if(curmarkerObject!=null){
	         	pvalue = curmarkerObject.title;
				if ((pvalue.toLowerCase().indexOf(v.toLowerCase()) > -1)) {
					p++;
					var _div = document.createElement("div");
					if (p == 1) {
						_div.className = "search_item_over";
					} else {
						_div.className = "search_item";
					}
					_div.innerHTML = pvalue;
					_div.title = pvalue;
					_div.setAttribute("username", curmarkerObject.title);
					_div.setAttribute("index", i);
					_div.setAttribute("userid",curmarkerObject.id);
					_div.onclick = function() {
						markerselectSearchItem(this.getAttribute("username"), this.getAttribute("userid"));///////////
					};
					_div.onmouseover = function() {
						this.className = "search_item_over";
						markeroverindex = this.getAttribute("index");
					};
					_div.onmouseout = function() {
						this.className = "search_item";
						markeroverindex = this.getAttribute("index");
					};
					_canvas.appendChild(_div);
				}  
			} 	   
			
		}
	if (p == 0) {
		_canvas.innerHTML = "<span style=\"background: #FFF;width: 185px;\">" + language.mycdsj + "</span>";
	}
}
function markerselectSearchItem(username, userid) {
	document.getElementById("markersearchinput").value = username;
	//document.getElementById("userid").value = userid;
	document.getElementById("markersearchListOutCanvas").style.display = "none";
	document.getElementById("markersearchinput").setAttribute("presearvalue", username);
	
	markersearchshow(userid);
}
function markermarkerrootItemStyle() {
	var _canvas = document.getElementById("markersearchListOutCanvas");
	for ( var i = _canvas.childNodes.length - 1; i >= 0; i--) {
		_canvas.childNodes[i].className = "search_item";
	}
}
function markersearchshow(id){
  var flag=false;

   openMarker(id);
   
   var curNode=treeObj.getNodeByParam("id",id);
   if(curNode!=null){
       var parentNode=curNode.getParentNode();
       if(parentNode!=null){
       		treeObj.expandNode(parentNode, true, true, true);	       		
       }
       treeObj.selectNode(curNode);//选中指定节点	
       treeObj.checkNode(curNode, true, false, false);       
   }
   flag=true;
      return false; 

  if(flag){
	 	 return false; 
  }
}
var markeroverindex = 0;
function markerselectNextItem() {
	var _canvas = document.getElementById("markersearchListOutCanvas");
	if (_canvas.firstChild.nodeName == "SPAN") {
		return
	}
	if (markeroverindex < _canvas.childNodes.length - 1) {
		_canvas.childNodes[markeroverindex].className = "search_item";
		markeroverindex++;
		_canvas.childNodes[markeroverindex].className = "search_item_over";
	}
	if (markeroverindex > 10) {
		_canvas.scrollTop = (markeroverindex - 10) * 18;
	}
	_canvas.childNodes[markeroverindex].className = "search_item_over";
}
function markerselectPrevItem() {
	var _canvas = document.getElementById("markersearchListOutCanvas");
	if (_canvas.firstChild.nodeName == "SPAN") {
		return
	}
	if (markeroverindex > 0) {
		_canvas.childNodes[markeroverindex].className = "search_item";
		markeroverindex--;
		_canvas.childNodes[markeroverindex].className = "search_item_over";
	}
	if (markeroverindex > 10) {
		_canvas.scrollTop = (markeroverindex - 10) * 18;
	}
	_canvas.childNodes[markeroverindex].className = "search_item_over";
}
function markerselectOverItem() {
	var _canvas = document.getElementById("markersearchListOutCanvas");
	if (_canvas.firstChild.nodeName == "SPAN") {
		return;
	}
	markerselectSearchItem(_canvas.childNodes[markeroverindex].getAttribute("username"),
			_canvas.childNodes[markeroverindex].getAttribute("userid"));
	
	_canvas.style.display = "none";
}
document.onkeydown = function(e) {
	if (ismarkerSearchFocus) {
		var theEvent = window.event || e;
		var k = theEvent.keyCode ? theEvent.keyCode
				: theEvent.which ? theEvent.which : theEvent.charCode;
		if (k == 40) {
			markerselectNextItem();
			return false; //解决点击箭头下拉，再用方向键问题。
		} else if (k == 38) {
			markerselectPrevItem();
			return false;
		} else if (k == 13) {
			markerselectOverItem();
			return false;
		}
	}
};
addListener(window.document, "click", function(){markertimeHiddenSearch();});

(function(doc){
	var ele = doc.getElementById("markersearchinput");
	if(ele && ele.value === ""){
		ele.value = language.qsrbzm;
	}
})(document);

function addListener(element,e,fn){ element.addEventListener?element.addEventListener(e,fn,false):element.attachEvent("on" + e,fn)};

