function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}





function showtext(x){
if (x!= ''){
document.getElementById('t1').style.display='none'
document.getElementById('t2').style.display='none'
document.getElementById('t3').style.display='none'
document.getElementById('t4').style.display='none'
document.getElementById('t5').style.display='none'
document.getElementById('t6').style.display='none'
document.getElementById('t7').style.display='none'

document.getElementById(x).style.display='block'
}

}

function swapImage(x){
if (x!= ''){
document.getElementById('image1').style.display='none'
document.getElementById('image2').style.display='none'
document.getElementById('image3').style.display='none'
document.getElementById('image4').style.display='none'
document.getElementById('image5').style.display='none'
document.getElementById('image6').style.display='none'
document.getElementById('image7').style.display='none'

document.getElementById(x).style.display='block'

}

}


function affichage_popup(nom_de_la_page, nom_interne_de_la_fenetre)
{
window.open (nom_de_la_page, nom_interne_de_la_fenetre, config='height=480, width=640, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')
}


function showregion(){
	$("#listingcat").hide();
	$("#listingregion").show();
	$("#liregion").html("R&eacute;gion");
	$("#licat").html('<a href="javascript:;" onclick="showcat();">Choisir une autre cat&eacute;gorie</a>');
}

function showcat(){
	$("#listingcat").show();
	$("#listingregion").hide();
	$("#liregion").html('<a href="javascript:;" onclick="showregion();">Choisir une autre r&eacute;gion</a>');
	$("#licat").html('Cat&eacute;gorie');
}

function showimg(hndl){
	$("#image img").css("backgroundImage","url(/images/383x253/"+hndl.attr("val")+")");
	$("#popupimg").attr("href","/images/800x0/"+hndl.attr("val")+"");
}

var carrousselState = 1;

function pagingCaroussel(dir){
	nbpic = $(".minipictures").length;
	if(dir=='prev'){
		//precedent
		if(carrousselState>1){
			carrousselState--;
		}
	}else{
		//suivant
		if(nbpic>=(carrousselState*4)+1){
			carrousselState++;
		}
	}
	$(".minipictures").hide();
	from = ((carrousselState-1)*4)+1;
	to = ((carrousselState-1)*4)+4;
	$(".minipictures").each(function(){
									 myid = $(this).attr("id").replace("photo_","");
									 if(myid>=from & myid<=to){$("#photo_"+myid).show();}
									 });
}

function recherche(){
	document.location = "/recherche/"+$("#input").val()+"/1";
}


jQuery(document).ready(function(){
	jQuery("a#popupimg").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'overlayOpacity': 0.7
	});
});

/*Section register*/
jQuery(document).ready(function(){
	/* --- DEBUG --- */
	//jQuery("#registerform").attr("action","/ajax/register");
	//jQuery("#registerform").attr("method","post");
	jQuery("#registerform").submit(function(e){e.preventDefault();handleregisterform();});
	
	jQuery("#lostpassword").submit(function(e){e.preventDefault();handlelostpassword();});
	
	jQuery("#demandeform").submit(function(e){e.preventDefault();handlenewdemande($(this));});

	jQuery("#demande_coordonnees_form").submit(function(e){e.preventDefault();handlenewdemande_coordonnees($(this));});
	
	jQuery("#unsubscribe").submit(function(e){e.preventDefault();handleunsubscribe();});
	
	//jQuery("#loginform").attr("action","/ajax/connection");
	//jQuery("#loginform").attr("method","post");
	jQuery("#loginform").submit(function(e){e.preventDefault();handleconnection();});
	jQuery("#transactions").click(function(e){e.preventDefault();loadmembredata("transactions");});
	jQuery("#modfiche").click(function(e){e.preventDefault();loadmembredata("modfiche");});
	jQuery("#modcompte").click(function(e){e.preventDefault();loadmembredata("modcompte");});
});

handlenewdemande = function(hndl){
	$.post("/ajax/newdemande",jQuery("#demandeform").serialize(),function(data){
														if(data.success){
															$("#formcontainer").html("<h3>Merci</h3><p>Nous avons bien reçu votre demande. Un agent communiquera avec vous dans les plus brefs délais.</p>");
														}else{
															$.fancybox("<h1>Erreur</h1><br /><p style=\"line-height:20px; font-size:14px;\">"+data.msg+"</p>",{width:"400",height:"150",autoDimensions:false});
														}
												},"json");
}

handlenewdemande_coordonnees = function(hndl){
	$.post("/ajax/newdemande_coordonnees",jQuery("#demande_coordonnees_form").serialize(),function(data){
														if(data.success){
															$("#formcontainer").html("<h3>Merci</h3><p>Nous avons bien reçu votre demande. Un agent communiquera avec vous dans les plus brefs délais.</p>");
														}else{
															$.fancybox("<h1>Erreur</h1><br /><p style=\"line-height:20px; font-size:14px;\">"+data.msg+"</p>",{width:"400",height:"150",autoDimensions:false});
														}
												},"json");
}


handleunsubscribe = function(){
	if($("#courriel").val()==""){
		$.fancybox("<h1>Erreur</h1><p>Veuillez entrer votre adresse courriel</p>");
	}else{
			jQuery.get("/ajax/unsubscribe?email="+jQuery("#courriel").val(),function(){$.fancybox("<h1>Confirmation</h1><p>Votre adresse courriel a été retiré de notre liste d'envoi</p>");$("#courriel").val("");});
	}
};

loadmembredata = function(w){
	jQuery.get("/ajax/membredata?w="+w,function(data){$("#membrecontent").html(data);});
}

handleregisterform = function(){
	jQuery.post("/ajax/register",jQuery("#registerform").serialize(),function(data){processRegisterReturn(data);},"json");
}

handlelostpassword = function(){
	$.post("/ajax/lostpassword",$("#lostpassword").serialize(),function(data){processLostPwdReturn(data);},"json");
}

handleconnection = function(){
	jQuery.post("/ajax/connection",jQuery("#loginform").serialize(),function(data){processLoginReturn(data);},"json");
}

renewnow = function(){
	$.post("/ajax/renew",function(data){$("#membrecontent").html(data);});
};

processLoginReturn = function(data){
	if(data.success){
		window.location = data.location;
	}else{
		$.fancybox("<h1>Erreur</h1><br /><p style=\"line-height:20px; font-size:14px;\">Mauvais nom d'utilisateur / mot de passe</p>",{width:"400",height:"150",autoDimensions:false});
	}
}

processLostPwdReturn = function(data){
	if(data.success){
		$.fancybox("<h1>Mot de passe perdu</h1><br /><p style=\"line-height:20px; font-size:14px;\">Votre mot de passe vous a &eacute;t&eacute; envoyé par courriel</p>",{width:"400",height:"150",autoDimensions:false})
	}else{
		$.fancybox("<h1>Erreur</h1><br /><p style=\"line-height:20px; font-size:14px;\">L'adresse courriel que vous avez saisi n'est pas associ&eacute; à un compte</p>",{width:"400",height:"150",autoDimensions:false})
	}
}

processRegisterReturn = function(data){
	if(data.success){
		jQuery("#registerhndl").html("<h2>Vous serez redirig&eacute; sur paypal dans quelques instant pour effectuer votre paiement.</h2><br /><p style='text-align:center;'><img src='/templates/quebec-tourisme/images/ajax-loader.gif'></p>"+data.paypalform);
		jQuery("#paypalRegister").submit();
	}else{
		$.fancybox("<h1>Erreur</h1><br /><p style=\"line-height:20px; font-size:14px;\">"+data.msg+"</p>",{width:"400",height:"150",autoDimensions:false});
	}
}
/*Fin section register*/

updateCompteParams = function(e,theform){
	e.preventDefault();
	$.post("/ajax/membredata?w=updateCompteParams",$(""+theform+"").serialize(),function(data){$.fancybox('<h1>Félicitation</h1><p style="padding-left:40px;padding-right:40px; padding-bottom:40px;padding-top:20px;">La mise à jour s\'est déroulée avec succès.</p>');});
}

setDeletetableImgLink = function(){
	//handle sur les lien supprimer l'image
	$(".imgdeleter").click(function(e){
		e.preventDefault();
		if(confirm("Voulez-vous supprimer cette image?")){
			myid = $(this).attr("id").replace("del_","");
			$("#img"+myid).show();
			$("#div_img"+myid).hide();
			$("#div_img"+myid).attr("src","");
			$.post("/ajax/membredata?w=deleteimage&img="+myid);
		}
	});
}

setDeletetableImgLinkReg = function(){
	$(".imgdeleter").click(function(e){
		e.preventDefault();
		if(confirm("Voulez-vous supprimer cette image?")){
			$("#image").show();
			$("#div_image1").hide();
			$("#div_image1").attr("src","");
			$.post("/ajax/membredata?w=deleteimage");
		}
	});
};





