var registration = Class.create();

registration.prototype = {
	
	
	initialize: function() {	
	
		this.validScreenname = "false";
	
		this.validEmail = "false";
		
	},
	
	
	checkScreenname: function() {

		var url = "/admin/register/backend/ajax_check_screenname.php";
		
		$( 'reg_screenname' ).value = $( 'reg_screenname' ).value.replace( /[^0-9a-zA-Z_]/g, "" );
		
		var params = 'reg_screenname=' + $F('reg_screenname');
		
		var checkScreennameResult = this.checkScreennameResult.bind(this);	
		
		var ajax = new Ajax.Request( url,
			{method: 'post', parameters: params, onFailure: checkScreennameResult, onSuccess: checkScreennameResult} );	

	},
	
	
	checkEmail: function() {

		var url = "/admin/register/backend/ajax_check_email.php";
		
		var params = 'reg_email=' + $F('reg_email');
		
		var checkEmailResult = this.checkEmailResult.bind(this);	
		
		var ajax = new Ajax.Request( url,
			{method: 'post', parameters: params, onFailure: checkEmailResult, onSuccess: checkEmailResult} );	

	},
	
	
	checkScreennameResult: function( response ) {
	
		this.validScreenname = response.responseText;

		var image = $('screennameValid');
		
		var box = $('reg_screenname');

		image.style.backgroundImage = "url(/images/TickCross.gif)";
		image.style.width = "19px";
		image.style.height = "19px";

		if( this.validScreenname == "true" ) {
		
			image.style.backgroundPosition = "left";
			box.style.border = "2px solid #8CC641";
			box.style.backgroundColor = "#D4F4A6";
			
		} else {
		
			image.style.backgroundPosition = "right";
			box.style.border = "2px solid #F1828B";
			box.style.backgroundColor = "#F9BDC4	";
		
		}
		
		image.style.display = "block";

	},
	
	
	checkEmailResult: function( response ) {
	
		this.validEmail = response.responseText;

		var image = $('emailValid');
		
		var box = $('reg_email');

		image.style.backgroundImage = "url(/images/TickCross.gif)";
		image.style.width = "19px";
		image.style.height = "19px";

		if( this.validEmail == "true" ) {
		
			image.style.backgroundPosition = "left";
			box.style.border = "2px solid #8CC641";
			box.style.backgroundColor = "#D4F4A6";
			
		} else {
		
			image.style.backgroundPosition = "right";
			box.style.border = "2px solid #F1828B";
			box.style.backgroundColor = "#F9BDC4	";
		
		}
		
		image.style.display = "block";

	},
	
	
	removeChildren: function( element ) {	
	
		if( element.hasChildNodes() ) {
	
			numberOfChildren = element.childNodes.length

			for( var i=0; i<numberOfChildren; i++ )
					element.removeChild( element.childNodes[0] );
			
		}

	}	
				
	
};

myRegistration = new registration();