function parseQueryString( aQueryString )
{
    var theNameValuePairs = aQueryString.replace('?', '').split('&');
    var theDict = new Array();
    for (i = 0; i < theNameValuePairs.length; i++)
    {
        var theNameValuePair = theNameValuePairs[i].split('=');
        theDict[theNameValuePair[0]] = theNameValuePair[1];
    }
    return theDict;
}

function fullyDecodeUriComponent( aUriComponent )
{
    var theDecodedValue = aUriComponent.replace( /\+/g, " " );
    return decodeURIComponent( theDecodedValue );
}

function trim( aString )
{
   var theRegExp = /^\s+|\s+$/g;
   return aString.replace( theRegExp, "" );
}

function isValidEmailAddress( anEmailAddressString )
{
	var theValidationRegExp = /^[\w-\.]{1,}@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
	return theValidationRegExp.test( anEmailAddressString );
}

function findFirstInvalidEmailAddress( aMultipleEmailAddressString )
{
	var theRecipientList = aMultipleEmailAddressString.split( /[;,]/g );
    for( var i=0; i < theRecipientList.length; i++ )
    {
        var theRecipient = trim( theRecipientList[i] );
        if ( theRecipient != "" && !isValidEmailAddress( theRecipient) )
        {
            return theRecipient;
        }
    }
	return null;
}

function findFirstValidEmailAddress( aMultipleEmailAddressString )
{
	var theRecipientList = aMultipleEmailAddressString.split( /[;,]/g );
    for( var i=0; i < theRecipientList.length; i++ )
    {
        var theRecipient = trim( theRecipientList[i] );
        if ( theRecipient != "" && isValidEmailAddress( theRecipient) )
        {
            return theRecipient;
        }
    }
	return null;
}

function getCountOfValidEmailAddresses( aMultipleEmailAddressString )
{
	var theNumberOfAddresses = 0;
	var theRecipientList = aMultipleEmailAddressString.split( /[;,]/g );
    for( var i=0; i < theRecipientList.length; i++ )
    {
        var theRecipient = trim( theRecipientList[i] );
        if ( theRecipient != "" && isValidEmailAddress( theRecipient) )
        {
            theNumberOfAddresses++;
        }
    }
	return theNumberOfAddresses;
}