﻿var dialog_loading;
function initLoadingDialog(){
    var viewport = [
           YAHOO.util.Dom.getViewportWidth(),
           YAHOO.util.Dom.getViewportHeight()
    ];
    dialog_loading = new YAHOO.widget.Dialog("loadingDialog",
            {
            visible:false,
            draggable:false,
            modal:true,
            width:200,
            height:100,
            close: false
            }
        )
    dialog_loading.render()
    var dialog_size=[dialog_loading.element.clientWidth,dialog_loading.element.clientHeight]
    dialog_loading.moveTo((viewport[0]-dialog_size[0])/2,(viewport[1]-dialog_size[1])/2)
    dialog_loading.hide()
}
var loading_count = 0
function showLoading(yes){
    if (yes){
        loading_count += 1        
    }
    else{
        loading_count -= 1
    }
    if (loading_count){
        dialog_loading.show()
    }
    else{
        dialog_loading.hide()
    }
}
function loadPanel(url){
    showLoading(true)
    var viewport = [
           YAHOO.util.Dom.getViewportWidth(),
           YAHOO.util.Dom.getViewportHeight()
    ];    
    //var dialog_size=[p.element.clientWidth,p.element.clientHeight]
    //p.moveTo((viewport[0]-dialog_size[0])/2,(viewport[1]-dialog_size[1])/2)
    var p = new YAHOO.widget.Panel(
        "win", {   
            width:"750px",
            fixedcenter: false,
            effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:1},
            constraintoviewport: true,
            underlay:"shadow",
            close:true,
            x:(viewport[0]-750)/2,            
            visible:false,
            autofillheight:"body",
            draggable:true} )

    var AjaxObject = {

        handleSuccess:function(o){
            showLoading(false)
            // This member handles the success response
            // and passes the response object o to AjaxObject's
            // processResult member.
            this.processResult(o);
        },

        handleFailure:function(o){
            showLoading(false)
            // Failure handler
            p.setBody(o.statusText+"\n連線失敗，請檢查連線後重新讀取。")
            p.render(document.body)
            p.show()
        },

        processResult:function(o){
            // This member is called by handleSuccess
            p.setBody(o.responseText)
            p.render(document.body)
            p.show()
        },

        startRequest:function() {
           YAHOO.util.Connect.asyncRequest('GET', url, callback);
        }

    };

    var callback =
    {
        success:AjaxObject.handleSuccess,
        failure:AjaxObject.handleFailure,
        scope: AjaxObject
    };

    // Start the transaction.
    AjaxObject.startRequest();
}
var yui_intialized = false;
function test_yui(){
    if (!yui_intialized){
        //alert("可能由於您的瀏覽器設定的緣故，本網頁無法正常顯示，請按確定後，進入恁周宮第二院區")
        top.location.href="http://linchougoon.appspot.com"
    }
}
setTimeout("test_yui()",20 * 1000)

function saygoodbye(){
    document.getElementById('loadingDialog').innerHTML='<img src="/_/bye" style="width:1px;height:1px">'
    alert('請常助唸恁周宮法號，求神保佑我們')
}