/*
**程序用途：搜索时提示用户
*/
<!--
function hideDiv(){
	if(document.getElementById("showTip"))
	{
    	document.getElementById("showTip").style.display="none";
	}
}

function hideTipDiv(){
	if(document.getElementById("showTip"))
	{
    	document.getElementById("showTip").style.display="none";
	}
}
var request = false;
var tb=document.getElementById("keyword");
var p=0;//当前移动的指针
var trcount=0;//当前查询出来的结果
var hidv="";//keyword里面的内容
var myid=0;
function requestHttp()
{
	if(window.XMLHttpRequest) {
		request = new XMLHttpRequest();
		if(request.overrideMimeType) {
			request.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject) {
		var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
		for(var i=0; i<versions.length; i++) {
			try {
				request = new ActiveXObject(versions[i]);
				break;
			} catch(e) {
			}
		}
	}
}
requestHttp();

function getNextElement(node) {
  if(node.nodeType == 1) {
	return node;
  }
  if (node.nextSibling) {
    return getNextElement(node.nextSibling);
  }
  return null;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function subSend(val,str){
if(myid==0)
{
	hidv=document.getElementById("keyword").value;
}
myid++;
 var ff=0;
	switch(event.keyCode){
		case 37:
		case 38:
		case 39:
		case 40:
		ff=1;
			return;
		break;
		default:
		break;
	}
	if(ff==1) return;
	p=-1;
	if(val.length<1){hideDiv();return;}
	if(window.XMLHttpRequest) {
		request.open('GET',"/config/Json.aspx?type="+str+"&keywords="+val+"&timespan="+(new Date()).getTime());
		request.onreadystatechange =DisposeRequest;
		request.send(null);
	} else {
		request.open("GET", "/config/Json.aspx?type="+str+"&keywords="+val+"&timespan="+(new Date()).getTime(), true);
		request.onreadystatechange = DisposeRequest;
		request.send();
	}
}

function DisposeRequest(){
	if (request.readyState == 4)
		if (request.status == 200){
		var oDiv=document.getElementById("showTip");
		oDiv.innerHTML=request.responseText;
		oDiv.style.display="";
		trcount=oDiv.getElementsByTagName("tr").length;
		selectTr();
	}
}

function searchSubmit(str){
	tbb=document.getElementById("keyword");
	var val=tbb.value;
	top.location=getdpath(str)+"/search.aspx?keywords="+val;
}

function keydown(str){
	var trtemp=document.getElementById('showTip').getElementsByTagName("tr");
	switch(event.keyCode){
		case 37:
		case 38:
			if(p>0) {p--;
			var sac=trtemp[p].innerText;
			var stb=document.getElementById("keyword");
			stb.value=sac.substr(0,sac.indexOf('￥'));
			}else{
				p=trcount-1;
				document.getElementById("keyword").value=hidv;
				}
		break;
		case 39:
		case 40:
			
			if(p<trcount-1) 
			{p++;
			sac=trtemp[p].innerText;
			stb=document.getElementById("keyword");
			stb.value=sac.substr(0,sac.indexOf('￥'));
			if(p==trcount-1){document.getElementById("keyword").value=hidv;}
			}
			else
			{
			p=0;
			sac=trtemp[p].innerText;
			stb=document.getElementById("keyword");
			stb.value=sac.substr(0,sac.indexOf('￥'));
			}
		break;
		case 13:
			try
			{
				var ac=trtemp[p].innerText;
				top.location=getdpath(str)+"/search.aspx?keywords="+ac.substr(0,ac.indexOf('￥'));
			}
			catch(exception)
			{
				var tb=document.getElementById("keyword");
				top.location=getdpath(str)+"/search.aspx?keywords="+tb.value;
			}
			return false;
		break;
		default: 
		hidv=document.getElementById("keyword").value;
		break;
	}
	selectTr();
}

function selectTr(){
	var trtemp=document.getElementById('showTip').getElementsByTagName("tr");
	for(i=0;i<trcount;i++){
		if(i==p && i!=trcount-1) trtemp[i].className="odd";
		else trtemp[i].className="current";
	}
}
function getdpath(str)
{
	var restr="";
	switch(str)
	{
				case "1":
		restr="http://shop.51mdq.com";
		break;
				case "2":
		restr="http://av.51mdq.com";
		break;
				case "3":
		restr="http://bx.51mdq.com";
		break;
				case "4":
		restr="http://bx.51mdq.com";
		break;
				case "5":
		restr="http://kt.51mdq.com";
		break;
		case "6":
		restr="http://mobile.51mdq.com";
		break;
		default:break;
	}
	return restr;
}
//-->
