var xmlhttp = null; var checkLoginTimeout = null; function checkLoginAvailability( login ) { clearTimeout( checkLoginTimeout ); setTimeout( "checkLoginAvailabilityRaw( '" + login + "' )", 1000 ); } function checkLoginAvailabilityRaw( login ) { login = login.replace( /^\s+/g, "" );// strip leading login = login.replace( /\s+$/g, "" );// strip trailing if( login.length < 1 ) { displayLoginAvailability( -1 ); return; } var sURL = "ajax_check_login_availability.php"; var sQueryString = 'u=' + login; if (window.XMLHttpRequest) {// code for Mozilla, Safari, etc xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=handleCheckLoginAvailability; xmlhttp.open("POST",sURL,true); xmlhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); xmlhttp.send(sQueryString); } else if (window.ActiveXObject) {//IE xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); if (xmlhttp) { xmlhttp.onreadystatechange=handleCheckLoginAvailability; xmlhttp.open("POST",sURL,true); xmlhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); xmlhttp.send(sQueryString); } } } function handleCheckLoginAvailability () { if( !xmlhttp ) { return } if (xmlhttp.readyState==4) { if (xmlhttp.status==200) { var oXML; oXML = xmlhttp.responseXML; var oRedirect = oXML.getElementsByTagName("redirect").item(0); if (oRedirect) { self.location = oRedirect.getAttribute("url"); } else { var oError = oXML.getElementsByTagName("e").item(0); if (oError) { alert (oError.getAttribute("m")); } else { var available = oXML.getElementsByTagName("loginAvailability").item(0); if( available ) { displayLoginAvailability( parseInt( available.getAttribute( 'available' ) ) ); } else { displayLoginAvailability( -2 ); } } } xmlhttp = null; } } } function displayLoginAvailability( state ) { message = null; if ( state == 0 ) { message = 'This username is unavailable!'; } if ( state == -1 ) { message = 'This username is too short!'; } if ( state == -2 ) { message = 'An error has occured. Please continue filling the form.'; } $( 'loginAvailabilityMessage' ).innerHTML = message; if( message ) { DrElement.show( $( 'loginAvailabilityMessage' ) ); } else { DrElement.hide( $( 'loginAvailabilityMessage' ) ); } } function clearLoginAvailabilityMessage() { $( 'loginAvailabilityMessage' ).innerHTML = ''; DrElement.hide( $( 'loginAvailabilityMessage' ) ); }