

function swapImage(el, pth) {
    document.getElementById(el).src = 'images/' + pth;
}

function tidyString(s) {
    var r1 = new RegExp('<', 'g');
    var r2 = new RegExp('>', 'g');
    var t = s.replace(r1, ' ');
    t = t.replace(r2, ' ');
    return t;
}
function countWords(w) {
    var n = 1;
    for (j = 0; j < w.length; j++) {
        if (w.charAt(j) == ' ') {
            n++;
            while (w.charAt(j) == ' ') { j++; }
        }
    }
    return n;
}
function getMax(w, t) {
    var n = 1;
    for (j = 0; j < w.length; j++) {
        if (w.charAt(j) == ' ') {
            n++;
            while (w.charAt(j) == ' ') { j++; }
        }
        if (n > t) { return j; }
    }
    return j;
}
function ignoreSpaces(string) {
    var temp = "";
    string = '' + string;
    splitstring = string.split(" ");
    for (i = 0; i < splitstring.length; i++)
        temp += splitstring[i];
    return temp;
}
function ignoreTrailingSpaces(string, tidy) {
    var temp = string;
    while ('' + temp.charAt(0) == ' ') {
        temp = temp.substring(1, temp.length);
    }
    while ('' + temp.charAt(temp.length - 1) == ' ') {
        temp = temp.substring(0, temp.length - 1);
    }
    if (tidy) {
        var x = temp;
        temp = tidyString(temp);
        if (x != temp) {
            alert("Sorry, but you cannot use the '<' or '>' symbols in your text-inputs. They have been replaced with spaces. You may want to re-write this entry.");
        }
    }
    return temp;
}
function ignoreTrailingSpacesAndCut(s, f, x, t) {
    var st = ignoreTrailingSpaces(s, t);
    if (countWords(st) > x) {
        alert("Your entry for " + f + " has been truncated to the maximum allowed for this field (" + x.toString() + " words)\nYou may wish to re-enter it.");
        st = st.substring(0, getMax(st, x));
        return st;
    }
    // st = st.substring(0,x);
    return st;
}
function checkEmail(source, args) {
    // var em = document.forms[0].txtEmail.value;
    var em = args.Value;
    args.IsValid = true;
    if (em.length > 0) {
        //var regex = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
        var regex = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
        args.IsValid = regex.test(em);
    }
    return;
}


