// JavaScript Document
function doOnLoad(context){

	$('.ami', context).click ( function () {
		//console.log();
		$('.popupami').oLightBox ();
		return false;
	});
	$('.amifiche', context).click ( function () {
		//console.log();
		$('.popupamifiche').oLightBox ();
		return false;
	});
	
}

function _closeLightBox () {
			//$('#lightbox-inner').find('#' + $popupContent.attr('id'))			
			//.css ({ position:'absolute', left:'-1000px', top:'0px' })
			$popupContent
				.addClass('popup')
				.appendTo('body');
				
			$('#lightbox-outter').remove();
			//$('#lightbox-overlay').fadeOut ( function() { $('#lightbox-overlay').remove(); });
			$('#lightbox-overlay').remove();
			$('embed, object, select', '.page').css({ 'visibility' : 'visible' });
		}

$(function () {

	doOnLoad($("body"));
	$('.amiEvent').click ( function () {
		//console.log();
		$('.popupamiEvent').oLightBox ();
		return false;
	});
	
	$('.pub').click ( function () {
		//console.log();
		$('.popupevent').oLightBox ();
		return false;
	});

//	$('.map').click ( function () {
//		$('.googlemap').oLightBox ();
//		return false;
//	});

	$('.reserver').click (function () {
	    var test = $(this).attr('rel') ;
		//console.log();
		 $('.popupreservation').oLightBox ();
		return false;
	});
	
	$('.devenirfan45').click (function () {
	    var test = $(this).attr('rel') ;
		//console.log();
		if(test>0){
		    var nom = $(this).attr('etab') ;
		  var messages = 'Voullez vous vraiement devenir fan de  '+nom;
		    if(confirm(messages))
            {
                alert('devenir fan confirmé');
            }
		}
		else{
		    var message = 'Pour devenir fan de cet etablissement, il faut être membres !, voulez vous connecter ou créer un compte ?';
		    if(confirm(message))
            {
                $('.popupconnect').oLightBox ({template:'template_2'});
            }
		}
		return false;
	});
	
	$('#envoi-ami4').submit (function () {
		// debut traitement
		// fin traitment
		$('.popupami')[0]._closeLightBox ();
		$('.popupami-confirm').oLightBox ();
		return false;
	});
	
	$('.avis').click (function () {
	    var test = $(this).attr('rel') ;
		//console.log();
		if(test>0){
		  $('.popupcomment').oLightBox ();
		}
		else{
		    var message = 'L\'ajout d\'un commentaire est reservé seulement aux membres !, voulez vous se connecter ou créer un compte ?';
		    if(confirm(message))
            {
                $('.popupconnect').oLightBox ({template:'template_2'});
            }
		}
		return false;
	});
     $('.mentionlegale').click ( function () {
		//console.log();
		$('.popupml').oLightBox ();
		return false;
	});
	$('.acces').click (function () {
	   $('.popupacces').oLightBox ();
		return false;
	});
	
	$('#publier').click (function () {
		$('.popupcomment').find('.nodisplay').removeClass('nodisplay');
		$(this).addClass('nodisplay');
	});
	$('#validermbr1').click (function () {
		if(tmt.validator.validateForm('form_membre_connect'))
			{
				$('.popupconnect')[0]._closeLightBox ();
				$('#form_membre_connect').submit();
			}
	});
	$('#corriger').click (function () {
		$('.popupcomment').find('.nodisplay').removeClass('nodisplay');
		$('.popupcomment .chapeau').addClass('nodisplay');
		$('.popupcomment .buttons span').addClass('nodisplay');
	});
	
	$('.toregisterbox').click ( function () {
		//console.log();
		$('.popupconnect')[0]._closeLightBox ();
		$('.popupmembre').oLightBox ({template:'template_2'});
		return false;
	});
	
    $('.toregister').click ( function () {
    		//console.log();
    		$('.popupmembre').oLightBox ({template:'template_2'});
    		return false;
    	});

	$('.lostpass').click ( function () {
		//console.log();
		$('.lostpwd').oLightBox ();
		return false;
	});

	$('.condition__').click ( function () {
		//console.log();
		$('.popupcondition').oLightBox ();
		return false;
	});
	
	$('#form_membre4').submit (function () {
	    alert('ffff');
		// debut traitement
		// fin traitment
		$('.popupmembre')[0]._closeLightBox ();
		$('.popupmembre-confirm').oLightBox ();
		return false;
	});
	
	
	// Bon plan
	$('.show-bonplan').each ( function () {
		$(this).click ( function () {
//			var linkPrint = $('<link>');
//			linkPrint.attr ({
//				type: 'text/css',
//				rel: 'stylesheet',
//				href: j_basepath + 'design/front/css/print-bonplan.css',
//				id: 'print-bonplan',
//				media: 'print'
//			});
//			
            var linkPrint = '<link type="text/css" href = "' + j_basepath + 'design/front/css/print-bonplan.css" rel="stylesheet" id="print-bonplan" media="print" />' ;
            $('head').append(linkPrint);
			
			idPop = '.' +  $(this).attr('id');
			$(idPop).oLightBox ({
				callClose: function () {
					$('head').find('#print-bonplan').remove();
				}
			});
			return false;
		});
	});
	
	
	$('.imprimer').click ( function () {
		window.print();
	})
	
	
	
	$('.show-map').click ( function () {
//		var linkPrint = $('<link>');
//		linkPrint.attr ({
//			type: 'text/css',
//			rel: 'stylesheet',
//			href: 'css/print-map.css',
//			id: 'print-map',
//			media: 'print'
//		});
		var linkPrint = '<link type="text/css" href = "' + j_basepath + 'design/front/css/print-map.css" rel="stylesheet" id="print-map" media="print" />' ;
		$('head').append(linkPrint);
		
		idPop = '.' +  $(this).attr('id');
		$('.googlemap').oLightBox ({
			callClose: function () {
				$('head').find('#print-map').remove();
			}
		});
		return false;
	});
	
	$('.imprimercarte').click ( function () {
		window.print();
	})
});
