function chargeSTheme(idtheme){
	//AJAX
	$.ajax({
		type: "post",
		mode: "abort",
		dataType :"html",
		url: "ajax/chargeSousTheme.php",
		data: "idT="+idtheme,
		success: function(html){
			$("#soustheme").html(html);
		}
	});
}

function chargePhoto(idStheme,site){
	//AJAX
	charg = (lang=='fr'?"Chargement en cours":"Loading");
	$("#LoadPhoto").addClass('placeDiv');
	$("#LoadPhoto").html("<img src='images/box/ajax-loader.gif'> "+charg+" ...");
	var nPhoto = $("#photoPage").val();
	$.ajax({
		type: "post",
		dataType :"html",
		url: "ajax/chargePhoto.php",
		data: "idST="+idStheme+"&nPhoto="+nPhoto+"&page=0",
		success: function(html){
			if(html != site){
				chargePhotoPagination(idStheme,nPhoto,'0');
				$("#LoadPhoto").removeClass('placeDiv');
				$("#LoadPhoto").html("");
				$("#contenerPhoto").html(html);
				//INFOBULLE
				majInfoBulle();
			}else{
			document.location.href = site;	
			}
			
		}
	});
}

function chargePhotoPagination(idSTR,photoPage,idpage){
	$.ajax({
		type: "post",
		dataType :"html",
		url: "ajax/chargePhotoPagination.php",
		data: "idST="+idSTR+"&nPhoto="+photoPage+"&page="+idpage,
		success: function(html){
			$("#contenerPagiPhoto").html(html);
		}
	});
}

function chargePhoto2(idStheme,site,nbPhoto,debut,page){
	//AJAX
	charg = (lang=='fr'?"Chargement en cours":"Loading");
	$("#LoadPhoto").addClass('placeDiv');
	$("#LoadPhoto").html("<img src='images/box/ajax-loader.gif'> "+charg+" ...");
	$.ajax({
		type: "post",
		dataType :"html",
		url: "ajax/chargePhoto.php",
		data: "idST="+idStheme+"&nPhoto="+nbPhoto+"&debut="+debut+"&page="+page,
		success: function(html){
			if(html != site){
				chargePhotoPagination(idStheme,nbPhoto,page);
				$("#LoadPhoto").removeClass('placeDiv');
				$("#LoadPhoto").html("");
				$("#contenerPhoto").html(html);
				//INFOBULLE
				majInfoBulle();
			}else{
			document.location.href = site;	
			}
		}
	});
}

function chargePhotoMotPagination(mot,idPTk,photoPage,idpage){
	$.ajax({
		type: "post",
		dataType :"html",
		url: "ajax/chargePhotoMotPagination.php",
		data: "mot="+mot+"&nPhoto="+photoPage+"&page="+idpage+"&idPTk="+idPTk,
		success: function(html){
			$("#contenerPagiPhoto").html(html);
		}
	});
}
function chargePhotoMot(mot,site){
	//AJAX
	charg = (lang=='fr'?"Chargement en cours":"Loading");
	$("#LoadPhoto").addClass('placeDiv');
	$("#LoadPhoto").html("<img src='images/box/ajax-loader.gif'> "+charg+" ...");
	var nPhoto = $("#photoPage").val();
	var idPTk = $("#idPTk").val();
	$.ajax({
		type: "post",
		dataType :"html",
		url: "ajax/chargePhotoMot.php",
		data: "mot="+mot+"&nPhoto="+nPhoto+"&idPTk="+idPTk+"&page=0",
		success: function(html){
			if(html != site){
				chargePhotoMotPagination(mot,idPTk,nPhoto,'0');
				$("#LoadPhoto").removeClass('placeDiv');
				$("#LoadPhoto").html("");
				$("#contenerPhoto").html(html);
				//INFOBULLE
				majInfoBulle();
			}else{
			document.location.href = site;	
			}
			
		}
	});
}
	
function chargePhotoMot2(mot,site,nbPhoto,debut,page){
	//AJAX
	charg = (lang=='fr'?"Chargement en cours":"Loading");
	$("#LoadPhoto").addClass('placeDiv');
	$("#LoadPhoto").html("<img src='images/box/ajax-loader.gif'> "+charg+" ...");
	var idPTk = $("#idPTk").val();
	$.ajax({
		type: "post",
		dataType :"html",
		url: "ajax/chargePhotoMot.php",
		data: "mot="+mot+"&nPhoto="+nbPhoto+"&debut="+debut+"&idPTk="+idPTk+"&page="+page,
		success: function(html){
			if(html != site){
				chargePhotoMotPagination(mot,idPTk,nbPhoto,page);
				$("#LoadPhoto").removeClass('placeDiv');
				$("#LoadPhoto").html("");
				$("#contenerPhoto").html(html);
				//INFOBULLE
				majInfoBulle();
			}else{
			document.location.href = site;	
			}
		}
	});
}


function ajoutSelection(idPhoto){
	//AJAX
	$.ajax({
		type: "post",
		mode: "abort",
		dataType :"json",
		url: "ajax/ajoutSelection.php",
		data: "idPhoto="+idPhoto,
		success: function(json){
			if(json.retour == "-2"){
				document.location.href = json.message;
			}else if(json.retour == "-1"){
				alert(json.message);
			}else{
				$("#nbselection").html(json.retour);
				alert(json.message);
			}
		}
	});
	
}
function supSelection(idSelection){
	//AJAX
	$.ajax({
		type: "post",
		mode: "abort",
		dataType :"html",
		url: "ajax/supSelection.php",
		data: "idSelection="+idSelection,
		success: function(html){
			window.location.reload(true); 
		}
	});
	
}

	
	
function majInfoBulle(){
	
//INFOBULLE
$('#vignette .tooltiplink').tooltip({ 
	track: true, 
	delay: 0, 
	showURL: false, 
	showBody: " - ", 
	extraClass: "tooloption",
	bodyHandler: function() {  return $(this).parents('p').next().html();},
	fade: 450
});
	
}

$(document).ready(function($){
	$("#rappel").click( function() {
			var mymail = $("#mymail").val();

		if(mymail!='e-mail' && isValidEmailAddress(mymail)){					 
			rappelPasse(mymail);
		}else{
			retour = (lang=='fr'?"L'adresse e-mail est obligatoire.":"E-mail is  compulsory.");
			alert(retour);
		}
	} );
	
	$("#validerRechMot").click( function() {
			var mot = $("#rechercheMot").val();

		if(mot.trim()!='' ){					 
			chargePhotoMot(mot,$("#liveSite").val());
		}else{
			retour = (lang=='fr'?"Vous devez renseigner un mot-clé pour lancer la recherche.":"You must fill a keyword to search.");

			alert(retour);
		}
	} );
	$("#logOut").click( function() {
			logOut();
	});
	
})


function logOut(){
	//AJAX
	$.ajax({
		type: "post",
		dataType :"json",
		url: "ajax/logOut.php",
		success: function(json){
				document.location.href=json.site;
		}
	});
	
}
function rappelPasse(mymail){
	//AJAX
	charg = (lang=='fr'?"Chargement en cours":"Loading");
	$("#LoadAction").addClass('placeDivOublie');
	$("#LoadAction").html("<img src='images/box/ajax-loader.gif'> "+charg+" ...");
	$.ajax({
		type: "post",
		mode: "abort",
		dataType :"html",
		url: "ajax/rappelPasse.php",
		data: "mymail="+mymail,
		success: function(html){
			$("#LoadAction").removeClass('placeDivOublie');
			$("#LoadAction").html("");
			alert(html);
		}
	});
	
}


String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)/g,'');
}

function isValidEmailAddress(emailAddress) {
  // If a simple regular expression doesn't work
  if(!new RegExp(/^test$/).test("test")) { return true; }

  // If the email address is empty
  if(emailAddress.trim() == '') { return false; }

  return new RegExp(/^([a-z]([_\.0-9a-z-]+)?@)([a-z]([_\.0-9a-z-]+)?\.)([a-z]{2,4})$/i).test(emailAddress.trim());
}

