function trim (myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
} 

var addthis_config = {
	data_track_clickback: true
	//ui_click: true
};

var winCatalog;

function openCatalog(){
	if( winCatalog && !winCatalog.closed ){
		winCatalog.focus();
	}else{
		var left = (screen.width - 1000) / 2;
		var top = (screen.height - 700) / 2;
		winCatalog = window.open( '/catalogue-interactif/', 'catalogueinteractif', 'width=1000,height=700,left=' + left + ',top=' + top );
	}
	return false;
}

/* Masque le label de recherche lorsque le champ reçoit le focus */
$(document).ready(function() {
	$('.prd-color a').click(function(){return false;});
	$('.prd-color a').tooltip({ 
		delay: 0, 
		showURL: false, 
		bodyHandler: function() { 
			html = '<p>'+$('img',this).attr('alt')+'</p>'+'<img src="'+$(this).attr('href')+'"/>'; 
			return html; 
		} 
	});
	
	
	$('a.lnk-consulter').click(function(){
		if( winCatalog && !winCatalog.closed  ){
			winCatalog.document.location = $(this).attr('href');
			winCatalog.focus();
		}else{
			var left = (screen.width - 1000) / 2;
			var top = (screen.height - 700) / 2;
			winCatalog = window.open( $(this).attr('href'), 'catalogueinteractif', 'width=1000,height=700,left=' + left + ',top=' + top );
		}
		return false;
	});
	
	// Empeche l'envoie du formulaire si vide 
	$('#moteur-de-recherche').submit(function(){
		if(trim($('#header-box-recherche-input-q').val()) == '' || $('#header-box-recherche-input-q').val() == elementInSearchDefault) {
			alert('Veuillez préciser votre recherche.');
			return false;
		}
		else
			return true;
	});
	
	$('#site-newsletter').submit(function(){
		if(trim($('#email',this).val()) == '' || $('#email',this).val() == elementInEmailDefault) {
			alert('Veuillez préciser votre email.');
			return false;
		} else {
			if(validEmail($('#email',this).val())) {
				return false;
			}
			else
				return true;
		}
	});
	
	//Champ de recherche
	elementInSearch = $('#header-box-recherche-input-q');
	elementInSearch.focus(function() {
		if(elementInSearch.val()== elementInSearchDefault) {
			elementInSearch.val('');
			elementInSearch.css('color','#000');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			elementInSearch.val(elementInSearchDefault);
			elementInSearch.css('color','#666');
		}
	});
	
	elementInZipCode = $('.js-zipcode');
	elementInZipCode.each(function(){
		$(this).focus(function() {
			if($(this).val()== elementInZipCodeDefault) {
				$(this).val('');
				elementInZipCode.css('color','#000');
			}
		}).blur(function() {
			if ($(this).val() == '') {
				$(this).val(elementInZipCodeDefault);
				elementInZipCode.css('color','#999');
			}
		});
	});
	
	elementInEmail = $('.js-nlr-email');
	elementInEmail.each(function(){
		$(this).focus(function() {
			if($(this).val()== elementInEmailDefault) {
				$(this).val('');
				elementInEmail.css('color','#000');
			}
		}).blur(function() {
			if ($(this).val() == '') {
				$(this).val(elementInEmailDefault);
				elementInEmail.css('color','#999');
			}
		});
	});
	// TrackEvent Google Analytics sur le téléchargement de brochures
	$('#footer .lnk-dl-catalog').click(function(){
		 _gaq.push(['_trackEvent','Téléchargement', 'Catalogue', 'Général 2010']);
	});
});

function createHtmlForWindow(store,urlfiche) {
	var html = '';
	html = '<div class="popup-gmaps">';
	if(urlfiche) 
		html += '<a href="'+store.urlfiche+'">';
	html += '<b>'+store.name+'</b>';
	if(urlfiche) 
		html += '</a>';
	html += '<br/>';
	html += store.address1+'<br/>';
	if(store.address2 != '') {
		html += store.address2+'<br/>';
	}
	html += store.zipcode+' '+store.city+'<br/>';
	html += 'Tel : '+store.phone+'<br/>';
	if(urlfiche)
		html += '<a href="'+store.urlfiche+'">'+storeCard+'</a><br/>';
	html += '</div>';
	return html;
}

function createHtmlForWindowTabDir(store) {
	var html = '';
	html = '<form action="http://maps.google.fr/maps" target="_blank"><input type="hidden" name="daddr" value="' + store.latitude +" " +store.longitude +'" />'+ storeAddress +' :<br /><input type="text" size="40" name="saddr" /><br />' + storeExemple + '<br /><input type="submit" value="' + storeItineraire + '"/></form>';
	return html;

}


