jQuery.noConflict();
var $ = jQuery;
$(document).ready(function() {
	$("#submitsh").submit(function() {
		$(this).ajaxSubmit({
					beforeSubmit: function(before) {
					$('#loadingsubmitsh').css('display','block');
					$("#resultsubmitsh").html('');
					$("#resultsubmitsh").css('display','none');
					},
					success: function(retour) {
						$('#loadingsubmitsh').css('display','none');
							 if(retour == 'errshort') {
								$('#resultsubmitsh').html('<p class=\"pasgood\">Your message is too short.</p>');
							} else if(retour == 'errlong') {
								$('#resultsubmitsh').html('<p class=\"pasgood\">Your message is too long. 300 characters maximum!</p>');
							} else if(retour == 'errurl') {
								$('#resultsubmitsh').html('<p class=\"pasgood\">URLs are forbidden.</p>');
							} else if(retour == 'errmail') {
								$('#resultsubmitsh').html('<p class=\"pasgood\">E-mail addresses are forbidden.</p>');
							}else {
								$('#resultsubmitsh').html('<p class=\"good\">Thanks for sharing your Advice with us. Come back soon to find out if it has been posted! Or not.<br><a href="javascript:submitToggle();">Close this form</a></p>');
								setTimeout("$('#submitsh #update').val('');",5000);
							}	
					$('#resultsubmitsh').hide();
					$('#resultsubmitsh').fadeIn(500);
					setTimeout("$('#resultsubmitsh').fadeOut();",5000);							
					}
			}); 
		return false;
	});		
});

function VDM(id,nb) {

	$('#vote'+id).css('display','none');
	$.post("/scomment_vote.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#vote'+id).html('dude! already done...').fadeIn();
		} else {
			$('#vote'+id).html('I Agree ('+html+')').fadeIn();
		}
	});
}

function VDM_BF(id,nb) {

	$('#votebf'+id).css('display','none');
	$.post("/scomment_vote.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#votebf'+id).html('dude! already done...').fadeIn();
		} else {
			$('#votebf'+id).html('I Disagree ('+html+')').fadeIn();
		}
	});
}

function VDM2(id,nb) {

	$('#vote'+id).css('display','none');
	$.post("/ucomment_vote.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#vote'+id).html('dude! already done...').fadeIn();
		} else {
			$('#vote'+id).html('I Agree ('+html+')').fadeIn();
		}
	});
}

function VDM_BF2(id,nb) {

	$('#votebf'+id).css('display','none');
	$.post("/ucomment_vote.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#votebf'+id).html('dude! already done...').fadeIn();
		} else {
			$('#votebf'+id).html('I Disagree ('+html+')').fadeIn();
		}
	});
}

function VDM_e(id,nb) {

	$('#vote2'+id).css('display','none');
	$.post("/scomment_vote_e.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#vote2'+id).html('dude! already done...').fadeIn();
		} else {
			$('#vote2'+id).html('I Agree ('+html+')').fadeIn();
		}
	});
}

function VDM_BF_e(id,nb) {

	$('#votebf2'+id).css('display','none');
	$.post("/scomment_vote_e.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#votebf2'+id).html('dude! already done...').fadeIn();
		} else {
			$('#votebf2'+id).html('I Disagree ('+html+')').fadeIn();
		}
	});
}

function blog(id,nb) {

	$('#vote'+id).css('display','none');
	$.post("/vote.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#vote'+id).html('dude! already done...').fadeIn();
		} else {
			$('#vote'+id).html('I Agree ('+html+')').fadeIn();
		}
	});
}

function blog_BF(id,nb) {

	$('#votebf'+id).css('display','none');
	$.post("/vote.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#votebf'+id).html('dude! already done...').fadeIn();
		} else {
			$('#votebf'+id).html('I Disagree ('+html+')').fadeIn();
		}
	});
}

function blog_e(id,nb) {

	$('#vote2'+id).css('display','none');
	$.post("/vote_e.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#vote2'+id).html('dude! already done...').fadeIn();
		} else {
			$('#vote2'+id).html('I Agree ('+html+')').fadeIn();
		}
	});
}

function blog_BF_e(id,nb) {

	$('#votebf2'+id).css('display','none');
	$.post("/vote_e.php",{"id":id,"v":nb},function(html) {
		if (html == 'NA') {
			$('#votebf2'+id).html('dude! already done...').fadeIn();
		} else {
			$('#votebf2'+id).html('I Disagree ('+html+')').fadeIn();
		}
	});
}

function INT(id,nb) {

	$('#INT'+nb).css('display','none');
	$.post("/int_vote.php",{"id":id,"v":nb},function(html) {
			$('#INT'+nb).html(html).fadeIn();
	});
	return false;
}
function INT2(id,nb) {

	$('#INT_'+id+'_'+nb).css('display','none');
	$.post("/int_vote.php",{"id":id,"v":nb},function(html) {
			$('#INT_'+id+'_'+nb).html(html).fadeIn();
	});
	return false;
}
function INT4(id,nb) {

	$('#INT_'+id+'_'+nb).css('display','none');
	$.post("/blog_vote.php",{"id":id,"v":nb},function(html) {
			$('#INT_'+id+'_'+nb).html(html).fadeIn();
	});
	return false;
}
function INT6(id,nb) {

	$('#INT_'+id+'_'+nb).css('display','none');
	$.post("/blog_vote.php",{"id":id,"v":nb},function(html) {
			$('#INT'+nb).html(html).fadeIn();
	});
	return false;
}
function callPublish(msg, attachment, action_link) {
		  FB.ui(
            {
                'method': 'stream.publish',
                'message': msg,
                'attachment': attachment
            }
        );
}

function signaler(type,id) {

	$('#signaler'+id).css('display','none');
	$.get("/blog/moderer.php?type="+type+"&id="+id,function(html) {
		$('#signaler'+id).html('abuse reported');
	});
	$('#signaler'+id).fadeIn();

}

function cut(input) {

	if (input.value.length >= 300) {
		input.value = input.value.substring(0,300);
	}

	var reste = 300 - input.value.length;
 	var print =  reste;
	
	$(".ok #compteur").html(input.value.length+'/300 characters');

}

function submitToggle() {

	if ($('#submit').css('display') == 'none') {
		$('#submit').slideDown();
	} else {
		$('#submit').slideUp();
	}

}

function plusToggle(id) {

	if ($('#plus'+id).css('display') == 'none') {
		$('#plus'+id).slideDown();
	} else {
		$('#plus'+id).slideUp();
	}

}

function displayMail() {

	$('#submit .input_mail').html('Email (optional) : <input type="text" name="mail">');

}

function Favori(action,id) {

	$.get("/blog/favori.php?action="+action+"&id="+id,function() {
		if (action == 'add') {
			$('#plus'+id+' .plus_bouton#favori').attr('OnClick',"Favori('delete','"+id+"');");
			$('#plus'+id+' .plus_bouton#favori .label').html('Delete from favorites');
		} else {
			$('#plus'+id+' .plus_bouton#favori').attr('OnClick',"Favori('add','"+id+"');");
			$('#plus'+id+' .plus_bouton#favori .label').html('Add to favorites');
		}
	});

}

function toggleSuiviComms(type,id) {

	$.get("/blog/togglesuivi.php?type="+type+"&id="+id,function(html) {
		if (html == '1') {			
			$('span.suivicomm').fadeOut( function() { $('span.suivicomm').html('<a href="javascript:toggleSuiviComms(\''+type+'\',\''+id+'\');">ON</a>'); $('span.suivicomm').fadeIn(); });
		} else {
			$('span.suivicomm').fadeOut( function() { $('span.suivicomm').html('<a href="javascript:toggleSuiviComms(\''+type+'\',\''+id+'\');">OFF</a>'); $('span.suivicomm').fadeIn(); });
		}
	});

}

function compte_SuiviListe() {

	if ($('#suivi').css('display') == 'none') {

		$.get("/blog/suivi.php?action=display",function(html) {
	
			$('#suivi').html(html);
			compte_SuiviEvent();
			$('#suivi').slideDown();
	
		});
	
	} else {
	
		$('#suivi').slideUp();
	
	}

}

function compte_SuiviEvent() {

	$('#suivi input[type=checkbox]').click(function() {

		nombre = parseInt($('span#suivi_nb').text());
		id = $(this).attr('id').replace('article','');
		if ($(this).is(':checked') == true) {
			nombre++;
			$.get("/blog/togglesuivi.php?type=article&id="+id);
		} else {
			nombre--;
			$.get("/blog/togglesuivi.php?type=article&id="+id);
		}
		$('span#suivi_nb').html(nombre);

	});

}

function displayValidInfos() {

	$('#valid_no_infos').parent('div.champ').css('height','108px');
	$('#valid_no_infos').parent('div.champ').find('label').css('height','80px');
	$('#valid_no_infos').html('Without having validated your address, you cannot use all website functions. If your address is correct, <a href="javascript:sendValid();">click here</a> to receive the confirmation email. If it is incorrect, please change it, to receive the confirmation email.');

}



function sendValid() {

	$('#valid_no_infos').slideUp(function() {
		$('#valid_no_infos').parent('div.champ').css('height','68px');
		$('#valid_no_infos').parent('div.champ').find('label').css('height','40px');
		$.get("/blog/valid_send.php",function() {
			$('#valid_no_infos').html('We have just sent you an email to validate your email address, you should receive it in a few minutes.');
			$('#valid_no_infos').slideDown();
		});
	});

}

function deleteRequest() {
	$.get("/account/delete/request",function(html) {
		if(html == "ok") {
			$('#deleteinstruction').fadeOut();
			$('#deleterequest').css('display','none');
			$('#deleterequest').html('An email has been sent to you containing all the instructions on how to validate the deletion. You should receive it within a few minutes. You can, if you wish, <a href="javascript:deleteAnnul()">cancel the procedure</a>.');
		}
		$('#deleterequest').fadeIn();
	});	
}

function deleteAnnul() {
	$.get("/account/delete/cancel",function(html) {
		if(html == "ok") {
			$('#deleterequest').css('display','none');
			$('#deleterequest').before('<span id="deleteinstruction">You can delete your account at any time. Once the request has been made via the link below, you\'ll receive a link in an email allowing you to confirm this deletion.<br></span>');
			$('#deleterequest').html('<a href="javascript:deleteRequest();">Request that your account be deleted</a>');
		}
		$('#deleterequest').fadeIn();
	});		
}

function compte_FormatNL() {

	$.get("/blog/format_nl.php",function(html) {
		if (html == 'Texte') {
			$('#format_nl').html('Texte');
			$('#formater_nl').html('change to HTML');
		} else {
			$('#format_nl').html('HTML');
			$('#formater_nl').html('change to text');
		}
	});

}

function afCountdown() {

	if ($('#alerte_af span#secondes')) {
		nombre = parseInt($('#alerte_af span#secondes').html());
		if (nombre > 0) {
			nombre = nombre-1;
			if (nombre == 0) nombre = '0';
			$('#alerte_af span#secondes').html(nombre);
			if (nombre == 1) $('#alerte_af span#secondes_txt').html('second');
			setTimeout('afCountdown();',1000);
		} else {
			$('#alerte_af').html('Now, you can comment ;)');
		}
	}

}

function afCountdownComment(id) {

	if ($('#commentEdit'+id+' span#secondes')) {
		nombre = parseInt($('#commentEdit'+id+' span#secondes').html());
		if (nombre > 0) {
			nombre = nombre-1;
			if (nombre == 0) {
				nombre = '0';
				$('#commentEdit'+id).fadeOut();
			}
			$('#commentEdit'+id+' span#secondes').html(nombre);
			if (nombre == 1) 
				$('#commentEdit'+id+' span#secondes_txt').html('second');
			setTimeout('afCountdownComment('+id+');',1000);
		}			
	}

}

function AbusDesc(id) {
	$('#abusdesc').css('display','none');
	$.get("/blog/account_abus_desc.php?id="+id,function(html) {
		$('#abusdesc').html('Abuse reported');
	});
	$('#abusdesc').fadeIn();
}

function ClosePub(){
	$.get("/blog/megaban_close.php",function(html) {
		$('#pub_megaban').slideUp();
	});
}

function fbs_click(u,t) {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
