recordPositionY = 0;
var ption=20;
var appName = navigator.appName.toLowerCase();
var isapp=false;
if(appName=='netscape')
{
  isapp=true;
}
function FixPosition()
{
var scrollPos; 
if (typeof window.pageYOffset != 'undefined') { 
   scrollPos = window.pageYOffset; 
} 
else if (typeof document.compatMode != 'undefined' && 
     document.compatMode != 'BackCompat') { 
   scrollPos = document.documentElement.scrollTop; 
} 
else if (typeof document.body != 'undefined') { 
   scrollPos = document.body.scrollTop; 
} 

	 movePixY = 0.2*(scrollPos-recordPositionY);
	if(movePixY>0)
	{
		movePixY = Math.ceil(movePixY);
	}
	else
	{
		movePixY = Math.floor(movePixY);
	}
	//document.all.Div_compare.style.pixelTop+= movePixY;
	obj=document.getElementById("Div_compare");
	ption +=movePixY;	
	obj.style.top=ption;
	recordPositionY = recordPositionY+movePixY;
}
window.setInterval("FixPosition()",2);

// unicode 编码程序
function BasketEncodeCookie(InputString)
{
	var strRtn="";
	for (var i=InputString.length-1;i>=0;i--)
	{
		strRtn+=InputString.charCodeAt(i);
		if (i) strRtn+="a"; // 用 a 作分隔符
	}
	return strRtn;
}

// unicode 解码程序
function BasketDecodeCookie(InputString)
{
	var strArr;
	var strRtn="";

	strArr=InputString.split("a");

	for (var i=strArr.length-1;i>=0;i--)
		strRtn+=String.fromCharCode(eval(strArr[i]));

	return strRtn;
}

// 读 Cookie
function BasketGetCookie(name)
{
	var strArg=name+"=";
	var nArgLen=strArg.length;
	var nCookieLen=document.cookie.length;
	var nEnd;
	var i=0;
	var j;

	while (i<nCookieLen)
	{
		j=i+nArgLen;
		if (document.cookie.substring(i,j)==strArg)
		{
			nEnd=document.cookie.indexOf (";",j);
			if (nEnd==-1) nEnd=document.cookie.length;
			return BasketDecodeCookie(unescape(document.cookie.substring(j,nEnd)));
		}
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}

// 写 Cookie
function BasketSetCookie(name,value,expires)
{
	var exp = new Date();
	exp.setTime(exp.getTime()+expires*60*1000);
	document.cookie=name+"="+escape(BasketEncodeCookie(value))+";expires="+exp.toGMTString()+";path=/";
}

// 判断 Cookie 是否存在
function BasketCheckSetCookieValue(name,value,expires)
{
	var nameCookieValue = BasketGetCookie(name);
	if ((nameCookieValue == "") || (nameCookieValue == null))
	{
		var exp = new Date();
		exp.setTime(exp.getTime()+expires*60*1000);
		document.cookie=name+"="+escape(BasketEncodeCookie(value))+";expires="+exp.toGMTString()+";path=/";
	}
	else
	{
		if (nameCookieValue.indexOf(value) == -1)
		{
			var arrCookies = nameCookieValue.split("；");
			var ValueNum = arrCookies.length;			
//		    if(isapp)
//		    {
//		        ValueNum--;
//		    }


			var exp = new Date();
			exp.setTime(exp.getTime()+expires*60*1000);
			document.cookie=name+"="+escape(BasketEncodeCookie(value+"；"+nameCookieValue))+";expires="+exp.toGMTString()+";path=/";
		}
	}
}

function hide()
{
  obj=document.getElementById("Div_compare");
  obj.style.display='none';
}

function show()
{
  obj=document.getElementById("Div_compare");
  obj.style.display='block';
}

function Empty()
{
	BasketSetCookie("CompareHouses","",24);
	redraw();
}



function AddCompareProduct(ProductSN,ProductName,ProductLink,ischeck,o)
{
	if(ischeck)
	{
		var CompareProducts = BasketGetCookie("CompareHouses");
		if ((CompareProducts != "") && (CompareProducts != null))
		{
			var arrCookies = CompareProducts.split("；");
			var lgh=arrCookies.length ;
			if (lgh < 6)
			{
				if (CompareProducts.indexOf(ProductSN) != -1)
				{
					//alert("（" + ProductName + "）已经被选择了！");
				}
				else
				{
					BasketCheckSetCookieValue("CompareHouses",ProductSN + "|" + ProductName + "|" + ProductLink , 1);
				}
			}
			else
			{
				o.checked=false;
				alert("对不起！您只能选择六条房源进行比较。");
			}
		}
		else
		{
			BasketCheckSetCookieValue("CompareHouses",ProductSN + "|" + ProductName + "|" + ProductLink,1);
		}
	}
	else
	{
		DelProduct(ProductSN);
	}
	redraw();
	ShowLayer();
}

function DelProduct(ProductSN)
{
	var nameCookieValue = BasketGetCookie("CompareHouses");
	if ((nameCookieValue != null) && (nameCookieValue != ""))
	{
		if (nameCookieValue.indexOf(ProductSN) > -1)
		{
			var arrCookies = nameCookieValue.split("；");
			var ValueNum = arrCookies.length;
			nameCookieValue = "";
			for (i=0; i < ValueNum; i++)
			{
				if (arrCookies[i].indexOf(ProductSN) == -1)
				{
					nameCookieValue += arrCookies[i] + "；";
				}
			}
			nameCookieValue = nameCookieValue.substring(0,nameCookieValue.length - 1);
			BasketSetCookie("CompareHouses",nameCookieValue,24);
		}
		redraw();
	}
}

function redraw()
{
	//FixPosition();
	var CompareProducts = BasketGetCookie("CompareHouses");
	if (CompareProducts == null)
	{
		CompareProducts = "";
	}
	var arrCookies = CompareProducts.split("；");
	var CompareTable =  "<h1><img src='http://img.soufun.com/secondhouse/image/50index/fcbg_title.jpg' alt='房源对比' /></h1>"
		+ "<ul>"
		+ "</tr>"
		+ "<tr>"
		+ "<td align='center' bgcolor='#E8F5FD'>";

	for (i = 0; i < arrCookies.length; i++)
	{
		if ((arrCookies[i] != "") && (arrCookies[i] != null))
		{
			if (arrCookies[i].indexOf("|") >= 0)
			{
				var ProductInfo = arrCookies[i].split("|");		
				if (ProductInfo.length = 4)
				{
					var ProductSN = ProductInfo[0];
					var ProductName = ProductInfo[1];
					var ProductLink = ProductInfo[2];
					if (ProductSN == null)
					{
						ProductSN = "";
					}
					if (ProductName == null)
					{
						ProductName = "";
					}
					if (ProductLink == null)
					{
						ProductLink = "";
					}
					if ((ProductName != "") && (ProductSN != "") && (ProductLink != "") )
					{
						CompareTable = CompareTable+"<li>"
						+"<p class='gxclose'><a class='cxwz' href='#' onClick=DelProduct('" + ProductSN + "');>撤销</a> <img src='http://img.soufun.com/secondhouse/image/50index/fcbg_cx.jpg' /></p>"
						+"<p class='wz'><a href='"+ ProductLink +"' target='_blank'>"+ProductName+"</a></p>"
						+"</li>";
					}
				}
			}
		}
	}
	CompareTable = CompareTable+"<li class='lastli'><a href='#' onClick=CompareCheck()>我要比较</a> <a onClick='HideLayer()' href='#'>隐藏</a> <a href='#'  onClick='Empty()' >清空</a></li>";
	obj=document.getElementById("Div_compare");
	obj.innerHTML = CompareTable;
}

function IsNumber(inputVal)
{
	var inputStr = inputVal.toString();
	var i = 0;
	for (i =0; i<inputStr.length; i++)
	{
		var oneChar = inputStr.charAt(i)
		if (oneChar < "0" || oneChar>"9")
		{
			return false;
		}
	}
	return true;
}

function CompareCheck()
{
	var URL = "/newsecond/sale_info/CompareHouse.aspx";
	var CompareProductsValue = BasketGetCookie("CompareHouses");
	if ((CompareProductsValue != "") && (CompareProductsValue != null))
	{
		var arrValues = CompareProductsValue.split("；");
		var ValuesNum = arrValues.length;
		if (ValuesNum < 2)
		{
			alert ('请至少选择两条房源进行对比！');
		}
		else
		{
			var QueryString = "house_id="
			for (i = 0; i < ValuesNum; i++)
			{
				var ProductInfo = arrValues[i].split("|");
				QueryString +=ProductInfo[0]+",";
				
			} 
			QueryString=QueryString.substr(0,QueryString.length-1)
			window.open(URL + "?" + QueryString);
			
		}
	}
}

redraw();

function HideLayer()
{
	BasketSetCookie("HiddenCompare","Hide",24);
	hide();
}

function ShowLayer()
{
	BasketSetCookie("HiddenCompare","Show",24);
	show();
}

if ((BasketGetCookie("HiddenCompare") == "Hide") || (BasketGetCookie("HiddenCompare") == "") || (BasketGetCookie("HiddenCompare") == null))
{
	HideLayer();
}
else
{
	ShowLayer();
}