﻿var dWait = 0;
var bChecking = false;

function setsession(category)
{
    Services.setKBcategory(category,setsessionback);
}

function setsessionback()
{
    location.href="moveware-knowledgebase.aspx";
}

function getFile(vID, vFileName)
{
    moveWait("move");
    moveWait("show", 30000);
    if (document.getElementById("i-waitsml"))
    {
        var ypos = parseInt(document.getElementById("i-waitsml").style.top) - 200;
        if (ypos < 0) { ypos = 0; }
        window.scrollTo(0, ypos);
    }
    Services.getattachment(vID, vFileName, getFileBack);
}

/*
function getFileBack(result)
{
var bFile = null;
if (result == "TRUE")
{
window.open("moveware-download.aspx","_parent");
}
moveWait("hide");
}
*/

function getFileBack(result)
{
    var sResult = result.toString();
    var bFile = null;

    if (sResult != "" && (sResult.length < 5 || sResult.substring(0, 5) != "FALSE"))
    {
        document.getElementById("i-printmsg").style.left = setLeft(parseInt((parseInt(document.body.clientWidth) - parseInt(document.getElementById("i-printmsg").style.width)) / 2)) + "px";
        document.getElementById("i-printmsg").style.top = parseInt((parseInt(document.body.clientHeight) - parseInt(document.getElementById("i-printmsg").style.height)) / 2) + "px";
        document.getElementById('i-printmsg').style.display = 'block';
        moveWait("show3");

        if (document.getElementById("i-waitsml"))
        {
            var ypos = parseInt(document.getElementById("i-waitsml").style.top) - 200;
            if (ypos < 0) { ypos = 0; }
            window.scrollTo(0, ypos);
        }
    }
    else
    {
        if (sResult == "") { checkLogin(); }
        else if (sResult.length > 5 && sResult.substring(0, 5) == "FALSE") { alert(sResult.substring(5)); }
        else { showMessage(1500, 100, 'FALSE', 'File Not Found', 'Y'); }
        moveWait("hidepop2");
    }
}

function moveWait(vaction, vtimeout)
{
    clearTimeout(dWait);
    dWait = 0;

    if (checkFileUpload(true))
    {
        switch(vaction)
        {
            case "show":
                if (document.getElementById("i-wait")) { document.getElementById("i-wait").style.display = "block"; }
                if (document.getElementById("i-waitsml")) { document.getElementById("i-waitsml").style.display = "block"; }
                dWait = window.setTimeout("moveWait('show2');", parseInt(vtimeout));
                break;

            case "show2":
                if (document.getElementById("i-waitsml")) { document.getElementById("i-waitsml").style.display = "none"; }
                if (document.getElementById("i-wait")) { document.getElementById("i-wait").style.display = "block"; }
                if (document.getElementById("i-unavail")) { document.getElementById("i-unavail").style.display = "block"; }
                break;

            case "hide":
                if (document.getElementById("i-unavail")) { document.getElementById("i-unavail").style.display = "none"; }
                if (document.getElementById("i-waitsml")) { document.getElementById("i-waitsml").style.display = "none"; }
                if (document.getElementById("i-wait")) { document.getElementById("i-wait").style.display = "none"; }
                break;

            case "hideall":
                if (document.getElementById("i-unavail")) { document.getElementById("i-unavail").style.display = "none"; }
                if (document.getElementById("i-waitsml")) { document.getElementById("i-waitsml").style.display = "none"; }
                if (document.getElementById("i-wait")) { document.getElementById("i-wait").style.display = "none"; }
                if (document.getElementById("waitarea")) { document.getElementById("waitarea").style.display = "none"; }
                if (document.getElementById("popuparea")) { document.getElementById("popuparea").style.display = "none"; }
                if (document.getElementById("controlarea")) { document.getElementById("controlarea").style.display = "none"; }
                if (document.getElementById("i-printmsg")) { document.getElementById("i-printmsg").style.display = "none"; }
                if (document.getElementById("popuparea")) { document.getElementById('popuparea').innerHTML = ""; }
                break;

            case "showpop":
                moveWait("hide");
                if (document.getElementById("waitarea")) { document.getElementById("waitarea").style.display = "block"; }
                if (document.getElementById("popuparea")) { document.getElementById("popuparea").style.display = "block"; }
                break;

            case "hidepop":
                if (document.getElementById("popuparea")) { document.getElementById("popuparea").style.display = "none"; }
                if (document.getElementById("waitarea")) { document.getElementById("waitarea").style.display = "none"; }
                if (document.getElementById("i-printmsg")) { document.getElementById("i-printmsg").style.display = "none"; }
                if (document.getElementById("popuparea")) { document.getElementById('popuparea').innerHTML = ""; }
                break;

            case "showpop2":
                moveWait("hide");
                if (document.getElementById("waitarea")) { document.getElementById("waitarea").style.display = "block"; }
                if (document.getElementById("i-waitsml")) { document.getElementById("i-waitsml").style.display = "block"; }
                break;

            case "hidepop2":
                if (document.getElementById("i-waitsml")) { document.getElementById("i-waitsml").style.display = "none"; }
                if (document.getElementById("waitarea")) { document.getElementById("waitarea").style.display = "none"; }
                break;

            case "showctls":
                moveWait("hide");
                if (document.getElementById("controlarea")) { document.getElementById("controlarea").style.display = "block"; }
                break;

            case "hidectls":
                if (document.getElementById("controlarea")) { document.getElementById("controlarea").style.display = "none"; }
                break;

            case "move":
            default:
                if (document.getElementById("i-wait"))
                {
                  document.getElementById("i-wait").style.width = parseInt(document.body.clientWidth) + "px";
                  document.getElementById("i-wait").style.height = parseInt(document.body.clientHeight) + "px";
                }
                if (document.getElementById("i-waitsml"))
                {
                  document.getElementById("i-waitsml").style.left = setLeft(parseInt((parseInt(document.body.clientWidth) - parseInt(document.getElementById("i-waitsml").style.width)) / 2)) + "px";
                  document.getElementById("i-waitsml").style.top = parseInt((parseInt(document.body.clientHeight) - parseInt(document.getElementById("i-waitsml").style.height)) / 2) + "px";
                }
                if (document.getElementById("i-message"))
                {
                  document.getElementById("i-message").style.left = setLeft(parseInt((parseInt(document.body.clientWidth) - parseInt(document.getElementById("i-message").style.width)) / 2)) + "px";
                  document.getElementById("i-message").style.top = parseInt((parseInt(document.body.clientHeight) - parseInt(document.getElementById("i-message").style.height)) / 2) + "px";
                }
                if (document.getElementById("i-unavail"))
                {
                  document.getElementById("i-unavail").style.left = setLeft(parseInt((parseInt(document.body.clientWidth) - parseInt(document.getElementById("i-unavail").style.width)) / 2)) + "px";
                  document.getElementById("i-unavail").style.top = parseInt((parseInt(document.body.clientHeight) - parseInt(document.getElementById("i-unavail").style.height)) / 2) + "px";
                }
                if (document.getElementById("logo") && parseInt(document.getElementById("logo").height) > 0)
                {
                    document.getElementById("waitarea").style.left = setLeft(parseInt(((parseInt(document.body.clientWidth) - 1008) / 2) + 150)) + "px";
                    document.getElementById("waitarea").style.top = parseInt(parseInt(document.getElementById("logo").height) + 33) + "px";
                }
                if (document.getElementById("popuparea"))
                {
                  document.getElementById("popuparea").style.left = setLeft(parseInt((parseInt(document.body.clientWidth) - parseInt(document.getElementById("popuparea").style.width)) / 2)) + "px";
                  document.getElementById("popuparea").style.top = parseInt((parseInt(document.body.clientHeight) - parseInt(document.getElementById("popuparea").style.height)) / 2) + "px";
                }
                if (document.getElementById("logo") && parseInt(document.getElementById("popuparea").style.top) < parseInt(document.getElementById("logo").height) + 16)
                {
                    document.getElementById("popuparea").style.top = parseInt(parseInt(document.getElementById("logo").height) + 16) + "px";
                }
                if (document.getElementById("controlarea"))
                {
                  document.getElementById("controlarea").style.left = setLeft(parseInt(((parseInt(document.body.clientWidth) - 1008) / 2) + 2)) + "px";
                  document.getElementById("controlarea").style.top = "250px";
                }
                break;
        }
    }
}

function setLeft(vL)
{
    if (vL < 0) { vL = 0; }
    return vL;
}

function incKB(){
Services.incKB(incKBback);
}
function incKBback(result){
      if (result == "TRUE"){
        location.href='moveware-knowledgebase.aspx';
        }
        else{
         document.getElementById("naverrorKB").innerHTML ="* No Next Records Founds";
        }
}
function decKB(){
Services.decKB(decKBback);
}
function decKBback(result){
 if (result == "TRUE"){
        location.href='moveware-knowledgebase.aspx';
        }
        else{
         document.getElementById("naverrorKB").innerHTML ="* No Previous Records Founds";
        }
}
function searchKB(){
var query = document.getElementById('searchKB').value;
Services.searchKB(query,searchKBback);
}

function searchKBback(result){
 location.href='moveware-knowledgebase.aspx';
}

function incnews(){
Services.incnews(incnewsback);
}
function incnewsback(result){
      if (result == "TRUE"){
        location.href='moveware-news.aspx';
        }
        else{
         document.getElementById("naverrornews").innerHTML ="* No Next Records Founds";
        }
}
function decnews(){
Services.decnews(decnewsback);
}
function decnewsback(result){
 if (result == "TRUE"){
        location.href='moveware-news.aspx';
        }
        else{
         document.getElementById("naverrornews").innerHTML ="* No Previous Records Founds";
        }
}
function searchnews(){
var query = document.getElementById('searchnews').value;
Services.searchnews(query,searchnewsback);
}

function searchnewsback(result){
 location.href='moveware-news.aspx';
}

function setsessionnews(category)
{
Services.setnewscategory(category,setsessionnewsback);
}
function setsessionnewsback(){
location.href="moveware-news.aspx";
}

function checkFileUpload(bAllow)
{
    var result = true;

    if (!bChecking)
    {
        bChecking = true;
        var frameid = getAttFrame();
        if (frameid >= 0 && frames[frameid] && frames[frameid].document && frames[frameid].document.getElementById("myFile") && (frames[frameid].document.getElementById("myFile").value != "" || frames[frameid].document.getElementById("myFile").text != ""))
        {
            result = false;
            if (bAllow) { result = confirm("There is a file waiting to be attached.\nYou may not have pressed the \"Attach\" button to attach your file to the message.\nAre you sure you would like to continue without attaching this file?"); }
            else { alert("There is a file waiting to be attached.\nPlease press the \"Attach\" button to attach your file before continuing."); }
            if (result) { frames[frameid].document.getElementById("myFile").value = ""; frames[frameid].document.getElementById("myFile").text = ""; }
        }
        bChecking = false;
    }
    else
    {
        result = false;
    }

    return result;
}

function getAttFrame()
{
    var frameid = -1;
    for (var i = 0; i < frames.length; i++)
    {
        if (frames[i].name == "attachment") { frameid = i; }
    }
    return frameid;
}

function getVar(sName)
{
    if (sName = (new RegExp('[?&]'+encodeURIComponent(sName)+'=([^&]*)')).exec(location.search))
    return decodeURIComponent(sName[1]);
}

function checkLogin()
{
    frames['content'].onbeforeunload = null;
    moveWait("hideall");
    frames['content'].location.href = "login.aspx?m=1";
}

function showMessage(iTime, iOpacity, sSuccess, sMessage, sSetup)
{
    if (sSetup == "Y")
    {
        if (sMessage != "" && sSuccess != "")
        {
            if (sSuccess == "TRUE")
            {
                document.getElementById('i-msgnotify').src = 'include/img/notify-success.jpg';            
                document.getElementById('i-msgnotify').alt = "Successful";
            }
            else if (sSuccess == "FALSE")
            {
                document.getElementById('i-msgnotify').src = 'include/img/notify-failed.jpg';        
                document.getElementById('i-msgnotify').alt = "Failed";
            }
            else if (sSuccess == "ALERT")
            {
                document.getElementById('i-msgnotify').src = 'include/img/notify-alert.jpg';        
                document.getElementById('i-msgnotify').alt = "Alert";
            }
            document.getElementById('i-msgnote').innerHTML = sMessage;
        }
        else
        {
            sSetup = "";
        }
    }

    if (sSetup != "")
    {
        if (iOpacity > 0)
        {
            document.getElementById('i-message').style.opacity = parseFloat(iOpacity / 100);
            document.getElementById('i-message').style.filter = "alpha(opacity=" + parseInt(iOpacity) + ")";
            document.getElementById('i-message').style.display = "block";
            tFailed = setTimeout("showMessage(" + parseInt(50) + "," + parseInt(iOpacity - 10) + ",'','','N');", iTime);
        }
        else
        {
            tFailed = null;
            document.getElementById('i-message').style.display = "none";
            document.getElementById('i-message').style.opacity = "1.0";
            document.getElementById('i-message').style.filter = "alpha(opacity=100)";
        }
    }
}

