// ActionScript Document
/**
 * @author zmhu
 */
var act = 'sell';
function byId(domid)
{
    return document.getElementById(domid);
}
function htmlshow(dom)
{
    byId(dom).style.display = "";
}
function htmlhide(dom)
{
    byId(dom).style.display = "none";
}
function jumpto(url)
{
    window.location.href = url;
}
function switchTab(obj,actstr)
{
    var tabObj = byId('searchtab');
    var lis = tabObj.getElementsByTagName('a');
    if(actstr == "sell")
    {
        lis[0].className="crutitle";
        lis[1].className="normal";
        //lis[2].className="normal";
        setSellTab("show");
        setRentTab("hide");
        //setCommTab("hide");
    }
    else if(actstr == "rent")
    {
        lis[0].className="normal";
        lis[1].className="crutitle";
        //lis[2].className="normal";
        setSellTab("hide");
        setRentTab("show");
        //setCommTab("hide");
    }
    else if(actstr == "comm")
    {
        lis[0].className="normal";
        lis[1].className="normal";
        //lis[2].className="crutitle";
        setSellTab("hide");
        setRentTab("hide");
        //setCommTab("show");
    }
    act = actstr;
}
function setSellTab(ctrl)
{
    var list = new Array("selsaleprice","selacreage","sellArea","sellPrice","sellAreaNum","sellModel");
    for(var i = 0; i<list.length ; i++)
    {
        if(ctrl == "show"){byId(list[i]).style.display='';byId('selhousemode').style.display='';}
        else if(ctrl == "hide")byId(list[i]).style.display='none';
    }
}
function setRentTab(ctrl)
{
    var list = new Array("selrentprice","selfitmenttype","rentArea","rentPrice","rentModel","rentFitType");
    for(var i = 0;i<list.length ;i++)
    {
        if(ctrl == "show"){byId(list[i]).style.display='';byId('selhousemode').style.display='';}
        else if(ctrl == "hide")byId(list[i]).style.display='none';
    }
}
function setCommTab(ctrl)
{
    var list = new Array("comunitprice","commusetype","commArea","commUnitPrice","commBuildType");
    for(var i = 0;i<list.length ;i++)
    {
        if(byId(list[i])!=null){
            if(ctrl == "show"){byId(list[i]).style.display='';byId('selhousemode').style.display='none';}
            else if(ctrl == "hide")byId(list[i]).style.display='none';
        }

    }
}

function swtichProp(type)
{
    if(type == "property")
    {
        byId("propertybasic_a").className = 'dian';
        byId("communitybasic_a").className = 'nodian';
        byId("roundcomm_a").className = "nodian";
        byId("propertybasic").style.display='';
        byId("communitybasic").style.display='none';
        byId("roundcomm").style.display='none';
    }
    else if(type == "community")
    {
        byId("propertybasic_a").className = 'nodian';
        byId("communitybasic_a").className = 'dian';
        byId("roundcomm_a").className = "nodian";
        byId("propertybasic").style.display='none';
        byId("communitybasic").style.display='';
        byId("roundcomm").style.display='none';
    }
    else if(type == "round")
    {
        byId("propertybasic_a").className = 'nodian';
        byId("communitybasic_a").className = 'nodian';
        byId("roundcomm_a").className = "dian";
        byId("propertybasic").style.display='none';
        byId("communitybasic").style.display='none';
        byId("roundcomm").style.display='';
    }
}
function jumpto(url)
{
    window.location.href=url;
}
/////////////////////////////dealwitch propertys ////////////////////
var dealPlayIntval = null;
var dealPlayPxIntval = null;
var dealPlayPause = null;
var dealPlayTop = 0;
var dealObj = null;//byId('newdealBox');
dealObj = byId('newdealBox');
function dealPlaying()
{
    dealPlayPause = false;
    dealObj =  byId('newdealBox');
    if(dealObj) {
        if(dealPlayTop<=1)
        {
            dealPlayIntval = window.setTimeout(function(){dealPlayOneRow(dealObj);},3000);
        }
    }
}
function dealPlayOneRow(dealObj)
{
    if( byId('newdealBox').scrollHeight -  byId('newdealBox').scrollTop <= 300)
    {
        window.clearTimeout(dealPlayIntval);
        dealObj.scrollTop = 0;
        dealPlaying();
    }
    else
    {
        dealPlayPxIntval = window.setInterval(function(){dealPlayOnePx(dealObj);},1);
    }
}
function dealPlayOnePx(obj)
{
    if(dealPlayTop>107)
    {
        dealPlayTop = 1;
        window.clearInterval(dealPlayPxIntval);
        if(dealPlayPause == false)
        {
            dealPlaying();
        }
    }
    else
    {
        obj.scrollTop+=1;
        dealPlayTop ++;
    }
}
function dealPlayingPause()
{
    dealPlayPause = true;
    window.clearTimeout(dealPlayIntval);
}
////////////////////////////////////////
var imageNum = 1;
function playingImage()
{
    for(var i=1;i<=3;i++)
    {
        if(imageNum == i)
        {
            if(byId('playimagesdiv'+i)!=null)
            htmlshow('playimagesdiv'+i);
        }
        else{
            if(byId('playimagesdiv'+i)!=null)
            htmlhide('playimagesdiv'+i);
        }
    }
    imageNum++;
    if(imageNum >= 4)imageNum=1;
}
//var playimagesdiv=document.getElementById('playimagesdiv1');
//if(playimagesdiv!=null)
//{
    window.onload = function(){window.setInterval(function(){playingImage();},2000);dealPlaying();}
//}
////////////////////////////////
function changeText(dom,txt,id,hdom)
{
    var obj = byId(dom).getElementsByTagName('span');
    obj[0].innerHTML = txt;
    obj[0].title = id;
    htmlhide(hdom);
}
function doSearch()
{
    var areaid = getSearchTxt('selarea');
    var blockid = getSearchTxt('selblock');
    var kw = encodeURIComponent(byId('kw').value);
    if(act == 'sell')
    {
        var salepriceid = getSearchTxt('selsaleprice');
        var arearangeid = getSearchTxt('selacreage');
        var housemodelid = getSearchTxt('selhousemode');
        var url = "./listptab-act-sell-do-dosearch-areaid-"+areaid+"-blockid-"+blockid+"-salepriceid-"+salepriceid+"-arearangeid-"+arearangeid+"-housemodelid-"+housemodelid+"-tagid--kw-"+kw+"-page-1.html";
        jumpto(url);
    }else if(act == 'rent')
    {
        var rentpriceid = getSearchTxt('selrentprice');
        var housemodelid = getSearchTxt('selhousemode');
        var fitmentid = getSearchTxt('selfitmenttype');
        var url = "./listptab-act-rent-do-dosearch-areaid-"+areaid+"-blockid-"+blockid+"-housemodelid-"+housemodelid+"-hirepriceid-"+rentpriceid+"-fitmentid-"+fitmentid+"-tagid--kw-"+kw+"-page-1.html";
        jumpto(url);
    }else if(act == 'comm')
    {
        var price = getSearchTxt('comunitprice');
        var usetype = getSearchTxt('commusetype');
        var url = "./listcomm-areaid-"+areaid+"-blockid-"+blockid+"-price-"+price+"-usetype-"+usetype+"-kw-"+kw+"-tag--py--page-1.html";
        jumpto(url);
    }
}
function getSearchTxt(dom)
{
    var ob = byId(dom);
    if(ob)
    {
        var obj = ob.getElementsByTagName("span");
        return obj[0].title;
    }
    else
    {
        return "";
    }
}
///////////////////////////////////
var net = new Object();
net.ContentLoader = function(url,postback,method,params)
{
    this.url = url;
    this.postback = postback;
    this.params = params;
    this.req = null;
    this.method = method;
    this.loadXMLDoc(url);
}
net.ContentLoader.prototype =
{
    createXMLHttpRequest:function()
    {
        if(window.XMLHttpRequest)
        {
            this.req = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            var arrVersions = ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0",
                               "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
            for(var i = 0;i< arrVersions.length;i++)
            {
                try
                {
                     this.req  = new ActiveXObject(arrVersions[i]);
                }
                catch(oError)
                { }
            }
        }
    return this.req;
    },

    loadXMLDoc:function(url)
    {
        if(this.createXMLHttpRequest())
        {
            try
            {
                var oThis = this;
                this.req.onreadystatechange = function()
                {

                    oThis.onReadyState.call(oThis);
                    //loader.onReadyState();
                }
                this.req.open(this.method,url,true);
                this.req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                this.req.send(this.params);
            }
            catch(oError)
            {}
        }
    },

  onReadyState:function()
  {
    if(this.req.readyState == 4)
    {
        if(this.req.status == 200 || this.req.status == 0 )
        {
            //this.postback.call(this);
            this.postback(this.req.responseText);
        }
    }
  }
}
function getHtmlFile(obj,url)
{
    var rtnfunc = function(data){
        obj.innerHTML = data;
    }
    var hf = new net.ContentLoader(url,rtnfunc,'get','');
}
function getBlock(areaid)
{
    //getHtmlFile(byId('view'),url);
    ob = byId('selblock').getElementsByTagName('span');
    ob[0].innerHTML = "板块";
    ob[0].title = "";
    obj = byId('viewblock');
    if(obj)
    {
        getHtmlFile(obj,'./ajax.php?action=getblock&typeid='+areaid);
    }
}
/////////////////////////////////////