/*************************************************************
clientBody
*************************************************************/

/*************************************************************
GetElement(id, frame)
*************************************************************/
function GetElement(id, frame){
var doc = frame?FrameDocument(frame):window.document;
return doc.getElementById ? doc.getElementById(id) : doc.all[id];
}



/*************************************************************
GetElementByClassName(elem, className)
*************************************************************/
function GetElementByClassName(elem, className) {
if (elem.className == className)
  return elem;

// Search for a descendant element assigned the given class.
for (var i=0; i<elem.childNodes.length; i++) {
  var tmp = GetElementByClassName(elem.childNodes[i], className);
  if (tmp != null)
    return tmp;
}
return null;
}

/*************************************************************
GetAllElementsByClassName(elem, className)
*************************************************************/
function GetAllElementsByClassName(elem, className, result) {
result = result || new Array();

if (elem.className == className)
  result.push(elem);

// Search for a descendant element assigned the given class.
for (var i=0; i<elem.childNodes.length; i++) 
  result = GetAllElementsByClassName(elem.childNodes[i], className, result);
return result;
}

/*************************************************************
Show(obj)
*************************************************************/
function Show(obj){
SetShow(obj, true);
}

/*************************************************************
Hide(obj)
*************************************************************/
function Hide(obj){
SetShow(obj, false);
}

/*************************************************************
SetShow(obj)
*************************************************************/
function SetShow(obj, show){
obj.style.display = show?'block':'none';
}

/*************************************************************
Enable(obj)
*************************************************************/
function Enable(obj){SetEnable(obj, true);}

/*************************************************************
Disable(obj)
*************************************************************/
function Disable(obj){SetEnable(obj, false);}

/*************************************************************
SetEnable(obj)
*************************************************************/
function SetEnable(obj, enabled){
obj.disabled = !enabled;
if (obj.OnEnable)
  obj.OnEnable();
}



/*************************************************************
LoadPage
*************************************************************/
function LoadPage(url){
var frame = GetMain();
frame.documentFrame.location.href = url;
frame.focus();
}




/*************************************************************
GetWidth = ydre bredde dvs incl evt ramme
*************************************************************/
function GetWidth(obj){
if (obj.offsetWidth) return obj.offsetWidth;
if (obj.scrollWidth) return obj.scrollWidth;
if (obj.clientWidth) return obj.clientWidth;
if (obj.style.pixelWidth) return parseInt(obj.style.pixelWidth);
if (obj.style.width) return parseInt(obj.style.width);
return -1;
}

/*************************************************************
GetHeight = ydre højde dvs incl evt ramme
*************************************************************/
function GetHeight(obj){
if (obj.offsetHeight) return obj.offsetHeight;
if (obj.scrollHeight) return obj.scrollHeight;
if (obj.clientHeight) return obj.clientHeight;
if (obj.style.pixelHeight) return parseInt(obj.style.pixelHeight);
if (obj.style.height) return parseInt(obj.style.height);
return -1;
}

/***********************************************************
FrameDocument(frame) return the document-object of frame
************************************************************/
function FrameDocument(frame){
if (frame == window) return window.document; //Special case for window
if (frame.contentDocument) return frame.contentDocument; // For NS6
if (frame.contentWindow) return frame.contentWindow.document; // For IE5.5 and IE6
if (frame.document) return frame.document;  // For IE5
return true;
}

/***********************************************************
ClientWidth(frame) return the width inside the browser-window
************************************************************/
function ClientWidth(frame){
return ClientWidthAndHeight(frame)[0];
}

/***********************************************************
ClientHeight(frame) return the height inside the browser-window
************************************************************/
function ClientHeight(frame){
return ClientWidthAndHeight(frame)[1];
}

/***********************************************************
ClientWidthAndHeight(frame)
************************************************************/
function ClientWidthAndHeight(frame) {
var docBody = FrameDocument(frame).body;
return [docBody.clientWidth, docBody.clientWidth];

/*
var cWidth = 0;
var cHeight = 0;
var win = frame?window.frames[frame.name]:window;
var doc = win.document;

if (typeof( win.innerWidth ) == 'number' ) {
  //Non-IE
  cWidth = win.innerWidth;
  cHeight = win.innerHeight;
} 

else 

if (doc.documentElement &&
    ( doc.documentElement.clientWidth || doc.documentElement.clientHeight ) ) {
  //IE 6+ in 'standards compliant mode'
  cWidth = doc.documentElement.clientWidth;
  cHeight = doc.documentElement.clientHeight;
} 

else 

if (doc.body && ( doc.body.clientWidth || doc.body.clientHeight ) ) {
  //IE 4 compatible
  cWidth = doc.body.clientWidth;
  cHeight = doc.body.clientHeight;
}

return [cWidth, cHeight];
*/
}

/***********************************************************
ScrollLeftAndTop(frame)
************************************************************/
function ScrollLeftAndTop(frame) {
var docBody = FrameDocument(frame).body;
return [docBody.scrollLeft, docBody.scrollTop];
}

/*****************************************************************
ReplaceStr(s, orgStr, newStr)
*******************************************************************/
function ReplaceStr(s, orgStr, newStr){
return s.split(orgStr).join(newStr);
}

/*********************************************************
TrimLead(str)
*********************************************************/
function TrimLead(str){//Fjerner forreste blanke fra str
for (var i=0; i<str.length; i++)
  if (str.charAt(i) != ' ')
    return str.substring(i, str.length);
return '';
}

/*********************************************************
TrimTrail(str)
*********************************************************/
function TrimTrail(str){//Fjerner bagerste blanke fra str
for (var i=str.length-1; i>=0; i--)
  if (str.charAt(i) != ' ')
    return str.substring(0, i+1);
return '';
}

/*********************************************************
Trim(str)
*********************************************************/
function Trim(str){//Fjerner forreste og bagerste blanke fra str
return TrimTrail(TrimLead(str));
}

/*************************************************************
AddClassName og RemoveClassName hhv tilføjer og fjerner sClassName fra obj's className
*************************************************************/
function AddClassName(obj, sClassName) {
var classsNameArray = obj.className.split(' ');
for (var i = 0; i < classsNameArray.length; i++) {
	if (classsNameArray[i] == sClassName)
		return;
}
classsNameArray[classsNameArray.length] = sClassName;
obj.className = classsNameArray.join(" ");
			
}

function RemoveClassName(obj, sClassName) {
var oldClasssNameArray = obj.className.split(' ');
var newClassNameArray = [];
var newLength = 0;
for (var i = 0; i < oldClasssNameArray.length; i++) {
	if (oldClasssNameArray[i] != sClassName)
		newClassNameArray[newLength++] = oldClasssNameArray[i];
}
obj.className = newClassNameArray.join(" ");
}

/*****************************************************************
OpenWindow(id, url, width, height, features)
*******************************************************************/
function OpenWindow(id, url, width, height, features){
features = features || 'scrollbars, toolbar, location, directories, status, menubar, resizable';
if (width) features += ', width=' + width;
if (height) features += ', height=' + height;
var win = window.open(url, id, features);
if (win) 
  win.focus();
return false;
}





/*****************************************************************
IsIE()
*******************************************************************/
function IsIE(){
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');
var is_opera = (agt.indexOf("opera") != -1);
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var is_konq = (agt.indexOf('konqueror') != -1);
var is_khtml  = (is_safari || is_konq);
return ((iePos!=-1) && (!is_opera) && (!is_khtml));
}


/*****************************************************************
OnMouseEnterRow(row)
*******************************************************************/
function OnMouseEnterRow(row){
for (var cell=row.firstChild; cell; cell=cell.nextSibling){
  cell.saveColor = cell.style.color;
  cell.saveTextDecoration = cell.style.textDecoration;
  cell.saveBackgroundColor = cell.style.backgroundColor;

  cell.style.color = 'red';
  cell.style.textDecoration = 'underline';
  cell.style.cursor = 'hand';
  cell.style.backgroundColor = 'rgb(224,234,244)';

}

}

/*****************************************************************
OnMouseLeaveRow(row)
*******************************************************************/
function OnMouseLeaveRow(row){
for (var cell=row.firstChild; cell; cell=cell.nextSibling){
  cell.style.color = cell.saveColor;
  cell.style.textDecoration = cell.saveTextDecoration;
  cell.style.cursor = 'default';
  cell.style.backgroundColor = cell.saveBackgroundColor;
}
}


/***********************************************************
FrameDocument(frame) returns the document-object of frame. Works both for window and iframe-objects
************************************************************/
function FrameDocument(frame){
//frame = GetFrame(frame);
if (frame == window) return window.document; //Special case for window
if (frame.contentDocument) return frame.contentDocument; // For NS6
if (frame.contentWindow) return frame.contentWindow.document; // For IE5.5 and IE6
if (frame.document) return frame.document;  // For IE5
return true;
}


/***********************************************************
IFrame_OnLoad(name)
************************************************************/
function IFrame_OnLoad(name){
//Adjust alle <a> to link to parent-frame
var aList = frames[name].document.getElementsByTagName("a");
for (var i=0; i<aList.length; i++)
  if ((aList[i].target == "") || (aList[i].target.toUpperCase() != '_BLANK'))
    aList[i].target = '_parent';

//Adjusting height
GetElement(name).height = frames[name].document.body.scrollHeight;
}



/***********************************************************
CheckLink_OnSelect
************************************************************/
function CheckLink_OnSelect(id){
var elem = GetElement(id);
var selected = parseInt(elem.getAttribute('selected'));
selected = !selected;
elem.setAttribute('selected', selected ? '1' : '0');
elem.innerHTML = selected? elem.getAttribute('textWhenOn') : elem.getAttribute('textWhenOff');
return true;
}

/***********************************************************
Select_GetSelectedOption
************************************************************/
function Select_GetSelectedOption(selId, frame){
var sel = GetElement(selId, frame);
if (sel.selectedIndex >= 0)
  return sel.options[sel.selectedIndex]
else
  return null;
}


/***********************************************************
Select_SetSelected
************************************************************/
function Select_SetSelected(sel, value){
var result = null;
sel = typeof sel == 'object'?sel:GetElement(sel);
if (sel)
  for (var i=0; i<sel.options.length; i++)
    if (sel.options[i].value == value){
      sel.selectedIndex = i;
      result = sel.options[i];
  }

if ((value != -1) && result && sel.getAttribute('removeInitOptionOnSelect'))
  Select_RemoveInitOption(sel);
return result;
}

/***********************************************************
Select_RemoveInitOption
************************************************************/
function Select_RemoveInitOption(sel){
if (sel.options[0].value == -1) 
  sel.options[0] = null;
}


/***********************************************************
Select_AddOption
************************************************************/
function Select_AddOption(selId, value, text, selected){
var sel = GetElement(selId);
var result = window.document.createElement('option');
result.value = value;
result.text = text;
if (selected)
  result.selected = true;

sel.options[sel.options.length] = result;
if (selected)
  sel.selectedIndex = sel.options.length-1;
}

/***********************************************************
Select_OnFocus
************************************************************/
function Select_OnFocus(sel){
//Fixing bug in IE that prevent <select disable> to work!
sel.setAttribute('saveIndex', sel.selectedIndex); 
}



/***********************************************************
Select_OnChangeOk
************************************************************/
function Select_OnChangeOk(sel){
sel.blur(); 
if (sel.options[sel.selectedIndex].getAttribute('disabled')) { 
  sel.selectedIndex = sel.getAttribute('saveIndex') || 0; 
  return false;
}
return true;
}

/***********************************************************
Select_PostOnChange
************************************************************/
function Select_PostOnChange(sel, resetOnSelect, removeInitOptionOnSelect){
sel.setAttribute('saveIndex', sel.selectedIndex); 
if (resetOnSelect)
  sel.selectedIndex = 0;
if (removeInitOptionOnSelect)
  Select_RemoveInitOption(sel);

for (var i=0; i<sel.options.length; i++)
  sel.options[i].style.color = sel.options[i].disabled ? "graytext" : "menutext"; 
}




/***********************************************************
Option_SetDisabled
************************************************************/
function Option_SetDisabled(option, disabled){
option.disabled = disabled?true:false;
option.style.color = disabled ? "graytext" : "menutext"; 
}



/*
document.onmousemove = mouseMove;

function mouseMove(ev){
	ev           = ev || window.event;
	var mousePos = mouseCoords(ev);
}

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}
*/