// JavaScript Document
var failCount = 0;

function captchaTest(formName, submitButton) {
	submitButton.disabled = true;
	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	} 
	http.open("GET", "/forms/captcha/testCaptcha.aspx?captchaPhrase="  + document.getElementById('captchaPhrase').value + "&captchaId=" + document.getElementById('captchaId').value, false);
	http.send(null);
	if (http.responseText == "PASS") {
		document.getElementById('send').value = "true";
		return true;
	} else {
		document.getElementById('result').innerHTML = http.responseText;
		submitButton.disabled = false;
		failCount = failCount + 1;
		if(failCount > 2){
			window.location = "/forms/error.aspx";
		}
		return false;
	}
}
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	if(errors == '') {
		document.MM_returnValue = captchaTest('form1',document.getElementById('submitBtn'));
	} else {
		document.MM_returnValue = (errors == '');	
	}
} }
