/(https?:\/\/.+?\/.+?\/)/.test(window.location);
var root = RegExp.$1;
window.Page = new Object();
window.Page.EnableLoadingForm     = true;
window.Page.LoadingForm           = document.createElement("table");
if (document.all)
{
	window.Page.LoadingForm.style.position = "absolute";
	window.Page.LoadingForm.style.height = document.documentElement.clientHeight + "px";
}
window.Page.LoadingForm.className = "WaitingPage";
window.Page.LoadingForm.Image     = document.createElement("img");
window.Page.LoadingForm.Image.src = root + "controls/images/progress.gif";

var tbody = document.createElement("tbody");
var tr    = document.createElement("tr");
var td    = document.createElement("td");
td.appendChild(window.Page.LoadingForm.Image);
tr.appendChild(td);
tbody.appendChild(tr);
window.Page.LoadingForm.appendChild(tbody);


window.Page.Submit = function()
{
	window.onkeypress = function(e)
	{
		if (!e)
		{
			e = window.event;
		}
		if (e.keyCode != 27)
		{
			return false;
		}
		document.body.removeChild(window.Page.LoadingForm);
	};
	if (window.Page.EnableLoadingForm)
	{
	    if (window.Page.LoadingForm.position == "absolute")
	    {	
		    window.Page.LoadingForm.left = document.documentElement.scrollLeft + "px";
		    window.Page.LoadingForm.top  = document.documentElement.scrollTop  + "px";
	    }
	    document.body.appendChild(window.Page.LoadingForm);	
	    window.Page.DisableControls();
	}	
}
window.Page.DisableControls = function()
{
	var inputs = document.getElementsByTagName("input");
	for(var i = 0; i < inputs.length; i++)
	{
		inputs[i].blur();
	}
}
window.Page.NoBack = function(e)
{
	if (e == null)
	{
		e                = window.event;
		e.which          = e.keyCode;
		e.target         = e.srcElement;
		e.preventDefault = function(){window.event.returnValue = false;window.event.cancelBubble = true;};
	}
	if (e.which == 37 && e.altKey)
	{
		e.preventDefault();
		window.Page.CancelButton.click(); 
	}
	else if (e.which == 8)
	{
		var tag = e.target.tagName.toLowerCase();
		switch (tag)
		{
			case "textarea": return true;
			case "input":    return e.target.type == "text";
			default:         
				e.preventDefault();
				window.Page.CancelButton.click();
		}
	}
};
window.Page.SetHandlers = function()
{
	if (typeof(window.Page.CancelButton) == "string")
	{//Looking for specified cancel button.
		window.Page.CancelButton = document.getElementById(window.Page.CancelButton);
	}
	if (!window.Page.CancelButton)
	{//if no cancel button is present set a default action.
		window.Page.CancelButton = {"click":function(){}};
	}
	//Update handler.
	if (document.all)
	{
		document.onkeydown = window.Page.NoBack;
	}
	else
	{
		document.onkeydown  = window.Page.NoBack;
		document.onkeypress = window.Page.NoBack;
	}
	//disable context menu.
	document.oncontextmenu = function(e)
	{
		if (!e) e = window.event;
		if (e.ctrlKey)
		{
			return true;
		}
		else
		{
			return false;
		}
	};
	UpdateReadOnlyStatus();
 
    //Pour empêcher l'affichage du WAITINGPAGE avec AJAX
    //begin
    try
    {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(function()
        { 
	        try {document.body.removeChild(window.Page.LoadingForm);} catch(ex) {}
        });
        prm.add_initializeRequest(function()
        { 
	        try {document.body.removeChild(window.Page.LoadingForm);} catch(ex) {}
        });        
    }
    catch(ex) {}	
    //end
}
function UpdateReadOnlyStatus()
{
	var inputs = document.getElementsByTagName("input");
	for(var i = 0; i < inputs.length; i++)
	{
		if (inputs[i].readOnly)
		{
			inputs[i].className += " readonly";
		}
	}
	inputs = document.getElementsByTagName("textarea");
	for(var i = 0; i < inputs.length; i++)
	{
		if (inputs[i].readOnly)
		{
			inputs[i].className += " readonly";
		}
	}
}
if (document.all)
{
	window.attachEvent("onload", window.Page.SetHandlers);
}
else
{
	window.addEventListener("load", window.Page.SetHandlers, false);
}
//Attach animation on submit method...
var form = document.forms[0];
if (form)
{
	form.initialSubmit = form.submit;
	form.submit = function()
	{
		window.Page.Submit();
		this.initialSubmit();
	};
}
