function init() {
	ajaxFunc('new_code');
	document.getElementById('submit_supp_req').disabled = true;
	document.getElementById('attempt').value = '';
	document.getElementById('result').innerHTML = '';
	document.getElementById('attempt').focus();
}

//Browser Support Code
function ajaxFunc(mode, item1, item2, item3) {
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}

	// functions that will receive data sent from the server

	// we add this param to prevent fetched content being brought from the cache
	var rnd = Math.random()*10000;

	// create new code
	if(mode == 'new_code') {
		ajaxRequest.onreadystatechange = function() {
			if(ajaxRequest.readyState == 4) {
				response = ajaxRequest.responseText;
				// alert(response);
				document.getElementById('code_img').innerHTML = '<img src="/images/code.php?obf=' + response + '" width="140" height="30" style="border:1px solid #000" alt="" />';
				document.getElementById('secret_code').value = response;
			}
		}
		ajaxRequest.open("GET", "/includes/functions/ajax.php?r=" + rnd + "&mode=new_code", true);
		ajaxRequest.send(null);
	}

	// test input
	if(mode == 'test_input') {
		ajaxRequest.onreadystatechange = function() {
			if(ajaxRequest.readyState == 4) {
				response = ajaxRequest.responseText;
				// alert(response);
				document.getElementById('result').innerHTML = response;
				if(response.indexOf('green') != -1) {
					document.getElementById('submit_supp_req').disabled = false;
				} else {
					document.getElementById('submit_supp_req').disabled = true;
				}
			}
		}
		var secret_code = document.getElementById('secret_code').value;
		var attempt = document.getElementById('attempt').value;
		ajaxRequest.open("GET", "/includes/functions/ajax.php?r=" + rnd + "&mode=test_input&secret_code=" + secret_code + "&attempt=" + attempt, true);
		ajaxRequest.send(null);
	}
}