﻿// <![CDATA[
var sLoadImage= "<img src='https://www.weiweitel.com/images/ajax-processing.gif' alt='Processing...' />";
var showLDiv = true;
var loaderDiv = "EmptyDiv";
var funcFinish = true;
var alertTimerId = 0;

function CallAnthem(methodName) 
{
    Anthem_InvokePageMethod(
        methodName,
        ['', ''],''
    ); 
}

function CallAnthem(methodName, showDiv) 
{
    showLDiv = showDiv;
    Anthem_InvokePageMethod(
        methodName,
        ['', ''],''
    ); 
}

function CallAnthemText(methodName, keyCode, val) 
{
    if (val.length > 0 && ((keyCode > 40) || (keyCode == 8)) ) 
    {
        clearTimeout(alertTimerId);
        alertTimerId = setTimeout("Anthem_InvokePageMethod('" + methodName + "', ['', ''],'')", 1000);
    }
}

function CallAnthemWLoader(methodName, div) 
{
    funcFinish = false;
    if (div != '') loaderDiv = div;   
    showLoader();
    Anthem_InvokePageMethod(
        methodName,
        ['', ''],
        function(result) 
        {
            hideLoader();
        }
    );
}

function CallAnthemWLoader2(methodName, div, param1) 
{
    funcFinish = false;
    if (div != '') loaderDiv = div;   
    showLoader();
    Anthem_InvokePageMethod(
        methodName,
        [param1, ''],
        function(result) 
        {
            hideLoader();
        }
    );
}


function SetLoaderDiv(div)
{
    loaderDiv = div;
}

function asbNumber_PreCallBack()
{
    alert("This happens before contacting the server");
} 

 
function DisableLoade()
{
    showLDiv = false;
}

function Anthem_PreCallBack() 
{
    if (showLDiv)
        showLoader();
    else
        showLDiv = true;
}
    
function Anthem_PostCallBack() 
{
    hideLoader();
}
 
function showLoader() {

    var LoaderPos;
    
    if (document.getElementById(loaderDiv) == null)
        LoaderPos = findElementPos(document.getElementById("EmptyDiv"));
    else
        LoaderPos = findElementPos(document.getElementById(loaderDiv));
        
    loaderDiv = "EmptyDiv";
        
    var xPos = LoaderPos[0]; 
    var yPos = LoaderPos[1];
    var loading = document.createElement("div");
    //alert("x:" + xPos + " y:" + yPos + " object coords: " + LoaderPos[2]);
    loading.id = "loadingGlobal";
    loading.className = "ajax_circle";
    //loading.style.backgroundColor = "#fff";
    loading.style.position = "fixed";
    loading.style.right = (xPos + 100) + "px";
    loading.style.top = (yPos + 100) + "px";
    loading.style.textAlign = "center";
    loading.style.zIndex = "1003";
    loading.style.width = "140px";
    loading.style.height = "140px";
//    if (LoaderPos[2]) // check if the coordinates are of "eventsPlace" otherwise use the window size plue scroll
//    {
//        loading.style.left = (xPos+200 > 400 ? 400 : xPos+250) + "px";
//        loading.style.top = (yPos < 350 ? 350 : yPos) + "px";
//    }
//    else
//    {
//        loading.style.left = (xPos-100) + "px";
//        loading.style.top = (yPos-100) + "px";
//    }

    loading.innerHTML = sLoadImage;
    document.body.appendChild(loading);
    
    funcFinish = true;
}

function hideLoader() 
{
    var loading = document.getElementById("loadingGlobal");
    if (loading != null)
    {
        document.body.removeChild(loading);
    }
}

function findElementPos(obj)

{

    var curleft = curtop = 0;

    var viewable;

    var bObjectPosSet= false;

 

    if (obj)

    {

        if (obj.offsetParent)

        {

            curleft = obj.offsetLeft

            curtop = obj.offsetTop

            while (obj = obj.offsetParent) {

                  curleft += obj.offsetLeft

                  curtop += obj.offsetTop

            }

            bObjectPosSet= true;

        }

    }

    else

    {   // Get the x and y of the current window

        viewable= getViewableScreen();

        curleft= viewable[0]/2 + viewable[2];

        curtop= viewable[1]/2 + viewable[3];

    }

    //alert("findelementpos x:" +  viewable[0] + " y:" + viewable[1]);

    

    return [curleft,curtop,bObjectPosSet];

}

 

function getViewableScreen()

{

    var height;

    var width;

    var scrollX;

    var scrollY;

    

    if (self.innerWidth)

    {   //Non-IE

        width = self.innerWidth;

        height = self.innerHeight;

        scrollX = self.pageXOffset;

          scrollY = self.pageYOffset;

    } 

    else if (document.documentElement && document.documentElement.clientWidth)

    {   //IE 6 'strict mode'

        width = document.documentElement.clientWidth;

        height = document.documentElement.clientHeight;

        scrollX = document.documentElement.scrollLeft;

        scrollY = document.documentElement.scrollTop;

    }

    else if (document.body)

    {   //other IE

        width = document.body.clientWidth;

        height = document.body.clientHeight;

        scrollX = document.body.scrollLeft;

        scrollY = document.body.scrollTop;

    }

    

    return [width,height,scrollX,scrollY];

}
    // ]]>
