﻿if (top.location !== self.location)
{
	top.location = self.location;
}

function GetKeyOnkeyup(evtstr,KeywordsStr)
{
//	KeywordsStr=KeywordsStr.substr(0,4);
//	evtstr = (evtstr) ? evtstr : ((window.event) ? window.event : "")
//    var pckey = evtstr.keyCode?evtstr.keyCode:evtstr.which;
//	if (KeywordsStr.length>0)
//	{
//		GetKeyResult(pckey,KeywordsStr);
//	}
//	else
//	{
//		document.getElementById("show").innerHTML = "";
//	}
	
}
function GetKeyOnblur(KeywordsStr)
{
	KeywordsStr=KeywordsStr.substr(0,4);
	if (KeywordsStr.length>0)
	{
		GetKeyResult(KeywordsStr);
	}
	else
	{
		showobj.innerHTML = "";
	}
}
function PckeyResult(evtstr,KeywordsStr)
{
//	evtstr = (evtstr) ? evtstr : ((window.event) ? window.event : "")
//    var pckey = evtstr.keyCode?evtstr.keyCode:evtstr.which;
//	if (KeywordsStr.length>0)
//	{
//		if((pckey==38)||(pckey==40))
//		{
//			SelectLi(pckey);
//		}
//	}
}
function KeywordIn(KeyinStr)
{
	document.getElementById("keyword").value = KeyinStr;
}
function Getonclick(KeyinStr)
{
	document.getElementById("show").innerHTML= "";
	document.getElementById("frm").submit();
}
function GetKeyResult(pckey,KeywordsStr)
{
	var showobj = document.getElementById("show");
	if ((KeywordsStr.length>0)&&(pckey!=38)&&(pckey!=40))
	{
		var XmlHttp;
		if(window.ActiveXObject)
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHttp");
		}
		else if(window.XMLHttpRequest)
		{
			XmlHttp = new XMLHttpRequest();
		}
		XmlHttp.open("get","http://www.mypsd.com.cn/keyword.aspx?key="+encodeURI(KeywordsStr),false);
		XmlHttp.send();
		var strResult =unescape(XmlHttp.responseText);
		var kwobj = document.getElementById("keyword");
		var divx = kwobj.getBoundingClientRect().left + document.documentElement.scrollLeft;
		var divy = kwobj.getBoundingClientRect().top + document.documentElement.scrollTop + kwobj.offsetHeight;
		var divw = kwobj.offsetWidth - 12;
		var ulvw = divw-1;
		var livw = ulvw-3;
		divxie = divx - 2;
		divyie = divy - 2;
		var DivInfo = "<div id='keyshow' onclick='Getonclick()' onmouseout='SelectLi(988)' style='left:"+divx+"px!important;left:"+divxie+"px;top:"+divy+"px!important;top:"+divyie+"px;width:"+divw+"px;'><table border='0' cellspacing='0' cellpadding='2' align='left' onmouseover='SelectLi(999)' id='keyt'>"+strResult+"</table></div>";
		if (strResult.replace(" ","").length<2)
		{
			showobj.innerHTML = "";
		}
		else
		{
			showobj.innerHTML = DivInfo;
		}
		
	}
}
var f=0;
function SelectLi(pckey)
{   
	var keyobj = document.getElementById("keyt");
	var keyliobj = keyobj.rows;
	if(keyobj)
	{
		var keyleng  = keyliobj.length;
		var keyliNow = -1;
    	
		if (pckey==988)
		{
			for(i=0;i<keyleng;i++)
			{
				keyliobj[i].style.backgroundColor ='';
				keyliobj[i].style.color ='';
				if(navigator.appVersion.indexOf("MSIE")!=-1)
				{
					keyliobj[i].cells(1).style.backgroundColor ='';
					keyliobj[i].cells(1).style.color ='';
				} 
			}
		}
		else if (pckey==999)
		{
			for(i=0;i<keyleng;i++)
			{
				keyliobj[i].onmouseover = function(){
					this.style.backgroundColor ='#2567DE';
					this.style.color ='#FFFFFF';
					if(navigator.appVersion.indexOf("MSIE")!=-1)
					{
						this.cells(1).style.backgroundColor ='#2567DE';
						this.cells(1).style.color ='#FFFFFF';
					}
					var keyinstr = this.innerHTML
					keyinstr = keyinstr.split("</")[0];
					keyinstr = keyinstr.split(">")[1];
					KeywordIn(keyinstr);
					f=1;
				};
				keyliobj[i].onmouseout = function(){
					this.style.backgroundColor ='';
					this.style.color ='';
					if(navigator.appVersion.indexOf("MSIE")!=-1)
					{
						this.cells(1).style.backgroundColor ='';
						this.cells(1).style.color ='';
					}
					f=0;
				};
			}
		}
		else
		{
			//var yy=""
			for(i=0;i<keyleng;i++)
			{
				//yy=yy+i+"："+keyliobj[i].className+"<br>"
				if (keyliobj[i].className=="ok")
				{
					keyliNow = i;
				}
			}
			//document.getElementById("r1").innerHTML=yy;
			for(i=0;i<keyliobj.length;i++)
			{
				keyliobj[i].style.backgroundColor ='';
				keyliobj[i].style.color ='';
				if(navigator.appVersion.indexOf("MSIE")!=-1)
				{
					keyliobj[i].cells(1).style.backgroundColor ='';
					keyliobj[i].cells(1).style.color ='';
				}
				keyliobj[i].className="";
				if (pckey==40)
				{
					if (keyliNow+1>=keyleng)
					{
						keyliNow = -1
					}
					if (keyliNow+1 == i)
					{
						keyliobj[i].style.backgroundColor ='#2567DE';
						keyliobj[i].style.color ='#FFFFFF';
						if(navigator.appVersion.indexOf("MSIE")!=-1)
						{
							keyliobj[i].cells(1).style.backgroundColor ='#2567DE';
							keyliobj[i].cells(1).style.color ='#FFFFFF';
						}
						keyliobj[i].className="ok";
						var keyinstr = keyliobj[i].innerHTML
						keyinstr = keyinstr.split("</")[0];
						keyinstr = keyinstr.split(">")[1];
						KeywordIn(keyinstr);
					}
				}
				if (pckey==38)
				{
					if (keyliNow<=0)
					{
						keyliNow = keyleng
					}
					if (keyliNow-1 == i)
					{
						keyliobj[i].style.backgroundColor ='#2567DE';
						keyliobj[i].style.color ='#FFFFFF';
						if(navigator.appVersion.indexOf("MSIE")!=-1)
						{
							keyliobj[i].cells(1).style.backgroundColor ='#2567DE';
							keyliobj[i].cells(1).style.color ='#FFFFFF';
						}
						keyliobj[i].className="ok";
						var keyinstr = keyliobj[i].innerHTML
						keyinstr = keyinstr.split("</")[0];
						keyinstr = keyinstr.split(">")[1];
						KeywordIn(keyinstr);
					}
				}
			}
		}	
	}
}
function windowresize()
{
	if(document.getElementById("keyshow"))
	{
		if(navigator.appVersion.indexOf("MSIE")!=-1)
		{
			var kwobj = document.getElementById("keyword");
			var divx = kwobj.getBoundingClientRect().left + document.documentElement.scrollLeft;
			var divy = kwobj.getBoundingClientRect().top + document.documentElement.scrollTop + kwobj.offsetHeight;
			var divw = kwobj.offsetWidth - 12;
			var ulvw = divw-1;
			var livw = ulvw-3;
			divxie = divx - 2;
			divyie = divy - 2;
			var divobj = document.getElementById("keyshow");
			divobj.style.left = divxie+'px';
			divobj.style.top  = divyie+'px';
			divobj.style.width= divw+'px';
		}
		else
		{
			GetKeyResult(997,document.getElementById("keyword").value);
		}
	}
}
function GetonBlur()
{
//	if(document.getElementById("keyshow")&&f==0)
//	{
//		document.getElementById("keyshow").style.display="none";
//	}
}
