/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * submitPwd.js
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to version 1.0 of the OpenFlyers
 * license that is available through the world-wide-web at the following
 * URI: http://www.openflyers.com/license/semifreelicense1_0.txt. If you did not receive a
 * copy of the OpenFlyers License and are unable to obtain it through the
 * web, please send a note to contact@openflyers.org so we can mail you
 * a copy immediately.
 *
 * @category    Javascript
 * @package     OpenFlyers
 * @author      Christophe LARATTE <christophe.laratte@openflyers.org>
 * @copyright   2008 OPENFLYERS S.A.R.L. <contact@openflyers.com>
 * @license     http://www.openflyers.com/license/semifreelicense1_0.txt  OpenFlyers License
 * @version     SVN: $Id: about.php 4610 2008-10-05 20:02:43Z christophe $*
 * @link       http://openflyers.org
 * @since      Wed Nov 19 2008
 */

function submit_pwd()
{
    var pwd = document.getElementById('rawPassword').value;
    //var authKey = document.getElementById('authKey').value;

    if (pwd != '') {
        document.getElementById('rawPassword').value = '';
        //document.getElementById('encryptPassword').value = encrypt(authKey+encrypt(pwd));
        document.getElementById('encryptPassword').value = encrypt(pwd);
    }
    return true;
}

function submit_two_pwd()
{
    var pwd1 = document.getElementById('raw_password').value;
    var pwd2 = document.getElementById('raw_password_confirmation').value;

    if (pwd1 != '' && pwd2 != '') {
        document.getElementById('raw_password').value = '';
        document.getElementById('raw_password_confirmation').value = '';
        document.getElementById('encrypt_password').value = encrypt(pwd1);
        document.getElementById('encrypt_password_confirmation').value = encrypt(pwd2);
    }
    return true;
}

function submit_three_pwd()
{
    var pwd1 = document.getElementById('old_password').value;
    var pwd2 = document.getElementById('raw_password').value;
    var pwd3 = document.getElementById('raw_password_confirmation').value;

    if (pwd1 != '' && pwd2 != '' && pwd3 != '') {
        document.getElementById('old_password').value = '';
        document.getElementById('raw_password').value = '';
        document.getElementById('raw_password_confirmation').value = '';
        document.getElementById('encrypt_old_password').value = encrypt(pwd1);
        document.getElementById('encrypt_password').value = encrypt(pwd2);
        document.getElementById('encrypt_password_confirmation').value = encrypt(pwd3);
    }
    return true;
}

function checkPassword(param)
{
    if (param[0] == 0 && trim(document.getElementById('raw_password').value) == '') {
        alert(param[1]);
        return false;
    }
    if ( trim(document.getElementById('raw_password').value) != trim(document.getElementById('raw_password_confirmation').value) ) {
        alert(param[2]);
        return false;
    }

    if (param[0] >= 0) {
        submit_two_pwd();
    }
    else {
        submit_three_pwd();
    }
}

function submitVisitorPwd()
{
    var pwd = document.getElementById('adminRawPassword').value;

    if (pwd != '') {
        document.getElementById('adminRawPassword').value = '';
        document.getElementById('adminEncryptPassword').value = encrypt(pwd);
    }
    return true;
}
