var MAF = { 

	add_friend : function () {
		var regex 		= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var name  		= $F('friend_name');
		var email 		= $F('friend_email');
		var halt 		= false;
		
		// validate
		if ( name == '' ) { halt = true; }
		if ( email == '' ) { halt = true; }
		if( ! email.match(regex) ) { halt = true; }
		
		if ( ! halt ) {
			$('error').hide();
			
			this.communicate('friends_container', 'http://www.induscorporation.com//mailafriend/handle/action=list/', 'name='+name+'&email='+email);
			
			// clear input
			$('friend_name').value = '';
			$('friend_email').value = '';
		} else {
			$('error').show();
		}
		
	},
	
	remove_friend : function (id) {
		if ( id == '0' ) { id = '_0'; }
		this.communicate('friends_container', 'http://www.induscorporation.com//mailafriend/handle/action=list/', 'id='+id);
	},
	
	validate : function () {
		var regex 		= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var your_name 	= $F('your_name');
		var your_email  = $F('your_email');
		var halt 		= false;
		
		if ( your_name == '' ) { halt = true; }
		if ( your_email == '' ) { halt = true; }
		if( ! your_email.match(regex) ) { halt = true; }

		if ( ! halt ) {
			$('error').hide();
			document.mailafriend.submit();
		} else {
			$('error').show();
		}
		
	},
	
	communicate : function (target, url, params) {
		if ( Ajax.Updater == 'undefined' ) {
			alert('Module requires prototype/scriptaculous!');
		} else {
			new Ajax.Updater(target, url, {
				method		: 'post',
				postBody	: params,
				asynchronous: true, 
				evalScripts : true,
				onLoading	: function() {
				},
				onComplete	: function() {
				},										
				onFailure: function() { 
					alert('error contacting the server'); 
				}
			});	
		}
	}
	
}