var lastInputTime2 = null;
function IntervalTime2()
{
	var nowInputTime=new Date().getTime();
	var flag=false;
	if(nowInputTime-lastInputTime2>100)
	{flag=true;}
	lastInputTime2=nowInputTime;
	return flag;
}

function getPosition2(obj)
{
  var topValue = 0, leftValue = 0;
  while (obj)
  {
	  leftValue += obj.offsetLeft;
	  topValue += obj.offsetTop;
	  obj = obj.offsetParent;
  }
  return{
	  left: leftValue,
	  top: topValue};
}

function suggestOver2(div_value)
{
	div_value.className='suggest_link_over';
}

function sugggestOut2(div_value)
{
  div_value.className='suggest_link';
}

function SearchSuggestGys(obj)
{
	if(IntervalTime2())
	{
		if (obj.value.length>=1)
		{
			var url="getGys.asp?k="+obj.value+"&d="+NewDate();
			var loader=new net.ContentLoader(url,handleSearchSuggestGys);
		}
		else
		{
			setGysInfo("",0);
		}
	}
}

function handleSearchSuggestGys()
{
    if(this.req.readyState==4)
    {
		if(this.req.status==200)
		{
			var list=this.req.responseText;
			var ss=getEle("search_gys");
			var fcur=getEle("input_gys");
			if(list.length>2)
			{
				ss.innerHTML="";
				ss.style.display="block";
				var position = getPosition2(fcur);
				ss.style.left=position.left  + "px";
				ss.style.top=position.top + 20 + "px";
				var ls=list.split("|");
				if(ls.length==2)
				{
					var lss=ls[0].split("$");
					setGysInfo(lss[0],lss[2]);
				}
				else
				{
					for (i=0;i<ls.length;i++ )
					{
						var lss=ls[i].split("$");
						if(lss.length>=3)
						{
							var suggest='<div onmouseover="javascript:suggestOver2(this);"';	
							suggest+='onmouseout="javascript:sugggestOut2(this);"';
							suggest+='onclick="javascript:setGysInfo(\''+lss[0]+'\',\''+lss[2]+'\');"';
							suggest +='class="suggest_link">'+lss[1]+'</div>';
							ss.innerHTML +=suggest;
						}
					}
				}
			}
			else
			{
				var showmsg=getEle("showmsg");
				if(!isEmpty(showmsg))
				{
					showmsg.className="red bold";
					showmsg.innerHTML=NotExist;
				}
				if(!isEmpty(ss))
				{
				ss.innerHTML="";
				}
				if(!isEmpty(fcur))
				{
				fcur.value="";
				}
			}
	}else{
		alert("Abnormal");
	}
	}
}

function setGysInfo(div_value,id_p)
{
	var txtSearch=getEle("input_gys");
	txtSearch.value=div_value;
	var id_produit=getEle("id_gys");
	id_produit.value=id_p;
	var ss=getEle("search_gys");
	ss.innerHTML="";
	ss.style.display="none";
	if(StrToNum(id_p)>0)
	{
		var myform=getEle("form2");
		if(!isEmpty(myform))
		{
			myform.submit();
		}
	}
}
