// file name   : checkinput.js
// version     : 1.0
// description : General and formal HTML function declare.
// created by  : Hercules CHOI
// created on  : 17 Dec 2008
// modified on : 17 Dec 2008

var message="";    // no right click without alert

function HandleOnClose() { document.cookie="user=; expires=Now(); path=/;"; }

function integerOnly(myfield, e, dec) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if ((key==null)||(key==0)||(key==8)||(key==9)||(key==13)||(key==27)) return true;
    else if ((("0123456789").indexOf(keychar) > -1)) return true;
    else return false;
}

function numericDecimal(myfield, e, dec) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if ((key==null)||(key==0)||(key==8)||(key==9)||(key==13)||(key==27)) return true;
    else if ((("0123456789").indexOf(keychar) > -1)) return true;
    else if ((keychar == ".") && myfield.value.indexOf(keychar) == -1) return true;
    else return false;
}

function noSpecialChar(myfield, e, dec) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if ((key==null)||(key==0)||(key==8)||(key==9)||(key==13)||(key==27)) return true;
    else if ((("\"\'\$:,;").indexOf(keychar) > -1)) return true;
    else return false;
}

function verifyDate(dateTXT,isEmpty,formName) {//isEmpty=0:empty, 1:notempty
    if (isEmpty > 0 || dateTXT.value.length > 0) {
        if (dateTXT.value.length > 0) {
            if (dateTXT.value.match("^\\d{4}-\\d{1,2}-\\d{1,2}$") == null) {
                alert("Date Format Invalid!");
                setTimeout("document." + formName.valueOf() + "." + dateTXT.name + ".focus();",0);
                return false;
            } else {
                var _bValid = true;
                var monthMax = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
                var vd = new Array();
                vd = dateTXT.value.split('-');

                if (vd[1] < 1 || vd[1] > 12) _bValid = false;
                if (_bValid) if (vd[2] < 1 || vd[2] > monthMax[vd[1]]) _bValid = false;
                if (_bValid) {
                    if (vd[1] == 2) {
                        var leap = (vd[0] % 4 == 0 && (vd[0] % 100 != 0 || vd[0] % 400 == 0));
                        if (vd[2] > 29 || (vd[2] == 29 && !leap)) _bValid = false;
                    }
                }
                if (!_bValid) {
                    alert("Date Invalid!");
                    setTimeout("document." + formName.valueOf() + "." + dateTXT.name + ".focus();",0);
                    return false;
                } else return true;
            }
        } else if (isEmpty > 0 && dateTXT.value.length == 0) {
            alert("Date Empty!");
            setTimeout("document." + formName.valueOf() + "." + dateTXT.name + ".focus();",0);
            return false;
        }
    } else return true;
}

function verifyEmail(emailTXT,isEmpty,formName) { //isEmpty=0:empty, 1:not empty
     if (emailTXT.value.length > 0 || isEmpty > 0) {
         if (emailTXT.value.length == 0 && isEmpty == 1) {
                alert('Email address Empty!');
                setTimeout("document." + formName.valueOf() + "." + emailTXT.name + ".focus();",0);
                return false;
         } else if (emailTXT.value.search(/^[a-z0-9_.%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/) == -1) {
                alert('Please enter a valid email address.');
                if (isEmpty == 1) //must input
                setTimeout("document." + formName.valueOf() + "." + emailTXT.name + ".focus();",0);
                // else // no need focus to text box
                return false;
         } else return true;
     } else  return true;
}

function clickIE() {
    if (document.all) {
       (message);
       return false;
    }
}

function clickNS(e) {
    if (document.layers || (document.getElementById && !document.all)) {
        if (e.which==2 || e.which==3) {
           (message);
           return false;
        }
    }
}

if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS;
} else {
    document.onmouseup=clickNS;
    document.oncontextmenu=clickIE;
}
/*document.oncontextmenu=new Function("return false;");*/