// --------------------------
// Début : Ajout amis
var urlAjax1 = "/modules/yogurt/ajouter-amis.php"

jQuery(document).ready(function(){
	$("#yoAddUser").click(function(){
		var id = $(this).attr("class");
		var title = $(this).attr("title");
		// -----------------------------
		addUserConfirm(id, title);
		// -----------------------------
		return false;
	});
});

function addUserConfirm(id){
	$.post(urlAjax1,{action:"addUserConfirm", id:id, ajax:"1"},function(data){
		JQ.facebox(data, "test", "test");
	});
}
// Fin : Ajout amis
// --------------------------

//validation of album form
jQuery(document).ready(function() {
	$("form#form_picture").submit(function() {
		return xoopsFormValidate_form_picture();
	});
});

// validation of youtube videos
jQuery(document).ready(function() {
	$("form#form_videos").submit(function() {
		
		if ($("form#form_videos input#codigo").val() == ""){
			window.alert("Merci d’entrer l’adresse de la vidéo");
			$("form#form_videos input#codigo").focus();
			return false;
		}
		return true;	
	});
});

//validation of scraps
jQuery(document).ready(function() {
	$("form#formScrapNew").submit(function() {
		return xoopsFormValidate_formScrapNew();
	});
});


jQuery(document).ready(function() {
	$("div.yogurt-scrap-details-form").hide();
});


jQuery(document).ready(function() {
	$("a.yogurt-scraps-replyscrap").click(function() {
		$(this).parents("div.yogurt-scrap-details").find('div.yogurt-scrap-details-form').slideToggle("slow");
		
	});
});

jQuery(document).ready(function() {
	$("input.resetscrap").click(function() {
		$(this).parents("div.yogurt-scrap-details-form").slideToggle("slow");
		
	});

});

// in album page show tips effect
jQuery(document).ready(function() {
	$("a#show_tips").click(function() {
		$("div#xtips").slideToggle("slow");
	});
});

jQuery(document).ready(function() {
	
	$("div#xtips").hide();
	
});
// in index.php
jQuery(document).ready(function() {
	
	$("div#yoSuspension").hide();
	
});

jQuery(document).ready(function() {
	$("img#yogurt-suspensiontools").toggle(function() {
		$("div#yoSuspension").show();
	},function(){
		$("div#yoSuspension").hide();
	});
});


jQuery(document).ready(function() {
	$("div#yogurt-license").hide();
});

jQuery(document).ready(function() {

	//    $("a#yogurt-license-link").click(function() {
	$("a#yogurt-license-link").mouseover(function() {

		$("div#yogurt-license").slideToggle("slow");
		
	});
});

//close all search results in contributions when the page loads for the first time
jQuery(document).ready(function() {
	$("div.yogurt-profile-search-module-results").slideUp("fast");
});

//open the search results for one specific module and close the others.
//If the button is clicked when the module results are open then it closes it

jQuery(document).ready(function() {

	$("a.yogurt-profile-search-module-title").click(function() {
		$("div.yogurt-profile-search-module-results").slideUp("slow");
		if ( $(this).parents("div.yogurt-profile-search-module").find('div.yogurt-profile-search-module-results').is(':hidden') )
		$(this).parents("div.yogurt-profile-search-module").find('div.yogurt-profile-search-module-results').slideDown("slow");
		
	});

});

jQuery(document).ready(function() {
	$("#text").click(function() {
		$(this).html("");
		
	});

});

jQuery(document).ready(function() {

	var ifChecked = "0";
	$("input#allbox").click(function() {

		if(ifChecked == "0") {
			$("input.yogurt-notification-checkbox").attr("checked","checked");
			ifChecked = "1";
		}
		else {
			$("input.yogurt-notification-checkbox").attr("checked","");
			ifChecked = "0";
		}
	});	
});


function xoopsFormValidate_form_picture() { myform = window.document.form_picture; if ( myform.sel_photo.value == "" ) { window.alert("Please enter Select Photo"); myform.sel_photo.focus(); return false; }return true;
}


function xoopsFormValidate_formScrapNew() {
	myform = window.document.formScrapNew;
	if ( myform.text.value == "" ) {
		window.alert("Please enter text");
		myform.text.focus();
		return false;
	}
	return true;
}

function cleanScrapForm(id,defaultvalue) {

	
	var ele = xoopsGetElementById(id);
	if (ele.value==defaultvalue){
		ele.value = "";
	}
}

function goToUserPage(id) {

	var ele = xoopsGetElementById(id);
	openWithSelfMain('index.php?uid='.ele.value);
}

function changeVisibility(id) {

	var elestyle = xoopsGetElementById(id);

	if (elestyle.style.visibility == "hidden") {
		elestyle.style.visibility = "visible";
		
	} else {
		elestyle.style.visibility = "hidden";
	}


}

function changeReplyVisibility(idform) {

	changeVisibility(idform);
}

function tribeImgSwitch(img) {
	var elestyle = xoopsGetElementById(img).style;
	elestyle.display = "none";
}

// Validation formulaire de création de tribus
jQuery(document).ready(function() {
	$("#submit_button").click(function() {
		valid = true;
		if($("#tribe_img").val() == ""){
			$("#tribe_img").next(".yoMsg-erreur").fadeIn().text("Veuillez sélectionner une image");
			valid = false;
		} else {
			$("#tribe_img").next(".yoMsg-erreur").fadeOut();
		}
		if($("#tribe_title").val() == ""){
			$("#tribe_title").next(".yoMsg-erreur").fadeIn().text("Veuillez entrer le titre");
			valid = false;
		} else {
			$("#tribe_title").next(".yoMsg-erreur").fadeOut();
		}
		if($("#tribe_desc").val() == ""){
			$("#tribe_desc").next(".yoMsg-erreur").fadeIn().text("Veuillez entrer une description");
			valid = false;
		} else if($("#tribe_desc").val().length > "1000"){
			$("#tribe_desc").next(".yoMsg-erreur").fadeIn().text("La description est trop longue. La limite est de 1000 caractères, espaces compris");
			valid = false;
		} else {
			$("#tribe_desc").next(".yoMsg-erreur").fadeOut();
		}
		return valid;
	});
});

// Validation formulaire Mémos
jQuery(document).ready(function() {
	$("#scrap_memo").click(function() {
		$(this).html("");
		
	});

});

jQuery(document).ready(function() {
	$("#post_scrap").click(function() {
		valid = true;
		if(($("#scrap_memo").val() == "") || ($("#scrap_memo").val() == "Laissez lui un commentaire sur son mur.")){
			alert("Veuillez rédiger un texte, avant de poster votre message.");
			valid = false;
		}
		return valid;
	});
});

jQuery(document).ready(function() {
	$("#yoSubmitPhoto").click(function() {
		var valid = true;
		var msg = "";
		if($("#sel_photo").val() == ""){
			msg = 'Veuillez sélectionner une image avant de valider.';
			$("#sel_photo").next(".repAjax").text(afficherRepAjax("<br /><div class=\"novalideMsg\">"+msg+"</div>"));
			valid = false;
		} else {
			$("#sel_photo").next(".repAjax").fadeOut();
		}
		if(($("#caption").val() == "") && ($("#sel_photo").val() != "")){
			msg = 'Veuillez entrer un titre (Légende) avant de soumettre votre image.';
			$("#caption").next(".repAjax").text(afficherRepAjax("<br /><div class=\"novalideMsg\">"+msg+"</div>"));
			valid = false;
		} else if((!$("#caption").val().match(/^[A-Za-z0-9 ]+/i)) && ($("#caption").val().length > "0")){
			$("#caption").css({'border-color' : '#FF0000'});
			msg = 'Seuls les caractères alphanumériques sont autorisés dans le champ "Légende".<br >Il faut renter un titre explicite. Exemple de titre : Ma photo de vacances d\'été';
			$("#caption").next(".repAjax").text(afficherRepAjax("<br /><div class=\"novalideMsg\">"+msg+"</div>"));
			valid = false;
		} else {
			$("#caption").next(".repAjax").fadeOut();
		}
		return valid;
	});
});

