
var summaryJson;
var doc = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

//instead document.getElementById().value
var $F = function (id) {
	return $(id).value;
};

var Auto = {
	
	autoGet : function(value,type) {
		if(value == '') {
			this.closePop(type);
		} else {
			// get the return value list from json
			if(type=="school"){
				getListJson2(value,type);
			}else{
				getListJson(value,type);
			}
			
			//this.autoCallback(jsonValue);
		}
	},
	
	autoCallback : function(list,type) {
		//remove the old pop li
		this.closePop(type);
		if (list.length > 0) {
			for(var i = 0;i < list.length; i++){
				if(type=="inner"){
					document.getElementById("autoUl").className = 'autoUl';
				}else if(type=="out"){
					document.getElementById("autoUl2").className = 'autoUl2';
				}else if(type=="school"){
				  document.getElementById("autoUl3").className = 'autoUl3';
				}
				var autoLi = document.createElement("li");
				
				autoLi.onmouseout = function() {
					this.className = 'mouseOut'; 
					 if(type=="school"){
						Assist2.isOnmouseover = false;
					 }else{
					 	Assist.isOnmouseover = false;
					 }
				}
				
				autoLi.onmouseover = function() {
					this.className = 'mouseOver';
					Assist.isOnmouseover = true;
					if(type=="school"){
						Assist2.isOnmouseover = true;
					 }else{
					 	Assist.isOnmouseover = true;
					 }
				}
				
				autoLi.onclick = function() {
					if(type=="school"){
						Assist2.autoPush(this,type);
					 }else{
						Assist.autoPush(this,type);
					 }
				}
				
				//alert(document.getElementById("autoUl").className )
				
				if(type=="inner"){
					liValue = '<div class="resultName">' + list[i].name + '</div>';
					autoLi.innerHTML = liValue;
					document.getElementById("autoUl").appendChild(autoLi);
				}else if(type=="out"){
					liValue = '<div class="resultName">' + list[i].name + '</div>';
					autoLi.innerHTML = liValue;
					document.getElementById("autoUl2").appendChild(autoLi);
				}else if(type=="school"){
					  //liValue = '<div class="resultName">' + list[i].name+","+list[i].id+'</div>';
					  liValue = '<div class="resultName" id="' + list[i].id + '">' + list[i].name + '</div>';
					  autoLi.innerHTML = liValue;
					  document.getElementById("autoUl3").appendChild(autoLi);
				}
			}
			
		}
	},
	
	closePop : function(type) {
		if(type=="inner"){
			var ul = doc("autoUl").childNodes.length;
			for(var i = ul - 1; i >= 0 ; i--) {
				document.getElementById("autoUl").removeChild(document.getElementById("autoUl").childNodes[i]);
			}
			document.getElementById("autoUl").className = "borderNull";
		}else if(type=="out"){
			var ul = doc("autoUl2").childNodes.length;
			for(var i = ul - 1; i >= 0 ; i--) {
				document.getElementById("autoUl2").removeChild(document.getElementById("autoUl2").childNodes[i]);
			}
			document.getElementById("autoUl2").className = "borderNull";
		}else if(type=="school"){
			var ul = doc("autoUl3").childNodes.length;
			for(var i = ul - 1; i >= 0 ; i--) {
				document.getElementById("autoUl3").removeChild(document.getElementById("autoUl3").childNodes[i]);
			}
			document.getElementById("autoUl3").className = "borderNull";
		}
		
		function getPosition(e) {
			var x = e.offsetLeft;
			var y = e.offsetTop+e.offsetHeight;
			while (e = e.offsetParent) {
				x += e.offsetLeft;
				y += e.offsetTop;
			}
			return {x:x, y:y};
		}
		
		
		
		var kw;
		var bookSearch;
		var xy;
		
		if(type=="out"){
			kw=document.getElementById("keyword123");
			bookSearch=document.getElementById("bookSearch");
			xy=getPosition(kw);
			bookSearch.style.left=xy.x+5+"px";
			bookSearch.style.top=xy.y+"px";
		}else{
		    kw=document.getElementById("schoolName");
			bookSearch=document.getElementById("schoolSearch");
			xy=getPosition(kw);
			bookSearch.style.left=xy.x+5+"px";
			bookSearch.style.top=xy.y+"px";
		}
		
	}
}



