function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 1; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + 6*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}


function Set_Cookie(num)
{
	temp = String(num);
	compstring = getCookie("comp");
	if (compstring == null) compstring="";
	if (compstring.indexOf(temp) == -1)
		{
		compstring = compstring + "|" + temp;
		SetCookie("comp",compstring);
		}
	document.getElementById("comp1").value = compstring;
	document.getElementById("comp2").value = compstring;
	divquery(compstring);
	document.getElementById("floatTips").style.display='block';
}
function Unset_Cookie(num)
{
	temp = String(num);
	compstring = getCookie("comp");
	if (compstring == null) compstring = "";
	if (compstring.indexOf(temp) != -1)
		{
		temp = "|" + temp;
		compstring = compstring.replace(temp,"");
		}

	document.getElementById("comp1").value = compstring;
	document.getElementById("comp2").value = compstring;
	SetCookie("comp",compstring);
	divquery(compstring);
}

function clear_all()
{	
	document.getElementById("comp1").value = "";
	document.getElementById("comp2").value = "";
	SetCookie("comp","");
	divquery("");
}

function createXMLHttpRequest()
{
	if(window.ActiveXObject){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	else if(window.XMLHttpRequest){
		xmlHttp=new XMLHttpRequest();
		}
}

function divquery(query_string){
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	var url="querydiv.php?query_string="+query_string;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function handleStateChange(){
	if(xmlHttp.readystate==4){
		if(xmlHttp.status==200){
			document.getElementById("floatTips").innerHTML = "<a href='#' onClick=floatTips.style.display='none'>关闭</a>   比较列表" + xmlHttp.responseText;
		}
	}
}

var tips; var theTop = 150/*这是默认高度,越大越往下*/; var old = theTop;
function initFloatTips() {
  tips = document.getElementById('floatTips');
  compstr = getCookie("comp");
  if (compstr == null)
	{document.getElementById("floatTips").style.display='none';}
	else
		{  divquery(compstr);
		compstr = compstr.split("|");
		if (compstr.length > 0){
			for (i=1;i < compstr.length;i++){
				checkitem = "check_" + compstr[i];
				if(typeof document.all[checkitem]  != "undefined"){   
					document.getElementById(checkitem).checked = true;
				}
			}
		}
		}
  moveTips();
};
function moveTips() {
  var tt=500;

  if (window.innerHeight) {
    pos = window.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop) {
    pos = document.documentElement.scrollTop;

  }
  else if (document.body) {
    pos = document.body.scrollTop;
  }
  pos=pos-tips.offsetTop+theTop;
  pos=tips.offsetTop+pos/10;
  if (pos < theTop) pos = theTop;
  if (pos != old) {
    tips.style.top = pos+"px";
    tips.style.left = document.body.clientWidth - 140;
    tt=30;
  }
  old = pos;
  setTimeout(moveTips,tt);
}


function fixDiv(){ 
    document.getElementById('floatTips').style.top = (document.documentElement.scrollTop + document.documentElement.clientHeight - document.getElementById('floatTips').clientHeight - 20) + "px"; 
    setTimeout("fixDiv('floatTips')",2); 
} 

