﻿// Created by Oleg
// http://www.regular-expressions.info/javascriptexample.html <-- a little about regex in javascript
// Gets an regex expression, and a text, and checking it
$.fn.validate = function(Regex) {
    var re = new RegExp(Regex);
    var Match = re.exec(this.val());
    
    if ((Match != null) && (this.val() == Match[0]))
    {
        return true;
    } 
    else
    {
        return false;
    }
}

// Email: "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"
// Telephone: "\\d{2,3}-\\d{7})|(\\d{9,10}"
// Not empty: "^.+$"
// Passwords: "^\\w{5,16}$"
// Integers: "^\\d+$"
// Date (dd/mm/yyy): "^[0-3]?[0-9](/|-)[0-2]?[0-9](/|-)[1-2][0-9][0-9][0-9]$"
// MegaDate (dd/mm/yyy): "^((((0?[1-9]|[12]\\d|3[01])[\\.\\-\\/](0?[13578]|1[02])[\\.\\-\\/]((1[6-9]|[2-9]\\d)?\\d{2}))|((0?[1-9]|[12]\\d|30)[\\.\\-\\/](0?[13456789]|1[012])[\\.\\-\\/]((1[6-9]|[2-9]\\d)?\\d{2}))|((0?[1-9]|1\\d|2[0-8])[\\.\\-\\/]0?2[\\.\\-\\/]((1[6-9]|[2-9]\\d)?\\d{2}))|(29[\\.\\-\\/]0?2[\\.\\-\\/]((1[6-9]|[2-9]\\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\\d)?\\d{2}))|((0[1-9]|[12]\\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\\d)?\\d{2}))|((0[1-9]|1\\d|2[0-8])02((1[6-9]|[2-9]\\d)?\\d{2}))|(2902((1[6-9]|[2-9]\\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$"
// Accept empty: surround the regex with "(" ")" and add "*" to the end


// Allows only numbers to be entered
function noChars(e)
{
    var keynum;
    if(window.event) // IE
    {
      keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
      keynum = e.which;
    }
    return((keynum>=48&&keynum<=57) || (keynum==45) || (keynum==8)) // 45: "-" 8:"BackSpace"
}

// Allows only chars to be entered
function noNumbers(e)
{
    var keynum;
    if(window.event) // IE
    {
      keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
      keynum = e.which;
    }
    return !(keynum>=48&&keynum<=57);
}

var blinkCount = 4;
$.fn.blink = function() {
    blinkCount--;
    if (blinkCount > 0)
    {
        this.animate({backgroundColor: "#fffff"}, "fast", "swing").animate({backgroundColor: "#ff9999"}, "fast", "swing").blink();
    }
    else
    {
        blinkCount = 4;
    }
}; 