function reload_captcha() {
	$oImg = document.getElementById("captcha");
	$oImg.src = "/qc/imagebuilder.php?ran="+Math.random();
}


var showErrors = true;
var cache = new Array();
var signupServerAddress = "http://www.worldarchive.co.uk/signupValidate.php";

// the function handles the validation for any form field
function validate(inputValue, fieldID) {
  // only continue if xmlHttp isn't void
  if (xmlHttp) {
    // if we received non-null parameters, we add them to cache in the
    // form of the query string to be sent to the server for validation
    if (fieldID) {
      // encode values for safely adding them to an HTTP request query string
      inputValue = encodeURIComponent(inputValue);
      fieldID = encodeURIComponent(fieldID);
      // add the values to the queue
      cache.push("inputValue=" + inputValue + "&fieldID=" + fieldID);
    }
    // try to connect to the server
    try {
      // continue only if the XMLHttpRequest object isn't busy
      // and the cache is not empty
      if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0) {
        // get a new set of parameters from the cache
        var cacheEntry = cache.shift();
        // make a server request to validate the extracted data
		serverGetRequest = signupServerAddress + "?" + cacheEntry;
//		alert ("|"+serverGetRequest+"|");
        xmlHttp.open("GET", serverGetRequest, true);
//        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = handleRequestStateChange;
        xmlHttp.send(null);
      }
    }
    catch (e) {
      // display an error when failing to connect to the server
      displayError(e.toString());
    }
  }
}

function processResponse (txtResponse) {
	if (txtResponse.length > 0) {
		fieldID = txtResponse.substr(0,txtResponse.indexOf("="));
		response = txtResponse.substr(txtResponse.indexOf("=")+1);
		document.getElementById(fieldID+"Failed").innerHTML = "<span class='error'>"+response+"</span>";
	}
	setTimeout("validate();", 250);
}
function validatePass1 () {
	if (document.getElementById("password").value.length < 6) {
			document.getElementById("passwordFailed").innerHTML = "<span class='error'>Password must be 6 characters or more.</span>";
	}
}

function validatePass2 () {
	if (document.getElementById("password").value.length > 0) {
		if (document.getElementById("password").value != document.getElementById("passwordConf").value) {
			document.getElementById("passwordFailed").innerHTML = "<span class='error'>Password and Password Confirmation must match.</span>";
		} else {
			document.getElementById("passwordFailed").innerHTML = "";
		}
	} else {
			document.getElementById("passwordFailed").innerHTML = "<span class='error'> Please enter a Password.</span>";
	}
}