<!--

/* ajax.Request */
function ajaxRequest(url,data,func) {
  var aj = new Ajax.Request(
    url, {
      method:'post',
      parameters: data,
      onComplete: eval(func)
      }
    );
}

/* ajax.getResponseMessage */
function getResponseMessage(oReq) {
  if(oReq.responseText != '' && oReq.responseText != 'NULL'){
    alert(oReq.responseText);
  }
}

var EmailAddressAlreadyExists = true;
var PasswordIsNotValid = true;
var ScreenNameAlreadyExists = true;


function doRegistration(){
  if(EmailAddressAlreadyExists == true){
    checkEmailAddress($F('email'));
    return false;
  }

  if(PasswordIsNotValid == true){
    checkPassword();
    return false;
  }

  if(ScreenNameAlreadyExists == true){
    checkScreenName($F('screenname'));
    return false;
  }

  if(document.rsRegForm.acceptterms.checked != true){
    alert('Please accept the Terms of Service!');
    return false;
  }

  document.rsRegForm.submit();
}


function checkEmailAddress(emailAddress){
  validEmail = checkMail(emailAddress,1);

  if(validEmail == true){
    ajaxRequest('ajaxincludes/register.ajax.php','func=checkEmailAddress()&emailAddress='+emailAddress,'getResponseOfEmailAddressCheck');
  }else{
    EmailAddressAlreadyExists = true;
    $('email').focus();
  }
}

function getResponseOfEmailAddressCheck(oReq) {
  if(oReq.responseText == 'true' ){
    alert('Sorry, this Email Address already exists!');
    EmailAddressAlreadyExists = true;
    $('email').focus();
  }else{
    EmailAddressAlreadyExists = false;
  }
}

function checkPassword(){
  var pwd = $F('password').replace(/^\s+|\s+$/g,"");
	var pwdConfirm = $F('confirmPassword').replace(/^\s+|\s+$/g,"");

  if(pwd.length < 6){
		alert("Sorry, your Password is too short!");
		PasswordIsNotValid = true;
		$('password').focus();
	}else if(pwdConfirm.length > 0){
    if(pwd != pwdConfirm){
      alert("Sorry, the Passwords do not match.");
      PasswordIsNotValid = true;
  		$('password').focus();
    }else{
      PasswordIsNotValid = false;
    }
  }else{
    PasswordIsNotValid = true;
  }
}

function checkScreenName(screenNameValue){
  if(screenNameValue.replace(/^\s+|\s+$/g,"").length == 0){
    alert('Please enter a Screen Name!');
    return false;
  }

  if(screenNameValue.match(/[^A-Za-z0-9\_\-\s]/)){
    alert('Sorry, special chars ar not allowed!');
    return false;
  }

  ajaxRequest('ajaxincludes/register.ajax.php','func=checkScreenName()&screenNameValue='+screenNameValue,'getResponseOfScreenNameCheck');
}

function getResponseOfScreenNameCheck(oReqScreenName) {
  if(oReqScreenName.responseText != '' && oReqScreenName.responseText != 'NULL'){
    alert(oReqScreenName.responseText);
    ScreenNameAlreadyExists = true;
    $('screenname').focus();
  }else{
    ScreenNameAlreadyExists = false;
  }
}
//-->