﻿

jQuery(document).ready(function() {
    P(inputId);  //定位弹出框的位置

    jQuery(inputId).keyup(function(){
    getData();
    });
    jQuery(inputId).click(function(){
    getData();
    })
});




var inputId="#txtsword";    //输入框ID
var getUrl="/site/searchsource.aspx";   //数据获取页地址

//位置
function P(obj) {
	jQuery("body").append("<div id='stipContent'></div>")
	var O=jQuery(obj).offset();
	var top=O.top;
	var left=O.left;
	var height=jQuery(obj).height();
	var width=jQuery(obj).width();
	jQuery("#stipContent").css("top",top+height+4+"px");
	jQuery("#stipContent").css("left",left+"px");
	jQuery("#stipContent").css("width",width+2+"px");
}



function getData(){
	//应该先去掉空格再查询
	val=jQuery(inputId).val();
		while(val.indexOf(" ")!=-1){
 			val=val.replace(" ","");
			}
	if(val==null || val==""){
	jQuery("#stipContent").hide();
	return false;
	}
//从searchsource.aspx获取数据
	jQuery.ajax({
		type: "GET",
		url: getUrl,
		data:"k="+encodeURI(val),  //searchsource.aspx 页面decodeurl
		success: function(msg){
			if (msg=="false"){jQuery("#stipContent").hide();	}
			else{	jQuery("#stipContent").html(msg);jQuery("#stipContent").show();}
  		}
});
}

function addwordtobox(word)
{
  jQuery("#txtsword").val(word);
  //window.location.href = "/web/productlist/0/index.html?s=" + encodeURI(word);
}

jQuery(document).click(function(){jQuery("#stipContent").hide();})  //点击空白处隐藏弹出框
