$( function() {

	/* Code Facebook */
	$( '#blocFacebook' ).html( '<iframe src="http://www.facebook.com/plugins/likebox.php?id=100197466969&amp;width=210&amp;connections=10&amp;stream=true&amp;header=true&amp;height=587" scrolling="no" frameborder="0" style="border:none;overflow:hidden;width:210px;height:587px;background-color:#FFFFFF;" allowTransparency="true"></iframe>' );
	
	/* Code des options */
	$( '#listeRecherche form#vehicule select[name="marque"]' ).change ( function(){ $.post( 'ajax/options.html',{ filtre : $( '#listeRecherche form#vehicule input[name="filtre"]' ).val(), marque : $( this ).val() }, function( data ){ $( '#listeRecherche form#vehicule select[name="modele"]' ).html( data ); } ); } );
  	$( '#listeRecherche form#vehicule select[name!="marque"]' ).change ( function(){ $( this ).parents( 'form' ).submit(); } );
  	
	$( '#listeRecherche form#appareil select[name="marque"]' ).change ( function(){ $.post( 'ajax/options.html',{ filtre : $( '#listeRecherche form#appareil input[name="filtre"]' ).val(), marque : $( this ).val() }, function( data ){ $( '#listeRecherche form#appareil select[name="modele"]' ).html( data ); } ); } );
  	$( '#listeRecherche form#appareil select[name!="marque"]' ).change ( function(){ $( this ).parents( 'form' ).submit(); } );
 
	$( 'form#assistant select[name="marque"]' ).change ( function(){ $.post( 'ajax/options.html',{ etape : $( 'form#assistant input[name="etape"]' ).val(), marque : $( this ).val() }, function( data ){ $( 'form#assistant select[name="modele"]' ).html( data ); } ); } );
  	$( 'form#assistant select[name!="marque"]' ).change ( function(){ $( this ).parents( 'form' ).submit(); } );
  		
	/* Code des onglets */
	if ( $( '#onglets' ).length > 0 ) {	$( '#onglets' ).tabs();	}

	/* Code ajout au panier */
	if ( $( '#apercuPanier' ).length > 0 ) {
		$( 'a.ajoutPanier' ).click( function(){
			var etape = ''; if ( this.href.indexOf( 'etape=' ) >= 0 ) { etape = this.href.split( 'etape=' )[ 1 ].split( '&' )[ 0 ]; }
			$.post( 'ajax/apercuPanier.html', this.href.split( '?' )[ 1 ], function ( data ) { 
				$( '#apercuPanier' ).html( data ); 
				if ( etape != '' ) { 
					self.location = self.location.href.split( '?' )[ 0 ] + '?etape=' + etape; return false;
				} 
			} ); 
			return false; 
		} );
	}	
	
	/* Code colorbox */
	if ( $( 'a[rel="colorbox"]' ).length > 0 ) { $( 'a[rel="colorbox"]' ).colorbox( { transition : 'elastic' } ); }
	
	/* Code du formulaire d'identification */
	$( '#identification input[type="checkbox"][name="autreAdresse"], #revendeurs input[type="checkbox"][name="autreAdresse"]' ).bind( 'click', function() {
		if ( $( this ).attr( 'checked' ) ) { $( '#adresse2' ).removeClass( 'cache' ); }
		else { $( '#adresse2' ).addClass( 'cache' ); }
	} );
	$( '#identification input[type="text"], #revendeurs input[type="text"]' ).bind( 'keyup', function() {
		var n = '#info_' + $( this ).attr( 'name' );
		if ( $( this ).val() == '' ) { $( n ).removeClass( 'ok' ); $( n ).addClass( 'erreur' ); $( n ).empty().append( 'Champ obligatoire' ); }
		else { $( n ).removeClass( 'erreur' ); $( n ).addClass( 'ok' ); $( n ).empty(); }
	} );
	
	$( '#identification select, #revendeurs select' ).bind( 'focus', function() {
		var n = '#info_' + $( this ).attr( 'name' );
		if ( $( this ).val() == '' ) { $( n ).removeClass( 'ok' ); $( n ).addClass( 'erreur' ); $( n ).empty().append( 'Champ obligatoire' ); }
		else { $( n ).removeClass( 'erreur' ); $( n ).addClass( 'ok' ); $( n ).empty(); }
	} );
	
	$( '#identification select, #revendeurs select' ).bind( 'change', function() {
		var n = '#info_' + $( this ).attr( 'name' );
		if ( $( this ).val() == '' ) { $( n ).removeClass( 'ok' ); $( n ).addClass( 'erreur' ); $( n ).empty().append( 'Champ obligatoire' ); }
		else { $( n ).removeClass( 'erreur' ); $( n ).addClass( 'ok' ); $( n ).empty(); }
	} );
		
} );