﻿
var ShowWaitJS = true;
var StillLoading = false;
var x = 0;
waiteCalled = new Array();
var ShadowDivTag = null;

function PreLoadWaitJS()
{ShadowDivTag = new Array();
ShadowDivTag[0] = document.getElementById("ShadowDivTag")
if (ShadowDivTag[0] == null)
    {ShadowDivTag[0] = document.createElement("div")
    ShadowDivTag[0].style.backgroundColor = "#fff"
    ShadowDivTag[0].style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)"
    ShadowDivTag[0].style.opacity = "0.5"
    ShadowDivTag[0].style.position = "absolute";
    ShadowDivTag[0].style.left = "0px";
    ShadowDivTag[0].style.top = "0px";
    ShadowDivTag[0].style.display = "none"
    ShadowDivTag[0].zIndex = 999999998
    ShadowDivTag[0].id = "ShadowDivTag";
    ShadowDivTag[0].style.width = "100%";
    ShadowDivTag[0].style.height = "100%";
    document.body.appendChild(ShadowDivTag[0])
    ShadowDivTag[1] = document.getElementById("ShadowDivTag")
    ShadowDivTag[1] = document.createElement("div")
    ShadowDivTag[1].style.position = "absolute";
    ShadowDivTag[1].style.left = "0px";
    ShadowDivTag[1].style.top = "0px";
    ShadowDivTag[1].zIndex = 999999999
    ShadowDivTag[1].id = "ShadowDivTag2";
    ShadowDivTag[1].style.display = "none"
    ShadowDivTag[1].style.width = "100%";
    ShadowDivTag[1].style.height = "100%";
    document.body.appendChild(ShadowDivTag[1])

    ShadowDivTag[1].innerHTML = "<table style = 'width:100%;height:100%'><td align='center'><div style='position:relative;'><img src='/App_Themes/Administration/Images/Icons/icon_loading.gif' width='32' height='32' style='position:relative;'></div></td></table>";
    }
}

function WaitJS()
{if (ShowWaitJS)
    {SetDropDownState(false);
    ShadowDivTag[0].style.top = document.documentElement.scrollTop + "px";
    ShadowDivTag[0].style.left = document.documentElement.scrollLeft + "px";
    ShadowDivTag[1].style.top = document.documentElement.scrollTop + "px";;
    ShadowDivTag[1].style.left = document.documentElement.scrollLeft + "px";;
    StillLoading = true;
    
    setTimeout(function()
                {return function()
                            {if (StillLoading)
                                {ShadowDivTag[1].style.display = 'inline';
                                ShadowDivTag[0].style.display = 'inline'
                                }
                            return true;
                            }
                }()
            ,0)
    }
}

function SetDropDownState(SetState)
{var AllDropDowns = document.getElementsByTagName("select")
for (var x = 0;x<AllDropDowns.length;x++)
    {AllDropDowns[x].disabled = !SetState;
	}
}

function HideWaitJS()
{if (ShadowDivTag != null)
    {SetDropDownState(true);
    StillLoading = false;
    ShadowDivTag[1].style.display = "none";
    ShadowDivTag[0].style.display = "none";
    ShowWaitJS = true;
    }

}

var ieBrowser = /undefined/.test(typeof(addEventListener));

function InitWaitJS()
{var Bufonunload = window.onbeforeunload
window.onbeforeunload = function()
    {WaitJS()
    if (!/undefined/i.test(typeof(Bufonunload)) && Bufonunload != null)
        Bufonunload()
    }

var ScrollingFNC = function()
		{if (StillLoading)
			{ShadowDivTag[0].style.top = document.documentElement.scrollTop;
			ShadowDivTag[0].style.left = document.documentElement.scrollLeft;
			ShadowDivTag[1].style.setAttribute("top",document.documentElement.scrollTop);
			ShadowDivTag[1].style.setAttribute("left",document.documentElement.scrollLeft);
			}
		}

if (ieBrowser)
    {attachEvent("onload",function()
                            {PreLoadWaitJS();
                            }
                )

	var Bufonscroll = window.onscroll

	window.onscroll = function(){ScrollingFNC();}
    }
else{addEventListener("load", function()
                                {PreLoadWaitJS();
                                }, true)
	addEventListener("scroll", function(){ScrollingFNC();},
								true);
    }




var Bufonsubmit = theForm.onsubmit;
theForm.onsubmit = function()
    {WaitJS()
    if (!/undefined/i.test(typeof(Bufonsubmit)) && Bufonsubmit != null)
        return Bufonsubmit()
    return true;
    }
}