//需要cookies_oper.js支持
document.write("<div id='Pro_float_layer' style='POSITION:absolute;TOP:175px;left:6px;z-index:99px;width:127px;display:none;'>");
document.write("<div style='height:33px'>");
document.write("<img src='{$rootpath}images/ProductCompare/lb.gif'>");
document.write("</div>");
document.write("<div style='padding:20px 5px 5px 5px;FILTER:ALPHA(opacity=100);z-index:99px; background:url({$rootpath}images/ProductCompare/bg.gif)' align=center>");
document.write("<div id='com_item'></div><br>");
document.write("<img src='{$rootpath}images/ProductCompare/bt.gif' onclick='comchk();' style='cursor:hand;'>");
document.write("</div>");
document.write("<div style='height:33px'>");
document.write("<img src='{$rootpath}images/ProductCompare/down.gif' style='cursor:hand;' onclick='Pro_float_layer.style.display=\"none\";'>");
document.write("</div>");
document.write("</div>");
/*漂浮框 开始 */
//似乎不支持firefox
lastScrollY = 0;
function heartBeat() {
	//alert(lastScrollY);
	var floatobj = document.getElementById("Pro_float_layer");
	diffY = document.documentElement.scrollTop;
	percent =.2*(diffY-lastScrollY);
	if(percent>0){
		percent = Math.ceil(percent);}
	else{
		percent = Math.floor(percent);}
	floatobj.style.pixelTop += percent;
	lastScrollY = lastScrollY + percent;
}

/*漂浮框 结束 */

/*比较相关函数 开始*/

var SelectedProductID = new Array();
var SelectedProductSite = new Array();
var SelectedProductName = new Array();

function add(Site,ProdID,ProductName){
	AddProduct(Site,ProdID,ProductName);
	draw();
}
function del(Site,ProdID) {
	for(var i=0;i<SelectedProductID.length;i++)
	{
		if(SelectedProductID[i]==ProdID)
		{
			SelectedProductID.splice(i,1);
			SelectedProductSite.splice(i,1);
			SelectedProductName.splice(i,1);
			break;
		}
	}
	setSelectedProductCookies();
	//setSelectedProduct();	
	draw();
}
function AddProduct(Site,ProdID,ProductName)
{
	if(!isSelectProduct(Site,ProdID))
	{	
		if(getSelectCount()>=10)
		{
			alert('最多只能有10款产品参加比较！');		
		}else{
			SelectedProductSite[SelectedProductSite.length]=Site;
			SelectedProductID[SelectedProductID.length]=ProdID;
			SelectedProductName[SelectedProductName.length]=ProductName;
			setSelectedProductCookies();						
		}
	}else{
		alert( ProductName+' 已选择！');
	}
	draw();
}

function isSelectProduct(Site,ProdID)
{
	var selected=false;
	for(var i=0;i<SelectedProductID.length;i++)
	{
		if(SelectedProductID[i]==ProdID&&SelectedProductSite[i]==Site)
		{
			selected=true;
			break;
		}
	}
	return selected;
}
function getSelectCount()
{
	return SelectedProductID.length;	
}
function setSelectedProduct()
{
	SelectedProductSite=new Array();
	SelectedProductID=new Array();
	SelectedProductName=new Array();
	var spstring=getCookie("SelectedProduct");
	
	if(spstring!="")
	{
		var spstring1=new Array();
		if(spstring.indexOf("$$$")>-1)
		{
			spstring1=spstring.split("$$$");			
		}else{
			spstring1[0]=spstring;
		}
		for(var i=0;i<spstring1.length;i++)
		{
			var spstring2=spstring1[i].split("|");
			SelectedProductSite[i]=spstring2[0];
			SelectedProductID[i]=spstring2[1];
			SelectedProductName[i]=spstring2[2];
		}
	}
}
function setSelectedProductCookies()
{
	var spstring="";
	if(SelectedProductID.length>0)
	{
		for(var i=0;i<SelectedProductID.length;i++)
		{
			if(SelectedProductID[i]!=""&&SelectedProductName[i]!="")
			{
				var tempstr=SelectedProductSite[i]+"|"+SelectedProductID[i]+"|"+SelectedProductName[i];
				if(spstring!="")
				{
					spstring+="$$$"+tempstr;
				}else{
					spstring+=tempstr;
				}
			}
		}				
	}
	setCookie("SelectedProduct",spstring,1);
}

function draw() {
	var out = "";
	if(SelectedProductID.length>0)
	{
		Pro_float_layer.style.display="block";
		for(var i=0;i<SelectedProductID.length;i++)
		{
			out += "<br><a href='{$rootpath}Html/Product/"+SelectedProductSite[i]+".html' target='_blank'><font color='797979'>"+SelectedProductName[i]+"</font></A>&nbsp;&nbsp;<font onclick=\"del('"+SelectedProductSite[i]+"','"+SelectedProductID[i]+"')\" style='cursor:hand;' color='EC1E10'>取消</font><br>";
		}
		out+="";
	}else{
		Pro_float_layer.style.display="none";
	}
	com_item.innerHTML = out;
}

function comchk() {
	if(getSelectCount() < 2) {
		alert('请至少选择两款商品！')
	}else {
		var out = "";
		for(var i=0;i<SelectedProductID.length;i++)
		{
			if(out!="")
			{
				
				out+=","+SelectedProductID[i];
			}else{
			
				out=SelectedProductID[i];
			}
		}
		var str = "{$rootpath}compare.asp?ck="+out;
		window.open(str);
	}
}
window.setInterval("heartBeat()",1);
setSelectedProduct();