﻿var ShowAjaxNoticeCounter = 0;// a counter of calls that called ShowAjaxNotice
var asyncCounter = 0; // a counter of outstanding async calls
var waitScript = new Array(); // array to hold ajax calls that need to wait until the async counter = 0
                        // or until blocked = false;
					    // all async ajax calls will increment and decrement the counter,
					    // the ajax call that returns to find the counter at 0 will eval(waitScript.shift())
var blocked = false;
var redirectWaiting = ''; // this string will hold a redirecting window.location (HREF)

// google analytics code
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20123877-3']);
  _gaq.push(['_setDomainName', '.portal.admailwest.com']);
	_gaq.push(['_setAllowHash', false]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
  
// end of google analytics code
  
function ShowAjaxNotice(message,big)
{
	ShowAjaxNoticeCounter += 1;
	if(big==true)
	{
	    // only show the big notice, hide the small one
		document.getElementById('AjaxNotice').style.visibility='hidden';
		document.getElementById('AjaxNoticeBig').style.visibility='visible';
		document.getElementById('AjaxNoticeBig').style.top=document.body.scrollTop + 200;
		document.getElementById('AjaxNoticeMessage').innerHTML=message; 
		document.getElementById('AjaxNoticeMessage').style.visibility='visible'; 
		document.getElementById('AjaxNoticeMessage').style.top=document.body.scrollTop + 140;
	}
	else
	{
		if(document.getElementById('AjaxNoticeBig').style.visibility!='visible')
		{
			document.getElementById('AjaxNotice').style.visibility='visible';
			document.getElementById('AjaxNotice').style.top=document.body.scrollTop + 248;
		}
	}
}
function TestForSubmit()
{
	var x=document.getElementById('form1'); 
	for (var i=0;i<x.length;i++) 
	{ 
		if(x.elements[i].name == "__EVENTTARGET")
		{
			return false;
		}
		return true;
	}
}

// Build an empty URL structure in which we will store
// the individual query values by key.
var objURL = new Object();

// Use the String::replace method to iterate over each
// name-value pair in the query string. Location.search
// gives us the query string (if it exists).
window.location.search.replace(
	new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
	// For each matched query string pair, add that
	// pair to the URL struct using the pre-equals
	// value as the key.
	function( $0, $1, $2, $3 )
	{
		objURL[ $1 ] = $3;
	}
);        

// this intercepts the previous submitUpdate, allowing for a wait setting
// that will wait/block until all other async scripts are finished
// wait and block are now combined
function submitUpdate(arg, context, message, block) 
{ 
    var firstBlock = false;

    if(message == null)
        message = '';

    if(block == null || block == '' || typeof(block) != 'boolean')
        block = false;

    if(block && !blocked)
    {
        firstBlock = true;
        blocked = true;            
    }

    if(!firstBlock && (blocked || (asyncCounter > 0 && block)))
	    waitScript.push('submitUpdate(\'' + arg + '\', \'' + context + '\', \'' + message + '\', ' + block + ');');
    else
    {	   
        // submit the ajax call.  Increment the outstanding ajax call counter (asyncCounter) and display any 
        // necessary message.
	    asyncCounter += 1;
	    if(message == null || message == '') 
		    ShowAjaxNotice('',false);
	    else 
		    ShowAjaxNotice(message ,true);

	    submitAJAXUpdate(block + '|' + arg, context);
    }

} 

