﻿var lightBoxAction;
var isNotHide=false;
var isNotHideChangeImage=false;
var isOpenAvatarTool=false;

window.addEvent('domready',function() 
{
    /* hide using opacity on page load */
    
    $('fb-modal').setStyles(
    {
        opacity:0,
        display:'block'
    });
    
    window.addEvent('keypress',function(e) 
    {   
        if(e.key == 'esc') 
        { 
             hidelightbox(); 
        } 
    });
   
    
    $(document.body).addEvent('click',function(e) 
    {  
        if($('fb-modal').get('opacity') == 1 && !$(e.target).getParent('.generic_dialog') && isNotHide==false) 
        {
            hidelightbox(); 
        }
        
        if(isOpenAvatarTool == true && !$(e.target).getParent('idAvatarHolder') && !$(e.target).getParent('idAvatarTool'))
        {
            isOpenAvatarTool=false;
            $('idAvatarTool').setStyle('display','none');
        }
    });
    
    //
    lightBoxAction = new LightBoxPost({
        idContent: 'pop_content', 
        url: 'LightBox'
    });  
});
//

//
function hidelightbox(isCapture)
{   
    isNotHide=false;
    $('fb-modal').fade('out'); 
    if(isCapture==true)
    {
        $('pop_content').empty();
        $('generic_dialod_popup').setStyle('top','125px');
        $('pop_dialog_table').setStyle('width','532px');
    }
}
//
//0:loan tin - 1:kết bạn - 2:báo tin xấu - 3:kết bạn từ suggestion
//
function showlightbox(action,value)
{
    $('pop_content').empty();
    $('pop_content').set('html','<div style="font-size: 18px; margin: 10px 15px 10px 15px">Đang tải nội dung...</div>');
    $('fb-modal').fade('in');
    switch(action)
    {   
        case 11:
        {
            lightBoxAction.setIsSpammerGet(value);
            break;
        }
        case 10:
        {
            lightBoxAction.markItemBoringGet(value);
            break;
        }
        case 9:
        {
            lightBoxAction.readSentPrivateMessage(value);
            break;
        }
        case 8:
        {
            lightBoxAction.readPrivateMessage(value);
            break;
        }
        case 7:
        {
            lightBoxAction.sendMessageBoxGet(value);
            break;
        }
        case 6:
        {
            lightBoxAction.changeMessageBoardFilterGet();
            break;
        }
        case 5:
        {
            lightBoxAction.changeEmailGet();
            break;
        }        
        case 4:
        {
            lightBoxAction.changePassGet();
            break;
        }
        case 3:
        {
            lightBoxAction.addFriendSuggestionGet(value);
            break;       
        }
        case 2:
        {
            lightBoxAction.reportItemGet(value);
            break;
        }
        case 1:
        {
            lightBoxAction.addFriendGet(value);
            break;       
        }
        case 0:
        {
            lightBoxAction.messengerGet(value);
            break;
        }
        default:
        {
            hidelightbox();
            break;
        }
    }
}
//
//
//Thực hiện báo quản trị
//
function setIsSpammerSet(value,idLoader,idMessage)
{   
    lightBoxAction.setIsSpammerSet(value,idLoader,idMessage);
}
//
function markItemBoringSet(valueA, valueB, idLoader)
{
    lightBoxAction.markItemBoringSet(valueA,valueB,idLoader);  
}
//
function delMultiSentPrivateMessage(value)
{
    lightBoxAction.delMultiSentPrivateMessage(value);    
}

function markReadMultiSentPrivateMessage(value)
{
    lightBoxAction.markReadMultiSentPrivateMessage(value);    
}

//
function delSentPrivateMessage(value)
{
    lightBoxAction.deleteSentPrivateMessage(value);    
}
//
function delMultiPrivateMessage(value)
{
    lightBoxAction.delMultiPrivateMessage(value);    
}

function markReadMultiPrivateMessage(value)
{
    lightBoxAction.markReadMultiPrivateMessage(value);    
}

//
function delPrivateMessage(value)
{
    lightBoxAction.deletePrivateMessage(value);    
}
//
function replyPrivateMessage(value,idLoader)
{
    lightBoxAction.replyPrivateMessage(value,idLoader);    
}
//
//Thực hiện gửi tin nhắn
//
function sendMessageBoxSet(value,idLoader,idSubject,idMessage)
{   
    lightBoxAction.sendMessageBoxSet(value,idLoader,idSubject,idMessage);
}
//
//Thực hiện gửi tin nhắn trả lời
//
function replyPrivateMessageSet(messageId,value,idLoader,idSubject,idMessage)
{
    lightBoxAction.replyPrivateMessageSet(messageId,value,idLoader,idSubject,idMessage);
}
//
//Thực hiện kết bạn suggestion
//
function addFriendSuggestionSet(value,idLoader,idMessage)
{   
    lightBoxAction.addFriendSuggestionSet('friend-suggestion-container',value,idLoader,idMessage);
}
//
//Thực hiện kết bạn
//
function addFriendSet(value,idLoader,idMessage)
{   
    lightBoxAction.addFriendSet(value,idLoader,idMessage);
}
//
//Thực hiện loan tin
//
function messengerSet(value,idLoader,idMessage)
{   
    lightBoxAction.messengerSet(value,idLoader,idMessage);
}
//
//Thực hiện báo quản trị
//
function reportItemSet(value,idLoader,idMessage)
{   
    lightBoxAction.reportItemSet(value,idLoader,idMessage);
}
//
//Thực hiện đổi pass
//
function changePassSet(idLoader,idOldPass,idNewPass)
{   
    var oldPass=$(idOldPass).get('value').trim();
    var newPass=$(idNewPass).get('value').trim();
    if(oldPass.length>=6 && newPass.length >=6)
        lightBoxAction.changePassSet(idLoader,oldPass,newPass);
    else
        alert('Mật khẩu phải ít nhất 06 ký tự!');
}

//
//Thực hiện đổi email
//
function changeEmailSet(idLoader,idNewEmail)
{   
    var newEmail=$(idNewEmail).get('value').trim();
    if(newEmail.IsValidEmail())
        lightBoxAction.changeEmailSet(idLoader,newEmail);
    else
        alert('Email mới chưa nhập hoặc không hợp lệ!');
}

//
//Thực hiện đổi Tùy chọn Hiển thị Trang Loan Tin
//

function changeMessageBoardFilterSet(idLoader,idNewValue)
{
    var newValue = $$('input[name='+idNewValue+']:checked').map(function(e) { return e.value; });
    lightBoxAction.changeMessageBoardFilterSet(idLoader,parseInt(newValue));
}