﻿function dupName(id)
{
    var lastname = document.getElementById('lastname');
    var firstname = document.getElementById('firstname');
    var proname = document.getElementById('proname');
    var prowebsite = document.getElementById('accountAlias');
    var type1 = document.getElementById('type1');
    var type3 = document.getElementById('type3');
    var type4 = document.getElementById('type4');
    var type5 = document.getElementById('type5');

    if (prowebsite != null)
    {
        if (type3.checked == false && type4.checked == false  && type5.checked == false )
        {
            prowebsite.value = NormalizeName(lastname.value + firstname.value);
        }
        else
        {
            if ((proname == null || proname.value == ""))
                prowebsite.value = NormalizeName(lastname.value + firstname.value);
			else
                prowebsite.value = NormalizeName(proname.value);
        }
    }
}

function NormalizeName(input)
{
    var intIndexOfMatch;
    var output = input.toLowerCase();
    
    while ((intIndexOfMatch = output.indexOf('é')) != -1)
        output = output.replace('é', 'e');

    while ((intIndexOfMatch = output.indexOf('è')) != -1)
        output = output.replace('è', 'e');

    while ((intIndexOfMatch = output.indexOf('ê')) != -1)
        output = output.replace('ê', 'e');

    while ((intIndexOfMatch = output.indexOf('ë')) != -1)
        output = output.replace('ë', 'e');

    while ((intIndexOfMatch = output.indexOf('à')) != -1)
        output = output.replace('à', 'a');

    while ((intIndexOfMatch = output.indexOf('â')) != -1)
        output = output.replace('â', 'a');

    while ((intIndexOfMatch = output.indexOf('ä')) != -1)
        output = output.replace('ä', 'a');

    while ((intIndexOfMatch = output.indexOf('î')) != -1)
        output = output.replace('î', 'i');

    while ((intIndexOfMatch = output.indexOf('ï')) != -1)
        output = output.replace('ï', 'i');

    while ((intIndexOfMatch = output.indexOf('ô')) != -1)
        output = output.replace('ô', 'o');

    while ((intIndexOfMatch = output.indexOf('ö')) != -1)
        output = output.replace('ö', 'o');

    while ((intIndexOfMatch = output.indexOf('ù')) != -1)
        output = output.replace('ù', 'u');

    while ((intIndexOfMatch = output.indexOf('û')) != -1)
        output = output.replace('û', 'u');

    while ((intIndexOfMatch = output.indexOf('ü')) != -1)
        output = output.replace('ü', 'u');

    myRe= new RegExp ("[^a-z0-9]", "g");
    output = output.replace(myRe, '');

    return output;
}

