var xmlhttp = null; function initXmlHttp(){ if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest() } else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } } function validateRegistration() { $usr = document.forms.f_registration.usr.value; $pwd = document.forms.f_registration.pwd.value; $pwdVerfiy = document.forms.f_registration.pwdVerify.value; if (!$usr=="") { if(checkValidEmail($usr)){ if (!$pwd=="") { if (checkPasswordLength($pwd)){ if ($pwd==$pwdVerfiy){ if (document.forms.f_registration.agb.checked){ return usr_handler("typ=0&usr="+$usr+"&pwd="+$pwd); } else{ alert("Please accept the Terms & Conditions by clicking here."); } } else{ alert("The password you have entered does not match with that which you have registered."); } } else{ alert("Your password must be between 6 and 16 characters."); } } else{ alert("Please enter your password"); } } else{ alert("You entered an invalid email address. Please try again."); } } else{ alert("Please enter your email address"); } return false; } function validateConfirmation() { $pwd = document.forms.f_confirmation.pwd.value; $cid = document.forms.f_confirmation.cid.value; if (!$pwd=="") { usr_handler("typ=1&pwd=" + $pwd + "&cid=" + $cid); } else{ alert ("Please enter your password"); } return false; } function validateLogin(){ $usr = document.forms.f_login.email.value; $pwd = document.forms.f_login.password.value; if ($usr == "") { alert("Please enter your email address"); return false; }else if (!checkValidEmail($usr)){ alert("You entered an invalid email address. Please try again."); return false; }else if ($pwd=="") { alert("Please enter your password"); return false; }else{ usr_handler("typ=2&pwd=" + $pwd + "&usr=" + $usr); return false; } } function validateAccountUpdate(){ $pwd = document.forms.f_accountupdate.password.value; $pwdVerify = document.forms.f_accountupdate.passwordVerify.value; if (!$pwd == ""){ if ($pwd == $pwdVerify){ if(checkPasswordLength($pwd)){ return true; } else{ alert("Your password must be between 6 and 16 characters."); return false; } } else{ alert("The password you have entered does not match with that which you have registered."); return false; } } } function usr_handler($params){ var params = $params; initXmlHttp(); xmlhttp.open("POST","./user/handler.php",true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.onreadystatechange=catch_usr_handler; xmlhttp.send(params); } function catch_usr_handler(){ if(xmlhttp.readyState==4){//data received var response = xmlhttp.responseText.replace(/^\s+|\s+$/g, '');//trim the response //alert(response); switch (response) { case "0.0": alert("The e-mail address you entered is already in use. Please use another e-mail address or if you have forgotton your password please click on the link on the right."); break; case "0.1": window.location="http://www.glass.co.uk/user/register.php?done"; break; case "0.2": alert("The e-mail address you entered is already in use. Please use another e-mail address or if you have forgotton your password please click on the link on the right."); break; case "1.0": //error alert("An error occured during confirmation. Please try again."); break; case "1.1": window.location ="http://www.glass.co.uk/user/confirm.php?done"; break; case "1.2": alert("The password you have entered does not match with that which you have registered. Please try again."); break; case "2.0": alert("Your login failed. Please check your email address and password and try again."); break; case "2.1": window.location.reload( false ); break; case "2.2": alert("In order to log-in, you must review the email we sent you with your confirmation code."); break; case "2.3": window.location ="http://www.glass.co.uk/user/showroom.php?added&list="; break; case "2.4": window.location ="http://www.glass.co.uk/user/showroom.php?exists&list="; break; default: alert("Unexpected error"); alert("response: " + response); } } } function validatePasswordChange(){ $pwd = document.forms.f_pwforgotten.pwd.value; $pwdVerify = document.forms.f_pwforgotten.pwdVerify.value; if ($pwd == $pwdVerify){ if(checkPasswordLength($pwd)){ return true; } else{ alert("Your password must be between 6 and 16 characters."); return false; } } else{ alert("The password you have entered does not match with that which you have registered."); return false; } } function validatePasswordRequest(){ $usr = document.forms.f_PWRequest.usr.value; if (checkValidEmail($usr)){ return true; } else{ alert("You entered an invalid email address. Please try again."); return false; } } function validateShrChangeName(){ document.changeVehicleName.submit(); } function validateShrDeleteEntry(){ var answer = confirm ("") if (answer){ $vehicleID = document.getElementById('vehicleID').value; usr_handler("typ=7&vehicleID="+$vehicleID); } } function checkValidEmail($emailAddr){ var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (filter.test($emailAddr)){ return true; } else{ return false; } } function checkPasswordLength($password){ if ($password.length >= 6 && $password.length <= 16){ return true; } else{ return false; } }