﻿/*
* jhashtable
*/
var Hashtable = (function() { var w = "undefined", f = "function", k = "string", j = "equals", t = "hashCode", o = "toString"; var r = (typeof Array.prototype.splice == f) ? function(y, x) { y.splice(x, 1) } : function(A, z) { var y, B, x; if (z === A.length - 1) { A.length = z } else { y = A.slice(z + 1); A.length = z; for (B = 0, x = y.length; B < x; ++B) { A[z + B] = y[B] } } }; function v(y) { var x; if (typeof y == k) { return y } else { if (typeof y[t] == f) { x = y.hashCode(); return (typeof x == k) ? x : v(x) } else { if (typeof y[o] == f) { return y.toString() } else { return String(y) } } } } function s(x, y) { return x.equals(y) } function b(x, y) { return (typeof y[j] == f) ? y.equals(x) : (x === y) } function d(x) { return function(y) { if (y === null) { throw new Error("null is not a valid " + x) } else { if (typeof y == w) { throw new Error(x + " must not be undefined") } } } } var g = d("key"), c = d("value"); function i(y, z, x) { this.entries = []; this.addEntry(y, z); if (x !== null) { this.getEqualityFunction = function() { return x } } } var a = 0, l = 1, h = 2; function p(x) { return function(z) { var y = this.entries.length, B, A = this.getEqualityFunction(z); while (y--) { B = this.entries[y]; if (A(z, B[0])) { switch (x) { case a: return true; case l: return B; case h: return [y, B[1]] } } } return false } } function u(x) { return function(A) { var B = A.length; for (var z = 0, y = this.entries.length; z < y; ++z) { A[B + z] = this.entries[z][x] } } } i.prototype = { getEqualityFunction: function(x) { return (typeof x[j] == f) ? s : b }, getEntryForKey: p(l), getEntryAndIndexForKey: p(h), removeEntryForKey: function(y) { var x = this.getEntryAndIndexForKey(y); if (x) { r(this.entries, x[0]); return x[1] } return null }, addEntry: function(x, y) { this.entries[this.entries.length] = [x, y] }, keys: u(0), values: u(1), getEntries: function(y) { var A = y.length; for (var z = 0, x = this.entries.length; z < x; ++z) { y[A + z] = this.entries[z].slice(0) } }, containsKey: p(a), containsValue: function(y) { var x = this.entries.length; while (x--) { if (y === this.entries[x][1]) { return true } } return false } }; function q() { } q.prototype = []; function e(A, x) { var y = A.length, z; while (y--) { z = A[y]; if (x === z[0]) { return y } } return null } function n(y, x) { var z = y[x]; return (z && (z instanceof q)) ? z[1] : null } function m(A, x) { var B = this; var E = []; var y = {}; var C = (typeof A == f) ? A : v; var z = (typeof x == f) ? x : null; this.put = function(I, K) { g(I); c(K); var F = C(I), J, H, G = null; var L = n(y, F); if (L) { H = L.getEntryForKey(I); if (H) { G = H[1]; H[1] = K } else { L.addEntry(I, K) } } else { J = new q(); J[0] = F; J[1] = new i(I, K, z); E[E.length] = J; y[F] = J } return G }; this.get = function(H) { g(H); var F = C(H); var I = n(y, F); if (I) { var G = I.getEntryForKey(H); if (G) { return G[1] } } return null }; this.containsKey = function(G) { g(G); var F = C(G); var H = n(y, F); return H ? H.containsKey(G) : false }; this.containsValue = function(G) { c(G); var F = E.length; while (F--) { if (E[F][1].containsValue(G)) { return true } } return false }; this.clear = function() { E.length = 0; y = {} }; this.isEmpty = function() { return !E.length }; var D = function(F) { return function() { var G = [], H = E.length; while (H--) { E[H][1][F](G) } return G } }; this.keys = D("keys"); this.values = D("values"); this.entries = D("getEntries"); this.remove = function(I) { g(I); var G = C(I), F, H = null; var J = n(y, G); if (J) { H = J.removeEntryForKey(I); if (H !== null) { if (!J.entries.length) { F = e(E, G); r(E, F); y[G] = null; delete y[G] } } } return H }; this.size = function() { var G = 0, F = E.length; while (F--) { G += E[F][1].entries.length } return G }; this.each = function(I) { var F = B.entries(), G = F.length, H; while (G--) { H = F[G]; I(H[0], H[1]) } }; this.putAll = function(N, I) { var H = N.entries(); var K, L, J, F, G = H.length; var M = (typeof I == f); while (G--) { K = H[G]; L = K[0]; J = K[1]; if (M && (F = B.get(L))) { J = I(L, F, J) } B.put(L, J) } }; this.clone = function() { var F = new m(A, x); F.putAll(B); return F } } return m })();


(function($) {
    $.fn.validateInput = function(options) {
        //usage $('#elem').validateInput({inputType: 'text', validationType: 'required', watermarks: 'Name*', errMessage: '0'});

        var defaults = { inputType: 'text', validationType: 'required', watermarks: '', errMessage: '0' };
        var inputSettings = $.extend({}, defaults, options);
        var regexp = "";

        return this.each(function() {

            var $this = $(this);
            var inputVal = "";
            var validateOK = $(this).next("span.validate").find("img.validateOK");
            var validateFAIL = $(this).next("span.validate").find("img.validateFAIL");
            var parentForm = $(this).parents(".formHolder");
            var validationSummary = $(this).parents(".formHolder").find(".validationSummary");
            var success = false;

            //input type
            if (inputSettings.inputType == 'select') {
                inputVal = $(this).find("option:selected").val();
            }
            else if (inputSettings.inputType == 'hidden') {
                inputVal = "";
            }
            else if (inputSettings.inputType == 'radio') {
                inputVal = $(this).find("input[@type='radio']:checked").val();
                if (inputVal == null) { inputVal = ""; }
                validateOK = $(this).find("span.validate img.validateOK");
                validateFAIL = $(this).find("span.validate img.validateFAIL");
            }
            else {
                inputVal = jQuery.trim($this.val());
                //check if the input is the same as default watermarks value
                if (inputVal == inputSettings.watermarks) { inputVal = "" }
            }

            //validation type                                    
            if (inputSettings.validationType == 'email') {
                // email validation                                
                if ((inputVal == "") || (echeck(inputVal) == false)) { success = false; }
                else { success = true; }
            }
            else if (inputSettings.validationType == 'confirmEmail') {
                // find email address 
                var emailVal = $("input.inputEmail").val();
                var emailOK = $("li.infoEmail").find("img.validateOK");

                if ($(emailOK).hasClass("show")) {
                    // if email is empty
                    if (inputVal == "") { success = false; }
                    else {
                        // if email and confirm email are a match
                        if (inputVal == emailVal) { success = true; }
                        else { success = false; }
                    }
                }
                else { success = false; }
            }
            else if (inputSettings.validationType == 'phone') {
                // phone validation                    
                regexp = /^\d{10}$/;
                if ((inputVal == "") || (inputVal.match(regexp) == null)) { success = false; }
                else { success = true; }
            }
            else if (inputSettings.validationType == 'age') {
                // age validation - valid from 1 - 100
                var age = parseInt(inputVal);
                if (age == null) { success = false; }
                else {
                    if ((age >= 1) && (age <= 100)) { success = true; }
                    else { success = false; }
                }
            }
            else if (inputSettings.validationType == 'postcode') {
                // postcode validation                                    
                regexp = /^\d{4}$/;
                if ((inputVal == "") || (inputVal.match(regexp) == null)) { success = false; }
                else { success = true; }
            }
            else if (inputSettings.validationType == 'creditcard') {
                // credit card validation
                var ccNumber = $("input.inputCCNumber").val();
                var ccNumberOK = $("li.ccNumber").find("img.validateOK");
                var ccNumberFAIL = $("li.ccNumber").find("img.validateFAIL");

                if (inputVal == "") {
                    // credit card type has not been chosen                    
                    success = false;
                    if (ccNumber == "") {
                        $(validationSummary).find("li:eq(11)").addClass("show");
                        $(ccNumberFAIL).addClass("show");
                        $(ccNumberOK).removeClass("show");
                    }
                    else { $(validationSummary).find("li:eq(11)").removeClass("show"); }
                }
                else {
                    // credit card type chosen                    
                    success = true;
                    if (ccNumber == "") {
                        $(validationSummary).find("li:eq(11)").addClass("show");
                        $(ccNumberFAIL).addClass("show");
                        $(ccNumberOK).removeClass("show");
                    }
                    else {
                        $(validationSummary).find("li:eq(11)").removeClass("show");
                        switch (inputVal) {
                            case 'visa': regexp = "^4.{15}$|^4.{12}$"; break;
                            case 'mc': regexp = "^5[1-5].{14}$"; break;
                            case 'amex': regexp = "^3[47].{13}$"; break;
                            default: ;
                        }
                        if (ccNumber.match(regexp) == null) {
                            $(ccNumberFAIL).addClass("show");
                            $(ccNumberOK).removeClass("show");
                            $(validationSummary).find("li:eq(12)").addClass("show");
                        }
                        else {
                            $(ccNumberOK).addClass("show");
                            $(ccNumberFAIL).removeClass("show");
                            $(validationSummary).find("li:eq(12)").removeClass("show");
                        }
                    }
                }
            }
            else if (inputSettings.validationType == 'ccexpiry') {
                // credit card expiry validation                                    
                var today = new Date();
                var ccExpiry = new Date($("select.selectCCExpiryYear option:selected").val(), $("select.selectCCExpiryMonth option:selected").val());
                var daysToExpire = ccExpiry - today; //unit is milliseconds
                daysToExpire = Math.round(daysToExpire / 1000 / 60 / 60 / 24);
                if (($("select.selectCCExpiryMonth option:selected").val() == "") ||
                    ($("select.selectCCExpiryYear option:selected").val() == "") ||
                    (daysToExpire < 0)) { success = false; }
                else { success = true; }
            }
            else {
                // required validation
                if (inputVal == "") { success = false; }
                else { success = true; }
            }

            if (success) {
                $(validateOK).addClass("show");
                $(validateFAIL).removeClass("show");
                $(validationSummary).find("li:eq(" + inputSettings.errMessage + ")").removeClass("show");
            }
            else {
                $(validateFAIL).addClass("show");
                $(validateOK).removeClass("show");
                $(validationSummary).find("li:eq(" + inputSettings.errMessage + ")").addClass("show");
            }

            if ($(validationSummary).find("li.show").length > 0) {
                $(validationSummary).find("ul").addClass("show");
            }
            else { $(validationSummary).find("ul").removeClass("show"); }

        });
    }
})(jQuery);

(function($) {
    $.fn.clearInput = function(options) {
        //usage $('#elem').clearInput({inputType: 'text', validationType: 'required', errMessage: '0'});

        var defaults = { inputType: 'text', errMessage: '0' };
        var inputSettings = $.extend({}, defaults, options);

        return this.each(function() {

            var $this = $(this);

            var validateOK = $(this).next("span.validate").find("img.validateOK");
            var validateFAIL = $(this).next("span.validate").find("img.validateFAIL");
            if (inputSettings.inputType == 'radio') {
                validateOK = $(this).find("span.validate img.validateOK");
                validateFAIL = $(this).find("span.validate img.validateFAIL");
            }

            var validationSummary = $(this).parents("form").find(".validationSummary");

            $(validateOK).removeClass("show");
            $(validateFAIL).removeClass("show");
            $(validationSummary).find("li:eq(" + inputSettings.errMessage + ")").removeClass("show");
        });
    }
})(jQuery);

function echeck(str) {
    var at = "@";
    var dot = ".";
    var lat = str.indexOf(at);
    var lstr = str.length;
    var ldot = str.indexOf(dot);
    if (str.indexOf(at) == -1) { return false; }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == (lstr - 1)) { return false; }
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == (lstr - 1)) { return false; }
    if (str.indexOf(at, (lat + 1)) != -1) { return false; }
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) { return false; }
    if (str.indexOf(dot, (lat + 2)) == -1) { return false; }
    if (str.indexOf(" ") != -1) { return false; }
    else { return true; }
}
