﻿//Global variable
//var http = createRequestObject();

//Return request object
function createRequestObject() {
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (f) { xmlhttp = null; }
    }
    if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function ShowMessageNoAjaxCall(contID) {
    $('#msgcont' + contID).slideDown();
}
function HideMessageNoReload(contID) {
    $('#msgcont' + contID).slideUp();
}
function ShowMessage(contID) {
    $('#msgcont' + contID).slideDown();
    sendRequestMarkOldMsg(contID);
}
function HideMessage(contID) {
    $('#msgcont' + contID).slideUp();
    window.location.reload();
}
function sendRequestMarkOldMsg(pmid) {
    try {
        http.open('Get', 'AjaxRequest/AjaxRequest.aspx?mode=markpmold&pmid=' + pmid);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(null);
    }
    catch (e) { alert("An error has occured."); }
    finally { }
}
//Đánh dấu là đọc hoặc chưa đọc
function sendRequestMarkOldMsgOnClickIconImage(uid, pmid, val) {
    try {
        http.open('Get', 'AjaxRequest/AjaxRequest.aspx?mode=markpmoldIconImg&uid=' + uid + '&pmid=' + pmid + '&val=' + val);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(null);
    }
    catch (e) { alert("An error has occured."); }
    finally { }

    window.location.reload();
}
//Chuyển tin nhắn vào thùng rác
function sendRequestMovePMToTrash(pmid) {
    try {
        http.open('Get', 'AjaxRequest/AjaxRequest.aspx?mode=movetotrash&pmid=' + pmid);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(null);
    }
    catch (e) { alert("An error has occured."); }
    finally { }

    window.location.reload();
}


function sendRequestMovePMBackToInbox(pmid) {
    try {
        http.open('Get', 'AjaxRequest/AjaxRequest.aspx?mode=movetoinbox&pmid=' + pmid);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(null);
    }
    catch (e) { alert("An error has occured."); }
    finally { }

    window.location.reload();
}


function sendRequestDeleteTrashInboxPM(pmid) {
    try {
        http.open('Get', 'AjaxRequest/AjaxRequest.aspx?mode=delinboxpm&pmid=' + pmid);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(null);
    }
    catch (e) { alert("An error has occured."); }
    finally { }

    window.location.reload();
}
function sendRequestDeleteSentPM(pmid) {
    try {
        http.open('Get', 'AjaxRequest/AjaxRequest.aspx?mode=delsentpm&pmid=' + pmid);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(null);
    }
    catch (e) { alert("An error has occured."); }
    finally { }

    window.location.reload();
}
function sendRequestEmptyTrash() {
    try {
        http.open('Get', 'AjaxRequest/AjaxRequest.aspx?mode=emptytrash');
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(null);
    }
    catch (e) { alert("An error has occured."); }
    finally { }

    window.location.reload();
}
