
function $(id){return document.getElementById(id);};

function GetMessagesCount()
{	

	//$('MessagesCount').innerHTML = this.responseXML.lastChild.firstChild.data;
	
}

function RefreshUserInfo()
{
	//if(CurrentUserID != UserID)
	//{
	//	Xml.Request('/Interface/IsAskUser.aspx?userid=' + CurrentUserID, null, GetUserInfoFinish);
	//}
	//else
	{
		window.location.href = window.location;
	}
}

function GetUserInfoFinish()
{
    var state = this.responseXML.lastChild.firstChild.data;
    if(state == '0')
    {
        IsAuthenticated = '2';
    }
    else
    {
        IsAuthenticated = state;
    }
	
	InitializeTopLinks();
}

function InitializeTopLinks()
{
	//$('UserLogin_OpenButton').style.display = (IsAuthenticated == '0' ? '' : 'none');
	//$('TopLink_Register').style.display = (IsAuthenticated == '0' ? '' : 'none');
	//$('TopLink_OpenMyAsk').style.display = (IsAuthenticated == '2' ? '' : 'none');
	//$('TopLink_MyAsk').style.display = (IsAuthenticated == '1' ? '' : 'none');
	//$('TopLink_Logout').style.display = (IsAuthenticated != '0'?'' : 'none');
	//$('s1').style.display = (IsAuthenticated == '0' ? '' : 'none');
	//$('s2').style.display = (IsAuthenticated != '0' ? '' : 'none');
	//$('s3').style.display = (IsAuthenticated != '0' ? '' : 'none');
	
	if(IsAuthenticated != '0')
	{
	    //alert('/Interface/GetUnreadMessagesCount.aspx?userid=' + CurrentUserID + '&username=' + escape(CurrentUserName));
		//Xml.Request('/ask/Interface/GetUnreadMessagesCount.aspx?channelcode=ask&userid=' + CurrentUserID + '&username=' + escape(CurrentUserName), null, GetMessagesCount);
		
		$("TopLink_MessageBox").href = 'http://passport.soufun.com/message.web/messageunreadlist.aspx/userid=' + CurrentUserID;
		
		/*if(IsAuthenticated == '1')
		{
			$('TopLink_MyAsk').href = '/Ask_' + CurrentUserID + '.htm';
			$('TopLink_MyAsk').innerHTML = $('TopLink_MyAsk').innerHTML.replace('[UserName]', CurrentUserName);
		}
		else
		{
			$('TopLink_OpenMyAsk').innerHTML = $('TopLink_OpenMyAsk').innerHTML.replace('[UserName]', CurrentUserName);
		}*/
		$('TopLink_MessageBox').style.display = (IsAuthenticated != '0' ? '' : 'none');
	}
	
	
}
InitializeTopLinks();

function InitializeNavigation()
{	
	$('NavigationLink_Icon').href = '/Ask_' + UserID + '.htm';
	$('AskTitle').href = '/Ask_' + UserID + '.htm';
	var size = GetStringLength($('AskTitle').innerHTML);
	if(size < 0) size = 20;
	$('AskTitle').size = size;
	
	$('DomainName').innerHTML = UserName;
	$('NavigationLink_DomainName').href = '/Ask_' + UserID + '.htm';
	if($('ForAskTitle') != null && $('ForAskTitle') != undefined)
	{
	    $('ForAskTitle').setAttribute('Action', '/Interface/UpdateUserAskTitle.aspx?userid=' + UserID + '&Asktitle=');
	    $('ForAskTitle').setAttribute('OnBind', 'return UserID != "0" && UserID == CurrentUserID;');
	    $('ForAskTitle').setAttribute('OnUpdate', 'if(this.textBox.value == "") this.textBox.value = this.element.innerHTML;');
	    $('ForAskTitle').setAttribute('OnFinish', 'if(this.returnValue != "100"){window.alert("Error Code:" + this.returnValue);return false;}');
	
	}
	
	InitializeSwapButtons();
}
function InitializeSwapButtons()
{
	for (var i=1; i<=5; i++)
	{
		document.images['SwapButton_' + i].onmouseover = 
			function()
			{
				this.src = this.src.replace('we_','ew_');
				this.className = 'colorButton';
			}
		document.images['SwapButton_' + i].onmouseout = 
			function()
			{
				this.src = this.src.replace('ew_','we_');
				this.className = 'grayButton';
			}
	}
	$('SwapButton_Ask').href = '/Ask/AskList_' + UserID + '.htm';
	$('SwapButton_Favorite').href = 'javascript:;';
	$('SwapButton_Favorite').onclick =
		function()
		{
			if (window.sidebar)			
			{
				window.sidebar.addPanel($('AskTitle').value, 'http://photo.soufun.com/Ask_' + UserID + '.htm', UserName + '的相册');
			}
			else if(navigator.appName == 'Microsoft Internet Explorer')
			{
				window.external.AddFavorite('http://photo.soufun.com/Ask_' + UserID + '.htm', $('AskTitle').value);
			}
			else
			{
				window.alert('你需要手工将此页面添加到你的收藏夹!');
			}
		}
	$('SwapButton_GuestBook').href = '/Ask/LeaveWord_' + UserID + '.htm';
	$('SwapButton_Blog').href = 'http://blog.soufun.com/blog_' + UserID + '.htm';
	$('SwapButton_RSS').href = '/RSS_' + UserID + '.xml';
}

if($('Navigation') != null)
{
	//InitializeNavigation();
}
/****UrlEncode*******************************************************/
//方法说明：url编码
 function url_encode(val) {
    var r = "";
    //alert(val);
    for (var i = 0; i < val.length; i++) {
    //alert(val.length);
    //alert(val.charAt(i));
        var code = "" + GetByteCode(val.charAt(i));
         //alert(code);
        if (code.length > 2) {
            var b1 = code.substr(0, code.length - 2);
            var b2 = code.substr(code.length - 2);

            if (i == 0) {

                //alert("" + code + ", " + b1 + ", " + code.length + ", " + b2);

            }

            r += "%" + b1 + "%" + b2;

        } else {

            r += "%" + code;

        }

    }

    return r;
}

