function isblank(formRef) {
    var s = formRef.value;
    while(''+s.charAt(s.length-1)==' ') s=s.substring(0,s.length-1);
    formRef.value = s;
    if(s == '') return true;
    else return false;
}
function verifyForm(f) {
    var msg;
    var empty_field = "";
    for (var i=0;i < f.length ; i++) {
        var e = f.elements[i];
        if((e.type == "text" ) || (e.type == "password")) {
            if((e.value == null) || (e.value == "") || isblank(e)) {
                if(e.name == 'schoolcode') e.name = 'School Code';
                else
                if(e.name == 'loginname') e.name = 'User Name';
                else
                if(e.name == 'password') e.name = 'Password';
                empty_field += "\n    " + e.name;
                continue;
            }
        }
    }
    if(!empty_field ) return true;
    else {
        msg = "\nThe following fields are required.\n";
        msg += "----------------------------------------";
        if (empty_field) msg += empty_field + "\n";
        window.alert(msg);
        return false;
    }
}
function set_name(Login) {
    var expdate = new Date ();
    expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
    var schoolcode = document.Login.schoolcode.value;
    var loginname = document.Login.loginname.value;
    if (schoolcode != "" && loginname != "") {
        SetCookie ("Jschoolcode", schoolcode, expdate);
        SetCookie ("Jloginname", loginname, expdate);
    }
}
function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}
function auto_show_name() {
    if(GetCookie("Jschoolcode") != null)
        document.Login.schoolcode.value=GetCookie('Jschoolcode');
    if(GetCookie("Jloginname") != null)
        document.Login.loginname.value=GetCookie('Jloginname');

    if(GetCookie("Jschoolcode") != null && GetCookie("Jloginname") != null)
        document.Login.password.focus();
    else document.Login.schoolcode.focus();
}
function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}