window.addEvent('domready', function(){
	
	$('count').set('tween', {duration: 300, property: 'margin-top'});
	
	$('joinlink').addEvent('click', function(e){
		e.stop();
		$('count').tween(-200);
	});
	
	$('joincancel').addEvent('click', function(e){
		e.stop();
		$('count').tween(0);
	});
	
	
	// join form
	$('join116').addEvent('submit', function(e){
		e.stop();
		if(this.name.value == '' || this.email.value == '' || this.phone.value == '' || this.zip.value == ''){
			this.getElement('.note').set('html', "Please complete the form!");
		}else{
		
			this.getElement('.note').set('html', "<em>Sending...</em>");
			var req = this.get('send');
			req.addEvent('success', function(text){
				var rsp = JSON.decode(text);
				
				if(rsp.status == "ok"){
					$('join116').reset();
					$('join116').getElement('.note').set('html', "Ya! You're in and changing the world!");
					(function(){ $('count').tween(0); }).delay(2000);
				}else{
					$('join116').getElement('.note').set('html', rsp.info[0]);
				}
			});
			
			req.send();
		}
	});
	// restrict phone to numbers
	$('phone').addEvent('keypress', function(e){
		var e = new Event(e);
		if(!e.key.match(/^[-0-9\(\)\.]+$/)){
			e.stop();
		}
	});
});