function ClickConfirm() {

	this.confirmBox = null;
	this.clickBox   = null;
	this.numClicks  = 0;
	this.maxClicks  = 3;

	this.init = function() {
		this.confirmBox = document.getElementById('confirm_box');
		this.clickBox   = document.getElementById('confirm_click_box');
	}

	this.randomizeColor = function() {

		var r = (Math.round((Math.random()*255)+1));
		var g = (Math.round((Math.random()*255)+1));
		var b = (Math.round((Math.random()*255)+1));

		var rgb = r + "," + g + "," + b;

		this.confirmBox.style.backgroundColor = "rgb(" + rgb + ")";

		r += 100;
		g -= 50;
		b -= 75;

		rgb = r + "," + g + "," + b;

		this.clickBox.style.backgroundColor = "rgb(" + rgb + ")";


		if( r+g+b < 450 )
			var color = 'white';
		else
			var color = 'black';

		this.clickBox.firstChild.style.color = color;

	}

	this.randomizeLocation = function() {

		var randomLeft = (Math.round((Math.random()*(this.confirmBox.offsetWidth))+1));
		var randomTop  = (Math.round((Math.random()*(this.confirmBox.offsetHeight))+1));

		//debug( "Random X: " + randomLeft + ", Random Y: " + randomTop + "<br>" );

		if( (randomLeft+69) > (this.confirmBox.offsetWidth) )
		{
			randomLeft = (randomLeft - 69);
		}

		if( (randomTop+22) > (this.confirmBox.offsetHeight) )
		{
			randomTop = (randomTop-22);
		}

		this.clickBox.style.top  = randomTop + 'px';
		this.clickBox.style.left = randomLeft + 'px';

	}

	this.addClick = function() {
		this.numClicks++;

		if( this.numClicks >= this.maxClicks )
		{
			this.done();
			return;
		}

		this.randomizeColor();
		this.randomizeLocation();
	}

	this.draw = function() {
		this.clickBox.style.display = 'block';
	}

	this.done = function() {
		this.clickBox.style.display='none';
		newP = document.createElement('p');
		newP.className = 'confirmed_human';
		newP.appendChild(document.createTextNode('CONFIRMED HUMAN!'));
		this.confirmBox.appendChild(newP);

		newI = document.createElement('input');
		newI.setAttribute('name', 'click_confirm');
		newI.setAttribute('value','done');
		newI.setAttribute('type', 'hidden');

		document.profile_add.insertBefore( newI, document.profile_add.firstChild );
	}
}

function debug(message)
{
	if( document.getElementById("debug") )
	{
		document.getElementById("debug").innerHTML += message;
		document.getElementById("debug").scrollTop += 25;
	}
}

window.onload = function() {

	cc = new ClickConfirm();
	cc.init();

	cc.randomizeColor();
	cc.randomizeLocation();
	cc.draw();

}

