/*
 * Login functions for planbord
 *
 * Author:       $Author: cash2003 $
 *
 * History:
 *  $Log: login.js,v $
 *  Revision 0.4  2008/12/05 15:07:15  cash2003
 *  Use object detection for screen size.
 *
 *  Revision 0.3  2008/12/05 14:44:44  cash2003
 *  Version with browser detection.
 *
 * Copyright (C) Henri de Veer / Cardware B.V. 2007-2008 
 */
function CheckForm() {

    // Set flag to avoid multiple errors
    ok = true;

    // Convert user value to string object
    user = document.loginscreen.user.value;
    if ((user == null || user == "") && ok) {
        alert("Een username/email adres is vereist!");
        ok = false;
        document.loginscreen.user.focus();
    } else {
        if ( user.length < 1 ) { // 6 @@@@
            alert("De username/het email adres is te kort!");
            ok = false;
            document.loginscreen.user.focus();
        } else {
            user = user.toLowerCase();
            // Convert case to lower case
            document.loginscreen.user.value = user;
        }
    }

    // Convert password value to string object
    pwd = document.loginscreen.password.value;
    if ((pwd == null || pwd == "") && ok) {
        alert("Een password is vereist!");
        ok = false;
        document.loginscreen.password.focus();
    } else {
        if ( pwd.length < 1 ) {  // 4 @@@
            alert("Het password moet minimaal 4 karakters land zijn!");
            ok = false;
            document.loginscreen.password.focus();
        }
    }

    //
    // Send form to server if ok.
    //
    if (ok) {
        // Create MD5 hash of session and password
        document.loginscreen.response.value= calcMD5(document.loginscreen.session.value.concat(document.loginscreen.password.value));
        // Erase the password so it will not be summitted.
        document.loginscreen.password.value = "";

        // Set the browser
        document.loginscreen.browser.value = navigator.appName + "," + navigator.appVersion;

        // Set screen size

        // Check if the Microsoft object method is present.
        if (document.documentElement.clientWidth) {
            document.loginscreen.x_size.value = document.documentElement.clientWidth;
            document.loginscreen.y_size.value = document.documentElement.clientHeight;
        } else {

            // Check if the Firefox/Netscape object method is present.
            if (window.innerWidth) {
                document.loginscreen.x_size.value = window.innerWidth - 24;
                document.loginscreen.y_size.value = window.innerHeight - 2;
            } else {
                // Assume a reasonable default
                document.loginscreen.x_size.value = 900;
                document.loginscreen.y_size.value = 675;
            }
        }

        // Submit the form
        document.loginscreen.submit();
    }

} // END CheckForm()

