lastScrollY = 0;
var floatid = "curfloat";

function heartBeat(){ 
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
 diffY = document.documentElement.scrollTop;
else if (document.body)
 diffY = document.body.scrollTop
else
    {/*Netscape stuff*/}
 
//alert(diffY);
percent=.1*(diffY-lastScrollY); 
if(percent>0)percent=Math.ceil(percent); 
else percent=Math.floor(percent); 
document.getElementById("curfloat").style.top=parseInt(document.getElementById ("curfloat").style.top)+percent+"px";
lastScrollY=lastScrollY+percent; 
//alert(lastScrollY);
}
document.write("<div id=\"curfloat\" style='right:10px;POSITION:absolute;TOP:200px;FILTER:ALPHA(opacity=80);z-index:99;width:100;' align='center'><img src='http://house.xafdc.net/js/compare.gif' width='100' alt='点击比较' onclick='comchk();' style='cursor:pointer;'><div id='com_item'></div></div>");

window.setInterval("heartBeat()",1);


var sel = new Array();
var sel_num = 0;

//Cookie存储对比数据begin
function GetCookieVal (offset){
	var endstr = document.cookie.indexOf (";", offset);
  	if (endstr == -1)
    	endstr = document.cookie.length;
  	return unescape(document.cookie.substring(offset, endstr));

}

function GetCookie (name){
  	var arg = name + "=";
  	var alen = arg.length;
  	var clen = document.cookie.length;
  	var i = 0;
  	while (i < clen){
    		var j = i + alen;
    		if (document.cookie.substring(i, j) == arg)
      			return GetCookieVal (j);
    		i = document.cookie.indexOf(" ", i) + 1;
    		if (i == 0) break; 
  	}
  	return null;
}

function SetCookie (name,value,expires,path,domain,secure){
  	document.cookie = name + "=" + escape (value) +
    	((expires) ? "; expires=" + expires.toGMTString() : "") +
    	((path) ? "; path=" + path : "") +
    	((domain) ? "; domain=" + domain : "") +
    	((secure) ? "; secure" : "");
         return value;
}

function DeleteCookie (name){
	if(GetCookie(name) != null)
	{
		SetCookie(name,"");
	}
}

//Cookie存储对比数据end 

function cookie_content(){
	i = 0;
	content = "";
	for(key in sel){
		if(i == 0)
		{
			content += key + "[" + sel[key] + "]";
		}
		else
		{
			content += "," + key + "[" + sel[key] + "]";
		}
		i++;
	}
	//alert(content);
	return content;
}

function add(id,nm) {
	
	if(!sel[id]){
		if(sel_num >= 4) 
		{
			alert('您好,为了保证对比查看效果您最多只能选择4个楼盘参加比较.');
		}
		else 
		{
			sel_num++;
			sel[id] = nm;
		}
	}
	else 
	{
		alert( nm+' 已经被选择,请不要重复添加同一楼盘(*^__^*');
	}
	draw();
	
}

function del(id) {
	sel2 = new Array();
	for(key in sel){
		if(id!=key) 
		{
			sel2[key] = sel[key];
		}
	}
	sel = sel2;
	sel_num--;
	draw();
	
}
function draw() {
	out = '';
	
	for(key in sel) {
		out += "<input type=button onclick=\"del('"+key+"')\" value='"+sel[key]+"' style='border:1px solid #cccccc ;background-color:#ffffff;height:24;width:98;cursor:pointer;color:'black';'><br>";
	}
	$("com_item").innerHTML = out;
}

function comchk() {
	
	if(sel_num < 2) {
		alert('您好,您至少需选择两个楼盘才能进行对比.')
	}else {
		out = '';
		i=0;
		for(key in sel){
			++i;
			out += key+'__';
			//out +=key+'&';
			
		}
		out = "houseId=" + out;
		out = out.replace(/\w{2}$/,"");   

		var str = "http://house.xafdc.net/HousePk.Asp?"+out;
		window.open(str);
	}
}

function inni_data()
{
	//alert(GetCookie("HFHOUSE_TMP_COMPARE_COOKIE"));
	var cookie_sel = new Array();
	cookie_str = GetCookie("HFHOUSE_TMP_COMPARE_COOKIE");
	if(cookie_str != "" && cookie_str != null)
	{
		cookie_sel = cookie_str.split(",");
		for( key in cookie_sel)
		{
			//alert(cookie_sel[key]);
			i = cookie_sel[key].indexOf("[");
			j = cookie_sel[key].indexOf("]");
			//alert(cookie_sel[key].substring(0, i));
			//alert(cookie_sel[key].substring(i+1, j));
			sel[cookie_sel[key].substring(0, i)] = cookie_sel[key].substring(i+1, j);
			sel_num++;
		}
		draw();
	}
}
window.onLoad=inni_data();


  


