var o = window.onload, num1, num2, captcha_answer, max = 10;
window.onload = function() {

	num1 = document.getElementById('num1');
	num2 = document.getElementById('num2');
	captcha_answer = document.getElementById('captcha_answer');
	
	generate_captcha();

	if( typeof o == 'function' ) {
		o();
	}

}

function generate_captcha() {

	num1.innerHTML = Math.floor(Math.random()*max+1);
	num2.innerHTML = Math.floor(Math.random()*max+1);

}
function validate_captcha() {
	
	var n1 = parseInt(num1.innerHTML);
	var n2 = parseInt(num2.innerHTML);
	
	if( n1 + n2 != parseInt(captcha_answer.value) ) {
	
		generate_captcha();
		alert('Captcha validation was incorrect. Please try again.');
		return false;
		
	}
	
	return true;
	
}

