/*	
	Chris Zegelin, started Mar 2009
	Thanks to Larry Ullman
*/

/*	The users's chosen username is sent to a PHP 
 *	script which will confirm its availability.
 */

// Function that starts the Ajax process
function check_uname( uname ) {

	// Confirm that the object is usable:
	if( ajax && uname.length>4){ 
		
		// Call the PHP script.
		// Use the GET method.
		// Pass the username in the URL.
		ajax.open( 'GET', 'checkuname.php?uname=' + encodeURIComponent(uname), true );
		
		// Function that handles the response:
		ajax.onreadystatechange = handle_check;
		
		// Send the request:
		ajax.send( null );

	}
}
function check_email( email) {

	// Confirm that the object is usable:
	if( ajax && email.length>4){ 
		
		// Call the PHP script.
		// Use the GET method.
		// Pass the username in the URL.
		ajax.open( 'GET', 'checkemail.php?email=' + email, true );
		
		// Function that handles the response:
		ajax.onreadystatechange = handle_check_email;
		
		// Send the request:
		ajax.send( null );

	}
}

// Function that handles the response from the PHP script:
function handle_check_email() {
	var obj = document.getElementById('email_lable');

	// If everything's OK:
	if( (ajax.readyState == 4) && (ajax.status == 200) ){

		// Assign the returned value to a document element:
		obj.innerHTML = ajax.responseText;
		if(ajax.responseText==' TAKEN:')
		{
			obj.style.color="red";
			document.getElementById('email_help').innerHTML="You already have account with us, directly go to <a href='/ZumeLifePortal'>login</a> page.";
			document.getElementById('submitbutton').disabled="true";
		}
		else
		{
			obj.style.color="green";
			document.getElementById('email_help').innerHTML="";
			document.getElementById('submitbutton').disabled="";
		}

	}
}

function handle_check() {
	var obj = document.getElementById('uname_lable');
	// If everything's OK:
	if( (ajax.readyState == 4) && (ajax.status == 200) ){

		// Assign the returned value to a document element:
		obj.innerHTML = ajax.responseText;
		if(ajax.responseText==' TAKEN:')
		{
			obj.style.color="red";
		}
		else
		{
			obj.style.color="green";
			
		}

	}
}
