function Query(page, queryType, field, aValue)
{
    var value = ( aValue == null )
        ? ""
        : trimAll( aValue );
        
    if ( value.Length == 0 )
        return;
    
	var separator = "$";
	
	var url = page.concat("?query=", queryType, separator, field, separator, URLEncode( value ) );
	
	window.location.href = url;
}

function ParseQuery(page, key, filter, field, aValue)
{
    var value = ( aValue == null )
        ? ""
        : trimAll( aValue );
    
    if ( value.Length == 0 )
        return;
        
	var url = null;
	
	switch ( field )
	{
	    case null:
	    case "":
    	    field = "all";
	    break;
	    
	    case "FamilyFL":
	        field = "Family";
	    break;
	    
	    case "LegalNameFL":
	        field = "LegalName";
	    break;
	        
	    case "TitleFL":
	        field = "Title";
	    break;
	}
	
	switch (filter)
	{
		case null:
			url = page + "?query=ParseQuery$" + field + "$" + URLEncode( value );
			break;
			
		default:
			url = page + "?query=ParseQuery$" + field + "$" + URLEncode( value ) + "%7C" + filter;
			break;
	}

	window.location.href = url;
}

function URLEncode(value)
{
	return escape(value).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
}

// Function from http://www.aspdev.org/articles/javascript-trim/
function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }

    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    
    return sString;
}

function SetFocus()
{
	if (document.forms[0])
	{
		var form = document.forms[0];
		var length = form.elements.length;
		
		var count = 0;
		
		for (i = 0; i < length; i++)
		{
			var element = form.elements[i];
			if ( ( ( element.type == "text" && element.id != "dummy") || element.type == "password" ) && element.id != "quickquery")
			{
			    count++;
			    element.focus();
			    
			    if ( count == 1 )
    			    break;
			}
		}
	}
}

function whatbrowser()
{
	var intBrowser = 0; // IE and generic browsers.

    if (document.layers)
	    intBrowser = 1; // Netscape Navigator 4.
    else
	    if (!document.all && document.getElementById)
		    intBrowser = 2; // Recent Netscape Navigators and FireFoxes.
	
	return intBrowser;
}
	

function CallPage()
{
    var callingMethod = whatbrowser();
    var xmlhttp = null ;
    
    switch ( callingMethod )
    {
        case 0:
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        break;
        
        default:
            xmlhttp = new XMLHttpRequest();
        break;
    }

    if ( xmlhttp != null )
    {
        xmlhttp.open( "GET", "/KeepAlive.aspx", false );
        xmlhttp.send( null );
    }
}

//  =============================== Email obfuscator ===============================
	// Email obfuscator script 2.1 by Tim Williams, University of Arizona
	// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
	// This code is freeware provided these four comment lines remain intact
	// A wizard to generate this code is at http://www.jottings.com/obfuscator/
	
	
function EmailObfuscator(coded, key)
{
	var shift = coded.length ;
	var link = "" ;

	for ( i = 0 ; i < coded.length ; i++ )
	{
		var c = coded.charAt(i) ;
		
    	if ( key.indexOf( c ) ==-1 )
			link += c ;
		else
		{     
			var ltr = ( key.indexOf( c ) - shift + key.length ) % key.length ;
			link += key.charAt(ltr) ;
		}
	}
	
	document.write( "<a href='mailto:" + link + "'>" + link + "</a>" );
}

function OnLoadProcedures()
{
	SetFocus();
	window.setInterval( "CallPage()", 60000 * 10 );
}

window.onload = OnLoadProcedures;