var Register = function() { // Members. this.HttpRequest = null; this.Username = function(__Parent) { // Members. this.Parent = __Parent; this.Element = document.getElementById("Page-Username"); // Methods. this.GetValue = function() { return this.Element.value; }; this.Validate = function() { if(this.Element.value.match(/^[a-z][a-z0-9_]{3,15}$/i) == null) { alert("Invalid username!\nMust start with a character from a-z.\nMust be 4-16 characters.\nMay only consist of the characters a-z, 0-9 and underscore."); return false; } return true; }; }; this.Username = new this.Username(this); this.Password = function(__Parent) { // Members. this.Parent = __Parent; this.Element = document.getElementById("Page-Password"); // Methods. this.GetValue = function() { return this.Element.value; }; this.Validate = function() { if(this.Element.value.match(/^.{8,32}$/) == null) { alert("Invalid password!\nMust be 8-32 characters."); return false; } return true; }; }; this.Password = new this.Password(this); this.EmailAddress = function(__Parent) { // Members. this.Parent = __Parent; this.Element = document.getElementById("Page-EmailAddress"); // Methods. this.GetValue = function() { return this.Element.value; }; this.Validate = function() { if(this.Element.value.match(/^[a-z0-9._-]+@[a-z0-9._-]+.[a-z]$/i) == null) { alert("Invalid e-mailaddress!\nPlease write a correct e-mailaddress.\nIf the e-mailadress is correct, please contact an administrator."); return false; } return true; }; }; this.EmailAddress = new this.EmailAddress(this); this.Captcha = function(__Parent) { // Members. this.Parent = __Parent; this.Element = document.getElementById("Page-Captcha"); this.Image = document.getElementById("Page-Captcha-Image"); // Methods. this.GetValue = function() { return this.Element.value; }; this.UpdateImage = function() { this.Image.src = "/!images/captcha.php?Random=" + Math.random(); }; this.Validate = function() { if(this.Element.value.match(/^[A-Z0-9]{6}$/) == null) { alert("Invalid captcha!\nMust be 6 uppercase characters and numbers."); return false; } return true; }; }; this.Captcha = new this.Captcha(this); // Methods. this.Validate = function() { if(!this.Username.Validate()) { return false; } if(!this.Password.Validate()) { return false; } if(!this.EmailAddress.Validate()) { return false; } if(!this.Captcha.Validate()) { return false; } return true; }; this.OnSubmit = function() { if(this.HttpRequest == null) { if(!this.Validate()) { return; } this.HttpRequest = JavaScript.HttpRequest.Create(); this.HttpRequest.onreadystatechange = function() { Register.OnSubmit() }; this.HttpRequest.open("POST", "register.php", true); this.HttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); this.HttpRequest.send("Username=" + JavaScript.UrlEncode(this.Username.GetValue()) + "&Password=" + JavaScript.UrlEncode(this.Password.GetValue()) + "&EmailAddress=" + JavaScript.UrlEncode(this.EmailAddress.GetValue()) + "&Captcha=" + JavaScript.UrlEncode(this.Captcha.GetValue())); } else { if(this.HttpRequest.readyState == 4) { if(this.HttpRequest.responseText == "OK") { window.location.href = "success/"; } else { alert(this.HttpRequest.responseText); this.Captcha.UpdateImage(); } this.HttpRequest = null; } } }; };