function InitializeTextEditor()
{
    $('ForAlbumName').setAttribute('Action', '/Interface/UpdateUserAlbumName.aspx?userid=' + UserID + '&albumid=' + AlbumID + '&name=');
	$('ForAlbumName').setAttribute('OnBind', 'return UserID != "0" && UserID == CurrentUserID;');	
	$('ForAlbumName').setAttribute('OnUpdate', 'if(this.textBox.value == "") this.textBox.value = this.element.innerHTML;');
	$('ForAlbumName').setAttribute('OnFinish', 'if(this.returnValue != "100"){window.alert("Error Code:" + this.returnValue);return false;} else {$("linkAlbumName").innerHTML=this.textBox.value;return true;}');
    $('ForDescription').setAttribute('Action', '/Interface/UpdateUserAlbumDescription.aspx?userid=' + UserID + '&albumid=' + AlbumID + '&description=');
	$('ForDescription').setAttribute('OnBind', 'return UserID != "0" && UserID == CurrentUserID;');
	$('ForDescription').setAttribute('OnEdit', 'if(this.element.innerHTML == this.title) this.textBox.value = "";');
	$('ForDescription').setAttribute('OnCancel', 'if(this.textBox.value == "") this.element.innerHTML = this.element.title;');
	$('ForDescription').setAttribute('OnFinish', 'if(this.textBox.value == ""){this.textBox.value = this.element.title;};return this.returnValue == "100";');
}
InitializeTextEditor();
function SetDisplay()
{
    $('linkAlbumName').innerHTML = $('txtAlbumName').innerHTML;
    if(UserID == CurrentUserID)
    {           
        $('textPicturePrivacyState').innerHTML = PrivacyState == '1'?'公开':'私有';
    }
    if ($('txtDescription').innerHTML == '' && UserID != CurrentUserID)
    {
        $('txtDescription').style.display = 'none';
    }
}
SetDisplay();
function ChangePrivacyState(sender)
{
    var objPrivacyState = $('textPicturePrivacyState');
    var PrivacyStateAlert="";
    if(objPrivacyState.innerHTML=="公开"){PrivacyStateAlert="将专辑改为私有后，其他人将看不到该专辑。确认改为私有吗？";}else{PrivacyStateAlert="将专辑改为公开后，所有人都能看到该专辑。确认改为公开吗？";}
	if (window.confirm(PrivacyStateAlert))
    {
    sender.disabled = true;
    var state = PrivacyState=='1'?'0':'1';
    objPrivacyState.innerHTML = state=='0'?'私有':'公开';
    Xml.Request('/Interface/UpdateUserAlbumPrivacyState.aspx?userid='+UserID+'&albumid='+AlbumID+'&privacystate='+state,null,FinishChangePicturePrivacyState); 
    }           
}
function FinishChangePicturePrivacyState()
{
    $('changePrivacyState').disabled = false;
    var nodes = this.responseXML.getElementsByTagName('Result');
    var objPrivacyState = $('textPicturePrivacyState');
    if(nodes.length <= 0)
    {
        return;
    }
    if(nodes[0].firstChild.data == '100')
    {
        PrivacyState = PrivacyState == '1'?'0':'1';
    }
    else
    {
        window.alert("更新专辑隐私状态失败！Error Code:" + nodes[0].firstChild.data);
    }
    objPrivacyState.innerHTML = PrivacyState=='1'?'公开':'私有';
}
function DeleteAlbum(sender,alterMsg)
{
    if(window.confirm("真的要"+alterMsg+"吗？") != true) return;
    Xml.Request("/Interface/DeleteUserAlbum.aspx?userid=" + UserID + "&albumid=" + AlbumID,null,FinishDeleteAlbum);
}
function FinishDeleteAlbum()
{
    var nodes = this.responseXML.getElementsByTagName('Result');
    if(nodes.length > 0)
    {
        var result=nodes[0].firstChild.data ;
        if(result== "100")
        {
            window.alert('删除专辑成功！');
            window.location.href= '/Album/' + UserID + '.htm';
        }
        else if(result=="105")
        {        
            window.alert("图片已清空，该专辑是系统分配的不能删除！");
        }
        else
        {
            window.alert('删除专辑失败！');
        }
    }
}
window.onload=
    function()
    {
        Div.FormatByEqualHeight('LayoutLeft', 'LayoutRight');
    }