
function Captcha()
{
 this.first_num = 0;
 this.second_num = 0;
 this.answer = 0;
 
 this.id = "";
 this.submit_id = "";
 
 
 
 this.init = function(id, submit_id)
 { 
 this.id = id;
 this.submit_id = submit_id;
 
 this.first_num = Math.floor( Math.random() * 11);
 this.second_num = Math.floor( Math.random() * 11);
 
 this.answer = this.first_num + this.second_num;
 
 if(document.getElementById('captcha_test_' + this.id))
 { 
 document.getElementById('captcha_test_' + this.id).innerHTML = this.getTest();
 }
 }
 
 this.getTest = function()
 {
 return "What is " + this.first_num + " + " + this.second_num + "?";
 }
 
 this.checkAnswer = function()
 {
 if(document.getElementById('captcha_answer_' + this.id))
 { answer = Number( document.getElementById('captcha_answer_' + this.id).value );
 
 if(answer == Number(this.answer))
 { this.enableSubmit();
 return true;
 }
 }
 
 this.wrongAnswer();
 }
 
 this.enableSubmit = function()
 {
 document.getElementById(this.submit_id).disabled = false;
 
 document.getElementById('captcha_message_' + this.id).innerHTML = "Correct, the form can now be submitted.";
 }
 
 this.wrongAnswer = function()
 {
 document.getElementById(this.submit_id).disabled = true;
 
 document.getElementById('captcha_message_' + this.id).innerHTML = "Incorrect";
 }
 
}

