ajax_speed = 'fast'; current_category=0; paste_from_word = false;
function _focus(_this,s) {
	if ($(_this).attr("value") == s) {
		$(_this).attr("value","");
	}
	return false;
}
function _blur(_this,s) {
	if ($(_this).attr("value") == "") {
		$(_this).attr("value",s);
	}
	return false;
}
function check(id) {
	if (!$('#check-'+id).hasClass('yes')) {
		$('#check-input-'+id).val('1');
		$('#check-'+id).addClass('yes');
	}	else {
		$('#check-input-'+id).val('0');
		$('#check-'+id).removeClass('yes');
	}
	return false;
}
function refresh_page() {
	window.location.replace( unescape(window.location.pathname));
}
function radio_click(radio_id,value_id) {
	$('.radio-'+radio_id).attr('src','img/radio-off.gif');
	$('.radio-'+radio_id).attr('alt','0');
	$('.radio-'+radio_id+'-'+value_id).attr('src','img/radio-on.gif');
	$('.radio-'+radio_id+'-'+value_id).attr('alt','1');
	$('#loader-'+radio_id).show();
	$.post('users/account/edit','radio_id='+radio_id+'&value_id='+value_id,function() {
		$('#loader-'+radio_id).hide();
	});
}
function mykritik_window_open(url) {
	url = unescape(url);
	window.open(url,'print_version','menubar=1,resizable=1,width=625,height=500,scrollbars=1');
	return false;
}
function do_login() {
	login_form = $('#login-form');
	login_status = $('#login-status');

	login_form.fadeTo(ajax_speed,0.2);
	login_status.slideUp(ajax_speed,function() {
		login_status.removeClass('error');
		login_status.addClass('info');
		login_status.html('Chargement...');
		login_status.slideDown(ajax_speed,function() {
			$.post(login_form.attr('action'),login_form.serialize(true),function(result) {
				if (result=='') {
					login_form.fadeTo(ajax_speed,1);
					login_status.removeClass('info');
					login_status.addClass('error');
					login_status.html('Une erreur s\'est produite. S\'il vous plaît essayez de nouveau.');
					login_status.slideDown(ajax_speed);
				}
				ar = result.split(':');
				if (ar[0]=='error') {
					login_status.slideUp(ajax_speed,function() {
						login_form.fadeTo(ajax_speed,1);
						login_status.removeClass('info');
						login_status.addClass('error');
						login_status.html(ar[1]);
						login_status.slideDown(ajax_speed);
					});
				} else {
					login_status.slideUp(ajax_speed,function() {
						login_status.removeClass('error');
						login_status.addClass('info');
						login_status.html(ar[1]);
						login_status.slideDown(ajax_speed,function() {
							refresh_page();
						});
					});
				}
			});
		});
	});
	return false;
}
is_doing_forget = false;
function do_forgot() {
	if (!is_doing_forget) {
		is_doing_forget = true;

		forgot_form = $('#forgot-form');
		forgot_status = $('#login-status');

		forgot_form.fadeTo(ajax_speed,0.2);
		forgot_status.slideUp(ajax_speed,function() {
			forgot_status.removeClass('error');
			forgot_status.addClass('info');
			forgot_status.html('Chargement...');
			forgot_status.slideDown(ajax_speed,function() {
				$.post(forgot_form.attr('action'),forgot_form.serialize(true),function(result) {
					ar = result.split(':');
					if (ar[0]=='error') {
						forgot_status.slideUp(ajax_speed,function() {
							forgot_form.fadeTo(ajax_speed,1);
							forgot_status.removeClass('info');
							forgot_status.addClass('error');
							forgot_status.html(ar[1]);
							forgot_status.slideDown(ajax_speed,function() {
								is_doing_forget = false;
							});
						});
					} else {
						forgot_status.slideUp(ajax_speed,function() {
							forgot_status.removeClass('error');
							forgot_status.addClass('info');
							forgot_status.html(ar[1]);
							forgot_status.slideDown(ajax_speed,function() {
								setTimeout('show_login()',2000);
								is_doing_forget = false;
							});
						});
					}
				});
			});
		});
	}
	return false;
}
function do_logout() {
	logout_status = $('#login-status');

	logout_status.addClass('info');
	logout_status.html('Chargement...');
	logout_status.slideDown(ajax_speed,function() {
		$.post('user/logout','ajax=1',function () {
			logout_status.slideUp(ajax_speed,function() {
				logout_status.html('La page est actualis&eacute;e');
				logout_status.slideDown(ajax_speed,function() {
					refresh_page();
				});
			});
		});
	});
	return false;
}
function show_login() {
	login_form = $('#login-form');
	login_status = $('#login-status');
	forgot_form = $('#forgot-form');

	login_status.slideUp(ajax_speed);
	forgot_form.fadeTo(ajax_speed,1).slideUp(ajax_speed,function() {
		login_form.slideDown(ajax_speed);
	});
	return false;
}
function show_forgot() {
	login_form = $('#login-form');
	login_status = $('#login-status');
	forgot_form = $('#forgot-form');

	login_status.slideUp(ajax_speed);
	login_form.slideUp(ajax_speed, function() {
		forgot_form.slideDown(ajax_speed);
	});
	return false;
}
function check_username() {
	status = $('.verifiez');
	status.slideUp(ajax_speed,function() {
		status.html('<div class="message info">Chargement...</div>');
		status.slideDown(ajax_speed,function() {
			$.post('user/check/','username='+$('#register-username').val(),function(result) {
				ar = result.split(':');
				if (ar[0]=='error') {
					status.slideUp(ajax_speed,function() {
						status.removeClass('error');
						status.removeClass('info');

						status.html('<div class="message error">'+ar[1]+'</div><a href="#verify-username" onclick="return check_username()">V&eacute;rifiez la disponibilit&eacute; de votre pseudo</a>');
						$('#register-username').addClass('error');
						status.slideDown(ajax_speed);
					});
				} else {
					status.slideUp(ajax_speed,function() {
						status.removeClass('error');

						status.removeClass('info');
						status.html('<div class="message info">'+ar[1]+'</div><a href="#verify-username" onclick="return check_username()">V&eacute;rifiez la disponibilit&eacute; de votre pseudo</a>');
						$('#register-username').removeClass('error');
						status.slideDown(ajax_speed);
					});
				}
			});
		});
	});
	return false;
}
function categories_expand(id,the_direction) {
	menu = $('.kategories-menu');
	if (id!=current_category) {
		menu.before('<div id="load-image" style="position:relative"><img src="img/ajax-load.gif" alt="..." style="position:absolute;left:50%;top:20px;"/></div>');
		$.scrollTo(0,'normal');
		menu.fadeTo(ajax_speed,0.2,function() {
			$.get('pages/category/'+id,null, function(result) {
				$('.the-menu .inner #load-image').remove();
				menu.fadeTo(ajax_speed,1, function() {
					menu.hide("slide", { direction: (the_direction=='right'?'left':'right') },ajax_speed,function() {
						menu.removeClass('kategories-children-'+current_category);
						menu.addClass('kategories-children-'+id);
						menu.html(result);
						menu.show("slide", { direction: the_direction },ajax_speed);
						current_category=id;
					});
				});
			});
		});
	}
	return false;
}
function reload_captcha() {
	$('#captcha').hide('fast');
	$('#captcha-load').show('fast');
	$('#captcha').load(function() {
		$('#captcha').show('fast');
		$('#captcha-load').hide('fast');
	});
	$('#captcha').attr('src','user/captcha?'+ Math.round(Math.random(0)*1000)+1);
	return false;
}

function show_help(id) {
	x = $('#help-'+id);
	x.slideToggle(ajax_speed);
	return false;
}

function _slide(id,arr,type) {
	if (type == 'down') {
		$('#menu-list-'+id).slideDown(ajax_speed);
		$('#menu-item-'+id).addClass('hover2');
	} else {
		$('#menu-list-'+id).slideToggle(ajax_speed);
		$('#menu-item-'+id).toggleClass('hover2');
	}
	for (x in arr) {
		$('#menu-list-'+arr[x]).slideUp(ajax_speed);
		$('#menu-item-'+arr[x]).removeClass('hover2');
	}
	return false;
}
function article_submit(id) {
	status = '#'+id+'-status';
	form = '#'+id+'-form';
	$(status).slideUp(ajax_speed,function() {
		$(status).html('Chargement...');
		$(status).addClass('info');
		$(status).removeClass('error');
		$(status).slideDown(ajax_speed, function() {
			$.post($(form).attr('action'),$(form).serialize(true),function (result) {
				eval(result);
			});
		});
	});
	return false;
}
function submit_vote_coup(vote) {
	id = 'vote-sidebar-coup';
	status = $('#'+id+'-status');
	form = $('#'+id+'-form');
	input = $('#'+id+'-input');

	input.val(vote);

	$('#sidebar-vote-'+(vote==0?1:0)).fadeTo(ajax_speed, 0.2);
	status.slideUp(ajax_speed,function() {
		status.html('Chargement...');
		status.addClass('info');
		status.removeClass('error');
		status.slideDown(ajax_speed, function() {
			$.post(form.attr('action'),form.serialize(true),function (result) {
				eval(result);
			});
		});
	});
	return false;
}
function submit_edit(id) {
	loader = $('#loader-'+id);
	form = $('#form-'+id);
	status = $('#status-'+id);

	loader.fadeIn(ajax_speed,function() {
		$.post(form.attr('action'),form.serialize(true), function(result) {
			loader.fadeOut(ajax_speed, function() {
				ar = result.split(':');
				if (ar[0]=='error') {
					status.slideUp(ajax_speed,function() {
						status.addClass('error');
						status.removeClass('info');

						status.html(ar[1]);
						status.slideDown(ajax_speed);
					});
				} else {
					$('#div-'+id).html(ar[1]);
					$('#input-'+id).val(strip_tags(ar[1]));
					$('#edit-'+id).slideUp(ajax_speed);
					status.slideUp(ajax_speed);
				}
			});
		});
	});

	return false;
}
function get_subcategories(id,load_plus_info) {
	cats = $('#publish-categories');
	title = $('.kategorie .title');
	if (load_plus_info == undefined) load_plus_info = true;
	if (load_plus_info) {
		fields_content = $('#publish-fields');
	}
	title.append('<img src="img/ajax-load.gif" alt="..." />');
	if (load_plus_info) {
		if (fields_content.attr('id')) {
			fields_content.slideUp(ajax_speed,function() {
				_get_subcategories_subfunction(id,load_plus_info);
			});
		} else {
			_get_subcategories_subfunction(id,false);
		}
	} else {
		_get_subcategories_subfunction(id,load_plus_info);
	}
}
function util_click(id,value) {
	$('#util-'+id+'-'+value).fadeTo(ajax_speed,1);
	if (value=='yes') value2 = 'no';
	else value2 = 'yes';
	$('#util-'+id+'-'+value2).fadeTo(ajax_speed,0.2);
	if (value=='yes') value3 = 1;
	else value3 = 0;
	$('#util-'+id+'-input').val(value3);
	return false;
}
function util_reset(id) {
	$('#util-'+id+'-yes').fadeTo(ajax_speed,1);
	$('#util-'+id+'-no').fadeTo(ajax_speed,1);
	$('#util-'+id+'-input').val('-1');
	return false;
}
function _get_subcategories_subfunction(id,load_plus_info) {

	cats.fadeTo(ajax_speed,0.2,function() {
		$.get('user/get_subcategories/'+id,null,function(result) {
			cats.html(result);
			$('select').replaceSelects();;
			if (load_plus_info) {
				$.get('user/get_fields/'+id,null,function(result2) {
					title.children('img').remove();
					cats.fadeTo(ajax_speed,1);
					fields_content.html(result2);
					fields_content.slideDown(ajax_speed);
				});
			} else {
				title.children('img').remove();
				cats.fadeTo(ajax_speed,1);
			}
		});
	});
}
_star = new Array();
function star(id,val,type) {
	if (type==undefined) type = '_red';
	for (i=1;i<=val;i++) {
		$('#star-'+id+'-'+i).attr('src','img/star'+type+'.jpg');
	}
	for (i=val+1;i<=5;i++) {
		$('#star-'+id+'-'+i).attr('src','img/star.jpg');
	}
}
function submit_star(id,value) {
	value = parseInt(value);
	if (value<0) value = 0;
	if (value>5) value = 5;
	document.getElementById('input-star-'+id).value = value;
	_star[id] = value;
}
function validate_movie(_this) {
	url = $(_this).parent().children('input').val();
	snapshot = $(_this).parent().parent().children('.snapshot').children('img');
	$(_this).html('<img src="img/ajax-load.gif" alt="..." />')
	$.post('user/validate_movie','url='+url,function(result) {
		ar = result.split(':');
		if (ar.length==2 && ar[0]=='error') {
			alert(ar[1]);
		} else {
			snapshot.attr('src',result);
			snapshot.css('width','130px');
			father = $(_this).parent();
			father.children('input').attr('readonly','readonly');

			previewer = father.children('.supprimer').children('.can-preview');
			previewer.fadeIn(ajax_speed);
			previewer.children('a').attr('href',url);
			$(_this).remove();
		}
		$(_this).html('<img style="vertical-align: middle;" alt="Valider" src="img/valider.jpg"/>')
	});
	return false;
}
photos=1;
function add_publish_video() {
	$('#div-has-videos').append('<div class="line video-invisible" style="display:none"><div class="snapshot"><img src="img/video_default.jpg" alt="default" /></div><div class="on-right"><input type="text" class="text" value="http://" name="videos[]" style="width:215px" onclick="this.select()" onfocus="this.select()"/> <a href="#" onclick="return validate_movie(this);"><img src="img/valider.jpg" alt="Valider" style="vertical-align:middle"/></a><div class="descriptif"><span class="text">Descriptif</span><input type="text" name="video_descriptions[]"/></div><div class="supprimer"><a href="#" class="delete-link" onclick="$(this).parent().parent().parent().slideUp(ajax_speed,function() { $(this).remove(); }); return false;">supprimer</a><span class="can-preview" style="display:none">| <a href="#" target="_blank">pr&eacute;visualiser</a></span></div></div><div class="clear">&nbsp;</div></div>');
	$('.video-invisible').slideDown(ajax_speed,function() {$(this).removeClass('video-invisible');});
	return false;
}
function add_publish_lien() {
	$('#div-has-liens').append('<div class="line lien-invisible" style="display:none"><div class="descriptif url"><div class="label">URL</div><div class="value"><input type="text" value="http://" name="lien_urls[]" onclick="this.select()" onfocus="this.select()"/></div><div class="clear">&nbsp;</div></div><div class="descriptif title"><div class="label">Titre</div><div class="value"><input type="text" value="" name="lien_titles[]"/></div><div class="clear">&nbsp;</div></div><div class="descriptif the-description"><div class="label">Descriptif</div><div class="value"><textarea name="lien_descriptions[]"></textarea></div><div class="clear">&nbsp;</div></div><div class="descriptif delete"><div class="label">&nbsp;</div><div class="value"><a href="#" onclick="$(this).parent().parent().parent().slideUp(ajax_speed,function() { $(this).remove(); }); return false;">supprimer</a></div><div class="clear">&nbsp;</div></div></div>');
	$('.lien-invisible').slideDown(ajax_speed,function() {$(this).removeClass('lien-invisible');});
	return false;
}
function on_upload_complete (response) {
	d = response.split(':');
	if (d.length!=2) {
		alert('An error occurred!');
	} else {
		$('#kritik-photos').prepend('<div class="the-photo" id="the-photo-'+d[0]+'" style="display:none"><div class="side-left"><img src="uploads/article-img/medium_'+d[1]+'" alt=""/></div> <div class="side-right"><input type="hidden" name="photos[]" value="'+d[0]+'"/><label><span>Descriptif</span> <input type="text" name="photo_descriptions[]" value="" /></label><label class="radio"><input type="radio" name="snapshot" value="'+d[0]+'" class="radio" /> cette photo illustrera votre article</label><div class="supprimer"><a href="#" onclick="$(this).parent().parent().parent().slideUp(ajax_speed,function() { $(this).remove(); }); return false;">supprimer</a></div></div><div class="clear">&nbsp;</div></div>');
		if (document.getElementById('the-photo-00')) {
			$('#the-photo-00').slideUp(ajax_speed,function() {$(this).remove()});
			$('#the-photo-'+d[0]+' .side-right label.radio input').attr('checked','true');
		}
		$('#the-photo-'+d[0]).slideDown(ajax_speed);
	}
}
function hmp_next_kh() {
	if (current_kh+1<kh) {
		next_kh = current_kh+1;
	} else {
		next_kh = 0;
	}
	return hmp_slide(next_kh);
}
function hmp_prev_kh() {
	if (current_kh-1>=0) {
		next_kh = current_kh-1;
	} else {
		next_kh = kh-1;
	}
	return hmp_slide(next_kh);
}
hmp_sliding = false; kh_no = 0; kh_limit = 7;
if($.browser.msie) {
	kh_limit = 5;
}
function hmp_slide(next_kh) {
	if (next_kh!=current_kh && !hmp_sliding && !is_hover_slide) {
		//reset interval
		if (kh_interval>0) {
			stop_auto_slide();
			hmp_auto_slide();
		}

		//start sliding
		var first = $('#kh-'+current_kh);
		var second = $('#kh-'+next_kh);

		var author = $('#kh-author');

		var first_photo = $('#kh-snapshot-'+current_kh);
		var second_photo = $('#kh-snapshot-'+next_kh);

		var first_author_vote = $('#kh-author-vote-'+current_kh);
		var second_author_vote = $('#kh-author-vote-'+next_kh);

		//change the photo
		first_photo.css('height','40px');
		second_photo.css('height','50px');

		//change the author
		author.fadeOut(ajax_speed,function() {
			author.html(kh_author[next_kh]);
			author.attr('href','profile/'+kh_author[next_kh]);
			author.fadeIn(ajax_speed);
		});

		//change the author's rating
		first_author_vote.fadeOut(ajax_speed,function() {
			second_author_vote.fadeIn(ajax_speed);
		});

		//view other photos if that is the case
		if (kh_no>kh_limit) {
			kh_start = next_kh-2;

			kh_end = next_kh+2;

			if (next_kh<=1) {
				kh_end = 4;
				kh_start = 0;
			}
			if (next_kh>=kh_no-2) {
				kh_end = kh_no-1;
				kh_start = kh_no-5;
			}
			if (kh_start<0) kh_start = 0;
			if (kh_end>=kh_no) kh_end = kh_no-1;

			for (ii=0;ii<kh_start;ii++) {
				$('#kh-a-'+ii).hide();
			}
			for (ii=kh_start;ii<=kh_end;ii++) {
				$('#kh-a-'+ii).show();
			}
			for (ii=kh_end+1;ii<kh_no;ii++) {
				$('#kh-a-'+ii).hide();
			}
		}

		//slide the content
		hmp_sliding = true;
		first.hide("slide", { direction: next_kh>current_kh?'left':'right' },ajax_speed,function() {
			second.show("slide", { direction: next_kh>current_kh?'right':'left' },ajax_speed, function() {
				//make next current
				current_kh = next_kh;
				hmp_sliding = false;
			});
		});
	}
	return false;
}
is_hover_slide = false;
function stop_auto_slide() {
	clearTimeout(kh_interval);
	kh_interval = 0;
}
kh_interval = 0;
function hmp_auto_slide() {
	kh_interval = setTimeout(hmp_next_kh,10000);
}
current_q = 0; q_sliding = false; qs = new Array();
function q_slide(next_q) {
	if (next_q!=current_q && !q_sliding) {
		first = $('#question-'+qs[current_q]);
		second = $('#question-'+qs[next_q]);

		first_sq = $('#a-'+qs[current_q]);
		second_sq = $('#a-'+qs[next_q]);

		first_sq.removeClass('selected');
		second_sq.addClass('selected');

		//slide the content
		q_sliding = true;
		first.hide("slide", { direction: 'left' },ajax_speed,function() {
			second.show("slide", { direction: 'right' },ajax_speed, function() {
				//make next current
				current_q = next_q;
				q_sliding = false;
			});
		});

	}
	return false;
}
function next_q() {
	if (current_q+1<qs.length) {
		next_qs = current_q+1;
	} else {
		next_qs = 0;
	}
	return q_slide(next_qs);
}
function prev_q() {
	if (current_q>0) {
		next_qs = current_q-1;
	} else {
		next_qs = qs.length-1;
	}
	return q_slide(next_qs);
}
function do_vote_response(id,vote) {
	if (vote!=1 && vote!=-1) vote=1;
	loader = $('#loader-comment-'+id);
	loader.show();
	$.post('users/vote_response/'+id,'vote='+vote,function(response) {
		loader.hide();
		eval(response);
	});
	return false;
}
function do_question_up(id) {
	loader = $('#question-loader');
	loader.show();
	$.post('users/vote_question/'+id,null,function(response) {
		loader.hide();
		eval(response);
	});
	return false;
}
current_lemag = 0; changing_lemag = false;
function show_lemag(id) {
	if (!changing_lemag) {
		changing_lemag = true;
		$('#lemag-'+current_lemag).hide("slide", { direction: 'left' },ajax_speed,function() {
			$('#lemag-'+id).show("slide", { direction: 'right' },ajax_speed, function() {
				changing_lemag = false;
				current_lemag = id;
			});
		});
	}
	return false;
}
$(document).ready(function () {
	$('body').click(function (event) {
		if (!$(event.target).is('[rel=clickable],[rel=clickable] *')) {
			$('#menu-list-kategories').slideUp(ajax_speed);
			$('#menu-list-decouvrir').slideUp(ajax_speed);
			$('#menu-list-recherche').slideUp(ajax_speed);
			$('#menu-item-kategories').removeClass('hover2');
			$('#menu-item-decouvrir').removeClass('hover2');
			$('#menu-item-recherche').removeClass('hover2');
		}
	});
	if ($.browser.msie) {
		$('.login-window-ajax-page').height($(document).height());
		$('.login-window-ajax-page').fadeTo(0,0.8);
		$('.login-window-ajax-page').hide();
	}

	if ($.fn.fancybox) {
		$('.fancybox').fancybox ({
			'hideOnContentClick': false,
			'swf': {wmode: 'transparent'},
			'titlePosition': 'inside'
		});
	}
	$('select').replaceSelects();
	$("a[rel=tooltip]").mousemove(function(e){
		id = $(this).attr('id').substr(10);
		$('#tooltip-'+id).css('left',e.pageX + 15);
		$('#tooltip-'+id).css('top',e.pageY + 15);
		$('.tooltip').each(function() {
			if (!$(this).is('#tooltip-'+id)) {
				$(this).hide();
			}
		});
		$('#tooltip-'+id).show();
	});
	$("a[rel=tooltip]").mouseleave(function() {
		id = $(this).attr('id').substr(10);
		$('#tooltip-'+id).hide();
	});
	$("#hmp-post-kh").mouseenter(function () {
		stop_auto_slide();
	});
	$("#hmp-post-kh").mouseleave(function () {
		hmp_auto_slide();
	});
	if ($('.instructions-window').size()>0) {

		$('.login-window-ajax-page').show();
		$('.instructions-window').show();

		h = $('.instructions-content').height()+70;
		$('.instructions-window').css('height',h+'px');
		$('.instructions-window').css('margin-top',(-h/2)+'px');
	}
});

current_comments_page = 1;
current_comments_sort = 'created';
current_comments_order = 'desc';

function load_comments (url, page, sort, order) {
	if (page==undefined || page=='') page = current_comments_page;
	if (sort==undefined) sort = current_comments_sort;
	if (order==undefined) order = current_comments_order;

	current_comments_page = page;
	current_comments_sort = sort;
	current_comments_order = order;

	coment_div = $('#article-comments');
	loader = $('#comments-loader');

	loader.fadeIn(ajax_speed);
	coment_div.fadeTo(ajax_speed,0.2,function() {
		coment_div.load('articles/comments/'+url+'/'+page+'/'+sort+'/'+order,null,function() {
			coment_div.fadeTo(ajax_speed,1);
			loader.fadeOut(ajax_speed);
		});
	});
}
function submit_poll_vote(id) {
	poll_div = $('#poll-vote-div-'+id);
	poll_form = $('#poll-vote-form-'+id);
	poll_status = $('#poll-vote-status-'+id);

	poll_div.fadeTo(ajax_speed,0.2);
	poll_status.slideUp(ajax_speed, function() {
		poll_status.addClass('info');
		poll_status.html('Chargement');
		poll_status.slideDown(ajax_speed,function() {
			$.post(poll_form.attr('action'),poll_form.serialize(true),function(result) {
				eval(result);
			});
		});
	});
	return false;
}
function vote_poll(id,_this) {
	val = $(_this).attr('value');
	$('#input-answers-'+id).val(val);
	$('.answers-'+id+' li').removeClass('selected');
	$(_this).addClass('selected');
	return false;
}
function search_submit() {
	url = '';
	place = $('#recherche-select-place').val();
	phrase = $('#recherche-mot').val();
	if (phrase == '') {
		phrase = 'pas une phrase';
	}

	if (place=='utilisateurs') {
		url = '/recherche/utilisateurs/'+phrase;
	} else {
		category = $('#recherche-select-kategorie').val();
		type = $('#recherche-select-type').val();

		url = '/recherche/'+place+'/'+phrase+'/1/'+category+'/'+type;

		extra = '';
		if ($('#recherche-check-tags').attr('checked')) {
			extra += 'tags'
		}
		if ($('#recherche-check-texte').attr('checked')) {
			if ($('#recherche-check-tags').attr('checked')) {
				extra += '-et-';
			}
			extra += 'texte'
		}
		if (extra!='') url += '/'+extra;
	}
	window.location = url;
	return false;
}
function search_submit_sidebar() {
	url = '';
	place = $('#sidebar-search-what').val();
	phrase = $('#sidebar-search-text').val();
	if (phrase == '') {
		phrase = 'pas une phrase';
	}

	if (place=='utilisateurs') {
		url = 'recherche/utilisateurs/'+phrase;
	} else {
		category = $('#sidebar-search-category').val();
		type = $('#sidebar-search-type').val();

		url = 'recherche/'+place+'/'+phrase+'/1/'+category+'/'+type;

		extra = '';
		if ($('#sidebar-search-check-tags').attr('checked')) {
			extra += 'tags'
		}
		if ($('#sidebar-search-check-texte').attr('checked')) {
			if ($('#sidebar-search-check-tags').attr('checked')) {
				extra += '-et-';
			}
			extra += 'texte'
		}
		if (extra!='') url += '/'+extra;
	}
	window.location = url;
	return false;
}
function activate_search_page_links() {
	link = $('.ajax-page-link');
	link.unbind();
	link.bind('click',function() {
		father = $(this).parent();
		the_one = father.parent().parent();
		father.children('.clear').remove();
		$(this).parent().append('<img src="img/ajax-load.gif" alt="..." style="float:left;margin-left:10px;vertical-align:bottom"/><div class="clear">&nbsp;</div>');
		$.post($(this).attr('href'),'is_ajax=1',function(result) {
			the_one.html(result);
			activate_search_page_links();
		});
		return false;
	});
}
media_moving = false;
media_speed = 2;
media_time = 5;

media_left_interval = 0; media_right_interval = 0;
function start_media_left() {
	clearInterval(media_right_interval);
	media_left_interval = setInterval(media_left,media_time);
	return false;
}
function stop_media_left() {
	clearInterval(media_left_interval);
	return false;
}
function start_media_right() {
	clearInterval(media_left_interval);
	media_right_interval = setInterval(media_right,media_time);
	return false;
}
function stop_media_right() {
	clearInterval(media_right_interval);
	return false;
}
function media_left() {
	interval = media_speed;
	mover_width = $('#pic-sizer').width();
	container_width = $('#pic-container').width();
	mover = $('#pic-mover');
	mover_left = parseInt(mover.css('left'));

	if (mover_left<0) {
		if (-mover_left<interval) interval = -mover_left;
		mover.css({
			left: (mover_left + interval) + 'px'
		});
	}
	return false;
}
function media_right() {
	interval = media_speed;
	mover_width = $('#pic-sizer').width();
	container_width = $('#pic-container').width();
	mover = $('#pic-mover');
	mover_left = parseInt(mover.css('left'));

	if (mover_left>container_width-mover_width) {
		if (mover_width-container_width+mover_left<interval) interval = mover_width-container_width+mover_left;
		mover.css({
			left: (mover_left - interval) + 'px'
		});
	}
	return false;
}
preview_kritik_window = 0;
function preview_kritik() {
	$('#do-preview').val(1);
	preview_kritik_window = window.open("", 'kritik_preview', "width=1050,height=550,scrollbars=1");
	preview_kritik_window.focus();
	document.getElementById('publish-kritik').target='kritik_preview';
	document.getElementById('publish-kritik').submit();
	return false;
}
function preview_article() {
	$('#do-preview').val(1);
	window.open("", 'article_preview', "width=1050,height=550,scrollbars=1");
	$('#publish-article').attr('target','article_preview');
	$('#publish-article').submit();
	return false;
}
function follow_channel() {
	select_type = $('#select-type').val();
	category = $('#select-category').val();

	type = 'tous'; action = '-1';
	switch (select_type) {
		case '0':
			type='0';
			break;
		case '1':
			type='1';
			break;
		case '2':
			type='1';
			action='coeur';
			break;
		case '3':
			type='1';
			action='gueule';
			break;
		case '4':
			type='2';
			break;
		case '5':
			type='3';
			break;
		case '6':
			type='3';
			action='1';
			break;
		case '7':
			type='3';
			action='2';
			break;
		case '8':
			type='3';
			action='3';
			break;
		case '9':
			type='3';
			action='4';
			break;
		case '10':
			type='3';
			action='5';
			break;
		case '11':
			type='3';
			action='6';
			break;
	}
	window.location='/rss/1/'+type+'/'+category+'/'+action;
	return false;
}
encore_loading = false;
function load_encore(direction) {
	if (!encore_loading) {
		encore_loading = true;
		$('#encore-loading').fadeIn(ajax_speed);
		no = 0;
		$('#div-encore a .encore-text').slideUp(50,function() {
			no ++;
			if (no==$('#div-encore a .encore-text').size()) {
				$('#div-encore').fadeTo(ajax_speed,0.2,function () {
					$.get('/pages/encore',null,function(result) {
						$('#encore-loading').fadeOut(ajax_speed);
						$('#div-encore').fadeTo(ajax_speed,1);
						$('#div-encore').hide("slide", { direction: (direction=='left'?'right':'left') },ajax_speed,function() {
							$('#div-encore').html(result);
							$('#div-encore').show("slide", { direction: direction },ajax_speed,function() {
								$('#div-encore a .encore-text').slideDown(50, function() {
									encore_loading = false;
								});
							});
						});
					});
				});
			}
		});
	}
	return false;
}
aubancdessai_loading = false; aubancdessai_cur_page = 1;
function load_aubancdessai(direction) {
	if (!aubancdessai_loading) {
		aubancdessai_loading = true;
		$('#aubancdessai-loading').fadeIn(ajax_speed);
		no = 0;

		$('#div-aubancdessai a .aubancdessai-text').slideUp(50,function() {
			no ++;
			if (no==$('#div-aubancdessai a .aubancdessai-text').size()) {
				$('#div-aubancdessai').fadeTo(ajax_speed,0.2,function () {
					if (direction=='left') {
						aubancdessai_cur_page--;
					} else {
						aubancdessai_cur_page++;
					}
					$.get('/decouvrir/lemag_aubancdessai/'+aubancdessai_cur_page,null,function(result) {
						$('#aubancdessai-loading').fadeOut(ajax_speed);
						$('#div-aubancdessai').fadeTo(ajax_speed,1);
						$('#div-aubancdessai').hide("slide", { direction: (direction=='left'?'right':'left') },ajax_speed,function() {
							$('#div-aubancdessai').html(result);
							$('#div-aubancdessai').show("slide", { direction: direction },ajax_speed,function() {
								$('#div-aubancdessai a .aubancdessai-text').slideDown(50, function() {
									aubancdessai_loading = false;
								});
							});
						});
					});
				});
			}
		});
	}
	return false;
}

function hide_all_windows() {
	$('._window').fadeOut(ajax_speed);
	$('.login-window-ajax-page').fadeOut(ajax_speed);
	return false;
}

function show_friend_window() {
	$('#send-friend-status').hide();
	$('.login-window-ajax-page').fadeIn(ajax_speed);
	$('.send-friend-window').fadeIn(ajax_speed);

	$('.send-friend-window .form .line .input input,.send-friend-window .form .line .input textarea').removeClass('error');
	return false;
}
function hide_friend_window() {
	$('.login-window-ajax-page').fadeOut(ajax_speed);
	$('.send-friend-window').fadeOut(ajax_speed);
	return false;
}
function send_friend_submit() {
	var validate_button = $('#send-friend-validate-button');
	var loader = $('#send-friend-loader');
	var form = $('#send-friend-form');
	var status_container = $('#send-friend-status');
	var status = status_container.children('.status');

	status_container.fadeOut('fast');
	validate_button.hide();
	loader.show();

	$('.send-friend-window .form .line .input input,.send-friend-window .form .line .input textarea').removeClass('error');

	$.post(form.attr('action'),form.serialize(true),function(result) {
		ar = result.split('<>');
		if (ar.length==3) {
			if (ar[0]=='error') {
				status.addClass('error');
				status.removeClass('info');
				inputs = strip_tags(ar[2]).split(',');
				for (xx in inputs) {
					$('#stf-input-'+inputs[xx]).addClass('error');
				}
			} else {
				status.addClass('info');
				status.removeClass('error');
				document.getElementById('send-friend-form').reset();
			}
			status.html(ar[1]);
		} else {
			status.addClass('error');
			status.removeClass('info');
			status.html('<ul><li>Error with AJAX sender</li></ul>');
		}
		status_container.fadeIn('fast');
		loader.fadeOut();
		validate_button.show();
		reload_captcha();
	});
	return false;
}


function show_login_window() {
	$('.login-window-ajax-page').fadeIn(ajax_speed);
	$('.login-window-ajax').fadeIn(ajax_speed);
	return false;
}
function hide_login_window() {
	$('.login-window-ajax-page').fadeOut(ajax_speed);
	$('.login-window-ajax').fadeOut(ajax_speed);
	return false;
}
function hide_intructions_window() {
	$('.login-window-ajax-page').fadeOut(ajax_speed);
	$('.instructions-window').fadeOut(ajax_speed);
	return false;
}
function show_intructions_window() {
	$('.login-window-ajax-page').fadeIn(ajax_speed);
	$('.instructions-window').fadeIn(ajax_speed);
	return false;
}
function ajax_window_show_forgot() {
	$('#login-window-ajax-state-login').slideUp(ajax_speed);
	$('#login-window-ajax-state-forgot').slideDown(ajax_speed);
	return false;
}
function ajax_window_show_login() {
	$('#login-window-ajax-state-forgot').slideUp(ajax_speed);
	$('#login-window-ajax-state-login').slideDown(ajax_speed);
	return false;
}
function do_window_login() {
	login_form = $('#form-window-login');
	login_status = $('#status-window-login');

	$('#login-window-description').slideUp(ajax_speed);
	$('#status-window-login-container').slideDown(ajax_speed);

	login_form.fadeTo(ajax_speed,0.2);
	login_status.slideUp(ajax_speed,function() {
		login_status.removeClass('error');
		login_status.addClass('info');
		login_status.html('Chargement...');
		login_status.slideDown(ajax_speed,function() {
			$.post(login_form.attr('action'),login_form.serialize(true),function(result) {
				ar = result.split(':');
				if (ar[0]=='error') {
					login_status.slideUp(ajax_speed,function() {
						login_form.fadeTo(ajax_speed,1);
						login_status.removeClass('info');
						login_status.addClass('error');
						login_status.html(ar[1]);
						login_status.slideDown(ajax_speed);
					});
				} else {
					login_status.slideUp(ajax_speed,function() {
						login_status.removeClass('error');
						login_status.addClass('info');
						login_status.html(ar[1]);
						login_status.slideDown(ajax_speed,function() {
							refresh_page();
						});
					});
				}
			});
		});
	});
	return false;
}
function do_window_forgot() {
	login_form = $('#form-window-forgot');
	login_status = $('#status-window-forgot');

	$('#forgot-window-description').slideUp(ajax_speed);
	$('#status-window-forgot-container').slideDown(ajax_speed);

	login_form.fadeTo(ajax_speed,0.2);
	login_status.slideUp(ajax_speed,function() {
		login_status.removeClass('error');
		login_status.addClass('info');
		login_status.html('Chargement...');
		login_status.slideDown(ajax_speed,function() {
			$.post(login_form.attr('action'),login_form.serialize(true),function(result) {
				ar = result.split(':');
				if (ar[0]=='error') {
					login_status.slideUp(ajax_speed,function() {
						login_form.fadeTo(ajax_speed,1);
						login_status.removeClass('info');
						login_status.addClass('error');
						login_status.html(ar[1]);
						login_status.slideDown(ajax_speed);
					});
				} else {
					login_status.slideUp(ajax_speed,function() {
						login_status.removeClass('error');
						login_status.addClass('info');
						login_status.html(ar[1]);
						login_status.slideDown(ajax_speed,function() {
							refresh_page();
						});
					});
				}
			});
		});
	});
	return false;
}
function text_counter(_this,limit) {
	if (_this.value.length > limit) {
		_this.value = _this.value.substring(0, limit);
		$('#char_no').html(_this.value.length+' caractère'+(_this.value.length==1?'':'s'));
		return false;
	}
	$('#char_no').html(_this.value.length+' caractère'+(_this.value.length==1?'':'s'));
	return true;
}
function forgetForeverInstructions() {
	$('#forget-forever-instructions a').hide(ajax_speed);
	$('#forget-forever-instructions img').show(ajax_speed);
	$.get('user/forget_forever_instructions/',null,function(){
		hide_intructions_window();
		$('#forget-forever-instructions img').hide(ajax_speed);
	});
	return false;
}
function strip_tags (str, allowed_tags) {
    // Strips HTML and PHP tags from a string
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strip_tags
    var key = '', allowed = false;
    var matches = [];    var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = '';
    var replacer = function (search, replace, str) {
        return str.split(search).join(replace);
    };
     // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
    }
     str += '';

    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);
     // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;        }

        // Save HTML tag
        html = matches[key].toString();
         // Is tag not in allowed list? Remove from str!
        allowed = false;

        // Go through all allowed tags
        for (k in allowed_array) {            // Init
            allowed_tag = allowed_array[k];
            i = -1;

            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}

            // Determine
            if (i == 0) {                allowed = true;
                break;
            }
        }
         if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
     return str;
}
