var newwindow;

function chrisdeletereport(id) {
//alert(id);
var cx1 = new Asynchronous( );
				cx1.call('GET', 'chrisdeletereport.php?docid='+id);
				item_list('brokenlinks');
				return false;
}

function reportbroken(id) {
  confirm("Do you want to report a broken link in this page ?");
  var cx = new Asynchronous( );
				cx.call('GET', 'chrisreportlink.php?docid='+id);
				return false;
}

function chrisrefresh() {
  window.opener.location.href = window.opener.location.href;

  
  window.close();
}


function chrispopup(url)
{
	newwindow=window.open(url,'chrisname','height=400,width=300');
	if (window.focus) {newwindow.focus()}	return false;	
}function chrislaunch(cat,it) {
    category_selected.length = 0;	// initiate list of categories
	indexterm_selected.length = 0;	// initiate list of indexterms
	if (cat!='') {category_selected[0]=cat; browsing = 'categories';}
	else if (it!='') {indexterm_selected[0]=it; browsing = 'indexterms';}    
	
	/*document.getElementById('centrecontent').innerHTML = '';
	$("BODY").attr("id","list");    $("#outer2").attr("id", "outer");    $("#clearheader").after("<div id='left'></div>"); */
	// the above 4 lines to be got and ,manipulated in chrisbrowse.php
	
						
//	compose_listtop(cat, it, status);

	chrisleft_menu();
	// Let's reset the right menu (Home - About- Contact)
	$(".li_selected").removeClass("li_selected");
	
}


function chrisleft_menu() 
{
	//var http_left = new Asynchronous( ); // We create the HTTP Object
	//http_left.call('GET', LEFT_MENU_PREFIX);
	//http_left.complete = function(status, statusText, responseText, responseXML) {
		if (document.getElementById('left') != null){
			//document.getElementById('left').innerHTML = '';
			//$('div #left').append(responseText);
			// Make slider visible and active for the left menu
			go_slider_left('categories');go_slider_left('indexterms');
			// Per default: only categories list is visible
			$(".show_hide_i").hide();
			// Make the search button active
			$("#submitnormalsearch").click(function() {
				if (document.getElementById('keywords').value != ''){status_selected=''; search_action('search_keyword='+document.getElementById('keywords').value, 'left');}
			});
			document.getElementById('keywords').focus();
			$(".search_options").click(function() {						//alert("line 72");
				if ($(".searchoptions_display").get(0) != null) {return false;}								
				//if ($("#document").get(0) != null) {return false;}
				var http_searchoptions = new Asynchronous( );
				http_searchoptions.call('GET', SHOWOPTIONS_PREFIX+'anyName=' + new Date().getTime());
				http_searchoptions.complete = function(status, statusText, responseText, responseXML) {//alert("line 83");
					$("#centrecontent").prepend(responseText);
					$(".searchoptions_display").slideDown("slow");
					$("#searchoptions_close").click(function() {
						$(".searchoptions_display").slideUp("slow", function() {$(this).remove()});
					})
					.mouseover(function() {$(this).toggleClass("searchmouse")})
					.mouseout(function() {$(this).toggleClass("searchmouse")});
					$("#searchoptions_top > IMG").click(function() {
						$(".searchoptions_display").slideUp("slow", function() {$(this).remove()});
					})
					
					$("#submitadvancedsearch").click(function() {
						if (document.forms['advancedsearch'].elements[0].value != '' || document.forms['advancedsearch'].elements[1].value != '' || document.forms['advancedsearch'].elements[2].value != '' || document.forms['advancedsearch'].elements[3].value != '' || document.forms['advancedsearch'].elements[4].value != '' || document.forms['advancedsearch'].elements[5].value != '' ){
							post = "name_value="+document.forms['advancedsearch'].elements['field_name'].value;
							post += "&web_value="+document.forms['advancedsearch'].elements['field_web'].value;
							post += "&category_value="+document.forms['advancedsearch'].elements['field_category'].value;
							post += "&indexterm_value="+document.forms['advancedsearch'].elements['field_indexterm'].value;
							post += "&precis_value="+document.forms['advancedsearch'].elements['field_precis'].value;
							post += "&description_value="+document.forms['advancedsearch'].elements['field_description'].value;
							search_action(post, 'left');
						}				
					});	

					
				}
			})
			.mouseover(function() {$(this).toggleClass("searchmouse")})
			.mouseout(function() {$(this).toggleClass("searchmouse")});
				
		}
	 
	$("#cat_plus_minus").mouseover(function() {
				$(this).css("cursor","pointer");
			}).click(function() {
				$(".show_hide_c").toggle();
				$(".show_hide_i").toggle();
					if (cat_original_slider_height == 0){record_slider_original("categories");}
				$(this).toggleClass("menu_plus").toggleClass("menu_minus");
				$("#indexterm_plus_minus").toggleClass("menu_plus").toggleClass("menu_minus");
			})
	$("#indexterm_plus_minus").mouseover(function() {
				$(this).css("cursor","pointer");
			}).click(function() {
				$(".show_hide_i").toggle();
				$(".show_hide_c").toggle();
					if (index_original_slider_height == 0){record_slider_original("indexterms");}				
				$(this).toggleClass("menu_minus").toggleClass("menu_plus");
				$("#cat_plus_minus").toggleClass("menu_minus").toggleClass("menu_plus");
			})
			
	if (category_selected.length!=0 && browsing =='categories'){
			$(".show_hide_i").hide();
			
			//If we relaunch the left menu after login/logoff, and that the previously selected category is no longer listed, we clear the content of the central panel
			if ($("#category"+category_selected[0]).get(0) == null){document.getElementById('centrecontent').innerHTML = "";}
			
			$("#category"+category_selected[0]).each(function(i){						//alert(197);
				$(this).toggleClass("category_selected");
			//	var http_submenu = new Asynchronous( ); // We create the HTTP Object
				//http_submenu.call('GET', SUBMENU_PREFIX+'category='+category_selected[0]);
					//var toinsert = $("#category"+category_selected[0]).parent();//alert(toinsert);
				//	http_submenu.complete = function(status, statusText, responseText, responseXML) {					//alert(responseText);
						//toinsert.after(responseText);
						if (cat_original_slider_height == 0){record_slider_original("categories");}
						// Fetch data that only match the category selected
						if (doc_selected == null || doc_selected == '' || doc_selected == 0) {	// we display the list of document sonly if there is no document selected (this is used after login/logout)
							 list_all_documents ();											
						}
						set_behaviour_submenu_elements('indexterms');
						$(".submenu").slideDown("slow", function(){adaptSlider('categories');slideto();});
						// If we relaunch the left panel after login/logoff, we need to set selected the indexterms in the submenu.
						for(i=0; i<indexterm_selected.length; i++){
							$("#subindexterm"+indexterm_selected[i]).addClass("submenu_selected");
						}
					//}
			})

	} else if (indexterm_selected.length!=0 && browsing == 'indexterms'){
			$(".show_hide_i").show(); 
			$(".show_hide_c").hide();
			$("#cat_plus_minus").toggleClass("menu_minus").toggleClass("menu_plus");
			$("#indexterm_plus_minus").toggleClass("menu_plus").toggleClass("menu_minus");
			
			//If we relaunch the left menu after login/logoff, and that the previously selected category is no longer listed, we clear the content of the central panel
			if ($("#indexterm"+indexterm_selected[0]).get(0) == null){document.getElementById('centrecontent').innerHTML = "";}
			

			$("#indexterm"+indexterm_selected[0]).each(function(i){
				$(this).toggleClass("indexterm_selected");
			//	var http_submenu = new Asynchronous( ); // We create the HTTP Object
				//http_submenu.call('GET', SUBMENU_PREFIX+'indexterm='+indexterm_selected[0]);
					//var toinsert = $("#indexterm"+indexterm_selected[0]).parent();
					//http_submenu.complete = function(status, statusText, responseText, responseXML) {
					//	toinsert.after(responseText);
						if (index_original_slider_height == 0){record_slider_original("indexterms");}
						// Fetch data that only match the category selected
						if (doc_selected == null || doc_selected == '' || doc_selected == 0) {	// we display the list of document sonly if there is no document selected (this is used after login/logout)
							list_all_documents ();											
						}
						set_behaviour_submenu_elements('categories');
						$(".submenu").slideDown("slow", function(){adaptSlider('indexterms');slideto();});
						// If we relaunch the left panel after login/logoff, we need to set selected the indexterms in the submenu.
						for(i=0; i<category_selected.length; i++){
							$("#subcategory"+category_selected[i]).addClass("submenu_selected");
						}
					//}
			})
	}
	
	// set the behaviour of the categories and indexterms displayed on the left menu
		// CATEGORIES
		$("div.left_cloud_content_cat").find("span.sub_item").click(function() {
		
			// Clear the potentially selected public/pending squares on the left panel
			$(".pending_selected").removeClass("pending_selected");
			$(".public_selected").removeClass("public_selected");
			// Clear the status_selected (public or pending or -empty-)
			status_selected = '';
			browsing = 'categories';
			
			var this_item = $(this);
			if (this_item.attr("class").indexOf("category_selected") != -1) {
				// CASE: the category is already selected and displays sub menu
				if ($(".submenu").css("display") == "none"){
					$(".submenu").slideDown("slow", function(){adaptSlider('categories');});
				} else {
					FixBuggWhenScrolling('categories');	// Traitement BUG - category - 
					$(".submenu").slideUp("slow", function(){adaptSlider('categories');});
//					$("div.left_cloud_content_cat").animate({top:futurTop},"slow");
				}	
				
			} else {
				// CASE: the category selected is a new one
				var id = this_item.attr("id");
				id = id.slice(8); // 8 is the length of "category"
				category_selected[0] = id;
				indexterm_selected.length = 0;
				list_all_documents ();
				
				if ($("div.left_cloud_content_index").find(".submenu").get(0) != null){
					// There is an INDEXTERM SELECTED already
//					alert("there is a category selected already \r\n Let's get rid of it properly !");
					$("div.left_cloud_content_index").find("span.indexterm_selected").removeClass("indexterm_selected");
					if ($(".submenu").css("display") == "none") {
						$(".submenu").remove();				
					} else {
						$("div.left_cloud_content_index").css("top",0+"px");
						$("div.left_cloud_content_index").find(".submenu").remove();
						original_slider('indexterms');
					}
					
					
				} else if ($("div.left_cloud_content_cat").find(".submenu").get(0) != null) {
					// There is a CATEGORY SELECTED
//					alert("There is an indexterm selected already \r\n Let's get rid of it");
					$(".left_cloud_content_cat").find(".category_selected").removeClass("category_selected");
					if ($(".submenu").css("display") == "none"){
						$(".submenu").remove();
					} else {
						// Traitement BUG - category - 
						FixBuggWhenScrolling("categories");
						var todelete_temp = $(".submenu");
						todelete_temp.slideUp("slow",function(){ todelete_temp.remove();/*adaptSlider('categories');*/});
					}
				
				} else {
					// There is NO CATEGORY SELECTED (i.e. after a search)
					
				}


				this_item.toggleClass("category_selected");

				var http_submenu = new Asynchronous( ); // We create the HTTP Object
				http_submenu.call('GET', SUBMENU_PREFIX+'category='+id);
					var toinsert = this_item.parent();
					http_submenu.complete = function(status, statusText, responseText, responseXML) {
						toinsert.after(responseText);
						set_behaviour_submenu_elements('indexterms');						
						$(".submenu").slideDown("slow", function(){adaptSlider('categories');});
					}
			}



		}) // end click behaviour for categories
		.hover(function(){
  			 $(this).addClass("category_hover");
		},function(){
   			$(this).removeClass("category_hover");
		});
		
		
		
		// INDEXTERMS
		$("div.left_cloud_content_index").find("span.sub_item").click(function() {
		
			// Clear the potentially selected public/pending squares on the left panel
			$(".pending_selected").removeClass("pending_selected");
			$(".public_selected").removeClass("public_selected");
			// Clear the status_selected (public or pending or -empty-)
			status_selected = '';
			browsing = 'indexterms';
			
			var this_item = $(this);
			if (this_item.attr("class").indexOf("indexterm_selected") != -1) {
				// CASE: this item is already selected and displays sub menu
				if ($(".submenu").css("display") == "none"){
					$(".submenu").slideDown("slow", function(){adaptSlider('indexterms');});
				} else {
					FixBuggWhenScrolling("indexterms");
					$(".submenu").slideUp("slow", function(){adaptSlider('indexterms');});
				}	
			} else {
				// CASE: the item is not yet selected
				var id = this_item.attr("id");
				id = id.slice(9); // 9 is the length of "indexterm"
				indexterm_selected[0] = id;
				category_selected.length = 0;
				
				list_all_documents ();
				
				if ($("div.left_cloud_content_cat").find(".submenu").get(0) != null){
					// There is a CATEGORY SELECTED already
//					alert("there is a category selected already \r\n Let's get rid of it properly !");
					$("div.left_cloud_content_cat").find("span.category_selected").removeClass("category_selected");
					if ($(".submenu").css("display") == "none") {
						$(".submenu").remove();				
					} else {
						$("div.left_cloud_content_cat").css("top",0+"px");
						$("div.left_cloud_content_cat").find(".submenu").remove();
						original_slider('categories');
					}
					
					
					
					
				} else if ($("div.left_cloud_content_index").find(".submenu").get(0) != null) {
					// There is an INDEXTERM SELECTED
//					alert("There is an indexterm selected already \r\n Let's get rid of it");
					$(".left_cloud_content_index").find(".indexterm_selected").removeClass("indexterm_selected");
					if ($(".submenu").css("display") == "none"){
						$(".submenu").remove();
					} else {
						// Traitement BUG - category - 
						FixBuggWhenScrolling("indexterms");
						var todelete_temp = $(".submenu");
						todelete_temp.slideUp("slow",function(){ todelete_temp.remove();/*adaptSlider('indexterms');*/});
					}
				
				} else {
					// There is NO ITEM SELECTED (i.e. after a search)
					
				}
					

				this_item.toggleClass("indexterm_selected");

				var http_submenu = new Asynchronous( ); // We create the HTTP Object
				http_submenu.call('GET', SUBMENU_PREFIX+'indexterm='+id);
					var toinsert = this_item.parent();
					http_submenu.complete = function(status, statusText, responseText, responseXML) {
						toinsert.after(responseText);
						set_behaviour_submenu_elements('categories');
						$(".submenu").slideDown("slow", function(){adaptSlider('indexterms');});
					}
			
				

			}
		})// end click behaviour for indexterms
		.hover(function(){
  			 $(this).addClass("indexterm_hover");
		},function(){
   			$(this).removeClass("indexterm_hover");
		});
		
		
		// SET the behaviour of the pending/public count when an administrator is logged-in
				// PUBLIC
		$(".public_count").click(function(){
			var this_element = $(this);
			status_selected = 'public';
			$(".public_selected").removeClass("public_selected");
			category_selected.length=0;
			indexterm_selected.length = 0;
			if (this_element.attr("id").indexOf("catpublic") != -1) { // This is in the category panel
				cat_id = this_element.attr("id").slice(9);
				category_selected[0]= cat_id;
				browsing = 'categories';
			} else if (this_element.attr("id").indexOf("indexpublic") != -1) {
				index_id = this_element.attr("id").slice(11);
				indexterm_selected[0] = index_id;
				browsing = 'indexterms';
			}
			clear_left_panel();
			this_element.toggleClass("public_selected");
			list_all_documents();
		}).hover(function(){
  			 $(this).addClass("public_hover");
		},function(){
   			$(this).removeClass("public_hover");
		});
		
						// PENDING
		$(".pending_count").click(function(){
			var this_element = $(this);
			status_selected = 'pending';
			category_selected.length=0;
			indexterm_selected.length = 0;
			if (this_element.attr("id").indexOf("catpending") != -1) { // This is in the category panel
				cat_id = this_element.attr("id").slice(10);
				category_selected[0]= cat_id;
				browsing = 'categories';
			} else if (this_element.attr("id").indexOf("indexpending") != -1) {
				index_id = this_element.attr("id").slice(12);
				indexterm_selected[0] = index_id;
				browsing = 'indexterms';
			}
			clear_left_panel();
			this_element.toggleClass("pending_selected");
			list_all_documents();
		}).hover(function(){
  			 $(this).addClass("pending_hover");
		},function(){
   			$(this).removeClass("pending_hover");
		});

		
	//} // end of asynchronous callback
	
			// Clear the status_selected (public or pending or -empty-)
			status_selected = '';

}
