function strip_spaces(frmelobj) {
    //  Remove spaces fore and aft
    frmelobj.value = frmelobj.value.replace(/^\s*(\S*)\s*$/, "$1");
    return frmelobj.value;
};
function kill_spaces(frmelobj) {
    //  Remove all spaces indiscriminately
    frmelobj.value = frmelobj.value.replace(/\s/g, "");
    return frmelobj.value;
};
function check_num(frmelobj) {
    //  Return true if all numeric
    strip_spaces(frmelobj);
    return (frmelobj.value.match(/^\d+$/));
};
function check_not_blank(frmelobj) {
    //  Return true if non-whitespace characters found
    strip_spaces(frmelobj);
    return (!(frmelobj.value.match(/^$/)));
};
function check_sthg_ticked(frmelobj) {
    //  Return true if something ticked within radio button set
    ok = false;
    for (i = 0; i < frmelobj.length; ++i) {
        if (frmelobj[i].checked) {
            ok = true;
        };
    };
    return (ok);
};
function check_phone(frmelobj) {
    //  Return true if element contains a valid telephone number
    n = kill_spaces(frmelobj);
    //  start by checking digit count is plausible ...
    ok = (n.match(/^01\d{7,9}$/) || n.match(/^0[27]\d{9}$/));
    //  ... reject single digits repeated x6, pairs of digits x4, ...
    if ((n.match(/(\d)\1\1\1\1\1/)) || (n.match(/(\d)(\d)\1\2\1\2\1\2/))
    //  ... and sequences unlikely to occur in real numbers
     || (n.match(/123456/)) || (n.match(/654321/))
     || (n.match(/234567/)) || (n.match(/765432/))
     || (n.match(/345678/)) || (n.match(/876543/))
     || (n.match(/456789/)) || (n.match(/987654/))) {
        ok = false;
    };
    return (ok);
};
    //  Change the existing check_login() to this

    function check_login() {
        //  Check customer login details
        f = window.document.theform;
        f1 = window.frames["addrsel"].document.inform;
        wt = "";
        if (!check_not_blank(f.new_user)) {
            wt += "Surname must not be blank!\n";
        };
        kill_spaces(f.telephone);
        if (!check_phone(f.telephone)) {
            wt += "Telephone number is invalid!\n";
        };
        kill_spaces(f.telephone2);
        if (f.telephone2.value.match(/.+/) && !(f.telephone2.value.match(/^\d{9,11}$/))) {
            wt += "Alt. telephone number should be all-numeric, 9-11 digits!\n";
        };
        kill_spaces(f.postcode);
        kill_spaces(f.p2);
        pc = f.postcode.value + " " + f.p2.value;
        if (!(pc.match(/^[A-Z]{1,2}[0-9]{1,2}[A-Z]?\s*[0-9][A-Z]{2}$/i))) {
            wt += "'" + pc + "' is not a real post code.\n";
        };
        if (f1.noaddress.value > 0) {
            wt += "No address is selected!\n";
        }
        else {
            f.addrfrompc.value = f1.addrfrompc.value;
            if (f1.addrfrompc.selectedIndex < 1) {
                wt += "Please select an address!\n";
            };
        };
        kill_spaces(f.email);
        if (!(f.email.value.match(/^([^@]+)@([0-9a-z._-])+\.([a-z]{2,4})$/i))) {
            if (email_tries-- > 0) {
                wt += "E-mail address is not valid!\n";
            }
            else {
                f.email.value="noemail@priceengines.co.uk";
            };
        };
        if (wt) {
            alert("Unable to proceed:\n" + wt);
        };
        return (wt=="");
    };

