// This variable is needed, because we can't find out the image source in this javascript.
// So, we have to give this value into the javascript method.
var url = '';

// This method is called only the first time, when the user clicks on the image on the page.
function refreshCaptcha(src) {
	url = src;

	var w3cdom = (document.createElement && document.getElementsByTagName);
	if (!w3cdom) return;
		
	div = document.getElementById('captcha');
	if(div) {
		// delete all the child nodes of the div tag
		while(div.hasChildNodes()) {
			var knoten = div.firstChild;
			div.removeChild(knoten);
		}
		// add a new child to the div tag
		img = document.createElement('img');
		img.src = url + '?tmp=' + Math.round(1000*Math.random());
		img.onclick = refresh;
		div.appendChild(img);
	}
}

// This method is called from the second time on, when the user clicks on the image on the page.
function refresh() {
	var w3cdom = (document.createElement && document.getElementsByTagName);
	if (!w3cdom) return;
		
	div = document.getElementById('captcha');
	if(div) {
		// delete all the child nodes of the div tag
		while(div.hasChildNodes()) {
			var knoten = div.firstChild;
			div.removeChild(knoten);
		}
		// add a new child to the div tag
		img = document.createElement('img');
		img.src = url + '?tmp=' + Math.round(1000*Math.random());
		img.onclick = refresh;
		div.appendChild(img);
	}
}
