// Values here are all defaults, and can be overriddenvar l_mon = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');var l_days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);var l_len = new Array(2, 3, 4);var l_yearbreak = 25;var m_pos = 1;var d_pos = 0;var y_pos = 2;var delim = ".";var m_type = "N";var NLSformat = "DD.MM.RRRR";var numericDate = 0;function datecheck(P_date, P_NLS_format) {    // check to see if the date is a string, otherwise treat it as an object    // reference.    var P_obj = false;    if (typeof P_date == "string") {        P_value = P_date;    } else {        P_obj = P_date;        P_value = P_date.value;    }    // exit if no date passed in    if (P_value == null | P_value == '' | P_value == ' ') {        return '';    }    // evaluate the NLS format and sets up for output formatting.    if (P_NLS_format) {        evalNLS(P_NLS_format);    } else {        evalNLS(NLSformat);    }    date = new Date();    if (P_value.length > 2 && P_value.substring(2, 3) != '.' && P_value.substring(1, 2) != '.') {        P_value = P_value.substring(0, 2) + '.' + P_value.substring(2, P_value.length);    }    if (P_value.length > 5 && P_value.substring(5, 6) != '.' && P_value.substring(4, 5) != '.' && P_value.substring(3, 4) != '.') {        P_value = P_value.substring(0, 5) + '.' + P_value.substring(5, P_value.length);    }    if (P_value.toUpperCase() == "D") {        P_value = date.getDate() + '.' + (date.getMonth() + 1) + '.' + (date.getYear());    } else {        if (P_value.indexOf('.') == -1 && P_value.length <= 2) {            P_value += '.' + (date.getMonth() + 1) + '.' + (date.getYear());        } else {            if (P_value.indexOf('.') != -1 && P_value.indexOf('.', P_value.indexOf('.') + 1) == -1)                P_value += '.' + (date.getYear());        }    }    var l_length = P_value.length;    var l_str = new Array(' ', ' ', ' ');    var temp = new Array('', '', '');    var l_swap = '';    var l_splitstr = '';    var l_index = 0;    var l_splitcount = 1;    var l_char = '';    var l_prevspace = true;    var y_extra = 0;    var d_extra = 0;    var m_extra = 0;    var l_delims = /\W/    // splits and arranges an all numeric input string into numeric values    // ordered D M Y    // assumes 2 characters for month and day, and assigns what is left over to    // year    if (parseFloat(P_value) == P_value) {        if (P_value.length < 5) {            P_value = P_value + "????????".substr(0, 8 - P_value.length);        } else {            if (P_value.length <= 6) {                y_extra = 0;                d_extra = 0;                m_extra = 0;            } else {                y_extra = P_value.length - 6;                if (d_pos - y_pos > 0) {                    d_extra = y_extra;                }                if (m_pos - y_pos > 0) {                    m_extra = y_extra;                }            }        }        l_str[0] = P_value.substr(d_pos * 2 + d_extra, 2);        l_str[1] = P_value.substr(m_pos * 2 + m_extra, 2);        l_str[2] = P_value.substr(y_pos * 2, 2 + y_extra);        if (l_str[1] > 12) {            l_swap = l_str[0];            l_str[0] = l_str[1];            l_str[1] = l_swap;        }    } else {        // otherwise, splits the string using delimiters after compressing        // spaces        // and common delimiter characters        for ( var count = 0; count < l_length; ++count) {            l_char = P_value.charAt(count);            if (l_char.search(l_delims) == 0) {                if (l_prevspace == false) {                    l_splitstr += l_char;                }                l_prevspace = true;            } else {                l_prevspace = false;                l_splitstr += l_char;            }        }        l_length = l_splitstr.length;        // splits string by delimiter into 3 parts        for ( var count = 0; count < l_length; ++count) {            l_char = l_splitstr.charAt(count);            if (l_char.search(l_delims) == 0) {                l_index = l_index + 1;            } else {                temp[l_index] += l_char;            }        }        l_str[0] = temp[d_pos];        l_str[1] = temp[m_pos];        l_str[2] = temp[y_pos];        // The array is now in the order of the NLS mask, but some sanity        // checking of the contents should still be done.        // If the string already in the year slot is > 31, leave it - otherwise        // if any string is > 31 and numeric (probably the year), swap it into        // the year slot.        if (!l_str[2] > 31) {            if (l_str[0] > 31 && !isNaN(l_str[0])) {                l_swap = l_str[2];                l_str[2] = l_str[0];                l_str[0] = l_swap;            }            if (l_str[1] > 31 && !isNaN(l_str[1])) {                l_swap = l_str[2];                l_str[2] = l_str[1];                l_str[1] = l_swap;            }        }        // strips off non-numeric characters from elements        var strip = ""        for (i = 0; i < l_str[0].length; i++) {            if (!isNaN(l_str[0].charAt(i))) {                strip += l_str[0].charAt(i);            }        }        // l_str[0] = (temp.length > 0)?temp + '':l_str[0] + '';        if (strip.length > 0) {            l_str[0] = parseFloat(l_str[0], 10) + '';        }        strip = ""        for (i = 0; i < l_str[1].length; i++) {            if (!isNaN(l_str[1].charAt(i))) {                strip += l_str[1].charAt(i);            }        }        if (strip.length > 0) {            l_str[1] = parseFloat(l_str[1], 10) + ''        }        // swaps the first two strings if the first one is not numeric        // so the month string is placed into position 1 in the array, or        // swaps any value > 12 in the months slot into the day slot        if (isNaN(l_str[0])) {            l_swap = l_str[0];            l_str[0] = l_str[1];            l_str[1] = l_swap;        } else {            if (l_str[1] > 12) {                l_swap = l_str[0];                l_str[0] = l_str[1];                l_str[1] = l_swap;            }        }        // If the month isn't numeric, checks the table of valid        // months to determine the numeric equivalent for the string. Uses this        // to        // check whether the day is valid for the particular month later.        if (isNaN(l_str[1])) {            for ( var count = 0; count <= 11; ++count) {                l_str[1] = l_str[1].substr(0, 3);                if (l_str[1].toUpperCase() == l_mon[count].toUpperCase()) {                    l_str[1] = (count + 1) + '';                    break;                }            }            if (count == 12) {                l_str[1] = "??";            } else {                if (l_str[1].length > l_len[1]) {                    l_str[1] = l_str[1].substr(0, l_len[1]);                } else {                    while (l_str[1].length < l_len[1]) {                        l_str[1] = '0' + l_str[1];                    }                }            }        } else {            if (l_str[1] > 12 || l_str[1] < 1) {                l_str[1] = "??"            }        }        // zero fills the day if less than defined length and truncates if more        if (l_str[0].length > l_len[0]) {            l_str[0] = l_str[0].substr(0, l_len[0]);        } else {            while (l_str[0].length < l_len[0]) {                l_str[0] = '0' + l_str[0];            }        }    }    // If the year isn't numeric, fill with ? and treat as unrecognizable,    // otherwise, convert to integer before    // filling to correct length.    if (isNaN(l_str[2])) {        l_str[2] = "????";    } else {        l_str[2] = parseFloat(l_str[2]) + '';    }    // If the year comes in as 3 digits, just pads it with a "1", otherwise    // fills    // it to at least 2 digits.    if (l_str[2].length > l_len[2]) {        l_str[2] = l_str[2].substr(0, l_len[2]);    } else {        if (l_str[2].length == 3) {            l_str[2] = '1' + l_str[2];        } else {            while (l_str[2].length < 2) {                l_str[2] = '0' + l_str[2];            }        }    }    // Adds century to a 2 digit year using an arbitrary split point    if ((l_str[2].length <= 2 || parseFloat(l_str[2]) < 100) && l_str[2].indexOf("?") == -1) {        l_str[2] = parseFloat(l_str[2]) + '';        while (l_str[2].length < 2) {            l_str[2] = '0' + l_str[2];        }        if (l_str[2] < l_yearbreak) {            l_str[2] = '20' + l_str[2];        } else {            l_str[2] = '19' + l_str[2];        }    }    // Check if day of month is valid for month in year (check leapyear too)    if (!isNaN(l_str[2]) && !isNaN(l_str[1])) {        if (((l_str[2] % 4 == 0) && (l_str[2] % 100 != 0)) || (l_str[2] % 400 == 0)) {            l_days[1] = 29;        } else {            l_days[1] = 28;        }        if (l_str[0] > l_days[l_str[1] - 1]) {            l_str[0] = l_days[l_str[1] - 1];        }    }    // If length of month > 2, just use the last two digits in the month.    if (l_str[1].length > 2) {        l_str[1] = l_str[1].substring(l_str[1].length - 2);    }    // If length of month < 2, zero fill it    while (l_str[1].length < 2) {        l_str[1] = '0' + l_str[1];    }    // Store numeric date for future range checking.    numericDate = parseFloat(l_str[2] + l_str[1] + l_str[0]);    numericDate = isNaN(numericDate) ? 0 : numericDate;    if (P_obj) {        P_obj.numericDate = numericDate;    }    // Replaces the numeric month with string from the table if type is "C"    if (m_type == "C") {        if (!isNaN(l_str[1]) && l_str[1] <= 12) {            l_str[1] = l_mon[l_str[1] - 1];        } else {            for ( var count = 0; count <= 11; ++count) {                if (l_str[1].toUpperCase() == l_mon[count].toUpperCase()) {                    l_str[1] = l_mon[count];                    break;                }            }            if (count == 12) {                l_str[1] = '???';            }        }    }    // Finally, swap items around into output format and add delimiters    temp[d_pos] = l_str[0];    temp[m_pos] = l_str[1];    temp[y_pos] = l_str[2];    l_splitstr = temp[0] + delim + temp[1] + delim + temp[2];    if (P_obj) {        P_obj.value = l_splitstr;    }    if (l_splitstr.indexOf('?') != -1) {        l_splitstr = "";    }    return l_splitstr;}// Accepts the NLS format string and populates the variables necessary to apply// it.function evalNLS(P_Dateformat) {    if (P_Dateformat) {        NLSformat = P_Dateformat;    }    m_pos = NLSformat.indexOf('MON');    m_type = "C";    l_len[1] = 3;    if (m_pos < 0) {        m_pos = NLSformat.indexOf('MM');        m_type = "N";        l_len[1] = 2;    }    d_pos = NLSformat.indexOf('DD');    y_pos = NLSformat.indexOf('RRRR');    if (m_pos != 0) {        delim = NLSformat.charAt(m_pos - 1);    } else {        delim = NLSformat.charAt(d_pos - 1);    }    if (m_pos > 5) {        m_pos = 2;    } else if (m_pos < 3) {        m_pos = 0;    } else {        m_pos = 1;    }    if (d_pos > 5) {        d_pos = 2;    } else if (d_pos < 3) {        d_pos = 0;    } else {        d_pos = 1;    }    if (y_pos > 5) {        y_pos = 2;    } else if (y_pos < 3) {        y_pos = 0;    } else {        y_pos = 1;    }}function fillCheck(P_date) {    var l_defaults = new Array('PP.KK.AAAA', 'TT:MM', 'DD.MM.YYYY', 'HH:MM', 'ДД.ММ.ГГГГ', 'ЧЧ:ММ');    for (d in l_defaults) {        if (P_date.value == l_defaults[d]) {            P_date.value = '';        }    }}