
function init_securite_passwd(form_name)
{
	var form = document.forms[form_name];
	
	for (name in mySecuritePasswordStatus) {
		form[name].onkeyup = checkPassword;
		form[name].onkeyup();
	}

	mySecuritePasswordError = false;
	
	form.onsubmit = checkForms;	
}

function checkForms()
{
	var poziom = new Array (jsI18Nwylaczony , jsI18Nniski , jsI18Nsredni , jsI18Nwysoki);
	for (name in mySecuritePasswordStatus) {
		if (!mySecuritePasswordStatus[name]) {
			alert (eval(jsI18Nhasla));
			return false;	
		}
	}
	
}

function checkPassword() 
{
	var poziom_string = new Array (jsI18Nbrak, jsI18Nniski , jsI18Nsredni, jsI18Nwysoki);
	var ret;
	obj = this;
	span_fault = document.getElementById('psl_' + obj.id + '_fault');
	span_correct = document.getElementById('psl_' + obj.id + '_correct');
	span_status = document.getElementById('psl_' + obj.id + '_status');
	var poziom = psl(obj.value);
	if (((mySecuritePasswordRequired || obj.value.length > 0) &&  poziom < mySecuritePasswordPSL) || mySecuritePasswordError) {
		mySecuritePasswordStatus[obj.id] = false;
		span_correct.hide();
		span_fault.show();
		ret = false;
	} else {
		mySecuritePasswordStatus[obj.id] = true;
		span_correct.show();
		span_fault.hide();
		ret = true;
	}
	
	if (mySecuritePasswordRequired || obj.value.length > 0) {
		span_status.innerHTML = poziom_string[poziom];
	} else {
		span_status.innerHTML = '';
	}
	return ret;
}


/**
 * psl, password security level function,
 *	checks security level of a password.
 *
 *	psl(&$password:String):UInt32
 *
 * @param	String		generic password by reference
 * @return	UInt32		security level from 0 to 3
 * ------------------------------------------
 * Security Level Values
 *
 *	0	You shouldn't allow this kind of passwords
 *	1	Low Security, less than 5 seconds with a brute force
 *	2	Medium Security, should be good enought
 *	3	High Security, really difficult to brute force
 * ------------------------------------------
 * @author		Andrea Giammarchi
 * @site		http://www.devpro.it/
 * @date		2006 / 11 / 10
 * @version		1.0
 * @compatibility	probably with every browse
 */
function psl(pwd){
	var	length = pwd.length, level = 0;
	if(length > 5) {
		level = 1;
		if(length > 6) {
			if(/[a-z]/.test(pwd) && /[A-Z]/.test(pwd) && /[0-9]/.test(pwd))
				level = 3;
			else if(
				(/[a-z]/.test(pwd) && (/[A-Z]/.test(pwd) || /[0-9]/.test(pwd))) ||
				(/[0-9]/.test(pwd) && (/[A-Z]/.test(pwd) || /[a-z]/.test(pwd))) ||
				(/[A-Z]/.test(pwd) && (/[a-z]/.test(pwd) || /[0-9]/.test(pwd)))
			)
				level = /[\x20-\x2F]|[\x3A-\x40]|[\x5b-\x60]|[\x7B-\uFFFF]/.test(pwd) ? 3 : 2;
		};
	};
	return level;
};
