
var if_drop_down;
var if_button;
var iftimeoutEvent;
var iftheme_id;
var http_request;

function if_channel(e, s)
{
/*
	if(window.event) {
      var e = window.event;
   }
   else if(e.keyCode == 13) {
      e.returnValue=false; 
      e.preventDefault(); 
      e.stopPropagation(); 
   }
   if(e.keyCode != 13) {
      return(true);
   }
*/

   http_request = false;

   if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
   }
   else if (window.ActiveXObject) { // IE
      try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
      }
   }

   if (!http_request) {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false; 
   }
  
   http_request.onreadystatechange = if_channel_get;
   http_request.open('GET', '/intranett/interne_sider/?factory=db&menu=channel_execute', true);
   http_request.send(null);


   return(false);
}

function if_channel_get()
{
   var j=0,len=0,n=0;

   if (http_request.readyState == 4) {
      if (http_request.status == 200) {
         var xmldoc = http_request.responseXML;
			if(!xmldoc) {
				alert("No responce!");
				return;
			}
         var root_node = xmldoc.getElementsByTagName('div').item(0);
         var content_node = document.getElementById('main');
			if(content_node) {
				if(root_node) {
				alert("Replace inner: " + root_node.nodeName);
				// content_node.innerHTML = root_node.childNodes[0].nodeValue;
				content_node.innerHTML = http_request.responseText;

				}
				else {
					alert("No root node");
				}
			}
			else {
				alert("Missing");
			}
      }
		else {
         alert('There was a problem with the request.');
      }
   }
}

function ifmenu_unfocus() 
{
	clearTimeout(iftimeoutEvent);
	if(if_drop_down) {
		if_drop_down.style.display = 'none';
	}
	if(if_button) {
		if_button.style.backgroundColor = '';
	}
	if(iftheme_id) {
		ifmenu_select_menu(iftheme_id);
	}
}

function ifmenu_focus(button) 
{
	clearTimeout(iftimeoutEvent);
	if(if_drop_down) {
		if_drop_down.style.display = 'none';
	}
	if(if_button) {
		if_button.style.backgroundColor = '';
	}
	// button.style.backgroundColor = '#b9d9dd';
	button.style.cursor = 'pointer';
	if_button = button;
	if_container = button;
	for(i=0; i<if_container.childNodes.length; i++) {
		if(if_container.childNodes[i].id == 'ifmenu') {
			if_container.childNodes[i].style.display = 'block';
			if_drop_down = if_container.childNodes[i];
		}
	}
}

function ifmenu_unfocus_item(menu) 
{
	menu.style.backgroundColor = '';
	menu.style.color = '';
}

function ifmenu_focus_item(menu) 
{
	clearTimeout(iftimeoutEvent);
	// menu.style.backgroundColor = '#CCCCCC';
	menu.style.cursor = 'pointer';
	menu.style.color = '#000000';
}

function if_menu_open(from,id)
{
	obj = document.getElementById(id);
	if(!obj) {
		return;
	}
	none = "none";
// alert("style '" + obj.style.display + "'");
	if(obj.style.display == '' || obj.style.display == 'none') {
		none = "inline";
		from.style.backgroundImage = "url('/graphics/arrow-down.gif')";
	}
	else {
		from.style.backgroundImage = "url('/graphics/arrow-right.gif')";
	}
	obj.style.display = none;
}

function ifmenu_chapter_open(article)
{
	var i=0;
	object = document.getElementById(article);
	if(object) {
		if(object.childNodes[0].style) {
			// IE
			object.childNodes[0].style.color = '#000000';
		}
		else {
			// FF
			object.childNodes[1].style.color = '#000000';
		}
		ul = object.parentNode;
		if(ul) {
			div = ul.parentNode;
			if(div && (div.style.display == 'none' || div.style.display == '')) {
				div.style.display = 'inline';
			}
		}
	}
}

function ifmenu_channel(menu_item_id, channel_id, extra)
{
	var extra_s = '';
	if(extra.length) {
		extra_s = "&" + extra;
	}
	window.location = "?factory=db&menu=channel&channel=" + channel_id +"&menu_item=" + menu_item_id + extra_s;
}

function ifmenu_select_menu(theme_id)
{
	obj = document.getElementById('theme-' + theme_id);
	if(obj) {
		ul = obj.parentNode;
		if(ul) {
			ul.style.backgroundColor = '#333333';
			iftheme_id = theme_id;
		}
	}
}

function ifmenu_select_tab(channel_id)
{
	obj = document.getElementById("channel-" + channel_id);
	if(obj) {
		obj.style.borderLeftColor = '#BBBBBB';
		obj.style.borderRightColor = '#FFFFFF';
		obj.style.borderTopColor = '#BBBBBB';
		obj.style.borderBottomColor = '#FFFFFF';
		obj.style.backgroundColor = '#FFFFFF';
	}
	obj = document.getElementById("channel-menu");
	if(obj) {
		obj.style.display = 'block';
	}
}

function ifmenu_tab_on()
{
	obj = document.getElementById("channel-menu");
	if(obj) {
		obj.style.display = 'block';
	}
}

