function percent_howmuch(what, from, answer) {
	$(answer).val($(what).val() / 100 * $(from).val());
}

function makepassword(length, special, speciali, numbers, bigletters, letters) {
	if(
		$(length).val() >= 1 && 
		($(special).attr('checked') || $(numbers).attr('checked') || $(bigletters).attr('checked') || $(letters).attr('checked'))
	) {
	    var text = "";
		var possible = "";
		var specials = "!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~";
		var points = 0;
		
		if($(special).attr('checked')) { points += 2; }
		if($(special).attr('checked') && $(speciali).attr('checked')) { possible += "!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"; points += 1; }
		if($(numbers).attr('checked')) { possible += "0123456789"; points += 1; }
		if($(bigletters).attr('checked')) { possible += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; points += 1; }
		if($(letters).attr('checked')) { possible += "abcdefghijklmnopqrstuvwxyz"; points += 1; }
		
		if($(length).val() <= 4)
			points = 0;
		if($(length).val() >= 8)
			points += 1;
		if($(length).val() > 19)
			points = 6;


		for( var i=0; i < $(length).val(); i++ ) {
			if(
			($(special).attr('checked') && Math.floor(Math.random() * 4) == 1 && !$(speciali).attr('checked')) ||
			(!$(numbers).attr('checked') && !$(bigletters).attr('checked') && !$(letters).attr('checked'))
			)
				text += specials.charAt(Math.floor(Math.random() * specials.length));
			else
				text += possible.charAt(Math.floor(Math.random() * possible.length));
		}

		$('#result').val(text);			
		
		if(points <= 2)
			$('#strength').html('Heikko');
		else if(points <= 4)
			$('#strength').html('Keskitaso');
		else
			$('#strength').html('Vahva');
	} else {
		$('#result').val('Pituus pitää olla nollaa suurempi ja jokin kentistä pitää olla valittu');
	}
}
