String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ""); };


function addAbstractAuthor ()
{
    var tbl = document.getElementById("fauthors");
    var children = tbl.getElementsByTagName("input");
    var i = children.length / 2;
    
    if (i < 10) {
        var newrow = document.createElement("tr");
        var col1 = document.createElement("td");
        col1.innerHTML = "<input type=\"text\" name=\"fAuthor" + i + "\" maxlength=\"50\" size=\"50\" />";
        var col2 = document.createElement("td");
        col2.innerHTML = "<input type=\"text\" name=\"fAffil" + i + "\" maxlength=\"100\" size=\"50\" />";
        newrow.appendChild(col1);
        newrow.appendChild(col2);
        tbl.tBodies[0].appendChild(newrow);
        document.getElementById("fnumberauthors").value = ++i;
    }
    else {
        // max author limit reached
    }
}

function abstractError (inp, msg)
{
    var box = document.getElementById("ferrorbox");
    box.innerHTML = msg;
    box.style.display = "block";
    inp.focus();
    return false;
}

function validateAbstractsForm (form)
{
    var anyauthor = false;
    var auths = document.getElementById("fauthors").getElementsByTagName("input");
    for (var i = 0; i < form.fNumAuthors.value; i += 2) {
        if (auths[i].name == "fAuthor" + (i / 2)) {
            if (auths[i].value.trim().length > 0)
                anyauthor = true;
        }
    }
    
    var errors = new Array(
        new Array("You must enter at least one author.", "Vous devez inscrire au moins un nom d'auteur."),
        new Array("You must enter the abstract's title.", "Vous devez inscrire un titre pour votre r&eacute;sum&eacute;."),
        new Array("An invalid section was chosen.", "Une section invalide a &eacute;t&eacute; s&eacute;lectionn&eacute;e."),
        new Array("You must enter an abstract.", "Vous devez r&eacute;diger un r&eacute;sum&eacute;.")
    );
    var langindex = (language == "ENG") ? 0 : 1;
    
    if (!anyauthor)
        return abstractError(form.fAuthor0, errors[0][langindex]);
    if (form.fEmail.value.trim().length == 0 || form.fEmail.value.indexOf("@") <= 0)
        return abstractError(form.fTitle, errors[2][langindex]);
    if (form.fSection.selectedIndex < 0 || form.fSection.selectedIndex > form.fSection.options.length)
        return abstractError(form.fSection, errors[3][langindex]);
    if (form.fData.value.trim().length == 0)
        return abstractError(form.fData, errors[4][langindex]);
    return true;
}


function toggleAwards (choice)
{
    var show = (choice == "yes" ? "block" : "none");
    document.getElementById("fAwardBox").style.display = show;
}

function setSectionalAward (secid)
{
    var sec = document.getElementById(secid);
    var section = sec.options[sec.selectedIndex].value;
    
    for (var i = 0; i < sec.options.length; i++)
    {
        document.getElementById("Award" + sec.options[i].value).style.display = (sec.options[i].value == section ? "block" : "none");
    }
}
