// place any scripts here that you want to define near the end of the Default.aspx output

var __oldDoPostBack = null;

if(typeof __doPostBack != "undefined")
{
    // Save a reference to the original __doPostBack
    __oldDoPostBack = __doPostBack;

    // Replace __doPostBack with custom function
    __doPostBack = iCPostBack;
}

function iCPostBack(eventTarget, eventArgument) 
{
    if (typeof g_fFieldsChanged != 'undefined' && g_fFieldsChanged != 'undefined') 
		if (g_fFieldsChanged > 0)
			document.Form.iCFieldsChanged.value ++
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) 
    {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
        	theForm.submit();
        	
        	BlockInput();
    }
 	else
 	{
		// The postback did not occur due to clientside validators
		// reset executingPostBack = false;
		executingPostBack = false;
 	}
}

// This function sets a flag that blocks any user input after
// a postback has been initiated.
function BlockInput()
{
    // Remove any pre-set key events from all elements on the page, ie. hotkeys.
	var allElems = document.body.getElementsByTagName('*');	
    for (var i=0; i<allElems.length; i++)
    {
	    allElems[i].onkeydown = null;
        allElems[i].onkeypress = null;
        allElems[i].onkeyup = null;           
    }	
	
	// Set flag which will display a pop-up warning message if the user
	// attempts to click or press a key after a postback has started.
    blockUserInput = true;   
}