$(document).ready(function(){
	$('.propose-news').fancybox({ 'hideOnContentClick':false,'zoomSpeedIn': 400, 'zoomSpeedOut': 400,'frameHeight':638,'frameWidth':500,'padding':1,'centerOnScroll':false, "callbackOnShow": ini_tiny_news});
	$(".connect-u").fancybox({ 'hideOnContentClick':false,'zoomSpeedIn': 400, 'zoomSpeedOut': 400,'frameHeight':135,'frameWidth':500,'padding':1,'centerOnScroll':false});
});

function ini_tiny_news(){
  
  tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	skin : "o2k7",
	skin_variant : "silver",
	language: "fr",
	plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
	theme_advanced_buttons1 : "bold,italic,underline,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,image,|,fontsizeselect",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_buttons4:"",
	
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : false
	});
   
   ini_form();
   $(".checkitnolimit").click(function(){
		if($(this).parents("fieldset").eq(0).find("input").eq(0).is(":checked")) $(this).parents("fieldset").eq(0).find("input").eq(0).removeAttr("checked");
		else $(this).parents("fieldset").eq(0).find("input").eq(0).attr("checked","checked");
	});
}

function propose_news(){
	if(valid_form($("#form_propose_news").get(0))) {
		var titre=$("#propos_titre").val();
		var photo=$("#propos_photo").val();
		var last3=photo.substring(photo.length-3,photo.length);
		if(last3!="jpg" && last3!="peg" && last3!="gif" && last3!="png" && photo!="") {
			if($("#propos_photo").parents("fieldset").eq(0).find("span.input-wrong").length==0) $("#propos_photo").parents("fieldset").eq(0).append("<span class=\"input-wrong\"><img src=\""+LIEN_ROOT+"img/pixel.gif\" class=\"ico ico-error\"/> gif, jpg, png</span>");
		}
		else {
			if(photo=="") photo="photo/avatar-1.jpg";
			var contenu=tinyMCE.get('propos_contenu').getContent();
			if($("#propos_anonym").is(":checked")) var anonym=1;
			else var anonym=0;
			if($("#propos_comm").is(":checked")) var comm=1;
			else var comm=0;
			$.post(LIEN_ROOT+"includes/front/ajaxed/propose_news.php", { titre:titre, photo:photo, contenu:contenu, anonym:anonym, comm:comm }, function(data){
				$(".alertbox-content").html("<p class=\"talignc\" style=\"margin-top:42px\"><strong>Merci pour votre article.</strong></p><p class=\"talignc\"><img src=\""+LIEN_ROOT+"img/btn-valid.png\" alt=\"Merci\"/></p><p class=\"talignc\">Nos experts vont valider votre article et le publier sous votre nom si il est conforme à l'éthique de DogFinance.</p><p class=\"talignc\" style=\"margin-top:10px;\"><a href=\"#\" onclick=\"closeFancy();return false;\" class=\"btn btn-inline\">Fermer la fenêtre</a></p>");
			});
		}
	}
}
