myPassword = "9999";
function getXMLHTTPRequest() {
  var req = false;
  try {
    req = new XMLHttpRequest();
  } catch (err) {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (err) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (err) {
        req = false;
      }
    }
  }
  return req;
};

function checkUsername(myUsername) {
  //document.getElementById('passwordinput').disabled = true;
  //document.getElementById('passwordconfirm').disabled = true;
  //document.getElementById('submitbutton').disabled = true;
  //document.getElementById('submitbutton').className = 'disabledbutton';
  document.getElementById('passwordcheck1').innerHTML = "(Passwords must be at least 5 characters in length!!)";
  var serverPage = 'check_account_request.php';
  myRand = parseInt(Math.random()*9999999999);
  var theURL = serverPage + "?rand="+myRand+"&username="+myUsername;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = usernameHTTPResponse;
  myReq.send(null);
};

function checkEmail(myEmail) {
	if ((myEmail.indexOf("@") == -1) || (myEmail.indexOf(".") < myEmail.indexOf("@")) || (myEmail.lastIndexOf(".") == myEmail.length-1)) {
    //document.getElementById('submitbutton').disabled = true;
    //document.getElementById('submitbutton').className = 'disabledbutton';
    //document.getElementById('usernameinput').disabled = true;
    document.getElementById('emailcheck1').innerHTML = "<font color='red'>illegal email</font>";
	}
	else if (myEmail.indexOf("\\") != -1) {
    //document.getElementById('submitbutton').disabled = true;
    //document.getElementById('submitbutton').className = 'disabledbutton';
    //document.getElementById('usernameinput').disabled = true;
    document.getElementById('emailcheck1').innerHTML = "<font color='red'>illegal email</font>";
	}
  else  {
    //document.getElementById('usernameinput').disabled = false;
    document.getElementById('emailcheck1').innerHTML = "<font color='green'>ok</font>";
	}
};

function checkPasswordLength(myPassword0) {
  myPassword = myPassword0;
	if (myPassword.length > 5) {
    //document.getElementById('passwordconfirm').disabled = false;
    //document.getElementById('submitbutton').disabled = true;
    //document.getElementById('submitbutton').className = 'disabledbutton';
    document.getElementById('passwordcheck1').innerHTML = "<font color='orange'>password is "+myPassword.length+"characters long</font>";
	}
  else {
    //document.getElementById('passwordconfirm').disabled = true;
    //document.getElementById('submitbutton').disabled = true;
    //document.getElementById('submitbutton').className = 'disabledbutton';
    document.getElementById('passwordcheck1').innerHTML = "<font color='red'>password is too short</font>";
	}
	/*
  var serverPage = 'check_account_request.php';
  myRand = parseInt(Math.random()*9999999999);
  var theURL = serverPage + "?rand="+myRand+"&password="+myPassword;
  myReq2.open("GET", theURL, true);
  myReq2.onreadystatechange = passwordHTTPResponse;
  myReq2.send(null);
  */
};

function checkPasswordConfirm(myPasswordConfirm) {
	if (myPasswordConfirm == myPassword) {
    //document.getElementById('submitbutton').disabled = false;
    //document.getElementById('submitbutton').className = 'button';
    document.getElementById('passwordcheck1').innerHTML = "<font color='green'>passwords match!!</font>";
	}
  else {
    //document.getElementById('submitbutton').disabled = true;
    //document.getElementById('submitbutton').className = 'disabledbutton';
    document.getElementById('passwordcheck1').innerHTML = "<font color='red'>passwords do not match</font>";
	}
	/*
  var serverPage = 'check_account_request.php';
  myRand = parseInt(Math.random()*9999999999);
  var theURL = serverPage + "?rand="+myRand+"&password="+myPassword+"&passwordconfirm="+myPasswordConfirm;
  myReq2.open("GET", theURL, true);
  myReq2.onreadystatechange = passwordHTTPResponse;
  myReq2.send(null);
  */
};

function usernameHTTPResponse() {
  if (myReq.readyState == 4) {
    if (myReq.status == 200) {
      //var messagecheck = myReq.responseXML.getElementsByTagName("message")[0];
      //document.getElementById('testresult').innerHTML = "test result "+messagecheck.childNodes[0].nodeValue;
      var usernamecheck = myReq.responseXML.getElementsByTagName("usernamecheck")[0];
      var usernamecolor = myReq.responseXML.getElementsByTagName("usernamecolor")[0];
      if (usernamecheck) {
        document.getElementById('usernamecheck1').innerHTML =
          "<font color='"+usernamecolor.childNodes[0].nodeValue+"'>"+usernamecheck.childNodes[0].nodeValue+"</font>";
        //if (usernamecolor.childNodes[0].nodeValue == "green") 
        //  document.getElementById('passwordinput').disabled = false;
      }
    }
  } else {
    document.getElementById('usernamecheck1').innerHTML = "checking...";
  }
}
/*
function passwordHTTPResponse() {
  if (myReq2.readyState == 4) {
    if (myReq2.status == 200) {
      var messagecheck = myReq2.responseXML.getElementsByTagName("message")[0];
      document.getElementById('testresult').innerHTML = "test result "+messagecheck.childNodes[0].nodeValue;
      var passwordcheck = myReq2.responseXML.getElementsByTagName("passwordcheck")[0];
      var passwordcolor = myReq2.responseXML.getElementsByTagName("passwordcolor")[0];
      if (passwordcheck) {
        document.getElementById('passwordcheck1').innerHTML =
          "<font color='"+passwordcolor.childNodes[0].nodeValue+"'>"+passwordcheck.childNodes[0].nodeValue+"</font>";
        if (passwordcolor.childNodes[0].nodeValue == "orange")
          document.getElementById('passwordconfirm').disabled = false;
        if (passwordcolor.childNodes[0].nodeValue == "green") {
          document.getElementById('submitbutton').disabled = false;
          document.getElementById('submitbutton').className = 'button';
        }
      }
    }
  } else {
    document.getElementById('passwordcheck1').innerHTML = "checking...";
    document.getElementById('submitbutton').disabled = true;
    document.getElementById('submitbutton').className = 'disabledbutton';
  }
}
*/

