﻿var _LoginOK = false, _Logout = false;
//function SetLogin(value) {
//    _LoginOK = value == "true" ? true : false;
//}
//Gadget Javascript
var GadgetGuid = "";
function GetGadgetGuid() {
    return GadgetGuid;
}
function SetGadgetGuid(guid) {
    GadgetGuid = guid;
}
//RunActiveObj--Soung
function SetRunActiveObj(guid) {
    if (this.parent != null)
    { this.parent.RunActiveObj = guid; }
}
function GetRunActiveObj() {
    return RunActiveObj;
}
//Sliverlight Control Loaded
var ContentLoaded = false;
function SetContentLoaded() {
    ContentLoaded = true;
}
function GetContentLoaded() {
    return ContentLoaded;
}
function GetContentUri() {
    return location.href;
}
function SetContent(cGuid) {
    ContentLoaded = false;
    slObj.content.ContentPage.SetContent(cGuid);
}
//for CachePage
function SelectContent(cGuid) {
    slObj.content.ContentPage.SelectContent(cGuid);
}
//for Olap link
function OlapLink(cUrl, params, cOption) {
    WindowOpen(cUrl, cOption, "", true, params);
}
//===========================================================================
// Window.Open
//===========================================================================
var wDict = new Dictionary();
function WindowOpen(cUrl, cOption, title, bPost, params) {
    if (cUrl.toLowerCase().indexOf(".gadget") > -1) {
        var div = document.getElementById('DownloadActionFrame');
        div.innerHTML = '<iframe name="downloadCount" frameborder="0" scrolling="no" width="0px" style=" height:0px" src="' + cUrl + '"></iframe>';
    }
    else {
        if (cOption == "" || cOption == undefined) {
            cOption = "top=10,left=10,height=650px,width=940px,directories=0,location=1,menubar=0,scrollbars=1,status=0,toolbar=0,titlebar=0,resizable=1";
        }
        if (title == "" || title == undefined) {
            //title = "OpenWindow";
            var d = new Date();
            title = d.getTime();
        }
        if (bPost || bPost == "true") {//Use Post
            var w = window.open(GetServerUrl() + "PostUrl.htm", title, cOption);
            var wParam = new WindowParam(w, cUrl, params);
            wDict.Add(title, wParam);
            TimeoutWindowOpen(title);
        }
        else
            window.open(cUrl, title, cOption);
    }
}
//WindowOpen Parameter Object
function WindowParam(w, url, params) {
    this.Window = w;
    this.Url = url;
    this.Params = params;
    this.CanPost = function() {
        if (this.Params == null)
            return this.Window.PostUrl;
        else
            return this.Window.PostUrlAndParam;
    }
    this.DoPost = function() {
        if (this.Params == null)
            this.Window.PostUrl(this.Url);
        else
            this.Window.PostUrlAndParam(this.Url, this.Params);
    }
}
function TimeoutWindowOpen(title) {
    //WindowParam
    var wParam = wDict.Lookup(title);
    if (wParam.CanPost()) {
        wParam.DoPost();
        wDict.Delete(title);
    }
    else
        setTimeout("TimeoutWindowOpen('" + title + "')", 100);
}
//-----Olap Editor-----
var olapList = new Array();
function CallOlapEditor(cGuid, cCaption) {
    for (var i = 0; i < olapList.length; i++) {
        var olapWin = olapList[i];
        if (olapWin.Guid == cGuid) {
            olapWin.Window.focus();
            return;
        }
    }
    var server = GetServerUrl();
    //var server = location.href.replace(location.search, "");
    //server = server.substring(0, server.lastIndexOf("/"));
    var cOption = "top=10,left=10,height=650px,width=940px,directories=0,location=1,menubar=0,scrollbars=0,status=0,toolbar=0,titlebar=0,resizable=1";
    var olapWin = new Object();
    olapWin.Guid = cGuid;
    olapWin.Window = window.open(server + "/OlapDesigner.aspx?Guid=" + cGuid + "&Caption=" + escape(cCaption) + "&Version=Silverlight&ServerUrl=" + encodeURIComponent(server), "_blank", cOption);
    while (olapWin.Window.document.body == null) {
    }
    olapWin.Window.document.body.onbeforeunload = function() { RefreshOlapDataSource(cGuid); }
    olapList.push(olapWin);
}
function RefreshOlapDataSource(cGuid) {
    for (var i = 0; i < olapList.length; i++) {
        var olapWin = olapList[i];
        if (olapWin.Guid == cGuid) {
            olapList.splice(i, 1);
            break;
        }
    }
    slObj.content.ContentPage.RefreshOlapDataSource(cGuid);
}
//-----Olap Editor-----
function Logout() {
    _Logout = true;
    location.reload(true);
}
//重新回到登入畫面(註冊畫面使用)
function Login() {
    alert("Registered successfully.");
    location.href = "Default.aspx";
}
//AD登出時使用
function WindowClose() {
    window.close();
}
function EmbedSmartQueryPage(cPageGuid, cCaption, cFolderAccount, cSessionID) {
    var cURL = location.href.replace(location.search, "") + "?Layout=View&PageGuid=" + cPageGuid + "&UserID=" + cFolderAccount + "&SessionID=" + cSessionID;
    parent.newQuery(cCaption, cURL, "0", true);
}
window.onbeforeunload = function() {
    //if (_LoginOK) {
    //        if (!slObj.content.ContentPage.CheckPageSaved()) {
    //            return slObj.content.ContentPage.CheckPageSavedMessage();
    //        }
    try {
        var time = slObj.content.ContentPage.BrowserOnBeforeUnload();
        clearAllFrame();
        var url = "Logout.aspx?Time=" + time;
        if (_Logout) url += "&Logout=true";
        window.showModalDialog(url, "Logout", "dialogHeight: 0px; dialogWidth: 0px; dialogTop: 10000px; dialogLeft: 10000px; edge: Raised; center: No; help: No; resizable: No; status: No;");
    }
    catch (e) {
        //alert("Logout failed.\n\nPlease disable Pop-up Blocker.");
    }
    //}
}
function MailToLC() {
    window.location.href = "mailto:SmarteVision@lcnet.com.tw?Subject=Smart-eVision for Microsoft Showcase";
}
function PassAjaxService(command, params, key, isCallback) {
    callAjaxService(command, params, key, isCallback == "true" ? AjaxCallback : null, window, "AjaxService.aspx");
}
function AjaxCallback(xml) {
    slObj.content.ContentPage.AjaxCallback(xml);
}
//CachePage
var cacheObj;
function InitCache() {
    var obj = document.createElement("object");
    document.body.appendChild(obj);
    obj.outerHTML =
    "<object id='cachOCX' classid='clsid:80ED9ACB-CCA8-4A91-B52E-DE78BDC16616'" +
        "codebase='CachePage.ocx#version=1,0,17,3' style='display:block;height:10px;width:10px;left:10px;top:10px;position:absolute;visibility:hidden'>" +
    "</object>";
    cacheObj = document.getElementById("cachOCX");
}
function ClearCache() {
    document.body.removeChild(cacheObj);
    cacheObj = null;
}
function RefreshCache(left, top, width, height) {
    if (cacheObj == null) return;
    cacheObj.style.left = left + "px";
    cacheObj.style.top = top + "px";
    cacheObj.style.width = width + "px";
    cacheObj.style.height = height + "px";
}
//not for firefox
function AddCache(id, url) {
    try {
        cacheObj.AddUrl(id, url);
    }
    catch (e) {
        setTimeout("AddCache('" + id + "','" + url + "');", 100);
    }
}
//not for firefox
function SelectCache(id) {
    cacheObj.SelectUrl(id);
}
function VisibleCache(value) {
    if (value == "true")
        cacheObj.style.visibility = "visible";
    else
        cacheObj.style.visibility = "hidden";
}
function CachePage(x, y, w, h, file) {
    setTimeout("DoCachePage(" + x + "," + y + "," + w + "," + h + ",'" + file + "');", 100);
}
function CacheWeb(id, file) {
    setTimeout("DoCacheWeb('" + id + "','" + file + "');", 100);
}
//確保頁面讀取完整
//not for firefox
function DoCachePage(x, y, w, h, file) {
    var img = cacheObj.SaveWindow(window, x, y, w, h);
    slObj.content.ContentPage.SaveCacheImage(img, file);
}
function DoCacheWeb(id, file) {
    var img = cacheObj.SaveUrl(id);
    slObj.content.ContentPage.SaveCacheImage(img, file);
}