﻿$(document).ready(function(){
    houseSaleLoad();
    $("span[name='spJudge'] > a").each(function(){
        $(this).click(function(){
            $("#txtContent").text("价格" + $(this).html() + "。补充理由："  );
            $("#txtContent").focus();
            return false;
        });
    });
});
//添加房源到收藏夹
function addFavorite() {
    var houseId=$("#hidHouseId").val();
    $.ajax({
        type:'GET',
        url:'/addFavorite.ashx',
        cache:false,
        data:"houseid="+houseId ,
        success:function(msg) {
            alert(msg);
        }
    });
}
function houseSaleLoad()
{
    checkfuneeeuser();
    getComment(1);
    loadVideo();
    
   //setTimeout(loadVideo(),10);
   //setTimeout(housePic(),10);
   //setTimeout("isJudege()",20);
   //setTimeout("IsOverDue()",50);
   //setTimeout("getJudge(1)",100);
   //setTimeout("getJudge(2)",100);
   //setTimeout("getJudge(3)",100);
   //setTimeout("getMarket()",200);
   //setTimeout("getEvsPrice()",250);
   //setTimeout("buildingLastMarket()",300);    
}
function nTabs(thisObj,Num){
if(thisObj.className == "active")return;
var tabObj = thisObj.parentNode.id;
var tabList = document.getElementById(tabObj).getElementsByTagName("li");
for(i=0; i <tabList.length; i++)
{
if (i == Num)
{
   thisObj.className = "content_table_cutr"; 
      document.getElementById(tabObj+"_Content"+i).style.display = "block";
}else{
   tabList[i].className = "normal"; 
   document.getElementById(tabObj+"_Content"+i).style.display = "none";
}
} 
}

function loadVideo()
{
	//var HouseInfoState = document.getElementById('hdHouseInfoState').value;
	var Id = document.getElementById('hidHouseId').value;
	var isHavePic=false;
    var file=RequestByGet("/getflvurl.aspx?infoId=" + Id);
    if(file.indexOf(".flv")>=0) //有视频
    {
        flv_js_playObject(file);
//          switch(HouseInfoState)
//		{
//			case '0'://正在转换
//			pic_js_picObject('http://images.funeee.com/images/waiting.gif');
//
//			break;
//			case '1'://转换成功
//
//			flv_js_playObject(file);
//			break;
//			case '3'://转换错误
//			pic_js_picObject('http://images.funeee.com/images/error.gif');
//
//			break;
//			default:
//			pic_js_picObject('http://images.funeee.com/images/error.gif');
//
//			break;
//		}

    }
    
}
function pic_js_picObject(str)
{
	var _into = "";
	_into += '<div id="videoPic">';
	_into += '<img src='+str+' width="320px" height="240px" />';
	_into += '</div>';
	document.getElementById('videoplayer').innerHTML = _into;
}
function flv_js_playObject(file)
{
	//var file=RequestByGet("/getflvurl.aspx?infoId=" + Id);
	var player = '/player/flv_player_self.swf';
	showPlayer(file,player);
}
function showPlayer(file,player)
{

	var _into = "";
	_into += '<div id="videoPlayer">';
	_into += '<div id="flvPlayBack" class="normalSize">';
	_into += '<object id="flvswf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://www.91vc.com/Podcasting/Camera/swflash.cab#version=8,0,22,0" width="100%" height="100%">';
	_into += '<param name="allowScriptAccess" value="always" />';
	_into += '<param name="movie" value="'+player+'" />';
	_into += '<param name="quality" value="high" />';
	//_into += '<param name="wmode" value="transparent" />';
	//_into += '<param name="bgcolor" value="#ffffff" />';
	_into += '<param name="Flashvars" value="vcastr_file=' + file + '"/>';
	_into += '<embed id="flvswf" src="'+player+'" flashvars="vcastr_file=' + file + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"  align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" wmode="transparent" width="100%" height="100%">';
	_into += '</embed>';
	_into += '</object>';
	_into += '</div></div>';
	_into += '<div id="maskForIe" style="left:0;top:0;position:absolute;width:expression(document.body.scrollWidth);height:expression(document.body.scrollHeight);display:none;background:#000;filter:alpha(opacity=100);z-index:101"></div>';
	_into += '<style>';
	_into += '#videoPlayer{margin:0;padding:0 !important;width:320px;height:260px;top:0;left:0}#program_player td{padding:0 !important;}'
	_into += '.maxmized{z-index:9999;}';
	//_into += '.maxmized #flvPlayBack{width:'+windowWidth+'px !important;height:'+windowHeight+'px !important;border:3px solid #000;top:0;left:0;}';
	//_into += '.maxmized #flvPlayBack{width:0px !important;height:0px !important;border:3px solid #000;top:0;left:0;}';
	_into += '.normalSize{width:320px;height:260px;}#flvPlayBack{margin:auto;height:100%;}</style>';
	//alert(_into);
	if(document.getElementById('videoplayer')){
		document.getElementById('videoplayer').innerHTML = _into;
	}
}
//用于视频显示
var windowWidth,windowHeight,thisWidth;
if (self.innerHeight) {
	windowWidth = self.innerWidth;
	windowHeight = self.scrollHeight;
	thisWidth = windowWidth;
	windowHeight = windowHeight-20;

} else if (document.documentElement && document.documentElement.clientHeight) {
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
	thisWidth = windowWidth;
	windowHeight = windowHeight-20;
	windowWidth = windowHeight*1.21;
} else if (document.body) {
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight-20;
	thisWidth = windowWidth;
}

function zoomMovie(){
	var objId='videoPlayer';
	var videoObject=document.all?document.all[objId]:document.getElementById(objId);
	var maskForIe=document.all?document.all['maskForIe']:document.getElementById('maskForIe');
	var videoPlayBack=document.all?document.all['flvPlayBack']:document.getElementById('flvPlayBack');

	var isMaxmized=/.*maxmized.*/i.test(videoObject.className);
	//
	if (self.innerHeight) {

		windowWidth = self.innerWidth;
		windowHeight = self.scrollHeight;
		thisWidth = windowWidth;
		windowHeight = windowHeight-15;

	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
		thisWidth = windowWidth;
		windowHeight = windowHeight-15;
		windowWidth = windowHeight*1.21;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight-15;
		thisWidth = windowWidth;
	}
    var mask;
	if(isMaxmized){
		videoObject.className='normalSize';
		videoObject.style.position='';
		//videoPlayBack.firstChild.BGCOLOR='ffffff';
		videoPlayBack.style.width=320;
		videoPlayBack.style.height=260;
		maskForIe.style.display='none';

		//document.getElementById("divMask").removeChild(videoObject);
		document.getElementById("divMask").style.display="none";
		document.getElementById('videoplayer').appendChild(videoObject);
		mask=document.getElementById("divMask");
		document.body.removeChild(mask);
		document.documentElement.style.overflowY='scroll';
	}else{
		//document.body.style.overflow='hidden';
	    document.documentElement.style.overflowY='hidden';
	    mask=document.createElement("DIV");
		mask.id="divMask";
		mask.className="divmask";
		document.body.appendChild(mask);
	    document.getElementById("divMask").appendChild(videoObject);
	    document.getElementById("divMask").style.width=document.documentElement.scrollWidth;
	    document.getElementById("divMask").style.height=document.documentElement.scrollHeight;
	    document.getElementById("divMask").style.display="block";
	    //window.scrollTo(0,0);
        videoObject.className='maxmized';
		videoObject.style.position='absolute';
		if(navigator.appName.lastIndexOf('Explorer')!=-1){
			videoObject.style.left=(thisWidth-windowWidth)/2;

			videoObject.style.top=document.documentElement.scrollTop;
			videoPlayBack.style.width=windowWidth;
			videoPlayBack.style.height=windowHeight;
			//maskForIe.style.display='';

		}else
		{
			window.scrollTo(0,0);
		}
		//videoPlayBack.firstChild.BGCOLOR='000000';
	}
	//videoObject.onclick=function(){zoomMovie();}
}

function checkfuneeeuser()
{
    var houseid=document.getElementById("hidHouseId").value;
    var html="信息来源:{14},点击数:{15}<br/>";
    html+="房源联系人：{0} {1} , 电话 {2}<br>发布人：(登录名：<a href='/blog/{3}' target='_blank'>{4}</a>) {5} {6} , 电话 {7} , 身份：{8}";
    html+="<br/>楼栋号:{9},房间号:{10}, 购房时间：{11},原购价：{12}，剩余按揭款：{13}";
    houseinfo.CheckIsFuneeeUser(html,houseid,checkfuneeeuser_callback);
}
var isfuneeeuser=false;
function checkfuneeeuser_callback(response)
{
    //alert(response.value);
    if(response.error!=null)
    return;
    if(response.value.length>0)
    {
        var div=document.getElementById("dvFuneeeUser");
        div.innerHTML="<div class='ha_sp_user'>以下是房易网内部用户看到的信息：<br>" + response.value+"</div>";
        replceClass(div,"dn","");
        isfuneeeuser=true;
    }
    getComment(1);
}
function getHousePic_CallBack(response)
{
   if(response.error!=null)
    {
        alert(response.error);
    }
    else
    {
      var res=response.value;
      

    }

}
function playAd()
{
    //mod by yzg 2008-03-14
    document.getElementById('dvPlayer').innerHTML="房易广告";
   
    if(document.getElementById('videoplayer')) {
	    document.getElementById('videoplayer').innerHTML="<div id='AF57AC05370A8E61CA326CE1EF12F6DC'></div>";
    }
}
function getMarket()
{
    var houseName = document.getElementById('hidHouseName').value;
    var html="<li class='c'>";
    html+="<span class='area1'><a href='/market/buildingmarket.aspx?buildingName="+encodeURI(houseName)+"' title='"+houseName+"'>{0}</a></span>";
    html+="<span class='area2 {3}'>{1}</span>";
    html+="<span class='area3 {3}'>{2}</span>";
    html+="</li>";
    houseinfo.GetBuildingMarket(html,houseName,getMarket_CallBack);

}
function getMarket_CallBack(response)
{
   if(response.error!=null)
   {
        alert(response.error);
   }
   else
   {
      var html="<ul class='c'>"
	  html+="<li class='tt c'>";
	  html+="<span class='area1'>日期</span>";
	  html+="<span class='area2'>楼盘均价</span>";
	  html+="<span class='area3'>涨幅</span>";
	  html+="</li>";
	  html+=response.value;
	  html+="</ul>";
     document.getElementById("dvMarket").innerHTML=html;
   }

}
function marketDetail()
{
   var buildingName=document.getElementById('hidHouseName').value;
   location.href='/market/buildingmarket.aspx?buildingName='+encodeURI(buildingName);
}
//发送举报信息
function prosecution(MessageId,isPros,houseid,housename)
{
	if (confirm("是否要举报此房源？"))
	{
	    var userId =GetCookie("user_id");
	    if(userId>0) {
		    if(!isPros)
		    {
			    var url = "/handler/AddMessageInfo.ashx?action=prosecution&MessageId="+MessageId+"&Msg=" + encodeURI("房源编号:") + houseid + "," + encodeURI("房源名称:") + encodeURI(housename);
			    var result = RequestByGet(url);
			    switch(result)
			    {
				    case "1":
				    alert("感谢您的举报,我们会即刻核实处理!");
				    switch(MessageId)
				    {
					    case 1:
					    isMsg1procf = true;
					    break;
					    case 2:
					    isMsg2procf = true;
					    break;
					    case 3:
					    isMsg3procf = true;
					    break;
					    case 4:
					    isMsg4procf = true;
					    break;
				    }
				    break;
				    case "-2":
				    alert("您已经举报过此房源!");
				    break;
				    default:
				    alert(result);
				    //alert("举报房源出现错误,请稍后再试");
				    break;
			    }
		    }
		    else
		    {
			    alert("您已经举报过此房源!");
		    }
		}
		else alert("请先登陆后再举报!");
	}
}
function getEvsPrice(houseid)
{
    var houseid = document.getElementById('hidHouseId').value;
    houseinfo.GetEvsPrice(houseid,getEvsPrice_callback);
}

function getEvsPrice_callback(response)
{
    //alert(response.value);
    if(response.value==null)
    {
        //alert("无法估价，可能输入数据有误！");
        return false;
    }
    else if(response.value=="0")
    {
        //alert("业主没有设置估价参数！");
        return false
    }
    else if(response.value=="-1")
    {
        //alert("业主设置了隐藏结果！");
        return false
    }
    else
    {
        var evs= document.getElementById("dvEvs");
        replceClass(evs,"dn","");
    }
}