﻿this.tablecloth = function(){
	
	// CONFIG 
	
	// if set to true then mouseover a table cell will highlight entire column (except sibling headings)
	var highlightCols = true;
	
	// if set to true then mouseover a table cell will highlight entire row	(except sibling headings)
	var highlightRows = false;	
	
	// if set to true then click on a table sell will select row or column based on config
	var selectable = true;
	
	// this function is called when 
	// add your own code if you want to add action 
	// function receives object that has been clicked 
	this.clickAction = function(obj){
		//alert(obj.innerHTML);
		
	};


	
	// END CONFIG (do not edit below this line)
	
	
	var tableover = false;
	this.start = function(){
		var tables = document.getElementsByTagName("table");
		for (var i=0;i<tables.length;i++){
			tables[i].onmouseover = function(){tableover = true};
			tables[i].onmouseout = function(){tableover = false};			
			rows(tables[i]);
		};
	};
	
	this.rows = function(table){
		var css = "";
		var tr = table.getElementsByTagName("tr");
		for (var i=0;i<tr.length;i++){
			css = (css == "odd") ? "even" : "odd";
			tr[i].className = css;
			var arr = new Array();
			for(var j=0;j<tr[i].childNodes.length;j++){				
				if(tr[i].childNodes[j].nodeType == 1) arr.push(tr[i].childNodes[j]);
			};		
			for (var j=0;j<arr.length;j++){				
				arr[j].row = i;
				arr[j].col = j;
				if(arr[j].innerHTML == "&nbsp;" || arr[j].innerHTML == "") arr[j].className += " empty";					
				arr[j].css = arr[j].className;
				arr[j].onmouseover = function(){
					over(table,this,this.row,this.col);
				};
				arr[j].onmouseout = function(){
					out(table,this,this.row,this.col);
				};
				arr[j].onmousedown = function(){
					down(table,this,this.row,this.col);
				};
				arr[j].onmouseup = function(){
					up(table,this,this.row,this.col);
				};				
				arr[j].onclick = function(){
					click(table,this,this.row,this.col);
				};								
			};
		};
	};
	
	// appyling mouseover state for objects (th or td)
	this.over = function(table,obj,row,col){
		if (!highlightCols && !highlightRows) obj.className = obj.css + " over";  
		if(check1(obj,col)){
			if(highlightCols) highlightCol(table,obj,col);
			if(highlightRows) highlightRow(table,obj,row);		
		};
	};
	// appyling mouseout state for objects (th or td)	
	this.out = function(table,obj,row,col){
		if (!highlightCols && !highlightRows) obj.className = obj.css; 
		unhighlightCol(table,col);
		unhighlightRow(table,row);
	};
	// appyling mousedown state for objects (th or td)	
	this.down = function(table,obj,row,col){
		obj.className = obj.css + " down";  
	};
	// appyling mouseup state for objects (th or td)	
	this.up = function(table,obj,row,col){
		obj.className = obj.css + " over";  
	};	
	// onclick event for objects (th or td)	
	this.click = function(table,obj,row,col){
		if(check1){
			if(selectable) {
				unselect(table);	
				if(highlightCols) highlightCol(table,obj,col,true);
				if(highlightRows) highlightRow(table,obj,row,true);
				document.onclick = unselectAll;
			}
		};
		clickAction(obj); 		
	};		
	
	this.highlightCol = function(table,active,col,sel){
		var css = (typeof(sel) != "undefined") ? "selected" : "over";
		var tr = table.getElementsByTagName("tr");
		for (var i=0;i<tr.length;i++){	
			var arr = new Array();
			for(j=0;j<tr[i].childNodes.length;j++){				
				if(tr[i].childNodes[j].nodeType == 1) arr.push(tr[i].childNodes[j]);
			};							
			var obj = arr[col];
			if (check2(active,obj) && check3(obj)) obj.className = obj.css + " " + css; 		
		};
	};
	this.unhighlightCol = function(table,col){
		var tr = table.getElementsByTagName("tr");
		for (var i=0;i<tr.length;i++){
			var arr = new Array();
			for(j=0;j<tr[i].childNodes.length;j++){				
				if(tr[i].childNodes[j].nodeType == 1) arr.push(tr[i].childNodes[j])
			};				
			var obj = arr[col];
			if(check3(obj)) obj.className = obj.css; 
		};
	};	
	this.highlightRow = function(table,active,row,sel){
		var css = (typeof(sel) != "undefined") ? "selected" : "over";
		var tr = table.getElementsByTagName("tr")[row];		
		for (var i=0;i<tr.childNodes.length;i++){		
			var obj = tr.childNodes[i];
			if (check2(active,obj) && check3(obj)) obj.className = obj.css + " " + css; 		
		};
	};
	this.unhighlightRow = function(table,row){
		var tr = table.getElementsByTagName("tr")[row];		
		for (var i=0;i<tr.childNodes.length;i++){
			var obj = tr.childNodes[i];			
			if(check3(obj)) obj.className = obj.css; 			
		};
	};
	this.unselect = function(table){
		tr = table.getElementsByTagName("tr")
		for (var i=0;i<tr.length;i++){
			for (var j=0;j<tr[i].childNodes.length;j++){
				var obj = tr[i].childNodes[j];	
				if(obj.className) obj.className = obj.className.replace("selected","");
			};
		};
	};
	this.unselectAll = function(){
		if(!tableover){
			tables = document.getElementsByTagName("table");
			for (var i=0;i<tables.length;i++){
				unselect(tables[i])
			};		
		};
	};	
	this.check1 = function(obj,col){
		return (!(col == 0 && obj.className.indexOf("empty") != -1));
	}
	this.check2 = function(active,obj){
		return (!(active.tagName == "TH" && obj.tagName == "TH")); 
	};
	this.check3 = function(obj){
		return (obj.className) ? (obj.className.indexOf("selected") == -1) : true; 
	};	
	
	start();
	
};

/* script initiates on page load. */
//window.onload = tablecloth;

        var tipTimer,pcount=0;
        var propertyIds="";
        var _proContent="<tr><th class='class_th' width='160px'>物业名称</th><th class='class_th'>面积</th><th class='class_th'>价格</th></tr>";
        var _toolContent_against = "<div id='xsnazzy' style='filter:Alpha(opacity=90);position:absolute; '><b class='xtop'><b class='xb1'></b><b class='xb2'></b><b class='xb3'></b><b class='xb4'></b></b><div class='xboxcontent' style='padding-bottom:23px; padding-top:10px;'><table align='center'  cellspacing='0' cellpadding='0' width='250px'>"+_proContent+"   </table></br><div style='float:right; padding-right:20px;font-size:10px;cursor:hand; color:#fbc900' onclick='hide();'><img src='/images/20081127/contrast.jpg' width='65' height='20' onclick='compareHouse();'/><span style='padding-right:10px;'></span><img src='/images/20081127/clear.jpg' width='65' height='20' onclick='unSetSelectedProperty();'/><span style='padding-right:10px;'></span><img src='/images/20081127/close.jpg' width='65' height='20'/> </div></div><b class='xbottom'><b class='xb4'></b><b class='xb3'></b><b class='xb2'></b><b class='xb1'></b></b></div>";
        var _toolContent = "<div  style='padding:2px; color:blue;font-weight:bolder;font-size:14;' onmouseover='tooltipAgainst(_toolContent_against);'><img src='/images/20081127/main.png' /></div>";
        tooltip(_toolContent);
        function againstBegin(id,propertyName,area,price)
        {
            againstProperty(id,propertyName,area,price);
            _toolContent_against = "<div id='xsnazzy' style='filter:Alpha(opacity=90);position:absolute; '><b class='xtop'><b class='xb1'></b><b class='xb2'></b><b class='xb3'></b><b class='xb4'></b></b><div class='xboxcontent' style='padding-bottom:23px; padding-top:10px;'><table align='center'  cellspacing='0' cellpadding='0' width='250px'>"+_proContent+"   </table></br><div style='float:right; padding-right:20px;font-size:10px;cursor:hand; color:#fbc900' onclick='hide();'><img src='/images/20081127/contrast.jpg' width='65' height='20' onclick='compareHouse();'/><span style='padding-right:10px;'></span><img src='/images/20081127/clear.jpg' width='65' height='20' onclick='unSetSelectedProperty();'/><span style='padding-right:10px;'></span><img src='/images/20081127/close.jpg' width='65' height='20'/> </div></div><b class='xbottom'><b class='xb4'></b><b class='xb3'></b><b class='xb2'></b><b class='xb1'></b></b></div>";
            var top = document.getElementById('dHTMLToolTip').style.top;
            //alert(_toolContent_against);
            tooltipAgainst(_toolContent_against);
            document.getElementById('dHTMLToolTip').style.top = top;
        }

        //增加对比房源
        function againstProperty(id,propertyName,area,price){
             var proContent;
             if(document.getElementById(id).checked == true && propertyIds.indexOf(id)<0 ){
                 if(pcount>=6){
                    alert('最多6个房源对比');
                    document.getElementById(id).checked = false;
                    return;
                 }
                 propertyIds = propertyIds  + id+ "|";
                 proContent = _proContent + "<tr><td class='class_td' style='padding-left:10px;'>"+propertyName+"</td>" + "<td class='class_td'>"+area+"</td>" + "<td class='class_td'>"+price+"</td></tr>";
                 pcount++;
             }
             else
             {
                  propertyIds = propertyIds.replace(id+'|','');
                  proContent = _proContent.replace("<tr><td class='class_td' style='padding-left:10px;'>"+propertyName+"</td>" + "<td class='class_td'>"+area+"</td>" + "<td class='class_td'>"+price+"</td></tr>","");
                  pcount--;
             }
            _proContent = proContent;
        }

        //去除房源列表中已选项
        function unSetSelectedProperty(){
              sarray = propertyIds.split('|');
              if(sarray.length>1){
                 for(var i=0 ; i< sarray.length ;i++){
                     try
                                    {   
                                        document.getElementById(sarray[i]).checked = false;
                                    }   
                                      catch(e)   {    
                                         continue;  
                                    }   
                                      finally   {     
                                     } 
                 }
              }
              propertyIds='';
               pcount=0;
              _proContent="<tr><th class='class_th'>物业名称</th><th class='class_th'>面积</th><th class='class_th'>价格</th></tr>";
            _toolContent_against = "<div id='xsnazzy' style='filter:Alpha(opacity=90);position:absolute; '><b class='xtop'><b class='xb1'></b><b class='xb2'></b><b class='xb3'></b><b class='xb4'></b></b><div class='xboxcontent' style='padding-bottom:23px; padding-top:10px;'><table align='center'  cellspacing='0' cellpadding='0' width='250px'>"+_proContent+"   </table></br><div style='float:right; padding-right:20px;font-size:10px;cursor:hand; color:#fbc900' onclick='hide();'><img src='/images/20081127/contrast.jpg' width='65' height='20' onclick='compareHouse();'/><span style='padding-right:10px;'></span><img src='/images/20081127/clear.jpg' width='65' height='20' onclick='unSetSelectedProperty();'/><span style='padding-right:10px;'></span><img src='/images/20081127/close.jpg' width='65' height='20'/> </div></div><b class='xbottom'><b class='xb4'></b><b class='xb3'></b><b class='xb2'></b><b class='xb1'></b></b></div>";
              hideTooltip('dHTMLToolTip');
               tooltip(_toolContent);
               sc1();
        }
        
        function hide()
        {
           hideTooltip('dHTMLToolTip'); 
           tooltip(_toolContent);
           sc1();
        }

        //在分页时保留房源列表中已选项
        function setSelectedProperty(){
              sarray = propertyIds.split('|');
              if(sarray.length>1){
                 for(var i=0 ; i< sarray.length ;i++){
                     try
                       {   
                           document.getElementById(sarray[i]).checked = true;
                       }   
                         catch(e)   {    
                            continue;  
                       }   
                         finally   {     
                        } 
                 }
              }
        }

         function tooltipAgainst(str){
             // setSelectedProperty();
              var tooltipAgainst = str;
              showTooltip_opacity('dHTMLToolTip',60,400, tooltipAgainst, '#fffff2','#000000','#000000','500000');
              sc1();
              tablecloth();
        }
        
          function tooltip(str){
              setSelectedProperty();
              var tooltipAgainst = str;
              showTooltip_opacity('dHTMLToolTip',0,400, tooltipAgainst, '#fffff2','#000000','#000000','500000');
        }

        function locateObject(n,d) { //v3.0
            var p,i,x; 
            if(!d) 
                d=document; 
            if((p=n.indexOf("?"))>0&&parent.frames.length)
            {
                d=parent.frames[n.substring(p+1)].document;
                n=n.substring(0,p);
            }
            if(!(x=d[n])&&d.all)
               x=d.all[n];
            for (i=0;!x&&i<d.forms.length;i++) 
               x=d.forms[i][n];
            for(i=0;!x&&d.layers&&i<d.layers.length;i++)
               x=locateObject(n,d.layers[i].document); 
            return x;
        } 

        function hideTooltip(object)
        {
        if (document.all)
        {
        locateObject(object).style.visibility="hidden"
        locateObject(object).style.left = 1;
        locateObject(object).style.top = 1;
        swin = 0;
        return false
        }
        else if (document.layers)
        {
        locateObject(object).visibility="hide"
        locateObject(object).left = 1;
        locateObject(object).top = 1;
        return false
        }
        else
        return true
        }


        function showTooltip_opacity(object,ex,ey, tipContent, backcolor, bordercolor, textcolor, displaytime){
        if (document.all)
        {
        locateObject(object).style.top=document.body.scrollTop + ey+20;
        locateObject(object).innerHTML=unescape(tipContent);
        if ((ex + locateObject(object).clientWidth) > (document.body.clientWidth + document.body.scrollLeft))
        { 
        locateObject(object).style.left = (document.body.clientWidth + document.body.scrollLeft) - locateObject(object).clientWidth-10;
        }
        else
        {
        locateObject(object).style.left=document.body.scrollLeft+ex
        }
        locateObject(object).style.visibility="visible"
        tipTimer=window.setTimeout("hideTooltip('"+object+"')", displaytime);
        return true;
        }
        else if (document.layers)
        {
        locateObject(object).document.write(unescape(tipContent))
        locateObject(object).document.close()
        locateObject(object).top=ey+20

        if ((ex + locateObject(object).clip.width) > (window.pageXOffset + window.innerWidth))
        {
        locateObject(object).left = window.innerWidth - locateObject(object).clip.width-10;
        }
        else
        {
        locateObject(object).left=ex;
        }
        locateObject(object).visibility="show"
        tipTimer=window.setTimeout("hideTooltip('"+object+"')", displaytime);
        return true;
        }
        else
        {
        return true;
        }
        }
        
         function compare()
        {
          comparePHouse(propertyIds);
        }
        
        function sc1()
        {
           document.getElementById('dHTMLToolTip').style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById('dHTMLToolTip').offsetHeight)/2)+80;
          // document.getElementById('dHTMLToolTip').style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById('dHTMLToolTip').offsetWidth)/2);
        }
        window.onscroll=sc1;
        window.onresize=sc1;
        window.onload=sc1;