function disableEnterKey(e)
{
	var key;

	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox

	if(key == 13)
		return false;
	else
		return true;
}

function getBrowserHeight()
{
	 var viewportwidth;
	 var viewportheight;
	 var mode;

	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 if (typeof window.innerWidth != 'undefined')
	 {
			mode = "FF";
		  	viewportwidth = window.innerWidth
		  	viewportheight = window.innerHeight
	 }
	 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
			mode = "IE6";
		   viewportwidth = document.documentElement.clientWidth
		   viewportheight = document.documentElement.clientHeight
	 }
	 // older versions of IE
	 else
	 {
			mode = "IE";
			viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
			viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	 }
	 return viewportheight;
	//alert(mode+":\n"+"width:"+viewportwidth+"\n"+"height:"+viewportheight);
}


function getBrowserWidth()
{
	 var viewportwidth;
	 var viewportheight;
	 var mode;

	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 if (typeof window.innerWidth != 'undefined')
	 {
			mode = "FF";
		  	viewportwidth = window.innerWidth
		  	viewportheight = window.innerHeight
	 }
	 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
			mode = "IE6";
		   viewportwidth = document.documentElement.clientWidth
		   viewportheight = document.documentElement.clientHeight
	 }
	 // older versions of IE
	 else
	 {
			mode = "IE";
			viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
			viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	 }
	 return viewportwidth;
	//alert(mode+":\n"+"width:"+viewportwidth+"\n"+"height:"+viewportheight);
}

// 090116: Get element id offset
function getOffsetTop(id)
{
	var obj = document.getElementById(id);
	var dx = 0;
	var dy = 0;

	while(obj.offsetParent != null)
	{
		obj = obj.offsetParent;
		dx = dx + obj.offsetLeft;
		dy = dy + obj.offsetTop;
	}
	dx = dx + obj.offsetLeft;
	dy = dy + obj.offsetTop;
	return dy;
}

function getOffsetLeft(id)
{
	var obj = document.getElementById(id);
	var dx = 0;
	var dy = 0;

	while(obj.offsetParent != null)
	{
		obj = obj.offsetParent;
		dx = dx + obj.offsetLeft;
		dy = dy + obj.offsetTop;
	}
	dx = dx + obj.offsetLeft;
	dy = dy + obj.offsetTop;

	return dx;
}

// 070805: set top frame
function setTopFrame()
{
	var mode = (top==self);
	if(!mode)
		top.location.href = self.location.href;
}

// global
var gNodeType = "";
var gNodeId = "";

// init
function initTree()
{
	// init contextmenu
	document.oncontextmenu=function()
	{
		return false;
	}
}

function debug()
{
	alert("Hello");
}


// context menu
function popMenuImage(event, nodeId, nodeType, userId)
{
	gNodeId = nodeId;
	gNodeType = nodeType;

	if(nodeId == 0) // root
	{
		// check create directory
		if( gUserRights.indexOf(';104;') == -1 )
			document.getElementById('idRootRights104').style.display='none';
		else
			document.getElementById('idRootRights104').style.display='block';

		contextMenu_Show(event,idMenuRoot);
	}
	else if(nodeType == 0) // branch
	{
		// check create directory
		if( gUserRights.indexOf(';104;') == -1 )
			document.getElementById('idBranchRights104').style.display='none';
		else
			document.getElementById('idBranchRights104').style.display='block';

		// check edit directory
		if( gUserRights.indexOf(';105;') == -1 )
			document.getElementById('idBranchRights105').style.display='none';
		else
			document.getElementById('idBranchRights105').style.display='block';

		// check create content
		if( gUserRights.indexOf(';101;') == -1 )
			document.getElementById('idBranchRights101').style.display='none';
		else
			document.getElementById('idBranchRights101').style.display='block';

		contextMenu_Show(event,idMenuBranch);
	}
	else // leaf
	{
//		alert(gUserId +" "+ userId);
		// check edit content
		if( gUserId == userId ) // own
		{
			if( gUserRights.indexOf(';102;') == -1 )
				document.getElementById('idLeafRights102').style.display='none';
			else
				document.getElementById('idLeafRights102').style.display='block';
		}
		else // everyone
		{
			if( gUserRights.indexOf(';103;') == -1 )
				document.getElementById('idLeafRights102').style.display='none';
			else
				document.getElementById('idLeafRights102').style.display='block';
		}

		contextMenu_Show(event,idMenuLeaf);
	}
}

function contextMenu_Show(event, idMenuName)
{
	contextMenu_Hide();
	//if(event.button==2)
	{
	    idMenuName.style.top = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	    idMenuName.style.left = event.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
	    idMenuName.style.visibility ='visible';
	}
}

var gContextMenuItem;
function contextMenu_Hide()
{
	if( gContextMenuItem!= null )
	    gContextMenuItem.style.background='white';

    idMenuRoot.style.visibility='hidden';
    idMenuBranch.style.visibility='hidden';
    idMenuLeaf.style.visibility='hidden';
}

function contextMenu_Selected(item)
{
	gContextMenuItem = item;
    item.style.background='lightblue';
}

function contextMenu_Deselected(item)
{
    item.style.background='white';
	gContextMenuItem = null;
}

// hightlight div
var gHighlightIconColor = "";
function hightlightIcon_Enter(item)
{
    gHighlightIconColor = item.style.background;
    item.style.background='lightblue';
}

function hightlightIcon_Exit(item)
{
    item.style.background=gHighlightIconColor;
}


// hyperlink to function
function openLink(url, target)
{
	contextMenu_Hide()

	if(target == undefined)
	{
		window.location = "/nhgpkd/LIB/"+url+"?p_id="+gNodeId
	}
	else
	{
		window.open("/nhgpkd/LIB/"+url+"?p_id="+gNodeId, target)
	}
}

// copylink to function
function copyLink(url)
{
	contextMenu_Hide()

	var baseUrl = document.location.href;
	baseUrl = baseUrl.substring(0, baseUrl.indexOf('/',7));

	if(window.clipboardData) // the IE-way
	{
		window.clipboardData.setData("Text", baseUrl+"/nhgpkd/LIB/"+url+"?p_id="+gNodeId);
	}
	else
	{
		alert("Hightlight & Copy Link\n\n"+baseUrl+"/nhgpkd/LIB/"+url+"?p_id="+gNodeId);
	}
}

// form function
function getFormSubmit(obj)
{
	var x = document.getElementById(obj);
	var query = x.action + "?";
	for (var i=0;i<x.length;i++)
	{
		if(x.elements[i].type == "checkbox")
		{
			if( x.elements[i].checked )
			{
				//alert(x.elements[i].type + ":" + x.elements[i].value + ":" + x.elements[i].type + ":" + x.elements[i].checked);
				query += x.elements[i].name+"="+encodeURIComponent(x.elements[i].value)+"&"
			}
		}
		else if(x.elements[i].type == "radio")
		{
			if( x.elements[i].checked )
			{
				//alert(x.elements[i].type + ":" + x.elements[i].value + ":" + x.elements[i].type + ":" + x.elements[i].checked);
				query += x.elements[i].name+"="+encodeURIComponent(x.elements[i].value)+"&"
			}
		}
		else
		{
			query += x.elements[i].name+"="+encodeURIComponent(x.elements[i].value)+"&"
		}
	}
	query = query.slice(0, query.length-1);
	//alert(query);
	return query;
}

// progress bar / in progress div
function showBusyBar(msg)
{
  var bodyTag = document.body;
  var newDiv;

  if( msg=='undefine' || msg==null)
    msg = "Request is in Progress<br>Please Wait ...";

  refreshFrameSize();

  newDiv = document.getElementById("id_busy");

  if(newDiv == null)
  {
    newDiv = document.createElement('div');
    newDiv.style.visibility ='hidden';

    newDiv.setAttribute('id', 'id_busy');
    newDiv.setAttribute('style', 'z-index:99; text-align: center;');
    newDiv.style.background='white';
    newDiv.style.position ='absolute';
    newDiv.style.top ='0px';
    newDiv.style.left ='0px';
    newDiv.style.width = viewportwidth + "px";
    newDiv.style.height = viewportheight + "px";
    newDiv.innerHTML = "<div id='id_progress' class='clsDivBusyMsg'>" + msg + "</div>";
    bodyTag.appendChild(newDiv);

	eval("createBar(300,15,'white',1,'black','blue',85,7,3,'', 'id_progress');")
  }
  newDiv.style.visibility ='visible';
  newDiv.style.top =document.body.scrollTop +"px";
}

var viewportwidth;
var viewportheight;

function refreshFrameSize()
{
	 var mode;

	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 if (typeof window.innerWidth != 'undefined')
	 {
			mode = "FF";
		  	viewportwidth = window.innerWidth
		  	viewportheight = window.innerHeight
	 }
	 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
			mode = "IE6";
		   viewportwidth = document.documentElement.clientWidth
		   viewportheight = document.documentElement.clientHeight
	 }
	 // older versions of IE
	 else
	 {
			mode = "IE";
			viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
			viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	 }
    //alert(mode+":\n"+"width:"+viewportwidth+"\n"+"height:"+viewportheight);
}

// To handle mouse over table row
var bkColor = "";
function eventIn(obj)
{
    bkColor = obj.style.background;
    obj.style.background='lightblue';
}

function eventOut(obj)
{
    obj.style.background=bkColor;
}

function eventClick(obj, url, target)
{
    obj.style.background=bkColor;
	if( target == null )
		window.open(url,'_self');
	else
		window.open(url,target);
}

function eventClickAjax(obj, url, target)
{
	//alert(url);
    obj.style.background=bkColor;
	ajaxOpen(url, target);
}
