// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var RANDOM_PASSWORD_CHARACTERS = 'abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789';
function generateRandomPass(desired_length) {
	var pass;
	do {
		pass = '';
		while(pass.length < desired_length) {
			pass += RANDOM_PASSWORD_CHARACTERS[Math.floor(Math.random()*RANDOM_PASSWORD_CHARACTERS.length)];
		}
	} while(!isValidPass(pass));
	return pass;
}

function isValidPass(password) {
	if(!password.match(/[0-9\?\!\@\#\$\%\^\&\*\(\)\[\]\{\}\=\+\-]/)) return false;
	if(!password.match(/[A-Z]/)) return false;
	if(!password.match(/[a-z]/)) return false;
	return true;
}

function setRandomPassword(field_id) {
	document.getElementById(field_id).value = generateRandomPass(6);
}
function restorePassword(field_id, password) {
	document.getElementById(field_id).value = password;
}

function disable(field_id) {
	document.getElementById(field_id).disabled = true;
}
function enable(field_id) {
	document.getElementById(field_id).disabled = false;
}