﻿var delay = (function () {
    var timer = 0;
    return function (callback, ms) {
        clearTimeout(timer);
        timer = setTimeout(callback, ms);
    };
})();

function IsValidEmail(email) {
    //alert(email);
    //var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    var re = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return re.test(email);
}

function set_cookie(cookie_name, cookie_value, lifespan_in_days, valid_domain) {
    var domain_string = valid_domain ? ("; domain=" + valid_domain) : '';
    document.cookie = cookie_name + "=" + encodeURIComponent(cookie_value) +
        "; max-age=" + 60 * 60 * 24 * lifespan_in_days +
        "; path=/" + domain_string;
}

function get_cookie(cookie_name) {
    var cookie_string = document.cookie;
    if (cookie_string.length != 0) {
        var cookie_value = cookie_string.match('(^|;)[\s]*' + cookie_name + '=([^;]*)');
        return decodeURIComponent(cookie_value[2]);
    }
    return '';
}

function delete_cookie(cookie_name, valid_domain) {
    var domain_string = valid_domain ? ("; domain=" + valid_domain) : '';
    document.cookie = cookie_name + "=; max-age=0; path=/" + domain_string;
}

//$("#txtAnything").CheckDecimalOnly();


//jQuery.fn.CheckDecimalOnly = function (event) {
//    return this.each(function () {
//        var $this = $(this);
//        alert($this);
//        if ((event.which != 46 || $this.val().indexOf('.') != -1) &&
//           ((event.which < 48 || event.which > 57) &&
//           (event.which != 0 && event.which != 8))) {
//            event.preventDefault();
//        }

//        var text = $(this).val();
//        if ((event.which == 46) && (text.indexOf('.') == -1)) {
//            setTimeout(function () {
//                if ($this.val().substring($this.val().indexOf('.')).length > 3) {
//                    $this.val($this.val().substring(0, $this.val().indexOf('.') + 3));
//                }
//            }, 1);
//        }

//        if ((text.indexOf('.') != -1) &&
//            (text.substring(text.indexOf('.')).length > 2) &&
//            (event.which != 0 && event.which != 8) &&
//            ($(this)[0].selectionStart >= text.length - 2)) {
//            event.preventDefault();
//        }
//    });
//};

    //jQuery.fn.extend({
    //    CheckDecimalOnly: function (event) {
    //        return this.each(function () {
    //            var $this = $(this);
    //            alert($this);
    //            if ((event.which != 46 || $this.val().indexOf('.') != -1) &&
    //               ((event.which < 48 || event.which > 57) &&
    //               (event.which != 0 && event.which != 8))) {
    //                event.preventDefault();
    //            }

    //            var text = $(this).val();
    //            if ((event.which == 46) && (text.indexOf('.') == -1)) {
    //                setTimeout(function () {
    //                    if ($this.val().substring($this.val().indexOf('.')).length > 3) {
    //                        $this.val($this.val().substring(0, $this.val().indexOf('.') + 3));
    //                    }
    //                }, 1);
    //            }

    //            if ((text.indexOf('.') != -1) &&
    //                (text.substring(text.indexOf('.')).length > 2) &&
    //                (event.which != 0 && event.which != 8) &&
    //                ($(this)[0].selectionStart >= text.length - 2)) {
    //                event.preventDefault();
    //            }
    //        });
    //    },
    //    CheckNumberOnly: function () {
    //        return this.each(function () {
    //            this.checked = false;
    //        });
    //    },
    //    CheckEmail: function () {
    //        return this.each(function () {
    //            this.checked = false;
    //        });
    //    }
    //});