function loadCaptchaImage(){
  var img = document.getElementById('captchaImage');
  var rand = Math.random() * 10;

  var url = '/getCaptcha.php?rand=' + rand;

  img.src = url;

}

function checkCaptcha(){
    var form = document.forms.form1;
    var captcha = form.captchaVal.value;
    
    var url = "checkCaptcha.php?val=" + captcha;
    var req = new Request({url: url,
			   async: false,
			   onComplete: function(text, xml){
		if (text == 1){
		    if (validateContact(form)) form.submit();
		}
		else {
		    form.captchaVal.value = '';
		    loadCaptchaImage();
		    alert("Security Image value did not match.  Please try again.");
		}
	    }
	});
    
    req.send(null);

}

function validateContact(form){
  var message = '';
  if (form.name.value == ''){
    message += "Please provide your name.\n";
  }
  if (form.phone.value == ''
      && form.email.value == ''){
    message += "Please provide a phone number or email where you can be contacted.\n";
  }

  if (message != ''){
    alert(message);
    return false;
  }
  return true;
}
