/*** weekview ***/

/**
 * make all tabs inactive and hide children
 */
function clear_tabs(prefix) {
  var tabs = document.getElementsByName('tab_' + prefix);
  for (var i=0; i<tabs.length; i++) {
    tabs[i].className = '';
  }
}
function hide_content(prefix) {
  var divs = $T('div', 'content_' + prefix);
  for (var i=0; i<divs.length; i++) {
    if (divs[i].parentNode.id == 'content_' + prefix) {
      divs[i].style.display = 'none';
    };
  }
}
function show_active_set(prefix, tabno) {
  var el;
  el = $e('content_' + prefix + tabno);
	if (el) el.style.display = 'block';
  el = $e('tab_' + prefix + tabno);
  if (el) {
    el.className = 'active';
  }
}
function weekview_show_tab(parent_id, no) {
  clear_tabs(parent_id);
  hide_content(parent_id);
  show_active_set(parent_id, no, arguments[2]);
  
	switch(parent_id) {
	  case 'E':
	  $e('forDisplay').style.display = (no==1) ? '' : 'none';
		$e('forCopy').style.display = (no==1) ? 'none' : '';
		break;
		case 'S':
	}
}
function thuisepd_show_tab(parent_id, no) {
  clear_tabs(parent_id);
  hide_content(parent_id);
  show_active_set(parent_id, no, arguments[2]);
  
  createCookie('thuisepdtab',no);
}
function showrecipe_show_tab(parent_id, no) {
  clear_tabs(parent_id);
  hide_content(parent_id);
  show_active_set(parent_id, no, arguments[2]);

  divs = $T('DIV', 'content_' + 'B');
  for (i=0; i<divs.length; i++) {
    if (divs[i].parentNode.id == 'content_' + 'B') {
      divs[i].style.display = 'none';
    }
  }
  el = $e('content_' + 'B' + no);
  el.style.display = 'block';
}
function search_show_tab(parent_id, no) {
  clear_tabs(parent_id);
  hide_content(parent_id);
  show_active_set(parent_id, no, arguments[2]);

	divs = $T('DIV', 'content_' + 'B');
	for (i=0; i<divs.length; i++) {
		if (divs[i].parentNode.id == 'content_' + 'B') {
		  divs[i].style.display = 'none';
		}
	}
	el = $e('content_' + 'B' + no);
	el.style.display = 'block';
	
	// set focus to the input control
  switch (no) {
    case 1:
      $e('food_search').focus();
      break;
    case 2:
      $e('recipe_search').focus();
      break;
    case 3:
      $e('menu_search').focus();
      break;
  }
}
function onderzoek_show_tab(parent_id, no) {
  clear_tabs(parent_id);
  hide_content(parent_id);
  show_active_set(parent_id, no, arguments[2]);

  createCookie('onderzoektab',no);
}
function dayview_show_tab(parent_id, no) {
	if (!f) f = document.forms['mainform'];
	clear_tabs(parent_id);
	hide_content(parent_id);
  show_active_set(parent_id, no, arguments[2]);

  // Record state of B
  if (parent_id == 'B') B_active = no;
  if (parent_id == 'F') F_active = no;

	// alles/niets beweging
	if (parent_id == 'E') {
		el = $e('forDisplay');
		if (el) el.style.display = (no==1) ? '' : 'none';
		el = $e('forCopy');
		if (el) el.style.display = (no==1) ? 'none' : '';
	}
	
  // Checkbox alles/niets voeding
  if (parent_id == 'B') {
    // lekker hard gecodeerd tabblad, terwijl de template de bladen zacht doornummert
    // dat is !handig als je een tabblad wil tussenvoegen
    var disp;
    if (no == '4') {
      disp = '';
    } else {
      disp = 'none';
    }
    // Checkboxes
    parent_obj = $e('all_items');
    items = $T('INPUT', parent_obj);
    for(i=0; i<items.length; i++) {
      if (items[i].type == 'checkbox') items[i].style.display = disp;
    }
    // Alles/niets links
    for (i=0; i<=mealitems; i++) $e('allesniets_' + i).style.display = disp;
    items = $T('allesniets');
    for(i=0; i<items.length; i++) {
      items[i].style.display = disp;
    }
  }
  if ((parent_id == 'B') && (no == 2)) {
     if (A_active == 1) $e('searchrecipe').focus();
  }
  if ((parent_id == 'B') && (no == 1)) {
     if (A_active == 1) $e('search').focus();
  }
  if (parent_id == 'A') {
     createCookie('dagboek',parent_id  + '' +  '' + no,0);
  }
}
function addrecipe_show_tab(parent_id, id) {
  clear_tabs(parent_id);
  hide_content(parent_id);
  show_active_set(parent_id, id, arguments[2]);
}

