function convert_date(a){
    var b = a.value.length, c = new Array("-", ".", "/", " ", ":", "_", ","), g = 7, e = new String(null), d = new String(null), f = new String(null), k = null;
    k = null;
    k = 0;
    var h = new Array("0", "0", "0"), l = String(a.value);
    if (b == 0) 
        return true;
    if (a.value.toUpperCase() == "NOW" || a.value.toUpperCase() == "TODAY") {
        var j = new Date;
        b = navigator.appName == "Netscape" ? j.getYear() + 1900 : j.getYear();
        l = j.getMonth() + 1;
        j = j.getDate();
        a.value = b + "-" + l + "-" + j;
        b = a.value.length;
        l = String(a.value)
    }
    if (b != 0 && (b < 6 || b > 11)) {
        invalid_date(a);
        return false
    }
    for (j = 0; j < 3; j++) 
        for (var m = 0; m < g; m++) 
            if (l.indexOf(c[m], k) != -1) {
                h[j] = l.indexOf(c[m], k);
                k = h[j] + 1;
                break
            }
    if (h[2] != 0) {
        invalid_date(a);
        return false
    }
    if (h[0] == 0 && h[1] == 0) {
        if (b == 6) {
            e = a.value.substring(0, 2);
            d = a.value.substring(2, 4);
            f = a.value.substring(4, 6);
            if ((f = validate_year(f)) == false) {
                invalid_date(a);
                return false
            }
        }
        else 
            if (b == 7) {
                e = a.value.substring(0, 2);
                d = a.value.substring(2, 5);
                f = a.value.substring(5, 7);
                if ((d = convert_month(d)) == false) {
                    invalid_date(a);
                    return false
                }
                if ((f = validate_year(f)) == false) {
                    invalid_date(a);
                    return false
                }
            }
            else 
                if (b == 8) {
                    e = a.value.substring(0, 2);
                    d = a.value.substring(2, 4);
                    f = a.value.substring(4, 8)
                }
                else 
                    if (b == 9) {
                        e = a.value.substring(0, 2);
                        d = a.value.substring(2, 5);
                        f = a.value.substring(5, 9);
                        if ((d = convert_month(d)) == false) {
                            invalid_date(a);
                            return false
                        }
                    }
        if ((k = validate_date(f, d, e)) == false) {
            alert("The value " + a.value + " is not a vaild date.\n\rPlease enter a valid date in the format yyyy-mm-dd");
            a.focus();
            a.select();
            return false
        }
        a.value = k;
        return true
    }
    if (h[0] != 0 && h[1] != 0) {
        f = a.value.substring(0, h[0]);
        d = a.value.substring(h[0] + 1, h[1]);
        e = a.value.substring(h[1] + 1, a.value.length)
    }
    if (isNaN(e) && isNaN(f)) {
        invalid_date(a);
        return false
    }
    if (e.length == 1) 
        e = "0" + e;
    if (d.length == 1) 
        d = "0" + d;
    if (f.length == 2) 
        if ((f = validate_year(f)) == false) {
            invalid_date(a);
            return false
        }
    if (d.length == 3 || d.length == 4) 
        if ((d = convert_month(d)) == false) {
            alert("month1" + d);
            invalid_date(a);
            return false
        }
    if ((e.length == 2 || d.length == 2 || f.length == 4) == false) {
        invalid_date(a);
        return false
    }
    if ((k = validate_date(f, d, e)) == false) {
        alert("The value " + a.value + " is not a vaild date.\n\rPlease enter a valid date in the format yyyy-mm-dd");
        a.focus();
        a.select();
        return false
    }
    a.value = k;
    return true
}

function convert_month(a){
    var b = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
    a = a.toUpperCase();
    if (a.length == 3) 
        for (var c = 0; c < 12; c++) {
            if (a == b[c]) {
                a = c + 1;
                if (c != 10 && c != 11 && c != 12) 
                    a = "0" + a;
                return a
            }
        }
    else 
        if (a.length == 4 && a == "SEPT") 
            return a = "09";
        else 
            return false
}

function invalid_date(a){
    alert("The value " + a.value + " is not in a vaild date format.\n\rPlease enter date in the format yyyy-mm-dd");
    a.focus();
    a.select();
    return true
}

function validate_date(a, b, c){
    var g = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31), e = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"), d = c + b + a, f = /^[0-9]{2}[0-9]{2}[0-9]{4}$/;
    if (!f.test(d)) 
        return false;
    f = /01|02|03|04|05|06|07|08|09|10|11|12/;
    if (!f.test(b)) 
        return false;
    d = Number(a);
    if (d % 4 == 0 && d % 100 != 0 || d % 400 == 0) 
        g[1] = 29;
    for (d = 0; d <= 11; d++) 
        if (e[d] == b) 
            if (c <= g[d] && c > 0) 
                return d = a + "-" + b + "-" + c;
            else 
                return false;
    return true
}

function validate_year(a){
    if (a < 10) 
        return a = "20" + a;
    else 
        if (a >= 10) 
            return a = "19" + a;
        else 
            return false
}

function isInputEmpty(a, b){
    if (a.value.length == 0) {
        alert(b);
        a.focus();
        return true
    }
}

function checkNum(a, b, c){
    if (isNaN(a.value)) {
        alert("Number only please!");
        a.value = "";
        return false
    }
    else 
        if (parseFloat(a.value) < b || parseFloat(a.value) > c) {
            alert("The value given is out of range!");
            a.value = "";
            return false
        }
}

function getRadioValue(a){
    for (var b = null, c = 0; c < a.length; c++) 
        if (a[c].checked) {
            b = a[c].value;
            break
        }
    return b
}

function isNotChecked(a, b){ /* akk 2010.04.30 */
    if (a != null) {
        if (a.checked) {
            return false;
        }
        else {
            alert(b)
            return true;
        }
    }
}

function gotoURL(a){
    location.hash = a;
    return true
}

function isRadioNotChecked(a, b){
    if (getRadioValue(a) == null) {
        alert(b);
        return true
    }
}

function isNotSelected(a, b){
    if (a.selectedIndex == 0) {
        alert(b);
        return true
    }
}

function getCookieVal(a){
    var b = document.cookie.indexOf(";", a);
    if (b == -1) 
        b = document.cookie.length;
    return unescape(document.cookie.substring(a, b))
}

function FixCookieDate(a){
    var b = new Date(0);
    b = b.getTime();
    b > 0 && a.setTime(a.getTime() - b)
}

function GetCookie(a){
    a = a + "=";
    for (var b = a.length, c = document.cookie.length, g = 0; g < c;) {
        var e = g + b;
        if (document.cookie.substring(g, e) == a) 
            return getCookieVal(e);
        g = document.cookie.indexOf(" ", g) + 1;
        if (g == 0) 
            break
    }
    return null
}

function SetCookie(a, b, c, g, e, d){
    document.cookie = a + "=" + escape(b) + (c ? "; expires=" + c.toGMTString() : "") + (g ? "; path=" + g : "") + (e ? "; domain=" + e : "") + (d ? "; secure" : "")
}

function DeleteCookie(a, b, c){
    if (GetCookie(a)) 
        document.cookie = a + "=" + (b ? "; path=" + b : "") + (c ? "; domain=" + c : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"
}

var expdate = new Date;
FixCookieDate(expdate);
expdate.setTime(expdate.getTime() + 86400000);
function isValidEmail(a){
    var b;
    if (a.value.length == 0) 
        return false;
    b = a.value.indexOf("@");
    if (b = b != -1 && b != 0 && b != a.value.length - 1 && a.value.indexOf("@", b + 1) == -1) {
        b = a.value.indexOf(".");
        b = b != -1 && b != a.value.length - 1
    }
    if (b == false) {
        alert("You misspelled the email?");
        a.focus();
        a.select();
        return false
    }
    return b
}

function checkOther(a, b, c){
    els = a.form[b];
    if (els.type == "select-one") 
        for (i = 0; i < els.options.length; i++) {
            if (els.options[i].value == c) {
                els.options[i].checked = true;
                els.options[i].selected = true;
                return
            }
        }
    else 
        for (i = 0; i < els.length; i++) 
            if (els[i].type == "checkbox" || els[i].type == "radio") 
                if (els[i].value == c) {
                    els[i].checked = true;
                    return
                }
}

function checkRegExpr(a, b){
    var c = new RegExp(b);
    if (c.test(a.value) == true) 
        return true;
    else {
        alert("Failed regular expression test pattern '" + b + "' Fieldvalue '" + a.value + "'");
        return false
    }
}

function closeMainWindow(){
    window.opener = null;
    window.close()
};

