﻿/*
*   Description : 视频看房网顶部头调用
*   Creator:    KaiSin
*   Create Data:    1/2008
*/
//使用说明:
//   如有区域性,请提供前置变量:   
//   如不提供默认转向:    010北京
//   引用前，须要引用样式：    http://lib.homevcache.com/head/style.css
//var CurrentPorvince = "北京"; 省
//var CurrentCity = "北京"; 市 
//var CityCode="010";   区号
//var CitySeed="bj";    城市代号，只能为两位字母
//var Product="sale";   产品名称,以下数组为相应的对应列表
//          new Array("首页","新闻","新房","二手房","租房","房吧");
//          new Array("www","news","house","sale","rent","bar");
//var SetProduct = "";  //设置当前显示菜单产品名
//
//var siteupdate__ = '<div style="font-size:12px; color:red; border:1px solid #FFCC33; background-color:#FDFBF2; height:25px; padding-top:8px; text-align:center; width:970px; margin-left:auto;margin-right:auto;">公告:本站将于4月2日24:00时至4月3日1:00时进行服务器升级，届时个别功能可能暂时无法使用，由此带来不便敬请谅解!</div>';
if (typeof sys_defaultlogin == 'undefined') var sys_defaultlogin = "";
if (typeof HomeV == 'undefined') var HomeV = {};
HomeV.$ = function(o){
  if (typeof o == 'object') return o;
  o = o.toString();
  if (document.getElementById) return document.getElementById(o);
  return undefined;
}
if (typeof HomeV.User == 'undefined') HomeV.User = {
ID:"",UserName:"",NickName:"",Password:"",LoginTime:""
}
if (typeof HomeV.AddEvent == 'undefined') HomeV.AddEvent = function(element,eventName,fun)
{
   if (typeof(element) == "string") element = GetObject(element);
   if (element.addEventListener)
      element.addEventListener(eventName, fun, false);
   else if (element.attachEvent)
      element.attachEvent('on' + eventName, fun);
   else
      element['on' + eventName] = fun;
}
if (typeof CitySeed == 'undefined') CitySeed = 'bj';
if (typeof CurrentCity  == 'undefined') CurrentCity = '北京';
if (typeof CurrentPorvince == 'undefined') CurrentPorvince = '北京';
if (typeof CityCode == 'undefined') CityCode = '010';
if (typeof Product  == 'undefined') Product = '';
if (typeof SiteDomain == 'undefined') SiteDomain = 'www.homev.cn';
if (typeof SiteBaseDomain == 'undefined') SiteBaseDomain = 'homev.cn';
if (typeof CurrentUrl == 'undefined') 
{
	try
	{CurrentUrl = top.location.href;}
	catch(e)
	{CurrentUrl = location.href;}
}
if (typeof SetProduct == 'undefined') SetProduct = "";
if (typeof IsAutoHead == 'undefined') IsAutoHead = true; //是否自动初始化头部
if (typeof IsViewLogin == 'undefined') IsViewLogin = true; //是否显示登录窗
if (typeof MemberURL == 'undefined') MemberURL = "http://member.homev.cn/";

var UserLoginID = ""; //帐户ID 未登录则为Empty
var UserLoginUserName = ""; //帐户名
var UserLoginNickName = ""; //昵称
var UserLoginPassword = ""; //用户密码
//以上全局变量，可供读取

//得到指定对象
function GetObject(o){ return HomeV.$(o); }
//事件添加
function AddEvent(element,eventName,fun)
{
   if (typeof(element) == "string") element = GetObject(element);
   if (element.addEventListener)
      element.addEventListener(eventName, fun, false);
   else if (element.attachEvent)
      element.attachEvent('on' + eventName, fun);
   else
      element['on' + eventName] = fun;
}
function LoadJScript(url,loadFn)
{
	this.bExec = false;
	this.sUrl = url;
	this.fnOnload = function()
	{
		if(!this.bExec)
		{
		    if (loadFn)
			    loadFn();
			this.bExec = true;
		}
	};
};
LoadJScript.prototype.init = function(id)
{
	var t = this;
	var oScript = document.createElement("script");
	var Scs = document.getElementsByTagName("script");
	for(var i=0;i<Scs.length;i++)
	{
	    if (Scs[i].src)
	    {
	        if (Scs[i].src.toLowerCase() == t.sUrl.toLowerCase())
	        {
	            oScript = Scs[i];
	            break;
	        }
	    }
	}
	AddEvent(oScript,'load',function(){
		    t.fnOnload();
	    }
	)
	AddEvent(oScript,'error',function(){
		    t.bExec = true;	
	    }
	)
	AddEvent(oScript,'readystatechange',function(){
		    if((oScript.readyState!="loaded")&&(oScript.readyState!="complete")) return;
		    oScript.onreadystatechange = null;		
		    t.fnOnload();	
	    }
	)
	oScript.setAttribute("type","text/javascript");	
	oScript.src = t.sUrl;
	document.getElementsByTagName("head")[0].appendChild(oScript);
};
//帐户登录
function GotoUserLogin(url){top.location.href = MemberURL + "Login.aspx?Backurl="+escape( url || CurrentUrl) + "&CitySeed=" + CitySeed;}
function GotoLoginOut(url){top.location.href = MemberURL + "Loginout.aspx?backurl="+escape(url || CurrentUrl) + "&CitySeed=" + CitySeed;}
function GotoUserRegister(url){top.location.href = "http://"+CitySeed+".homev.cn/Users/UserReg.aspx?From="+ CitySeed+"&Backurl="+escape( url || CurrentUrl);}
function GotoCityIndex(name){top.location.href = "http://" + name + "." + SiteBaseDomain;}
var _o_login = function(){
this.toLogin = function(url){top.location.href = MemberURL + "MemberLogin.aspx?Backurl="+( url || CurrentUrl);}
this.toOut = function(url){top.location.href = MemberURL + "SetOut.aspx?backurl="+(url || CurrentUrl);}
this.toReset = function(url){top.location.href = MemberURL + "FindPassWord.aspx?backurl="+(url || CurrentUrl);}
this.toRegister = function(url){top.location.href = "http://"+CitySeed+".homev.cn/Users/UserReg.aspx?From="+ CitySeed+"&Backurl="+escape( url || CurrentUrl);}
}
HomeV.Members = new _o_login();
HomeV.VerifyLogin = function(fm){
	if (typeof fm == 'string') fm = HomeV.$(fm);
	if (!fm) return false;
	if (!fm.UserName){alert('表单缺少UserName;');return false;}
	if (!fm.Password){alert('表单缺少Password;');return false;}
	if (!fm.Backurl){alert('表单缺少Backurl;');return false;}
	 if (fm.UserName.value.length < 6){
  	   alert('请输入你正确的用户名!');
  	   return false;
	  }
	  if (fm.Password.value.length < 5){
	    alert("请你输入你正确的登录密码!");
	    return false;
	  }
	  fm.action = MemberURL + "VerifyLogin.aspx";
	  if (fm.Backurl.value == "")
	  	fm.Backurl.value = CurrentUrl;
	  
	  //fm.submit();
	  return true;
}
function GotoProductURL(name)
{
    name = name.toString().toLowerCase();
    switch(name){
       case 'www':
        return 'http://' + CitySeed + '.'+SiteBaseDomain;
       case 'news':
        return 'http://' + CitySeed + '.'+SiteBaseDomain+'/news/';
       case 'house':
        return 'http://' + CitySeed + '.'+SiteBaseDomain+'/house/Search.aspx';
       case 'sale':
        return 'http://' + CitySeed + '.'+SiteBaseDomain+'/sale/Search.aspx';
       case 'rent':
        return 'http://' + CitySeed + '.'+SiteBaseDomain+'/rent/Search.aspx';
       case 'forum':
        return 'http://' + CitySeed + '.'+SiteBaseDomain+'/forum/';
       case 'plot':
        return 'http://' + CitySeed + '.'+SiteBaseDomain+'/plot/Search.aspx';
         case 'super':
        return 'http://' + CitySeed + '.'+SiteBaseDomain+'/super/';
        case 'property':
        return 'http://wuye.homev.cn';
       default:
	    if (CitySeed != "") return "http://"+ CitySeed +"." + SiteBaseDomain;
        return 'http:\/\/'+SiteDomain;
    }
}
function GotoProduct(name){ top.location.href = GotoProductURL(name)}
function CloseCity(){document.getElementById('head_city').style.display = 'none';}
//cookie读取
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function ReadHeadUser(){
   var cookie =   readCookie("PersonalName");
   if(cookie != "")
    {
          cookie = unescape(cookie).split('&');
          UserLoginUserName = cookie.length > 0 ? cookie[0].substr(cookie[0].indexOf('=') + 1) : "";
          UserLoginID       = cookie.length > 1 ? cookie[1].substr(cookie[1].indexOf('=') + 1) : "";
          UserLoginPassword = cookie.length > 2 ? cookie[2].substr(cookie[2].indexOf('=') + 1) : "";
          UserLoginNickName = cookie.length > 3 ? cookie[3].substr(cookie[3].indexOf('=') + 1) : "";
          //UserLoginColor    = cookie.length > 4 ? cookie[4].substr(cookie[4].indexOf('=') + 1) : "";
          
          HomeV.User.UserName = cookie.length > 0 ? cookie[0].substr(cookie[0].indexOf('=') + 1) : "";
          HomeV.User.ID = cookie.length > 1 ? cookie[1].substr(cookie[1].indexOf('=') + 1) : "";
          HomeV.User.Password = cookie.length > 2 ? cookie[2].substr(cookie[2].indexOf('=') + 1) : "";
          HomeV.User.NickName = cookie.length > 3 ? cookie[3].substr(cookie[3].indexOf('=') + 1) : "";
          HomeV.User.LoginTime = cookie.length > 4 ? cookie[4].substr(cookie[4].indexOf('=') + 1) : "";
    }
    HomeV.Broker = undefined;
    cookie = readCookie("BrokerInfo");
    if (cookie != ""){
    	cookie = unescape(cookie).split('&');
    	HomeV.Broker = {Site:"",Domain:""};
    	HomeV.Broker.Domain = cookie.length > 0 ? cookie[0].substr(cookie[0].indexOf('=') + 1) : "";
    	HomeV.Broker.Site = cookie.length > 1 ? cookie[1].substr(cookie[1].indexOf('=') + 1) : "";
    	
        if (HomeV.Broker.Site != CitySeed) HomeV.Broker = undefined;
    }
}
//写出数据
//vis 是否显示
//w 显示宽,不设置则为 null
//iscity 是否显示城市
function HeadInitialize(vis,w,iscity){
	function gn(){if (Product=='www') return ""; else return Product;}
    if (!vis) return;
    if (typeof siteupdate__ != 'undefined') document.write(siteupdate__);
    var channel,str;
    if (SetProduct && SetProduct!= null && SetProduct!= "")
        channel = SetProduct.toLowerCase();
    else
        channel = Product.toLowerCase();
    //if (channel == '') channel = 'www'; //置当前产品    

var nav_alt = new Array("首页","新房","二手房","租房","小区","豪宅","资讯","物业","论坛");
    var nav_name = new Array("www","house","sale","rent","plot","super","news","property","forum");
    if (typeof w == 'undefined' || w == null) w = 970;
    if (typeof iscity == 'undefined' || iscity == null) iscity = true;
    
    str = '<div style="height:5px;line-height:0px;"></div><div id="head_mainnav">';
    str += '<div class="mainnavLeft">';
  		str += '<a href="http://www.homev.cn/" style="cursor:pointer;" title="视频看房网 - 中国房地产第一门户"><div id="top_logo_div" class="logo"></div></a>';
  		str += '<div class="city" id="head_city">';
		if (CitySeed == 'cq')
                str += '<span id="top_city_span">重庆</span>';
        else
        		str += '<span id="top_city_span">北京</span>';
        str += '<div class="switch" style="color:#999;">[切换城市]</div><div style="position:absolute;">';
        str += '<div id="head_city2" style="position:absolute;top:-50px;left:55px!important;left:20px;background:url(http://lib.homevcache.com/head/images/v2/bg.gif) no-repeat left;/*filter:alpha(opacity=90);-moz-opacity:0.9;opacity: 0.9;*/ display:none; width:100px; border-right:1px solid #f2dcc3;  padding:5px 0px 0px 0px;margin:2px 0px 0px 0px; line-height:18px; height:20px;">';
             str += '<a href="http://bj.homev.cn/">北京</a>&nbsp;&nbsp;<a href="http://cq.homev.cn/">重庆</a>';
        str += '</div></div>';
	    str += '</div>';
		    
    str += '</div>';
        
    str += '<div class="head_subnav">';
        str += '<div class="loginHead">';
        
        var is_help = '<!-- <a href="http://www.homev.cn/" style="behavior: url(#default#homepage);" onclick="this.sethomepage(\'http://www.homev.cn/\');return false;">设为主页</a> | --><a href="javascript:window.external.AddFavorite(\'http://www.homev.cn/\',\'视频看房网北京站\')">收藏本站</a> | <a href="http://about.homev.cn/help/" target="_blank">帮助</a> |';

        	if (IsViewLogin)
        	{
        		if (sys_defaultlogin == "")
				{
			        if (HomeV.User.ID != "")
			        {
			            str = str.concat('你好[<b>'+ HomeV.User.UserName  +'</b>] 站内短信(<label style="color:red;" id="lab_messagecount">0</label>)条&nbsp;');
			            str = str.concat('[<a href="'+ MemberURL +'Main.aspx?From='+ CitySeed +'" target="_blank">进入管理中心</a>] ');  
			            str = str.concat(' [<a href="javascript:GotoLoginOut();" onclick="return confirm(\'确认要退出吗？\');">退出</a>]&nbsp');
			            //登录后不显示帮助
			            is_help = "";
			        }
			        else
			        {
			            str = str.concat(' <a href="javascript:GotoUserRegister();">注册</a>&nbsp;|&nbsp;<a href="javascript:GotoUserLogin();">登录</a>&nbsp;');				        
			        }
			        str = str.concat('|&nbsp;');
			   }
			   else 
			   	str += sys_defaultlogin; 
        		
        	}
        str += is_help + ' <img src="http://lib.homevcache.com/head/images/v2/houseup.gif" style="margin-right:2px;position:relative; top:3px;vertical-align:0;" width="15" height="15"><a href="http://member.homev.cn/Main.aspx?CitySeed='+ CitySeed +'">发房源</a></div>';
            str += '<div class="clear"></div>';
            str += '<div class="beta"></div>';
			str += '<div class="clear"></div>';
            for(var i=0;i<nav_alt.length;i++)
		    {
		        var stylename1='tab1';
		        var stylename2='tab2';		       
		        if (CitySeed == "cq" && nav_name[i] == "super") continue;
		        if (CitySeed == "cq" && nav_name[i] == "property") continue;	
		        if (CitySeed == "cq" && nav_name[i] == "news") continue;		        
			   	mc = (channel==nav_name[i])?stylename1:stylename2;
				str += '<div class="tab">';
	            	str += '<div class="'+mc+'"><div class="nav"><a href="'+GotoProductURL(nav_name[i])+'" title="'+nav_alt[i]+'" class="head_v2a">'+nav_alt[i]+'</a></div></div>';
	            str += '</div>';
		    }
			str += '<div class="tab">';            	
            str += '</div>';
//           if(channel=='news')
//            str += '<div class="taxis"></div>';
//            else
//			str += '<div class="taxis"> <a href="http://'+ CitySeed +'.homev.cn/Ranking/" target="_blank" class="head_a3">排行榜</a></div>';
			
        str += '<div class="clear"></div>';
    str += '</div>';
    
    str += '<div class="clear"></div><div class="clear"></div>';
	str += '</div>';
	
    document.getElementById('homev:header').innerHTML += str;
	AddEvent('head_city','mouseover',function(){
		clearTimeout(window.city_handle);
		document.getElementById('head_city2').style.display = '';
	});
	AddEvent('head_city','mouseout',function(){
		window.city_handle = setTimeout("document.getElementById('head_city2').style.display = 'none';",500);
	});
}
document.write('<span id="homev:header"></span>');
ReadHeadUser();
HeadInitialize(IsAutoHead,970,true);

function OpenCallMe(){
document.write('<scr'+'ipt type="text/javascript" src="http://ts.homev.cn/hfzvideolink/show/script.shtml?code=homev7439&id=261"></scr'+'ipt>');
}
/*
if (location.href.toString().toLowerCase().indexOf('bj.homev.cn') > -1 || location.href.toString().toLowerCase().indexOf('cq.homev.cn') > -1 || location.href.toString().toLowerCase().indexOf('www.homev.cn') > -1)
{ 
	document.write('<style type="text/css">');
	document.write('body,object,embed{filter:Gray;}');
	document.write('img{filter:Gray;}');
	document.write('.wrap,.wrap div{filter:Gray;}');
	document.write('.i_search, .i_search div,.i_search, .i_search ul {filter:Gray;}');
	document.write('.wraps .left .h5 div {filter:Gray;}');
	document.write('</style>');
}*/