function parseQueryString( aQueryString )
{
    var theNameValuePairs = aQueryString.replace('?', '').split('&');
    var theDict = new Array();
    for (i = 0; i < theNameValuePairs.length; i++)
    {
        var theNameValuePair = theNameValuePairs[i].split('=');
        if(theNameValuePair.length > 1)
        {
            theDict[theNameValuePair[0]] = theNameValuePair[1];
        }
        else
        {
            theDict[theNameValuePair[0]] = "";
        }
    }
    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 )
{
//^[\\w-\\.!#\\$%&'\\*\\+\\-/=\\?\\^_`\\{\\}\\|~]{1,}@([\\da-zA-Z-]{1,}\\.){1,}[\\da-zA-Z-]{2,6}$
    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;
}
