﻿function hndE(f, e, a) { var b = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; if (b == 13) { if (a.length > 0) { try { document.getElementById(a).click(); return false } catch (e) { } } else { var i; for (i = 0; i < f.form.elements.length; i++) { if (f == f.form.elements[i]) { i = (i + 1) % f.form.elements.length; try { f.form.elements[i].focus() } catch (e) { } return false } } } } else { return true } }

function valPC(p) { if ($(p).val() != "") { var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i; if (postcodeRegEx.test($(p).val()) == false) { $(p).val(""); alert('Please Enter Correct Postcode.'); } } }

function valTXT(f, a) {
    var b;
    var t;
    switch (a) {
        case 1:
            b = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_- ";
            break;

        case 2:
            b = "0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ_-+£%@,()&/\/:#[]{}* ";
            break;

        case 3:
            b = "0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ_-+@:/!#$%&'*=?^`{|}~";
            break;

        case 4:
            b = "0123456789 ";
            break;

        case 5:
            b = "0123456789";
            break;

        case 6:
            b = "0123456789.";
            break;

        default:
            b = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            break;
    }

    var i = 0;

    for (i = 0; i < f.value.length; i++) {
        t = "" + f.value.substring(i, i + 1);
        var c = ascVal(t);
        if (c == 13) {
            f.value = f.value.substring(0, i) + ' ' + f.value.substring(i + 2);
            t = "" + f.value.substring(i, i + 1);
        }
        try {
            if (b.toUpperCase().indexOf(t.toUpperCase()) == "-1") {
                if (f.value.toUpperCase().indexOf(t.toUpperCase()) == "0") {
                    if (f.value.length == f.value.toUpperCase().indexOf(t.toUpperCase()) + 1) {
                        f.value = "";
                    }
                    else {
                        var d = f.value;
                        while (d.toUpperCase().indexOf(t.toUpperCase()) != -1) {
                            d = d.replace(t, "");
                            i = i - 1;
                        }
                        f.value = d;
                    }
                }
                else {
                    if (f.value.indexOf(t) == (f.value.length - 1)) {
                        var d = f.value;
                        while (d.toUpperCase().indexOf(t.toUpperCase()) != -1) {
                            d = d.replace(t, "");
                            i = i - 1;
                        }
                        f.value = d;
                    }
                    else {
                        var d = f.value;
                        while (d.toUpperCase().indexOf(t.toUpperCase()) != -1) {
                            d = d.replace(t, "");
                            i = i - 1;
                        }
                        f.value = d;
                    }
                }
            }
        }
        catch (e) { }
    }
}

function ascVal(c) { c = c.charAt(0); var i; for (i = 0; i < 256; ++i) { var h = i.toString(16); if (h.length == 1) { h = "0" + h } h = "%" + h; h = unescape(h); if (h == c) { break } } return i }
