$(document).ready(function(){
	setTimeout(function(){
		if(!$('#iframed_banner').hasClass('closed')){
			hide_rsr_banner();
		}
	}, 4000);		
	
	$('#banner_rsr_button').click(function(){ 
		if($('#iframed_banner').hasClass('closed')){
			show_rsr_banner();
		}else{
			hide_rsr_banner();
		}
	});
	if(getCookie('banner_status') != 'true'){
		var expdate = new Date ();
		DateExpiration (expdate);
		expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); 
		FixCookie('banner_status', 'true', expdate);	
	}
	ajax_serv = "http://"+document.domain+"/";
		$('.small_croppable').each(function(){
			$(this).crop({x:15, y:48, height:57, width:80});
		});
		$('.medium_croppable').each(function(){
			url = $(this).attr('src');
			$(this).crop({x:4, y:60, height:110, width:154});
		});
	   	$('.add_article_playlist').click(function(){ 
 			add_item_to_playlist($(this).attr('id'), 'transfer', '', 'thema_index');
		});			
	/*	
		if($("#next_topic").length > 0){
			$("#scrollable").scrollable({loop: false,size:4,next: '#next_topic',prev: '#prev_topic',clickable: false});
			if($('.topic_actif').length > 0){
				tokens = $('.topic_actif').attr('id').split('_');
				pos = tokens[3] *1;
				page = Math.floor((pos)/4);
			}else{
				page = 0;
			}
			$("#scrollable").scrollable().setPage(page);
		}
	*/
		$("a#super_admin_zone_anchor").fancybox({
			'zoomSpeedIn':	0, 
			'zoomSpeedOut':	0,
			'frameWidth' : 800,
			'frameHeight' : 600
		});
		$("a.admin_modify_repertory").fancybox({
			'zoomSpeedIn':	0, 
			'zoomSpeedOut':	0,
			'frameWidth' : 800,
			'frameHeight' : 400
		});	  	
		$("a#admin_add_repertory").fancybox({
			'zoomSpeedIn':	0, 
			'zoomSpeedOut':	0,
			'frameWidth' : 800,
			'frameHeight' : 400
		});	  	
		//$("#search").bind("click", load_search_zone);
		$("#auth_form").fancybox({
			'zoomSpeedIn':	145, 
			'zoomSpeedOut':	0, 
			'frameWidth' : 300,
			'frameHeight' : 260,
			'overlayShow':	true
		});
	$("a#show_manual").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0,
		'frameWidth' : 1020,
		'frameHeight' : 355
	});
		$('.read_article_lien').each(function(){
				var href = $(this).attr('href');
				var target = $(this).attr('target');
				$(this).parent().parent().children('.article_p2').click(function(){
					document.location.href = href;
				});
				$(this).parent().parent().children('.article_p1').click(function(){
					document.location.href = href;
				});
			});		
		$('#onglet_logout').click(function(){
			disconnect_user();
		});
	   	current_topic_index = $('#actif_topic_id').text();
	   	current_topic_index = current_topic_index *1;
	   	for(i=0 ; i < ($('.bloc_article').length) ; i++){
	   		itemID = $(".bloc_article:eq("+i+")").attr('id');
	   		itemID = itemID.substr(6, itemID.length);
	   		if(!$(".bloc_article:eq("+i+")").hasClass('added')){
	   			$(".bloc_article:eq("+i+")").draggable({opacity: 0.50,containment:document.getElementById('bloc_principal'),scroll:true,revert: 'invalid', helper: 'clone'});
	   		}else{
	   			$('.bloc_article:eq('+i+')').draggable({opacity: 0.50,containment:document.getElementById('bloc_principal'),scroll:true,revert: 'invalid', helper: 'clone', handle:$(".bloc_article:eq("+i+")").children('div article_p2_photo')});
	   			$('.bloc_article:eq('+i+')').draggable('disable');
	   		}
	   	}
		$('.carre').droppable({						
			accept: '.zone_news, .bloc_article',
			activeClass: 'droppable-active',
			hoverClass: 'droppable-hover',
			over: function(){
				$('#carre_playlist').removeClass('carre');
				$('#carre_playlist').addClass('carre_on');
			},
			out: function(){
				$('#carre_playlist').removeClass('carre_on');
				$('#carre_playlist').addClass('carre');
			},
			drop: function(ev, ui) {	
				$('#carre_playlist').removeClass('carre_on');
				$('#carre_playlist').addClass('carre');				
				itemID = ui.draggable.attr('id').substr(5, ui.draggable.attr('id').length);
				stringToPrepend = "";
				if(ui.draggable.attr('class').substr(0, 9) == "zone_news"){
					clickStr = 'remove_from_playlist('+itemID+')';
					stringToPrepend = '<div class="item_in_pl" id="in_pl'+itemID+'"><div class="remove_from_pl" onclick='+clickStr+'><img src="'+ajax_serv+'img/cross.gif"/></div>'+cutIflong($('#titre_news').text())+'</div>';
				}else{
					clickStr = 'remove_from_playlist('+itemID+')';
					stringToPrepend = '<div class="item_in_pl" id="in_pl'+itemID+'"><div class="remove_from_pl" onclick='+clickStr+'><img src="'+ajax_serv+'img/cross.gif"/></div>'+cutIflong(ui.draggable.contents('.article_p1').contents('.titre_milieu').text())+'</div>'; 
				}
				add_item_to_playlist(itemID, 'drag', stringToPrepend, 'thema_index');
			}
		});	
		$("#search").bind("click", load_search_zone);
		if(getCookie('animation') != "true"){
			setTimeout("toggledMenuInit(0)",1000);
			var expdate = new Date ();
			DateExpiration (expdate);
			expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); 
			FixCookie('animation', 'true', expdate, '/');
		}
		$('.delete_rep').click(function(){
			if(confirm('Voulez-vous vraiment supprimer ce dossier?')){
				rep_id = $(this).attr('id').split('_')[2];
				delete_rep(rep_id);			
			}
		});
});
function set_topic_scrollable(){	
	var step = 0;
	$("#scrollable").scrollable({size:4, prev:'.prev_topic', next:'.next_topic', clickable: false});
	if($('.topic_actif').length > 0){			
		tokens = $('.topic_actif').attr('id').split('_');
		
		pos = tokens[3] *1;
		
		page = Math.floor((pos)/4);
		if($("#scrollable").scrollable().getStatus().page != page){

			step = pos - ($("#scrollable").scrollable().getStatus().size-1);
			for(i=0; i< step; i++){
				$("#scrollable").scrollable().next(10);
			}
		}
	}
	if(step==($("#scrollable").scrollable().getStatus().total-$("#scrollable").scrollable().getStatus().size)){
		$('#next_topic').removeClass('next_appear');
		//$('#next_topic').hide(); 
	}else{
		$('#next_topic').addClass('next_appear');
		//$('#next_topic').show(); 
	}
	if(step == 0){
		$('#prev_topic').removeClass('prev_appear');
		//$('#prev_topic').hide();
	}else{
		$('#prev_topic').addClass('prev_appear');
		//$('#prev_topic').show();
	}
	

	//alert($("#scrollable").scrollable().getStatus().total);

	$('#next_topic').click(function(){
		step++;
		$('#prev_topic').addClass('prev_appear');
		//$('#prev_topic').show();	
		$("#scrollable").scrollable().next();
		if(($("#scrollable").scrollable().getStatus().size+$("#scrollable").scrollable().getStatus().index)==$("#scrollable").scrollable().getStatus().total){
			$('#next_topic').removeClass('next_appear');
			//$('#next_topic').hide();
		}
	});
	$('#prev_topic').click(function(){
		step--;
		$('#next_topic').addClass('next_appear');
		//$('#next_topic').show();
		$("#scrollable").scrollable().prev();
		if($("#scrollable").scrollable().getStatus().index==0){
			$('#prev_topic').removeClass('prev_appear');
			//$('#prev_topic').hide();
		}
	});
}
function auth_user(){
	login = "";
	password = "";
	$('#fancy_div').children('div:eq(0)').children('div:eq(0)').children().each(function(){
		if($(this).attr('id')=='login_input'){
			login = $(this).val();
		}else if($(this).attr('id')=='password_input'){
			password = $(this).val();
			if(password != ""){
			password = password.md5();
			}
		}
	});
	if((login != "") && (password != "")){
		data_string = 'login='+login+'&password='+password;
		$.ajax({
		   type: 'POST',
		   url: ajax_serv+'auth_user.php',
		   data: data_string,
		   success: function(msg){
		   	if(msg.substr(-8) == "not_auth"){
		   		show_error_field();
		   		$('#fancy_div').children('div:eq(0)').children('#login_info').append("<div id='auth_error'><br /></div>");
		   		$('#fancy_div').children('div:eq(0)').children('#login_info').children('#auth_error').fadeIn('slow').append("Mauvais login et/ou password");
		   	}else if(msg == "reload"){
		   		window.location.reload();
		   	}
		   }
		 }); 		
	}else if((login == "") && (password == "")){ 
		show_error_field();
		$('#fancy_div').children('div:eq(0)').children('#login_info').append("<div id='auth_error' style='display:none'><br />Champs Login vide!<br />Champs Password vide!</div>");
		$('#fancy_div').children('div:eq(0)').children('#login_info').children('#auth_error').fadeIn('slow');
	}else{
		show_error_field();
		if(login == ""){
			$('#fancy_div').children('div:eq(0)').children('#login_info').append("<div id='auth_error' style='display:none'><br />Champs Login vide!</div>");
		}else if(password == ""){
			$('#fancy_div').children('div:eq(0)').children('#login_info').append("<div id='auth_error' style='display:none'><br />Champs Password Vide</div>");
		}
		$('#fancy_div').children('div:eq(0)').children('#login_info').children('#auth_error').fadeIn('slow');
	}
}
function disconnect_user(){
	data_string = '';
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'disconnect_user.php',
	   data: data_string,
	   success: function(msg){
   		window.location.reload();
	   }
	 }); 
}
function show_error_field(){
	if($('#auth_error').text()==""){
		$('#fancy_outer').animate({"height": "+=40px"}, 'slow');
	}else{
		$('#auth_error').remove();
	}
}
function handle_pwd_form(){
	if(!$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_loosed').hasClass('shown')){
		$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_loosed').addClass('shown');
		$('#fancy_outer').animate({"height": "+=50px"}, 'fast', function(){
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').fadeIn('fast');
		});
	}else{
		$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_loosed').removeClass('shown');
		$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').fadeOut('fast', function(){
			$('#fancy_outer').animate({"height": "-=50px"}, 'fast');
		});
	}
}
function regenerate_password(){
	email = $('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_email_input').val();
	if(echeck(email)){
		data_string = 'email='+email;
		$.ajax({
		   type: 'POST',
		   url: ajax_serv+'regenerate_password.php',
		   data: data_string,
		   success: function(msg){
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_email_input').removeClass('account_form_error');
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_reg_msg').remove();
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').append("<div id='pwd_reg_msg' style='display:none'><br />"+msg+"</div>");
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_reg_msg').fadeIn('slow');
		   }
		 }); 
	 }else{
	 	$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_email_input').addClass('account_form_error');
	 }
}
function handle_account_form(){
	if(!$('#fancy_div').children('div:eq(0)').children('#account').children('#create_account').hasClass('shown')){
		$('#fancy_div').children('div:eq(0)').children('#account').children('#create_account').addClass('shown');
		$('#fancy_outer').animate({"height": "+=120px"}, 'fast', function(){
			$('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').fadeIn('fast');
		});
	}else{
		$('#fancy_div').children('div:eq(0)').children('#account').children('#create_account').removeClass('shown');
		$('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').fadeOut('fast', function(){
			$('#fancy_outer').animate({"height": "-=120px"}, 'fast');
		});
	}
}
function create_new_account(){
	errors = false;
	login = "",
	password = "";
	email = "";
	$('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children().each(function(){
		verify_field($(this).attr('id'));
	});
	$('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children().each(function(){
		if($(this).hasClass('account_form_error')){
			errors = true;
		}else{
			if($(this).attr('id')=="account_login_input"){
				login = $(this).val();
			}else if($(this).attr('id')=="account_password_input"){
				password = $(this).val();
			}else if($(this).attr('id')=="account_email_input"){
				email = $(this).val();
			}
		}
	});
	if(errors == true){
	}else{
		data_string = 'login='+login+'&password='+password+'&email='+email;
		$.ajax({
		   type: 'POST',
		   url: ajax_serv+'add_new_user.php',
		   data: data_string,
		   success: function(msg){
			if(msg == "login used"){
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#account_login_input');
				element.addClass('account_form_error');
			}else if(msg == "mail adress used"){
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#account_email_input');
				element.addClass('account_form_error');
			}else if(msg == "login and mail adress used"){
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#account_login_input');
				element.addClass('account_form_error');
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#account_email_input');
				element.addClass('account_form_error');
			}else{
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form');
				element.empty();
				element.append("<div id='create_account_success'>Inscription effectuée avec succès! Pour terminer votre inscription, cliquez sur le lien envoyé par mail!</div>");
			}
		   }
		 }); 					
	}
}
function verify_field(element_name){
	element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#'+element_name);
	if(element_name == 'account_login_input'){
		if((element.val() =="") || (element.val().length < 2)){
			element.addClass('account_form_error');
		}else{
			element.removeClass('account_form_error');
		}
	}
	if(element_name == 'account_password_input'){
		if((element.val() =="") || (element.val().length < 4)){
			element.addClass('account_form_error');
		}else{
			element.removeClass('account_form_error');
		}		
	}
	if(element_name == 'account_password_input_bis'){
		if((element.val() =="") || (element.val().length < 4) ||((element.val())!=(element.parent().children('#account_password_input').val()))){
			element.addClass('account_form_error');
		}else{
			element.removeClass('account_form_error');
		}		
	}
	if(element_name == 'account_email_input'){
		if(!echeck(element.val())){
			element.addClass('account_form_error');
		}else{
			element.removeClass('account_form_error');
		}		
	}
}
function add_item_to_playlist(element, animation, stringToPrepend, location){	
	isRep = true;
	if(animation == 'transfer'){
		itemID = "";
		divID = "";
		text = "";
		if((((element+'').substr(0, 12))=='article_list')||(((element+'').substr(0, 12))=='reperto_list')){
			
			if($('#'+element).hasClass('rep')){
				isRep = true;
			}
			itemID = (element+'').substr(12, (element+'').length);
			itemIDSTR = itemID+"";
			if(itemID.substr(0, 3)=='rep'){
				itemID = (itemID+'').substr(3, (itemID+'').length);
			}
			if(isRep){
				divID = "repid"+itemID;
			}else{
				divID = "itemid"+itemID;
			}	
			if($('#'+element).hasClass('front')){
				item_title = $('#'+divID+'').contents('#titre_news').text();
			}else{
				item_title = $('#'+divID+'').contents('.article_p1').contents('.titre_milieu').text();
			}
			if(isRep){
				clickStr = 'remove_from_playlist("rep_'+itemID+'")';	
			}else{
				clickStr = 'remove_from_playlist('+itemID+')';				
			}
			if(isRep){
				text = '<div class="item_in_pl rep" id="in_plrep_'+itemID+'"><div class="remove_from_pl" onclick='+clickStr+'><img src="'+ajax_serv+'img/cross.gif"/></div>'+cutIflong(item_title)+'</div>';
				itemID = 'rep_'+itemID;
			}else{
				text = '<div class="item_in_pl" id="in_pl'+itemID+'"><div class="remove_from_pl" onclick='+clickStr+'><img src="'+ajax_serv+'img/cross.gif"/></div>'+cutIflong(item_title)+'</div>';
			}	
		}else if(((element+'').substr(0, 15))=='current_article'){ 
			itemID = (element+'').substr(15, (element+'').length);
			divID = "titre_milieu_large";		
			clickStr = 'remove_from_playlist('+itemID+')';	
			text = '<div class="item_in_pl" id="in_pl'+itemID+'"><div class="remove_from_pl" onclick='+clickStr+'><img src="'+ajax_serv+'img/cross.gif"/></div>'+cutIflong($('#'+divID+'').text())+'</div>';		
		}
	}else{		
		itemID = 'rep_'+element;
		text = stringToPrepend;
	}
	data_string = 'item_id='+itemID;
	if(isRep){
		if(itemID.length > 4){
			if(itemID.substr(0, 3)=='rep'){
				itemID_tokens = itemID.split('_');
				itemID = itemID_tokens[1]; 
			}
		}	
	}
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'add_item_to_playlist.php',
	   data: data_string,
	   success: function(msg){
         	if(msg == "success"){
			if(itemID.length > 4){
				if(itemID.substr(0, 3)=='rep'){
					itemID_tokens = itemID.split('_');
					itemID = itemID_tokens[1]; 
					isRep = true;
				}
			}
			if($('#text_playlist')!=null)
			{
				$('#text_playlist').remove();
			}
			$('#carre_playlist').prepend(text);
			if(location == "thema_index"){
				$('#article_list'+itemID).children('.ajouter_article_icon').hide();
				$('#article_list'+itemID).children('.ajouter_article').hide();
				$('#article_list'+itemID).children('.supprimer_article_icon').show();
				$('#article_list'+itemID).children('.supprimer_article').show();
				if($('#current_article'+itemID).length > 0){
					$('#current_article'+itemID).children('.ajouter_article_icon').hide();
					$('#current_article'+itemID).children('.ajouter_article').hide();
					$('#current_article'+itemID).children('.supprimer_article_icon').show();
					$('#current_article'+itemID).children('.supprimer_article').show();				
				}
			}else if(location == "article_index"){
				$('#current_article'+itemID).children('.ajouter_article_icon').hide();
				$('#current_article'+itemID).children('.ajouter_article').hide();
				$('#current_article'+itemID).children('.supprimer_article_icon').show();
				$('#current_article'+itemID).children('.supprimer_article').show();
				if($('#article_list'+itemID).length > 0){
					$('#article_list'+itemID).children('.ajouter_article_icon').hide();
					$('#article_list'+itemID).children('.ajouter_article').hide();
					$('#article_list'+itemID).children('.supprimer_article_icon').show();
					$('#article_list'+itemID).children('.supprimer_article').show();				
				}
			}
			if(animation=='transfer'){
				$('#'+divID+'').effect("transfer", { to: "div.carre", className: "transferring" }, 1000);
				if(isRep){
					$('#repid'+itemID).draggable( "disable" );
				}else{
					$('#itemid'+itemID).draggable( "disable" );
				}				
			}else{
				if(isRep){
					$('#repid'+itemID).draggable( "disable" );
				}else{
					$('#itemid'+itemID).draggable( "disable" );
				}
			}
		}else{
			if(itemID.length > 4){
				if(itemID.substr(0, 3)=='rep'){
					itemID_tokens = itemID.split('_');
					itemID = itemID_tokens[1]; 
					isRep = true;
				}
			}	
			if(location == "thema_index"){
				$('#article_list'+itemID).children('.supprimer_article_icon').hide();
				$('#article_list'+itemID).children('.supprimer_article').hide();	
				$('#article_list'+itemID).children('.ajouter_article_icon').show();
				$('#article_list'+itemID).children('.ajouter_article').show();	
					if(isRep){
						$('#repid'+itemID).draggable( "enable" );
					}else{
						$('#itemid'+itemID).draggable( "enable" );
					}
				if($('#current_article'+itemID).length > 0){
					$('#current_article'+itemID).children('.supprimer_article_icon').hide();
					$('#current_article'+itemID).children('.supprimer_article').hide();
					$('#current_article'+itemID).children('.ajouter_article_icon').show();
					$('#current_article'+itemID).children('.ajouter_article').show();				
				}
			}else if(location == "article_index"){
				$('#current_article'+itemID).children('.supprimer_article_icon').hide();
				$('#current_article'+itemID).children('.supprimer_article').hide();
				$('#current_article'+itemID).children('.ajouter_article_icon').show();
				$('#current_article'+itemID).children('.ajouter_article').show();
				if($('#article_list'+itemID).length > 0){
					$('#article_list'+itemID).children('.supprimer_article_icon').hide();
					$('#article_list'+itemID).children('.supprimer_article').hide();	
					$('#article_list'+itemID).children('.ajouter_article_icon').show();
					$('#article_list'+itemID).children('.ajouter_article').show();				
				}
			}	
			if(isRep){
				$('#in_plrep_'+itemID).empty();
				$('#in_plrep_'+itemID).remove();
			}else{
				$('#in_pl'+itemID).empty();
				$('#in_pl'+itemID).remove();
			}
			if($('.item_in_pl').length==0){
				$('#carre_playlist').append('<div id="text_playlist">Glisser ici les articles que vous souhaitez ajouter à la playlist</div>');
			}
		}
         }
	 });
}
function toggledMenuInit(menu_id){
	id = menu_id;
	menus_count = $('.menu_toggle').length;
	if(menu_id < menus_count){
		menu_id = $('.menu_toggle')[menu_id].id;
		if(!$("#"+menu_id).hasClass('activ') && !$("#"+menu_id).hasClass('inactiv')){
			InitMenu(menu_id, id);
		}else{
			menu_id = id + 1;
			this.toggledMenuInit(menu_id);
		}
	}else{
		menus_count = $('.menu_toggle').length;
		for(i=0;i<menus_count;i++){
			menu_id = $('.menu_toggle')[i].id;
			if(!$("#"+menu_id).hasClass('activ')){
				onmouseoverInit(menu_id);
			}
		}
	}
}
function InitMenu(menu_id, id){
	$('#'+menu_id).addClass('inactiv');
	$('#'+menu_id).toggle("slide", {direction:"right"}, 100, function callback() 
		{
			onmouseoverInit(menu_id);
		});
	id = id+1;
	setTimeout("toggledMenuInit("+id+")",100);
}
function onmouseoverInit(menu_id){
	if(document.getElementById(menu_id) != null){
		document.getElementById(menu_id).onmouseover = function() {
			document.getElementById(menu_id).onmouseover = "";
			onmouseoutInit(menu_id);
			$('#'+menu_id).toggle("slide", {direction: "left"}, 100, function(){
				if($('#'+menu_id).parent().attr('id')!='menu_left3'){
						document.getElementById(menu_id).onclick = function(){sortByMedia(menu_id);};
				}
			});
		};	
	}
}
function onmouseoutInit(menu_id){
	if(document.getElementById(menu_id) != null){
		document.getElementById(menu_id).onmouseout = function(){
			document.getElementById(menu_id).onmouseout = "";
			$('#'+menu_id).toggle("slide", {direction:"right"}, 100, function callback()
			{
					onmouseoverInit(menu_id);										
			});
		};
	}
}
function sortByMedia(element_id){
	if((element_id != 'onglet_blogs') && (element_id != 'onglet_forum')){
		href = $('#'+element_id).children('a').attr('href');
		window.location.replace(href);
	}
}
function remove_from_playlist(itemID){
		add_item_to_playlist(itemID, 'drag', '', 'thema_index');
}
function delete_rep(rep_id){
	action = 'delete_rep';
	data_string = 'action='+action+'&repid='+rep_id;
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'super_admin_functions.php',
	   data: data_string,
	   success: function(msg){
	   	$('#repid'+rep_id+'').fadeOut('fast');
	   	//updateHash(hashContent);
	   }
	 }); 

}
function cutIflong(str){
	if(str.length > 35){
		str = str.substr(0, 35);
		str += " ...";
	}
	return str;
}
function load_search_zone(){
	$("#search").unbind("click", load_search_zone);
	thema_id = $('#current_thema_id').text();
	data_string = 'thema_id='+thema_id;
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'load_search_zone.php',
	   data: data_string,
	   success: function(msg){
	   	$('#searching_forms').children('form').remove();
	   	//$('#searching_forms').css('z-index', 100);
	  	$('#searching_forms').prepend(msg);
	  	show_search_zone();
	   }
	 });
}
function show_search_zone(){
	$('#search_form_container').height(0);
	$('#super_admin_zone_anchor').fadeOut('fast');
	$('#onglet_mode_emplois').fadeOut('fast');
	$('#accueil_zone_anchor').fadeOut('fast');
	$('#banner_rsr_button').fadeOut('fast');
   	$('#search_form_container').animate({"height": "+=130px"}, 'fast', function(){
   		$('#search_form').fadeIn('medium');
		$("#search").bind("click", hide_search_zone);
   	}); 	
}
function hide_search_zone(){
	$("#search").unbind("click", hide_search_zone);
	$('#search_form').fadeOut('medium', function(){
   		$('#search_form_container').animate({"height": "-=130px"}, 'fast', function(){
   			//$('#searching_forms').css('z-index', 89);
   			$('#super_admin_zone_anchor').fadeIn('fast');
   			$('#onglet_mode_emplois').fadeIn('fast');
   			$('#accueil_zone_anchor').fadeIn('fast');
   			$('#banner_rsr_button').fadeIn('fast');
   		});
		$("#search").bind("click", load_search_zone);
   	}); 	
}
function check_radio_list(radio){
	if(radio == 'thema'){
		if($('#topics_to_search_in').css('display')=='none'){
			$('#topics_to_search_in').fadeIn('fast');
		}
	}else{
		if($('#topics_to_search_in').css('display')=='block'){
			$('#topics_to_search_in').fadeOut('fast');
		}
	}
}
function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	if (str.indexOf(" ")!=-1){
		return false;
	}
	return true;					
}
function show_rsr_banner(){
		$('#super_admin_zone_anchor').fadeOut('fast');
		$('#onglet_mode_emplois').fadeOut('fast');
		$('#accueil_zone_anchor').fadeOut('fast');
		$('#search').fadeOut('fast');	
	$('#iframed_banner').slideDown('slow', function(){
		$('#iframed_banner').removeClass('closed');
		button_src = $('#banner_rsr_button').children('img').attr('src');
		new_button_src = button_src.replace("close", "open");
		$('#banner_rsr_button').children('img').attr('src', new_button_src);
	});
}
function hide_rsr_banner(){
	$('#iframed_banner').slideUp('slow', function(){
		$('#iframed_banner').addClass('closed');
		button_src = $('#banner_rsr_button').children('img').attr('src');
		new_button_src = button_src.replace("open", "close");
		$('#banner_rsr_button').children('img').attr('src', new_button_src);
		$('#super_admin_zone_anchor').fadeIn('fast');
		$('#onglet_mode_emplois').fadeIn('fast');
		$('#accueil_zone_anchor').fadeIn('fast');
		$('#search').fadeIn('fast');	
	});
}
function getCookie(nom) {
	deb = document.cookie.indexOf(nom + "=");
	if (deb >= 0) {
		deb += nom.length + 1;
		fin = document.cookie.indexOf(";",deb);
		if (fin < 0) fin = document.cookie.length;
		return unescape(document.cookie.substring(deb,fin));
	}
	return "";
}
function FixCookie(nom,valeur,expire,path,domaine,securise) {
      document.cookie = nom + "=" + escape (valeur) + ((expire) ? "; expires=" + expire.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domaine) ? "; domain=" + domaine : "") + ((securise) ? "; secure" : "");
}
function DateExpiration (DateExp) {

      var aujourdhui = new Date(0);
      var aujourdhuidate = aujourdhui.getTime();
      if (aujourdhuidate > 0)
            DateExp.setTime (DateExp.getTime() - aujourdhuidate);

}

