addLoadEvent( findLogin );

function findLogin() {
    var email = document.getElementById("email");
    if( email ) {
        email.onblur = function() {
	        var _url = "http://"+hostname+"/profile/ax_profile_check.phtml?email=" + encodeURIComponent( email.value );
	        httpRequest( "GET", _url, true, handleProfileResponse );
    	}
    }
}


//event handler for XMLHttpRequest
function handleProfileResponse() {
   
    try{
        if( request.readyState == 4 ) {
            if( request.status == 200 ) {
            	var response = request.responseText;
            	var profileFound = document.getElementById("profileFound");
            	if( profileFound ) {
            		profileFound.parentNode.removeChild(profileFound);
            	}
            	if( response == '1' ) {
            		var email = document.getElementById("email");
            		if( email ) {
		            	var docfrag = document.createDocumentFragment();
				
						var div = document.createElement("div");
						div.id = "profileFound";
						
						var divtext = document.createTextNode('Een profiel met dit email adres bestaat reeds. U kunt inloggen via de "My KVO" dialoog links, of indien u uw paswoord vergeten bent kunt u dit opvragen via de form onderaan op deze pagina.');
						
						div.appendChild( divtext );
								
						docfrag.appendChild( div );
						
						email.parentNode.appendChild( docfrag );

						var emailLogin = document.getElementById("emailLogin")
						if( emailLogin ) {
							emailLogin.value = email.value;
						}					
						
						var emailRecover = document.getElementById("emailRecover")
						if( emailRecover ) {
							emailRecover.value = email.value;
						}					
					}
				}
            } else {
                //request.status is 503
                //if the application isn't available;
                //500 if the application has a bug
                //alert(
                //        "A problem occurred with communicating between "+
                //        "the XMLHttpRequest object and the server program.");
            }
        }//end outer if
        
        
    } catch (err)   {
        //alert("It does not appear that the server is "+
        //      "available for this application. Please"+
        //      " try again very soon. \nError: "+err.message);

    }
}



