var mouserOverTxtGround = "#FFFFFF"; //鼠标停留在某行时候的字景色
var mouserOverBackGround = "#0000ff"; //鼠标停留在某行时候的背景色
var mouserEleaveTxtGround = "#333333"; //鼠标离开在某行时候的字景色
var mouserEleaveBackGround = "#ffffff"; //鼠标离开在某行时候的背景色
var resultColor = "#339900";

/* 处理用户相关搜索 */
function change(data){
	document.getElementById('Related').style.display = '';
	var objDiv = document.getElementById( "searchKeywords" );
 	var top = objDiv.offsetTop;
  	var left = objDiv.offsetLeft;
  	while(objDiv=objDiv.offsetParent){
  		top+=objDiv.offsetTop
  		left+=objDiv.offsetLeft
  	}
  	//
  	if(navigator.userAgent.indexOf("MSIE")>0) {
		document.getElementById('Related').style.left = parseInt(left);
		document.getElementById('Related').style.top = parseInt(top)+20;  	
  	}
  	else {
		document.getElementById('Related').style.left = parseInt(left)+"px";
		document.getElementById('Related').style.top = parseInt(top)+19+"px";  	
  	}
	//得到表格中的行数
	var count = document.getElementById('tab').rows.length;
	//如果表中存在行,将所有行删除
	if (count > 0){
		for(var i=count-1; i>=0; i--){
				document.getElementById('tab').deleteRow(i); 
		}
	}
	var dataLenght = data.length;
	//如果存在相关搜索记录 
	if(dataLenght > 0) {
		for(var i=0;i<=dataLenght;i++){
			var objTr = document.getElementById('tab').insertRow(i); //TR
			var objTd = objTr.insertCell(0);//TD
			objTd.style.width = "402px";
			objTd.style.cursor = "hand";
			objTd.style.background = mouserEleaveBackGround;
			if (i < dataLenght) {
				objTd.innerHTML = "<div style='color:" +resultColor+ ";font-size:12px;float:right;width:130px;text-align:right;'>" +data[i].views+ "次</div>" +
				              "<div style='color:" +mouserEleaveTxtGround+ ";font-size:12px;float:left;width:262px;text-align:left;' onclick='clickHistory(this)'>" +data[i].name+ "</div>";
				objTd.onmouseover = function() {
					var divObj = this.childNodes;
					divObj[0].style.color = mouserOverTxtGround;
					divObj[1].style.color = mouserOverTxtGround;
					this.style.background = mouserOverBackGround;
				}
				objTd.onmouseout = function() {
					this.style.color = mouserEleaveTxtGround;
					var divObj = this.childNodes;
					divObj[0].style.color = resultColor;
					divObj[1].style.color = mouserEleaveTxtGround;
				this.style.background = mouserEleaveBackGround;
				};
			}
			else {
				var objTr = document.getElementById('tab').insertRow(i); //TR
				var objTd = objTr.insertCell(0);//TD
				objTd.style.width = "402px";
				objTd.style.cursor = "hand";
				objTd.style.background = mouserEleaveBackGround;
				objTd.innerHTML = "<div style='font-size:12px;float:right;width:402px;text-align:right;'><a href='javascript:onclick=searchBarClose()' style='color:#FF0000;text-decoration:underline'>关闭</a></div>";
			}
		}

	}
	else {
		document.getElementById('Related').style.display = 'none';
	}
}


/* 鼠标点击相关搜索内容时执行 */
function clickHistory(object) {
	document.searchForm.searchKeywords.value = object.innerHTML;
	document.getElementById('Related').style.display = 'none';
	document.searchForm.submit();
}

	
/* 用户在搜索框中按键事件处理 */
function keySelectHistory() {
	var searchKeywords = document.getElementById("searchKeywords");
	searchKeywords.onkeyup = function(event) {
		searchKeywords.value=searchKeywords.value.replace(/[^\a-zA-Z0-9\u4E00-\u9FA5\s]/g,'');
		event = event || window.event;
		var nKeyCode = event.keyCode;
		if(!(nKeyCode == 38 || nKeyCode == 40)){
			var str = document.searchForm.searchKeywords.value; 
			history.getHistory(str,change); 	
		}
	}
}
	
/* 关闭历史查询记录 */
function searchBarClose(){
	document.getElementById('Related').style.display = 'none'; 
}
	
	
//////////////////////////////////////////////////////////////


var message = "请输入您感兴趣的信息";
var peleseChoose = "对不起，您至少选中一个选项！";

var first = 1;

/**
 * 搜索条焦点进入
 */
function searchOnfocus() {
	if (first == 1) {
		getElementByID("searchKeywords").value = "";
		first ++;
		return;
	}
	else {
		return;
	}
}

/**
 * 搜索分类
 */
function selectSearchPart() {
  	var ddl = document.getElementById("searchPart");
  	var index = ddl.selectedIndex;
  	var value = ddl.options[index].value;
	document.searchForm.action = value;
}


/**
 * 验证搜索表单
 */
function validateSearchForm() {
	if (getElementByID("searchKeywords").value.substring(0,3)=='请输入') {
		alert(message);
		return false;
	}
	else if(getElementByID("searchKeywords").value == '') {
		alert(message);
		return false;
	}
}

/**
 * 验证搜索表单
 */
function validateSearchForm2() {
	if (getElementByID("searchKeywords").value.substring(0,3)=='请输入') {
		alert(message);
		return false;
	}
	else if(getElementByID("searchKeywords").value == '') {
		alert(message);
		return false;
	}
	else {
		return true;
	}
}

/**
 * 验证搜索表单(帮助)
 */
function validateHelpSearchForm() {
	if (getElementByID("helpSearchKeywords").value.substring(0,3)=='请输入') {
		alert(message);
		return false;
	}
	else if(getElementByID("helpSearchKeywords").value == '') {
		alert(message);
		return false;
	}
	else {
		return true;
	}
}

function initPage() {
	showULKeywords();
	showULSystemGroup();
}


function showULKeywords() {
	getElementByID("single_Results_Keywords").style.display = "block";
	getElementByID("more_Results_Keywords").style.display = "none";
}

function hiddenULKeywords() {
	getElementByID("single_Results_Keywords").style.display = "none";
	getElementByID("more_Results_Keywords").style.display = "block";
}

function showULSystemGroup() {
	getElementByID("single_Results_SystemGroup").style.display = "block";
	getElementByID("more_Results_SystemGroup").style.display = "none";
}

function hiddenULSystemGroup() {
	getElementByID("single_Results_SystemGroup").style.display = "none";
	getElementByID("more_Results_SystemGroup").style.display = "block";
}


////////////////////////////////////////////////////////////////////////////////////

