function readCookie(name)
{
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)
	{ 
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{ 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
				cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}
function writeCookie(name, value, hours)
{
	var expire = "";
	if(hours != null)
	{
		expire = new Date((new Date()).getTime() + 10 * 60000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
}

function change_select(kw,sid)
{	
	////检查是否为相同的搜索结果 
	//subcat_id_change(kw,sid)
	////读出产品串后用函数返回一个数组 
	tmp=readCookie(kw); 
	
	//alert(tmp+"=="+pid+"==="+tmp.indexOf(pid));
	if (tmp.indexOf(sid)!=-1)
	{
		
		del(kw,sid);
	}
	else
	{
		add(kw,sid);
	}
}
function add(kw,sid)
{
	////检查是否为相同的子类 
	subcat_id_change(kw,sid) 
	
	////读出产品串后用函数返回一个数组 
	tmp=readCookie(kw); 
	////检查数组的个数（即选择产品的个数）
	tmp_arr=stringToArray(tmp,"###");
	if (tmp_arr.length<6)
	{
		/////看是否有相同的产品已被选择
		//alert(tmp+"=="+sid+"==="+tmp.indexOf(sid));
		if (tmp.indexOf(sid)!=-1)
		{
			alert("（"+sid+"）already selected!!!");
		}
		else
		{
			writeCookie(kw,tmp+sid+"###"); 
		}
	}
	else
	{
		alert("sorry,too much things selected!!!");
		document.getElementById('checkbox'+sid).checked=false;
	}
	//redraw();
	//writeCookie("hid_float", 0, 100);
}
////该函数功能是 
function subcat_id_change(kw,id)
{
  ////alert("函数参数subcatid="+subcat);
  //change=false;
  tmp_subcat=readCookie("keyword");
  if (tmp_subcat==null || tmp_subcat=="") /////还没有选择产品呢！！！
  {   
	writeCookie("keyword",kw);
  }
  else if (kw != tmp_subcat)////选择另类产品 
  {	
	  writeCookie("keyword",kw);
	  writeCookie("pro_str","");	
  }
  //return change;
}
/////用指定的字符串div切开str字符串后返回一个数组 
function stringToArray(str,div)
{
	objArr=str.split(div);
	return objArr;
}
function del(kw,sid)
{
	tmp=readCookie(kw); 	
	writeCookie(kw,tmp.replace(sid+"###",""));
	tmp=readCookie(kw); 
	/////如果没有产品了，自动清空keyword
	if (tmp=="" || tmp==null)
	{
		writeCookie("keyword","");
	}
	//redraw();
}

function comparecheck(kw,url)
{
	tmp=readCookie(kw); 
	item_arr=tmp.split("###");
	var numVar = item_arr.length;
	if(numVar<3) 
	{
		alert ('Please select more than 2 items to compare!'); 
	}
	else 
	{
		try
		{
			// 点击按钮 清空复选框
			var checkboxs = $$("input[type=checkbox]");
			for(i=0; i<checkboxs.length; i++)
			{
				checkboxs[i].checked = '';
			}
		}
		catch(e)
		{}
		window.open(url);
	}
}
