//###assign events to the beginning and ending of a REQUEST
try{	
	Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}catch(e){ 
	throwException( '_post_async.js : Sys.WebForms.PageRequestManager...', e.lineNumber, e, e.message ); 
}

//###the id of the OBJECT sending the REQUEST
var pbObj = null;
function BeginRequestHandler(sender, args)
{
	try{
		pbObj = args.get_postBackElement(); //###assign the firing element to the global variable pbObj		
		//ActivateAlertDiv('visible', 'error_div', pbObj.id + ' processing...');
		
	}catch(e){ 
		throwException( '_post_async.js : BeginRequestHandler()', e.lineNumber, e, e.message ); 
	}
}

function EndRequestHandler(sender, args)
{
	try{	
		//ActivateAlertDiv('visible', 'error_div', '');
		//setTimeout( "ActivateAlertDiv('hidden', 'error_div', '')", 1000 );
		
		//###let's run our usual afterTheRequest(), post async process
		afterTheRequest();
	}catch(e){ 
		throwException( '_post_async.js : EndRequestHandler()', e.lineNumber, e, e.message ); 
	}
}

function ActivateAlertDiv(visstring, elem, msg)
{
	try{	
		var adiv = $get(elem);
		adiv.style.visibility = visstring;
		adiv.innerHTML = msg;                     
	}catch(e){ 
		throwException( '_post_async.js : ActivateAlertDiv()', e.lineNumber, e, e.message ); 
	}
}


function afterTheRequest(){
	try{	
		
		switch( pbObj.id ){
			
			case return_visitor_button_id:
			case new_visitor_button_id:
			
				if( getObject( prefix+"Label1" ).innerHTML.indexOf("<span") == -1 ){
					setTimeout( function(){ window.location=location.href; }, 3000 );
				}
				
			break;
			
		}
		
	}catch(e){ 
		throwException( 'post_async.js : afterTheRequest()', e.lineNumber, e, e.message ); 
	}
}
