function create_XMLHttp() 
{
	var xhr = null;
	if (window.XMLHttpRequest)
		xhr = new XMLHttpRequest ();
	else if (window.ActiveXObject)
		try { xhr = new ActiveXObject ("Msxml2.XMLHTTP"); }
		catch (e)
		{
			try { xhr = new ActiveXObject ("Microsoft.XMLHTTP"); }
			catch (e) {}
		}
	return xhr;
}

function matrice_ajax()
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_matrice').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_matrice.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = 'none=0';
  var retazec = document.getElementById('matrice_active').value;
  var pole = retazec.split('|');
  for (i=0; i<pole.length; i++) 
  {
    if(document.getElementById('matrices[' + pole[i] + ']').checked)
      param += '&matrices[]=' + pole[i];
  }
  //alert(param);
  xHttp.send(param);     
}

function org_ajax(type)
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_org').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_organisation.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = '';
  if(type == 1)
  {
    param += 'save_org=1';
    param += '&name=' + document.getElementById('name').value;
    param += '&street=' + document.getElementById('street').value;
    param += '&pobox=' + document.getElementById('pobox').value;
    param += '&city=' + document.getElementById('city').value;
    param += '&zip=' + document.getElementById('zip').value;
    param += '&country=' + document.getElementById('country').value;
    param += '&mail=' + document.getElementById('mail').value;
    param += '&web=' + document.getElementById('web').value;
  }
  else if(type == 2)
    param += 'no_save_org=1';
  else
    param += 'id=' + document.getElementById('organisation').value;
  //alert(param);
  xHttp.send(param);     
}

function exp_ajax(type)
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_exp').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_expert.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = '';
  if(type == 1)
  {
    param += 'save_exp=1';
    param += '&family_name=' + document.getElementById('family_name').value;
    param += '&first_name=' + document.getElementById('first_name').value;
    param += '&mr_ms=' + document.getElementById('mr_ms').value;
    param += '&title=' + document.getElementById('title').value;
    param += '&phone=' + document.getElementById('phone').value;
    param += '&fax=' + document.getElementById('fax').value;
    param += '&email=' + document.getElementById('email').value;
    param += '&current_position=' + document.getElementById('current_position').value;
    param += '&department=' + document.getElementById('department').value;
    param += '&organisation=' + document.getElementById('organisation').value;
  }
  else if(type == 2)
    param += 'no_save_exp=1';
  else
    param += 'id=' + document.getElementById('expert').value;
  //alert(param);
  xHttp.send(param);     
}

function org_pro_ajax(action,i,type_id)
{
  var xHttp;
  if(!i)
    i = document.getElementById('i').value;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_pro'+i).innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_organisation_project.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = '';
  if(action == 1)
  {
    param += 'save_org=1';
    param += '&i=' + i;
    param += '&name=' + document.getElementById('name' + i).value;
    param += '&street=' + document.getElementById('street' + i).value;
    param += '&pobox=' + document.getElementById('pobox' + i).value;
    param += '&city=' + document.getElementById('city' + i).value;
    param += '&zip=' + document.getElementById('zip' + i).value;
    param += '&country=' + document.getElementById('country' + i).value;
    param += '&phone=' + document.getElementById('phone' + i).value;
    param += '&fax=' + document.getElementById('fax' + i).value;
    param += '&mail=' + document.getElementById('mail' + i).value;
    param += '&web=' + document.getElementById('web' + i).value;
  }
  else if(action == 2)
  {
    param += 'no_save_org=1';
    param += '&i=' + i;
  }
  else
  {
    param += 'id=' + document.getElementById('organisations_id' + i).value;
    param += '&i=' + i;
  }  
  param += '&type_id=' + type_id;
  //alert(param);
  xHttp.send(param);     
}

function pro_ajax(action,i,type,type_id)
{
  var xHttp;
  if(!i)
    i = document.getElementById('i').value;
  //alert('ajax_pro'+i);
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_pro'+i).innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_project.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = '';
  if(action == 1)
  {
    param += 'save_pro=1';
    param += '&i=' + i;
    param += '&project_title=' + document.getElementById('project_title' + i).value;
    param += '&project_abbreviation=' + document.getElementById('project_abbreviation' + i).value;
    param += '&project_registration=' + document.getElementById('project_registration' + i).value;
    param += '&web=' + document.getElementById('web' + i).value;
    param += '&project_start_m=' + document.getElementById('project_start_m' + i).value
    param += '&project_start_r=' + document.getElementById('project_start_r' + i).value;
    param += '&project_completion_m=' + document.getElementById('project_completion_m' + i).value
    param += '&project_completion_r=' + document.getElementById('project_completion_r' + i).value;
  }
  else if(action == 2)
  {
    param += 'no_save_pro=1';
    param += '&i=' + i;
  }
  else
  {
    param += 'id=' + document.getElementById('projects_id' + i).value;
    param += '&i=' + i;
  }
  param += '&type=' + type;
  param += '&type_id=' + type_id;
  //alert(param);
  xHttp.send(param);     
}

function subclass_ajax(trieda,subtrieda,latky)
{
  if(document.getElementById('subclass[' + subtrieda + ']').checked)
  {
    document.getElementById('class[' + trieda + ']').checked = true;
    document.getElementById('ajax_subclass_' + subtrieda).style.display = 'block';
  }
  else
  {
    var pole = latky.split('|');
    for (j=0; j<pole.length; j++) 
    {
      if(pole[j].length)
        document.getElementById('substances[' + pole[j] + ']').checked = false;
    }
    //document.getElementById('substances_other[' + subtrieda + ']').value = '';
    document.getElementById('ajax_subclass_' + subtrieda).style.display = 'none';
  }
}

function class_ajax(trieda,subtrieda,latky)
{
  var pole = subtrieda.split('|');
  if(document.getElementById('class[' + trieda + ']').checked)
  {
    for (i=0; i<pole.length; i++) 
    {
      document.getElementById('ajax1_class_' + pole[i]).style.display = 'block';
      document.getElementById('ajax2_class_' + pole[i]).style.display = 'block';
      document.getElementById('ajax3_class_' + pole[i]).style.display = 'block';
      document.getElementById('ajax_class_other_' + trieda).style.display = 'block';
    }
  }
  else
  {
    var pole_trieda = latky.split('*');
    for (i=0; i<pole.length; i++) 
    {
      document.getElementById('subclass[' + pole[i] + ']').checked = false;
      document.getElementById('subclass_other[' + trieda + ']').value = '';
      document.getElementById('ajax1_class_' + pole[i]).style.display = 'none';
      document.getElementById('ajax2_class_' + pole[i]).style.display = 'none';
      document.getElementById('ajax3_class_' + pole[i]).style.display = 'none';
      subclass_ajax(trieda,pole[i],pole_trieda[i]);
    }
    document.getElementById('class_other[' + trieda + ']').value = '';
    class_other_ajax(trieda);
    document.getElementById('ajax_class_other_' + trieda).style.display = 'none';
    document.getElementById('ajax_subclass_other_' + trieda).style.display = 'none';
  }
}

function class_other_ajax(trieda)
{
  if(document.getElementById('class_other[' + trieda + ']').value.length && !isblank(document.getElementById('class_other[' + trieda + ']').value))
  {
    document.getElementById('class[' + trieda + ']').checked = true;
    document.getElementById('ajax_subclass_other_' + trieda).style.display = 'block';
  }
  else
  {
    document.getElementById('subclass_other[' + trieda + ']').value = '';
    document.getElementById('ajax_subclass_other_' + trieda).style.display = 'none';
  }
}

function project_add(from_to,coordinator,order)
{
  if(from_to)
  {
 		var check1 = '';
 		var check2 = '';
    if(coordinator)
  		check1 = ' checked="checked"';
    else
    	check2 = ' checked="checked"';
    document.getElementById('ajax_pro_year' + order).innerHTML = from_to;
  	document.getElementById('ajax_pro_coor' + order).innerHTML = '<input type="radio" name="projects_coordinator' + order + '" value="0"' + check1 + '/>';	
  	document.getElementById('ajax_pro_part' + order).innerHTML = '<input type="radio" name="projects_coordinator' + order + '" value="1"' + check2 + '/>';
    //alert('<input type="radio" name="projects_coordinator' + order + '" value="0"' + check1 + '/>');	
  }
}

// ********* Empodat ********** //
function show_compound(unit)
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_compound').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_compound.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = 'compound=' + document.getElementById('compound').value;
  param += '&unit=' + unit;
  //alert(param);
  xHttp.send(param); 
}

function show_unit()
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('unit').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_unit.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = 'matrix=' + document.getElementById('matrix').value;
  //alert(param);
  xHttp.send(param); 
}

function show_matrix(table)
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('data_matrix').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_matrix.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = 'matrix=' + document.getElementById('matrix').value;
  param += '&table=' + table;
  //alert(param);
  xHttp.send(param); 
}

function show_organism()
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_organism').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_organism.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = 'dbio_id=' + document.getElementById('dbio_id').value;
  //alert(param);
  xHttp.send(param); 
}

function show_concentration_data()
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_concentration_data').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_concentration.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = 'dcod_id=' + document.getElementById('dcod_id').value;
  //alert(param);
  xHttp.send(param); 
}

function show_identification(type)
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('ajax_identification').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_identification.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = 'type=' + type;
  //alert(param);
  xHttp.send(param); 
}

function search_cas()
{
  var xHttp;
  xHttp = create_XMLHttp();
  xHttp.onreadystatechange = function ChangeState()
  { 
    if (xHttp.readyState == 4 && xHttp.status == 200) 
      document.getElementById('id_search_cas').innerHTML = xHttp.responseText; 
  } 
  xHttp.open('POST','ajax_search.php',true);
  xHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
  var param = 'nis_cas=' + document.getElementById('nis_cas').value;
  //alert(param);
  xHttp.send(param); 
}
