function site(){
	loadSponsors();
}

function sponsors(){
	$('sponsorImg').hide();
	
	new Ajax.Updater('sponsorImg', 'inc/queries.php?a=getSponsors', {
    	onComplete: function() {
    		new Effect.Appear('sponsorImg');
    	}
	});
}

function loadSponsors(){
	sponsors();
	new PeriodicalExecuter(sponsors, 3);
}

function googleMaps(){
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(46.244200, 7.422800), 16);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setMapType(G_HYBRID_MAP); // Vue mixte
	
		// Create our "tiny" marker icon
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		
		var point = new GLatLng(46.244200, 7.422800);
		map.addOverlay(new GMarker(point, icon));
	}
}

function clearForm(input){
	// if already cleared, do nothing
	if ($(input)._cleared) return
	
	// when this code is executed, "this" keyword will in fact be the field itself
	$(input).clear()
	$(input)._cleared = true
}

function sendContactForm(){
	var valid = $('name').present() && $('email').present() && $('message').present() && $F('name') != 'Votre nom' && $F('email') != 'Votre adresse E-Mail' && $F('message') != 'Votre message'

	if (valid) {
		$('contactForm').request({
			onComplete: function () {
				new Effect.BlindUp('content', {
					duration: 0.5,
					afterFinish: function (){
						new Effect.BlindDown('contentConfirm', {
							duration: 0.5,
							afterFinish: function (){
								new Effect.Pulsate('contentConfirm', {duration: 0.5, pulses: 2});
							}
						});
					}
				});
			}
		})

	return false
	}
	else {
		new Effect.BlindDown('error', {
			duration: 0.5,
			afterFinish: function (){
				new Effect.Pulsate('error', {duration: 0.5, pulses: 2});
			}
		});
		
		return false
	}
}

function sendTrainingForm(){
	var valid = $('training').present() &&
	            $('name').present() &&
	            $('firstname').present() &&
	            $('street').present() &&
	            $('npa').present() &&
	            $('phone').present() &&
	            $('email').present() &&
	            $('birthday').present() &&
	            $F('name') != 'Nom' &&
	            $F('firstname') != 'Prénom' &&
	            $F('street') != 'Rue' &&
	            $F('npa') != 'Code postal et localité' &&
	            $F('phone') != 'Numéro de téléphone' &&
	            $F('email') != 'Adresse E-Mail' &&
	            $F('birthday') != 'Date de naissance';

	if (valid) {
		$('trainingForm').request({
			onComplete: function () {
				new Effect.BlindUp('trainingForm error', {
					duration: 0.5,
					afterFinish: function (){
						new Effect.BlindDown('contentConfirm', {
							duration: 0.5,
							afterFinish: function (){
								new Effect.Pulsate('contentConfirm', {duration: 0.5, pulses: 2});
							}
						});
					}
				});
			}
		})

	return false
	}
	else {
		new Effect.BlindDown('error', {
			duration: 0.5,
			afterFinish: function (){
				new Effect.Pulsate('error', {duration: 0.5, pulses: 2});
			}
		});
		
		return false
	}
}

function sendRegisterForm(){
	var valid = $('name').present() &&
	            $('street').present() &&
	            $('npa').present() &&
	            $('phone').present() &&
	            $('email').present() &&
	            $F('name') != 'Votre nom' &&
	            $F('street') != 'Votre rue' &&
	            $F('npa') != 'Votre code postal et localité' &&
	            $F('phone') != 'Votre numéro de téléphone' &&
	            $F('email') != 'Votre adresse E-Mail'

	if (valid) {
		$('registerForm').request({
			onComplete: function () {
				new Effect.BlindUp('register', {
					duration: 0.5,
					afterFinish: function (){
						new Effect.BlindDown('registerConfirm', {
							duration: 0.5,
							afterFinish: function (){
								new Effect.Pulsate('registerConfirm', {duration: 0.5, pulses: 2});
							}
						});
					}
				});
			}
		})

	return false
	}
	else {
		new Effect.BlindDown('error', {
			duration: 0.5,
			afterFinish: function (){
				new Effect.Pulsate('error', {duration: 0.5, pulses: 2});
			}
		});
		
		return false
	}
	
}
