var domain=window.location.href.match(/:\/\/(.[^/]+)/)[1];
var regEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var regExHtml = /<(.|\n)*?>/;

function GlobalFunction() {
    this.ValidateEmailFormat = function(val){
        if(!val.toString().match(regEx)) return false;
        
        return true;
    }
    this.ValidateRequireField = function(val){
        if(val.toString() == "") return false;
        
        return true;
    }
    this.ValidateLength = function (val, len){
        if(this.Trim(val.toString()).length < len) return false;
        
        return true;
    }
    this.MatchRegExHTML = function(val){
        if(val.toString().match(regExHtml)){
            return true;
        }
        else {
            return false;
        }
    }
    this.CheckDateTime = function(day, month, year) {
        var cmpDate = new Date();
        if (day < 1 || month < 1 || year < 1) {
            return false;
        }
        if ((year < cmpDate.getFullYear() - 100) && (year > cmpDate.getFullYear())) {
            return false;
        }
        if (month == 2) {
            if (day == 29) {
                if (year % 4 != 0 || (year % 100 == 0 && year % 400 != 0)) {
                    return false;
                }
                else {
                    return true;
                }
            }
            else if (day > 28) {
                return false;
            }
        }
        else if (month == 4 || month == 6 || month == 9 || month == 11) {
            if (day > 30) {
                return false;
            }
            else {
                return true;
            }
        }
        else {
            if (day > 31) {
                return false;
            }
            else {
                return true;
            }
        }
    }
    this.IsDigit = function(e, xobj)  {
        var xkey;
        if (document.all) {
            xkey = window.event.keyCode;
        } 
        else {
            xkey = e.which;
        }
        if ((xkey >= 48 && xkey <= 57) || (xkey == 8)) {
            return true;
        }
        else {
            return false;
        }
    }
    this.IsSpace = function(e, xobj)  {
        var xkey;
        if (document.all) {
            xkey = window.event.keyCode;
        } 
        else {
            xkey = e.which;
        }
        if ((xkey == 32)) {
            return false;
        }
        else {
            return true;
        }
    }
    this.IsTab = function (e, xobj){
        var xkey;
        if(document.all){
            xkey = window.event.keyCode;
        }
        else {
            xkey = e.which;
        }
        
        if(xkey == 9){ return true; }
        else { return false; }
    }
    this.Trim = function (val){
        var intIndexOfMatch = val.indexOf(" ");
        var newVal = val;
        while (intIndexOfMatch != -1){
            newVal = newVal.replace(" ", "");
            intIndexOfMatch = newVal.indexOf(" ");
        }
        return newVal;
    }
    this.ReplaceChar = function(val, replaceChar, replaceBy){
        var intIndexOfMatch = val.indexOf(replaceChar);
        var newVal = val;
        while (intIndexOfMatch != -1){
            newVal = newVal.replace(replaceChar, replaceBy);
            intIndexOfMatch = newVal.indexOf(replaceChar);
        }
        return newVal;
    }
}
