var submitSend = false;

function fnForm() {

    theForm = window.document.forms["Form1"];
    if (theForm == null) {
        theForm=window.document.forms["aspnetForm"]
    }
    if (theForm == null) {
       theForm= document.getElementById("Form1")
   }
   if (theForm == null) {
       theForm = document.getElementById("aspnetForm")
   }
    return theForm;
}

function fnDisableForm(bMakeDisable) 
{
	var i;
	var theForm;
	var nbElements;
	
	

	/*if ( typeof(Page_ValidationVer) != "undefined" )
	{
		alert("Page_IsValid="+Page_IsValid);
	}
	*/
	if ( typeof(Page_ValidationVer) != "undefined" && ! Page_IsValid && bMakeDisable)
	{
		return;
	}


	theForm = fnForm();
	nbElements=theForm.elements.length;

	for ( i=0; i<nbElements;i++)
	{
		theForm.elements[i].disabled=bMakeDisable;
	}
}

function fnDisableLinks()
{
	if ( typeof(Page_ValidationVer) != "undefined" && ! Page_IsValid )
	{
		return;
	}
	var i;
	var nbElements;
	nbElements=window.document.links.length;
	for ( i=0; i<nbElements;i++)
	{
		window.document.links[i].href="#";
	}
}

function fnDisableFormCallBack()
{
	// Pas form et pas link
	if ( ! submitSend && ! fnIsPostBack() )
	{
		return;
	}
	var timeOut=10;
/*
	if ( typeof(Page_ValidationVer) != "undefined" )
	{
		timeOut=2000;
	}
*/

	setTimeout("javascript:fnDisableForm(true);fnDisableLinks();",timeOut);
	callHideProceed();
}

function fnEnableFormCallBack()
{
	// si  form ou link
	if ( submitSend || fnIsPostBack() )
	{
		return;
	}
	var timeOut=10;
	/*
	if ( typeof(Page_ValidationVer) != "undefined" )
	{
		timeOut=2000;
	}
	*/
	setTimeout("javascript:fnDisableForm(false);",timeOut);
}

function fnIsPostBack()
{
	var theForm;
	var eventTarget;

	theForm = fnForm();
	eventTarget = theForm.elements["__EVENTTARGET"];
	//alert("fnIsPostBack");
	if ( eventTarget==null )
	{
		return false;
	}
	else if ( eventTarget.value!="" )
	{
		return true;
	}
	else
	{
		return false;
	}
}

//window.document.body.onbeforeunload=fnDisableFormCallBack;
//window.document.body.onfocus=fnEnableFormCallBack;

function callHideProceed()
{
	var timeOut=200;
	setTimeout("javascript:hideProceed();",timeOut);
}
function hideProceed()
{
//return;
	//alert("hideProceed:typeof(Page_ClientValidate)="+typeof(Page_ClientValidate));
	if (typeof(Page_ClientValidate) == 'function' )
	{
		//Page_ClientValidate();
		if(Page_IsValid)
		{
			doTransition();
		}
		else
		{
			//alert("Not valid");
		}
	}
	else 
	{

		doTransition();
		//alert("Pas de controle");
	}
}

function doTransition() {

        //alert("doTransition");
		//document.location.href='#';
        var theForm =  fnForm();
		var theContenu=document.getElementById("HiddenTransition");
		var theTransition = document.getElementById("Transition");
		//alert(theForm!=null?"FORM OK":"FORM KO");
		//alert(theContenu != null ? "theContenu OK" : "theContenu KO");
		//alert(theTransition != null ? "theTransition OK" : "theTransition KO");

		if ( theForm == null 
		 || theContenu==null 
		 || theTransition==null )
		{
			return;
		}
		theForm.target = "_top";
		theContenu.style.display="none";
		theTransition.style.display = "block";
		theForm.style.cursor = "wait";		
}
//alert("typeof(Page_ClientValidate)="+typeof(Page_ClientValidate));