function change_display_functions(){
	var number_form = parseInt($j('#id_' + init_prefix + '-TOTAL_FORMS').val());
	var links_display = document.getElementsByName('displayTranslateDisplay');
	var links_program = document.getElementsByName('displayTranslateProgram');
	var translations_display=document.getElementsByName("translate_display");

	for(var i=0;i<number_form;i++){
		links_display[i].onclick =  function(){
		current_display = translations_display[i-1].style.display;
		if (current_display == "block"){
			translations_display[i-1].style.display = "none";
		}
		else{
			translations_display[i-1].style.display = "block";
		}
	}
		links_program[i].onclick =  function(){
			display_translate_program(i);
		}
	}
}

function init_events(){

	//change_display_functions();
	var number_form = parseInt($j('#id_' + init_prefix + '-TOTAL_FORMS').val());
	if(number_form<2){
		$j(".delete-row").hide();
	}
	var translations_display=document.getElementsByName("translate_display");
	var translations_program=document.getElementsByName("translate_program");
	/*id_nb_form = "#id_" + init_prefix + "-TOTAL_FORMS";
	for(var k=0;k<translations_display.length;k++){
		translations_display[k].style.display="none";
		translations_program[k].style.display="none";
	}
	
	$j(".delete-row").bind('click', function() { change_display_functions() } );*/
	 
	$j(".add-row").click(function() {
		//change_display_functions();
		var number_form = parseInt($j('#id_' + init_prefix + '-TOTAL_FORMS').val())-1;
		/*var translations_display=document.getElementsByName("translate_display");
		var translations_program=document.getElementsByName("translate_program");
	
		translations_display[number_form].style.display = "none";
		translations_program[number_form].style.display = "none";*/
		$j(".delete-row").show();
		tinyMCE.init({
		    mode: "textareas",
		    theme: "advanced",
	        plugins : "autolink,lists,spellchecker,layer,table,save,advhr,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
		
	     	theme_advanced_buttons1 : "save,newdocument,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
	        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,search,replace,bullist,numlist,outdent,indent,blockquote,undo,redo,link,unlink,anchor,cleanup,help,code,insertdate,inserttime,preview,forecolor,backcolor",
	        theme_advanced_buttons3 : "tablecontrols,hr,removeformat,visualaid,sub,sup,charmap,emotions,iespell,advhr,ltr,rtl,fullscreen",
	        theme_advanced_toolbar_location : "top",
	        theme_advanced_toolbar_align : "left",
	        theme_advanced_statusbar_location : "bottom",
	        theme_advanced_resizing : true,
		});
		$j('textarea').each(function () {
            tinyMCE.execCommand('mceAddControl', false, this.id);
        });
			
	});
		
}

function display_translate_display(nb_form){
	var translations_display=document.getElementsByName("translate_display");
	current = translations_display[nb_form].style.display
	if (current == "block"){
		translations_display[nb_form].style.display = "none";
	}
	else{
		translations_display[nb_form].style.display = "block";
	}
}

function display_translate_program(nb_form){
	var translations_program=document.getElementsByName("translate_program");
	current = translations_program[nb_form].style.display
	if (current == "block"){
		translations_program[nb_form].style.display = "none";
	}
	else{
		translations_program[nb_form].style.display = "block";
	}
}

