/*
 * (c) 2009 Sincerial AS
 */

/*
 * Fouces on the given element. Nicely copied from O'Reilly's book "JavaScript & DHTML Cookbook, 2nd Edition"
 */
function focusElement(formName, elemName) {
    var elem = document.forms[formName].elements[elemName];
    elem.focus();
    elem.select();
}

/*
 * Validates the text in the given element to see if it's an email address. Nicely copied from
 * O'Reilly's book "JavaScript & DHTML Cookbook, 2nd Edition"
 */
function isEMailAddr(elemId) {
    var elem = document.getElementById(elemId);
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Verify the email address format.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}
