function windows_live_hotmail_yahoo_mail_gmail_on_click(emailservice) {
    var input;

    input = document.createElement('input');
    input.type = 'hidden';
    input.name = 'import';
    document.getElementById('invite').appendChild(input);
    input = document.createElement('input');
    input.type = 'hidden';
    input.name = 'emailservice';
    input.value = emailservice;
    document.getElementById('invite').appendChild(input);

    document.getElementById('invite').submit();
}

function select_all_name_emails() {
    for (n = contacts.length, i = 0; i < n; i++) {
        add_delete_name_email(contacts[i][0], contacts[i][1], true);
        document.getElementById('selfriendnameemail' + i).checked = true;
    }
}

function unselect_all_name_emails() {
    for (n = contacts.length, i = 0; i < n; i++) {
        add_delete_name_email(contacts[i][0], contacts[i][1], false);
        document.getElementById('selfriendnameemail' + i).checked = false;
    }
}

function add_delete_name_email(name, email, ifchecked) {
    var matches;
    var iflastmatch;
    var p, s, t, u, v;

    if (ifchecked == true) {
        if (document.getElementById('friendnameemails').value.match(/(?:[,;\n\r]|^) *$/) === null) {
            s = ', ';
        }
        else s = '';
        if (name == '') s += email;
        else s += (name + ' <' + email + '>');
        document.getElementById('friendnameemails').value += s;
    }
    else {
        s = document.getElementById('friendnameemails').value;
        matches = s.match(/^[,; \n\r]*/);
        t = matches[0];
        p = t.length;
        iflastmatch = false;
        while (true) {
            matches = s.substring(p).match(/^([^,;\n\r]+)[,; \n\r]*/);
            if (matches === null) break;        // end of s
            u = matches[0];
            v = RegExp['$1'];
            if ((v.match(/^ *([^ ]+) *$/) !== null && RegExp['$1'] == email) ||
                (v.match(/<([^<> ]+)> *$/) !== null && RegExp['$1'] == email)) {
                iflastmatch = true;
            }
            else {
                t += u;

                iflastmatch = false;
            }
            p += u.length;
        }
        if (iflastmatch == true) {
            document.getElementById('friendnameemails').value = t.replace(/[,; \n\r]+$/, '');
        }
        else document.getElementById('friendnameemails').value = t;
    }
}
