
/**
 * Inscription newsletter
 */
function inscriptionNewsletter() {

	var nom = $('#form_inscription_newsletter_nom').val();
	var prenom = $('#form_inscription_newsletter_prenom').val();
	var mail = $('#form_inscription_newsletter_email').val();
	var codepostal = $('#form_inscription_newsletter_cp').val();
	var dataInscription = 'mail=' + mail + '&inscription=' + '1' + '&nom=' + nom + '&prenom=' + prenom + '&codepostal=' + codepostal;
	//alert ("Inscription : " + dataInscription);
		
	$.ajax({         
		url: "db/newsletterdao.php",   
		type: 'POST',
		timeout: 10000,
        data: dataInscription,		       
		success: function(content){       
			if (content == '' || content == '0') {
				alert("L'adresse " + mail + " recevra la prochaine newsletter Cycles 84.");
			}
			else {
				alert(content);
			}
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			  // typically only one of textStatus or errorThrown 
			  // will have info
			  //alert(textStatus + '\n' + errorThrown); // the options for this ajax request
			  alert("L'inscription a échoué. Merci de bien vouloir réessayer plus tard.");
		}

	});
	
	// effacement du formulaire
	$('#form_inscription_newsletter').clearForm();	
	
} 

function swapImages(){      var $active = $('#myGallery .active');      var $next = ($('#myGallery .active').next().length > 0) ? $('#myGallery .active').next() : $('#myGallery img:first');      $active.fadeOut(function(){      $active.removeClass('active');      $next.fadeIn().addClass('active');      });    }


$.fn.clearForm = function() {
	  return this.each(function() {
	    var type = this.type, tag = this.tagName.toLowerCase();
	    if (tag == 'form')
	      return $(':input',this).clearForm();
	    if (type == 'text' || type == 'password' || tag == 'textarea')
	      this.value = '';
	    else if (type == 'checkbox' || type == 'radio')
	      this.checked = false;
	    else if (tag == 'select')
	      this.selectedIndex = -1;
	  });
	};
	

$(document).ready(function(){
	
	//hover states on the static widgets
	/*$('ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);*/	

	// cachés au démarrage
	$('#marques').find("div").hide();//("class:divMarqueVelo").hide();
	$('#Orbea').show("slow");
	//affichage du div correspondant au li sélectionné
	$('#liste_marques>li').click(
		function() {
			var marque = $(this).text();
			var marque="#" + marque;
			$('#marques').find("div").hide();
			$(marque).show("slow");
		}
	);
		

	// menu accueil
	$('#menu_tree_accueil').click(function () {
		$('#tabs').tabs('select',0);
		return false;
	});
	
	// contact
	$('#a-contact').click(function () {
		$('#tabs').tabs('select',4);
		return false;
	});
	// contact
	$('#a-contact2').click(function () {
		$('#tabs').tabs('select',4);
		return false;
	});
	
	// marques
	$('#a-marques').click(function () {
		$('#tabs').tabs('select',1);
		return false;
	});

	// prestations
	$('#a-prestations').click(function () {
		$('#tabs').tabs('select',2);
		return false;
	});
	
	//newsletter
	$('#a-newsletter').click(function () {
		$('#tabs').tabs('select',4);
		return false;
	});

	//inscription newsletter
	$("#boutonInscriptionNewsletter").click(function() {
		inscriptionNewsletter();	
				
		return false;
	});	

	// Run our swapImages() function every 15secs      
	setInterval('swapImages()', 15000);
	
	// Tabs
	$('#tabs').tabs({
		//event: 'mouseover',
		fxFade: true
		,fxAutoHeight: true
	});
	
	
});




