function addInviteMoreContent(invite_id, base_name, container) {
    var url = 'ajax_invite_more_content_input_element.php?invite_id=' + escape(invite_id) + '&base_name=' + escape(base_name);
    var p = E('P');
    p.innerHTML = loadJSON(url);
    container.appendChild(p);
}

function showOrHideTimeOptions(date_field, time_span, null_word) {
    if (null_word == null) null_word = '';
    if (date_field.value != null_word && date_field.value != '') {
        time_span.style.display = '';
    } else {
        date_field.value = null_word;
        time_span.style.display = 'none';
    }
}

function clear_field( item )
{
    document.getElementById( item ).innerHTML = "";
}

function submit_if_should(form)
{
    if (form.onsubmit()) {
        form.submit();
    }
}

/*
Just check the syntax of the email and password, logic for signup and login will be implemented on the backend.
Also make sure we submit whether this is a signup or a login action as this will determine they type of error message.

Form member variable name for submit_value shouldn't clash with name hidden field.
Trim whitespace from the email value to avoid confusion if it is entered by accident.
*/
function check_get_account( form )
{
    submit_value = form.submit_value;
    form.submit_value = '';
    
    email = getFormField(form, 'emailaddress');
    email.value = email.value.replace( /(^\s+|\s+$)/g, '' );
    var result2 = check_email_syntax(email.value, form.id+'emailaddress_fillin', true);
    var result3 = check_password(getFormField(form, 'password').value, form.id+'password_fillin');
    
    if( result2 && result3)
    {
        if( submit_value != '' ){
            document.getElementById(form.id+'submit_button').value = submit_value;
        }
        return true;
    }
    
    return false;
}

/*
Just validate the format of the email address (regex copied from validate.php).
Didn't want to user the validate_email_address() function because it uses alerts.

allow_id is whether an value should be allowed to validate, 
in which case we just make sure that the field is not empty and has no white space.
*/
function check_email_syntax( email, element_id, allow_id ){
    if( ( allow_id && email.match( /^\w+$/ ) ) || email.match( /[\w\.\+\-=]+@[\w\.\-]+\.[\w\-]+/ ) ){
        return true;
    }
    document.getElementById(element_id).innerHTML = '<br>Please double-check the e-mail address you entered. It does not appear to be valid.';
    return false;
}

function check_password( password, element_id )
{
    if( password.length < 4 )
    {
        document.getElementById(element_id).innerHTML = "<br>Your password must be at least 4 characters.";
        return false;
    }
    else
    {
        document.getElementById(element_id).innerHTML = "";
        return true;
    }
}


function getFormFieldByName(form, field_name) {
    var fields = new Array();
    for (var i = 0; i < form.elements.length; i++) {
        if (form.elements[i].name == field_name) {
            fields[fields.length] = form.elements[i];
        }
    }

    return fields;
}
