// JavaScript Document
//var URL_SITE = 'http://127.0.0.1:8080/anatomie3/';
var URL_SITE = 'http://www.cours-medecine.info/';

function ShowBloc(id_section, id_bloc)
{
  //alert('SECTION = ' + id_section + ' BLOC = ' + id_bloc);
	// hides all blocks except the one in parameter
	// id like : section_X_bloc_Y

  var test_id = 'section_' + id_section + '_bloc_' + id_bloc;
  var test    = 'section_' + id_section + '_bloc_';

	var c = document.getElementById(test_id);
	for (var i = -1; i<=50; i++)
	{
		if (document.getElementById(test + i))
    {
      /*alert('Désactive BLOC '+i);*/
      document.getElementById(test + i).style.display='none';
    }
	}
	if (c)
  {
    /*alert('Active BLOC '+thisone);*/
    c.style.display='block';
  }
}



function HideAllBlocs(id_section, hide_default)
{
  var id_hide_section = parseInt(id_section);
  var id_hide_default = parseInt(hide_default); // 1 or 0
  //alert('MASQUER SECTION ID=' + id_hide_section);

  var testbloc = 'section_' + id_hide_section + '_bloc_';
  var start_id_hide = (id_hide_default == 1) ? 0 : 1;

	for (var i = start_id_hide; i<=15; i++)
	{
		if (document.getElementById(testbloc + i))
    {
      //alert('Désactive BLOC '+i);
      document.getElementById(testbloc + i).style.display='none';
    }
	}
}

function RevealBloc(id_section, id_bloc)
{
  var id_reveal_section = parseInt(id_section);
  var id_reveal_bloc = parseInt(id_bloc);
  var testbloc_id = 'section_' + id_reveal_section + '_bloc_' + id_reveal_bloc;

  HideAllBlocs(id_reveal_section, 1);
	var c = document.getElementById(testbloc_id);
	if (c)
  {
    //alert('Active BLOC '+id_bloc);
    c.style.display='block';
  }
}



function SwitchCheckAll(action)
{
	var checkboxes = document.getElementById('table_form_qcm').getElementsByTagName('input');
	for (var i=0;i<checkboxes.length;i++)
	{
		if (checkboxes[i].type == 'checkbox')
		{
			if (action == 'check')
			{
				checkboxes[i].checked = true;
			}

			if (action == 'uncheck')
			{
				checkboxes[i].checked = false;
			}

			if (action == 'invert')
			{
				if (checkboxes[i].checked)
					checkboxes[i].checked = false;
				else
					checkboxes[i].checked = true;
			}
		}
	}
	return true;
}



function CheckSubCenters(main_center)
{
  //alert('MAIN = ' + main_center);
  var main_center_status = (document.getElementById(main_center).checked) ? true : false;
  //var main_status = (main_center_status) ? 'coché' : 'non coché';
  //alert(main_status);

 	var checkboxes = document.getElementById('search_main').getElementsByTagName('input');
	for (var i=0;i<checkboxes.length;i++)
	{
		if (checkboxes[i].type == 'checkbox')
		{
      var checkbox_id = checkboxes[i].id;
      var array_checkbox_id = checkbox_id.split('-_-'); // [0] sub   [1] main_center ......
      if ((array_checkbox_id[1]) && (array_checkbox_id[1] == main_center))
      {
        // this checkbox belongs to main center. Activate/Deactivate it.
        checkboxes[i].checked = (main_center_status) ? true : false;
        checkboxes[i].disabled = (main_center_status) ? true : false;
      };
		};
	};
	return true;
};



function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=480,height=320');");
}
























function ExpandCat(id_cat)
{
	/*alert ("bloc : "+id_cat);*/
	if(document.getElementById('cat_'+id_cat).style.display=='none')
	{
		document.getElementById('cat_'+id_cat).style.display='';
		if(document.getElementById('img_'+id_cat))
      document.getElementById('img_'+id_cat).src='../img/hide.png';
	}
	else
	{
		document.getElementById('cat_'+id_cat).style.display='none';
		if(document.getElementById('img_'+id_cat))
		document.getElementById('img_'+id_cat).src='../img/show.png';
	}
}



function ShowDetails(id_details, id_img, src_img_display, src_img_hide)
{
	//if(document.getElementById('details'.$annonce['id'].'\').style.display==\'none\'){ document.getElementById(\'details'.$annonce['id'].'\').style.display=\'\'; document.getElementById(\'dvp'.$annonce['id'].'\').src=\'img/16/eyes_close.png\'; } else { document.getElementById(\'details'.$annonce['id'].'\').style.display=\'none\'; document.getElementById(\'dvp'.$annonce['id'].'\').src=\'img/16/eyes_open.png\'
	if(document.getElementById(id_details).style.display=='none')
	{
		document.getElementById(id_details).style.display='';
		if (id_img != '')
			document.getElementById(id_img).src=src_img_hide;
	}
	else
	{
		document.getElementById(id_details).style.display='none';
		if (id_img != '')
			document.getElementById(id_img).src=src_img_display;
	}
}


function PermuterAffichage(id_element)
{
  if (document.getElementById(id_element).style.display=='none')
    document.getElementById(id_element).style.display='';
  else
    document.getElementById(id_element).style.display='none';
}




function MasquerTout(id)
{
  for (var i=0; i < 1000; ++i)
  {
    if (document.getElementById(id+i))
    {
      document.getElementById(id+i).style.display='none';
    }
  }
}





function ajax_leftside_searchword(search_word, dictionnary)
{
  //alert('URL_SITE = ' + URL_SITE);
	//var ts = parseInt(timestamp);
  //alert('SEARCH WORD = ' + search_word)
	var url = URL_SITE + 'ajax.php?act=search_word&dic='+dictionnary;
	var httpRequest = false;

	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType)
		{
			httpRequest.overrideMimeType('text/xml');
			// Voir la note ci-dessous à propos de cette ligne
		}
	}
	else if (window.ActiveXObject)
	{ // IE
		try
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}

	if (!httpRequest)
	{
		alert('Abandon :( Impossible de créer une instance XMLHTTP');
		return false;
	}

	httpRequest.onreadystatechange = function() { alertAjax_leftside_searchword(httpRequest, search_word); };
	httpRequest.open('GET', url + '&word=' + search_word, true);
	httpRequest.send(null);
	return true;
}

function alertAjax_leftside_searchword(httpRequest, search_word)
{
	//alert('RDY : ' + httpRequest.readyState + ' STATUS : ' +httpRequest.status);
	if (httpRequest.readyState == 4)
	{
		if (httpRequest.status == 200)
		{
			//alert(httpRequest.responseText);
			// Edit page content
			str = httpRequest.responseText;
			document.getElementById('trouve').innerHTML = '<div class="reponse">' + str + '</div>';
		}
		else
		{
			alert('Un problème est survenu avec la requête.');
		}
	}
}















