// Main script file for Delos 7G
// Contain XCheck.js, XForms.js, XRollover.js, XShowHide.js

function getObjectById(ID) {
	if (document.getElementById)
		return document.getElementById(ID);
	else if (document.all)
		return document.all(ID);
}

function getElementByID(ID) {
	return getObjectById(ID);
}

function getObject(obj) {
	if (typeof obj == 'string')
		return getObjectById(obj);
	else
		return obj;
}

function getParentObjectById(ID) {
	if (!parent)
		return null;
	if (parent.getObjectById)
		return parent.getObjectById(ID);
	else if (parent.document.getElementById)
		return parent.document.getElementById(ID);
	else if (parent.document.all)
		return parent.document.all(ID);
	else
		return null;
}

function getFirstObjectById(IDs) {
	var obj;
	for (var i = 0; i < IDs.length; i++)
	{
		obj = getObjectById(IDs[i]);
		if (obj)
			return obj;		
	}
}

function getNamedAttribute(ID, name) {
	var obj;
	var att = null;
	obj = getObject(ID);
	if (obj.attributes)
	{
		if (obj.attributes.getNamedItem)
			att = obj.attributes.getNamedItem(name);
	} else {
		att = eval(obj + "." + name);
	}
	return att;
}

function addEvent(id, type, fn) {
	var obj;
	if (obj = getObject(id))
	{
		if (obj.attachEvent)
		{
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn](window.event); };
			obj.attachEvent('on'+type, obj[type+fn]);
		} else
			obj.addEventListener(type, fn, false);
	}
}

function removeEvent(id, type, fn) {
	var obj;
	obj = getObject(id);
	if (obj)
	{
		if (obj.detachEvent)
		{
			obj.detachEvent('on'+type, obj[type+fn]);
			obj[type+fn] = null;
		}
    else
			obj.removeEventListener(type, fn, false);
	}
}

function installScript(wnd, id) {
	var script;
	if (!wnd || !wnd.document || !wnd.document.getElementById)
		return;
	script = wnd.document.getElementById(id);
	if (!script)
		return;
	if (window.execScript)
	{
		window.execScript(script.innerHTML);
		return;
	}
	var global = this; // global scope reference
	if (global.eval)
	{
		global.eval(script.innerHTML);
	} else {
		eval(script.innerHTML);
	}
}

function copyElements(id, src) {
	if (!src)
		return;
	if (id === '')
		return;
	var dest = getObjectById(id);
	if (!dest)
		return;
	Show(dest);
	SetContent(dest, src.innerHTML);
}

function getType(obj) {
	try {
		switch (typeof obj) {
			case "object":
				if (obj === null)
					return "null";
				else if (obj.constructor == Date)
					return "date";
				else if (obj.constructor == Array)
					return "array";
				else if (obj.constructor == String)
					return "string";
				else if (obj.constructor == Number)
					return "number";
				else if (obj.constructor == Boolean)
					return "boolean";
				else if (obj == undefined)
					return "undefined";
				else
					return "object";
			case "function": return "function";
			case "number": return "number";
			case "string": return "string";
			case "boolean": return "boolean";
			case "undefined": return "undefined";
			default: return "unknown";
		}
	} catch (err) {
		return "unknown";
	}
}

function ObjectToJSON(obj) {
	switch(getType(obj)){
		case 'string':
			return '"' + obj.replace(/(["\\])/g, '\\$1') + '"';
		case 'array':
      var string = [];
      for (var i = 0; i < obj.length; i++)
        string.push(ObjectToJSON(obj[i]));
			return '[' + string.join(',') + ']';
		case 'object':
			var string = [];
			for (var property in obj) string.push(ObjectToJSON(property) + ':' + ObjectToJSON(obj[property]));
			return '{' + string.join(',') + '}';
		default:
			return 'null';
	}
	return String(obj);
}

function ShowHide(Items) {
	var Alpha = -1;
	var arg = arguments;
	var clientHeight;
	var clientWidth;
	var obj;
	var Height = -1;
	var i;
	var ImageID;
	var Images;
	var img;
	var ImagePlus;
	var ImageMinus;
	var Index;
	var List;
	var MaxWidth = 0;
	var MaxHeight = 0;
	var ShowAll = null;
	var Show;
	var Visibility;
	var Width = -1;

	for (i=1; i<arg.length; i++) {
		if (arg[i] == 'IMG') Images = arg[++i];
		if (arg[i] == '+') ImagePlus = arg[++i];
		if (arg[i] == '-') ImageMinus = arg[++i];
		if (arg[i] == 'WIDTH') Width = arg[++i];
		if (arg[i] == 'HEIGHT') Height = arg[++i];
		if (arg[i] == 'MAXWIDTH') MaxWidth = 1;
		if (arg[i] == 'MAXHEIGHT') MaxHeight = 1;
		if (arg[i] == 'ALPHA') Alpha = arg[++i];
		if (arg[i] == 'SHOW') ShowAll = arg[++i];
	}

	if (typeof Items == 'string')
		List = new Array(Items);
	else
		List = Items;
	if (typeof Images == 'string')
		Images = new Array(Images);

	clientHeight = document.body.clientHeight;
	clientWidth = document.body.clientWidth;

	for (Index = 0; Index < List.length; Index++) {
		if (obj = getObject(List[Index]))
		{
			if (ShowAll != null)
				Show = ShowAll
			else
				Show = (obj.style.display == 'none') ? '1' : '0';
      var styles = { 'visibility': 'hidden', 'display': 'none' };
			if (Show == '1')
			{
				styles['visibility'] = 'visible';
				styles['display'] = '';
			}
			if (Height != -1) styles['height'] = Height+'px';
			if (Width != -1) styles['width'] = Width+'px';
			if (MaxHeight == 1) styles['height'] = (clientHeight - obj.offsetTop - 15)+'px';
			if (MaxWidth == 1) styles['width'] = (clientWidth - obj.offsetLeft - 15)+'px';
			if (Alpha != -1) styles['filter'] = 'alpha(opacity='+Alpha+')';
			SetObjectStyle(obj, styles)
		}
		if (Images == null)
			continue;
		if (Images.length == 1)
			ImageID = Images[0];
		else
			ImageID = Images[Index];
		if (img = getObject(ImageID))
		{
			if (Show == '1')
				img.src = ImageMinus;
			else
				img.src = ImagePlus;
		}
	}
}

function Show(ID) {
  SetObjectStyle(ID, {'visibility': 'visible', 'display': ''});
}

function Hide(ID) {
  SetObjectStyle(ID, {'visibility': 'hidden', 'display': 'none'});
}

function isVisible(ID) {
	var obj;
	var result;
	result = false;
	obj = getObject(ID);
	if (obj && obj.style)
		result = obj.style.display == 'none' ? false : true;
	return result;
}

function isDisabled(ID) {
	var obj;
	var result;
	result = false;
	if (obj = getObject(ID))
		result = obj.disabled;
	return result;
}

// --- Rollover functions ---

function SwapImages(btn, Prefix, Suffix, Folder) {
	var Path;
	var row;
	var cell;
	var obj;
	if (btn == null) return;
	if (Prefix == 'TOOL')
	{
		Path = 'toolbarbutton/';
		if (Folder != null && Folder != '')
			Path = Path + Folder + '/';
		Path = XMLC_SkinPath + Path + 'toolbutton_';
	}
	else if (Prefix == 'DROPDOWN')
	{
		Path = 'toolbarbutton/';
		if (Folder != null && Folder != '')
			Path = Path + Folder + '/';
		Path = XMLC_SkinPath + Path + 'toolbutton_down_';
	}
	else
		Path = XMLC_SkinPath + 'button/button_';
	if (row = btn.rows[0])
	{
		if (cell = row.cells[0])
			if (obj = cell.childNodes[0])
				obj.setAttribute('src', Path + 'left' + Suffix + '.gif', 0);
		if (cell = row.cells[1])
			cell.style.backgroundImage = 'url('+Path+'main'+Suffix+'.gif)';
		if (cell = row.cells[2])
			if (obj = cell.childNodes[0])
				obj.setAttribute('src', Path + 'right' + Suffix + '.gif', 0);
	}
}

function BtnOver(btn, Prefix, Folder, Gradient, ID) {
	if (btn == null) return;
	if (btn.getAttribute('Pushed') != '1')
		SwapImages(btn, Prefix, '_over', Folder);
	if (ID != null)
	{
		Show(ID + '.CaptionHighlight');
		Hide(ID + '.Caption');
	}
}

function BtnOut(btn, Prefix, Folder, Gradient, ID) {
	if (btn == null) return;
	if (btn.getAttribute('Pushed') == '1')
	{
		return; // ON 20060614
		BtnPushed(btn, Prefix, Folder, Gradient);
		if (ID != null)
		{
			Show(ID + '.CaptionHighlight');
			Hide(ID + '.Caption');
		}
	}
	else
	{
		SwapImages(btn, Prefix, '', Folder);
		if (ID != null)
		{
			Hide(ID + '.CaptionHighlight');
			Show(ID + '.Caption');
		}
	}
}

function BtnDown(btn, Prefix, Folder, ID) {
	if (btn == null) return;
	if (btn.getAttribute('Pushed') != '1')
		SwapImages(btn, Prefix, '_down', Folder);
	if (ID != null)
	{
		Show(ID + '.CaptionHighlight');
		Hide(ID + '.Caption');
	}
}

function BtnPushed(btn, Prefix, Folder, Gradient, ID) {
	if (btn == null) return;
	btn.setAttribute('Pushed', '1');
	Suffix = '_pushed';
	if (Folder == 'BIG' && Gradient != null && Gradient == '1')
		Suffix = '_pushed_gradient';
	SwapImages(btn, Prefix, Suffix, Folder);
	if (ID != null)
	{
		Show(ID + '.CaptionHighlight');
		Hide(ID + '.Caption');
	}
}

function BtnUnpushed(btn, Prefix, Folder, ID) {
	if (btn == null) return;
	btn.setAttribute('Pushed', '');
	SwapImages(btn, Prefix, '', Folder);
	if (ID != null)
	{
		Hide(ID + '.CaptionHighlight');
		Show(ID + '.Caption');
	}
}

function BtnToggleClick(btn, Prefix, Folder, Gradient, ID) {
	if (btn == null) return;
	if (btn.getAttribute('Pushed') == '1') {
		BtnUnpushed(btn, Prefix, Folder, ID);
	}
	else {
		BtnPushed(btn, Prefix, Folder, Gradient, ID);
	}
}

function BtnDropdown(e, ID, Size, Width, Height, DisplayCaptionHighlight, Fill) {
	var obj;
	var X, Y;
	e = GetEventObj(e);
	obj = getObjectById(ID);
	if (obj === null)
		return false;
	if (isVisible(ID+'Menu'))
	{
		HideFilledFrame();
		return;
	}
	if (DisplayCaptionHighlight == 'true')
		BtnPushed(obj, 'DROPDOWN', Size, ID);
	else
		BtnPushed(obj, 'DROPDOWN', Size);
	if (Fill != '0')
		FillFrame(e, ID+'Menu', ID+'Content', Width, Height, true, ID);
	X = GetObjectPosX(ID);
	//Y = GetObjectPosY(ID)+GetObjectHeight(ID)+1;
	//MoveObject(ID+'Menu', X, Y);
	MoveObject(ID+'Menu', X, -1);
}

function BtnDropdownURL(e, ID, URL, Force) {
	var obj;
	var wasVisible;
	obj = getObjectById(ID+'Menu');
	wasVisible = isVisible(obj);
	HideFilledFrame();
	if (wasVisible)
		return;
	BtnDropdown(e, ID, '', -1, -1, true, '0');
	if (wasVisible)
		return;
	OpenedFrameID = ID+'Menu';
	PushedButton = ID;
	Show(obj);
	LoadFrameURLObj(window, ID+'Menu', URL, Force);
	var fn = function() { HideFilledFrame(); removeEvent(document, 'click', fn); }
	addEvent(document, 'click', fn);
	CancelEvent(e);
	return true;
}

function ImgOver(obj, url) { if (obj.tagName == 'IMG') obj.src = url+'_over.gif'; }
function ImgOut(obj, url)	{ if (obj.tagName == 'IMG') obj.src = url+'.gif'; }
function ImgDown(obj, url) { if (obj.tagName == 'IMG') obj.src = url+'_down.gif'; }

function EnableButton(ID) {
	Show(ID);
	Hide(ID + 'Disabled');
}

function DisableButton(ID) {
	var obj;
	if (obj = getObjectById(ID + 'Disabled'))
	{
		Hide(ID);
		Show(ID + 'Disabled');
	}
}

function ChangeClass(ID, Class) {
	setClass(ID, Class);
}

function addClass(id, Class) {
	var obj;
	if (obj = getObject(id))
	{
		if (!hasClass(obj, Class))
			obj.className += (obj.className ? ' ' : '')+Class;
	}
}

function hasClass(id, Class) {
	var obj;
	if (obj = getObject(id))
		return new RegExp('\\b'+Class+'\\b').test(obj.className);
}

function removeClass(id, Class) {
	var obj;
	if (obj = getObject(id))
	{
		if (hasClass(obj, Class))
		{
			var rep = obj.className.match(' '+Class) ? ' '+Class : Class;
			obj.className = obj.className.replace(rep, '');
		}
	}
}

function setClass(id, Class) {
	var obj;
	if (obj = getObject(id))
		obj.className = Class;
}

function swapClass(id, Class, NewClass) {
	var obj;
	if (obj = getObject(id))
	{
		if (hasClass(obj, Class))
		{
			obj.className = obj.className.replace(new RegExp('\\b'+Class+'\\b'), NewClass);
		} else
			addClass(obj, NewClass);
	}
}

function ForceClose() {
	if (window.opener == null)
		window.opener = self;
	window.close();
}

function SetFocus(ID, Begin, Select) {
	var obj, txt;
	if (Begin == null)
		Begin = true;
	if (Select == null)
		Select = false;
	if (obj = getObject(ID))
	{
		if (isVisible(obj) == false || isDisabled(obj))
			return;
		obj.focus();
		if (Begin == false)
		{
			if (obj.createTextRange)
			{
				txt = obj.createTextRange();
				txt.collapse(false);
				txt.select();
			}
		}
		if (Select == true)
		{
			obj.select();
		}
	}
}

function FindAndSelectText(ID, Value, Pos) {
	var obj;
	var txt;
	obj = getObject(ID);
	if (obj === null)
		return;
	if (! obj.createTextRange)
		return;
	txt = obj.createTextRange();
	if (txt == null)
		return;
	obj.focus();
	if (Pos != null)
		Pos = Pos;
	else
		Pos = -1
	txt.moveStart("character", Pos);
	txt.findText(Value);
	txt.select();
	txt.scrollIntoView();
}

function SelectText(ID) {
	var obj, txt;
	if (obj = getObject(ID))
	{
		if (obj.createTextRange)
		{
			txt = obj.createTextRange();
			txt.select();
		}
	}
}

function MoveCaret(ID, Pos) {
	var obj;
	var txt;
	if (obj = getObject(ID)) {
		if (Pos == null || Pos == '')
			Pos = obj.value.length;
		if (obj.createTextRange) {
			txt = obj.createTextRange();
			txt.moveStart('character', Pos);
			txt.collapse();
			txt.select();
		}
	}
}

function TranslateStrToStr(S, OldPattern, NewPattern, CaseSensitive) {
	var re;
	if (CaseSensitive == null || CaseSensitive)
		reOptions = 'gi';
	else
		reOptions = 'g';
	re = new RegExp(OldPattern, reOptions);
	if (S.replace)
		return S.replace(re, NewPattern);
	return S;
}

function FormatStr(S, Values) {
	var re;
	for (var i = 0; i < Values.length; i++)
	{
		re = new RegExp('\\{'+i.toString()+'\\}', 'gm');
		S = S.replace(re, Values[i]);
	}
	return S;
}

function Trim(S) {
	var re = /^(\s*)([\W\w]*)(\b\s*$)/;
	if (re.test(S)) { return S.replace(re, '$2'); }
}

function StrToIntDef(Str, Default) {
	if (typeof(Str) == 'string' && Str.indexOf('px') != -1)
		Str = Str.slice(0, Str.indexOf('px'));
	var Result = parseInt(Str);
	if (isNaN(Result))
	{
		if (Default == '' || Default == null)
			Default = 0;
		Result = Default;
	}
	return Result;
}

// Event functions

function GetEventObj(e) {
	if (e)
		return e;
	else if (window.event)
		return window.event;
	else
		return null;
}

function GetEventLeftClick(e) {
	var result = false;
	e = GetEventObj(e);
	if (!e) return;
	if (e.button)
		result = (e.button == 1);
	if (e.which)
		result = (e.which == 1);
	return result;
}

function GetEventRightClick(e) {
	var result = false;
	e = GetEventObj(e);
	if (!e) return;
	if (e.button)
		result = (e.button == 2);
	if (e.which)
		result = (e.which == 3);
	return result;
}

function GetEventKeyCode(e) {
	e = GetEventObj(e);
	if (!e) return;
	if (e.keyCode)
		return e.keyCode;
}

function SetEventKeyCode(keyCode, e) {
	e = GetEventObj(e);
	if (!e) return;
	if (e.keyCode)
		e.keyCode = keyCode;
}

function GetEventCtrlKey(e) {
	e = GetEventObj(e);
	if (!e) return;
	if (e.ctrlKey)
		return e.ctrlKey;
	return false;
}

function GetEventShiftKey(e) {
	e = GetEventObj(e);
	if (!e) return;
	if (e.shiftKey)
		return e.shiftKey;
	return false;
}

function CancelEventBubble(e) {
	e = GetEventObj(e);
	if (!e) return;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function CancelEventReturn(e) {
	e = GetEventObj(e);
	if (!e) return;
	e.returnValue = false;
	if (e.preventDefault) e.preventDefault();
}

function CancelEvent(e) {
	e = GetEventObj(e);
	if (!e) return;
	CancelEventBubble(e);
	CancelEventReturn(e);
	return false;
}

function GetEventXPosition(e) {
	var value = 0;
	e = GetEventObj(e);
	if (!e) return;
	if (e.clientX)
	{
		value = StrToIntDef(e.clientX, 0) + StrToIntDef(document.body.scrollLeft, 0);
		return value;
	}
	else if (e.pageX)
	{
		value = StrToIntDef(e.pageX, 0)
		return value;
	}
}

function GetEventYPosition(e) {
	e = GetEventObj(e);
	if (!e) return;
	if (e.pageY)
		return e.pageY;
	else if (e.clientY)
		return e.clientY + document.body.scrollLeft;
}

function GetEventTarget(e) {
	var obj;
	e = GetEventObj(e);
	if (!e) return;
	if (e.srcElement)
		obj = e.srcElement;
	else if (e.target)
		obj = e.target;
	if (obj.nodeType == 3) // defeat Safari bug
		obj = obj.parentNode;
	return obj;
}

// --- Form functions ---

function SubmitForm(FormName) {
	var F;
	var arg = arguments;
	var i;
	var ConfirmQuestion = '';
	var Action = null;
	var Target = null;
	var RestoreOptions = false;
	var Partial = false;
	var OldAction;
	var OldTarget;
	if (!FormName || FormName == '')
		FormName = 'MainForm';
	if (typeof FormName == 'string')
		F = document.forms[FormName];
	else
		F = FormName;
	if (F == null)
		return false;
	for (i=0; i < arg.length; i++)
	{
		switch(arg[i].toUpperCase())
		{
			case 'ACTION': Action = arg[++i]; break;
			case 'TARGET': Target = arg[++i]; break;
			case 'CONFIRM': ConfirmQuestion = arg[++i]; break;
			case 'RESTORE': RestoreOptions = true; break
			case 'PARTIAL': Partial = true; break
		}
	}
	if (ConfirmQuestion != '')
	{
		if (confirm(ConfirmQuestion) == false)
			return false;
	}
	if (F.onsubmit && typeof F.onsubmit	== 'function')
		if (F.onsubmit() == false)
			return false;
	if (RestoreOptions || Partial)
	{
		OldAction = F.action;
		OldTarget = F.target;
	}
	if (Partial)
	{
		SetField(F, 'XMLC_Partial', '1');
		Target = 'XMLC_PartialFrame';
	}
	if (Action != null)
		F.action = Action;
	if (Target != null)
		F.target = Target;
	F.submit();
	if (RestoreOptions || Partial)
	{
		F.action = OldAction;
		F.target = OldTarget;
	}
	if (Partial)
		SetField(F, 'XMLC_Partial', '');
	return true;
}

function ResetForm(FormName){
	var F;
	if (!FormName || FormName == '')
		FormName = 'MainForm';
	if (typeof FormName == 'string')
		F = document.forms[FormName];
	if (!F)
		return false;
	return F.reset();		
}

function handleFormKeyPress(FormName, e) {
	var keyCode = GetEventKeyCode(e);
	if (keyCode == 13)
		SubmitForm(FormName);
}

function ConfirmDelete(FormName, DeleteAction, Prompt) {
	SubmitForm(FormName, 'ACTION', DeleteAction, 'CONFIRM', Prompt);
}

function SetFormAction(FormName, Action) {
	var F;
	if (typeof FormName == 'string')
		F = document.forms[FormName];
	else
		F = FormName;
	if (F == null)
		return false;
	F.action = Action;
}

function SetField(FormName, FieldName, FieldValue) {
	var E = GetFieldObj(FormName, FieldName);
	if (!E)
		return false;
	if (FieldValue == null)
		FieldValue = '';
	E.value = FieldValue;
}

function GetFieldValue(FormName, FieldName) {
	return GetField(FormName, FieldName);
}

function GetField(FormName, FieldName) {
	var obj = GetFieldObj(FormName, FieldName);
	if (!obj)
		return null;
	return obj.value;
}

function GetRadioField(FormName, FieldName) {
	var obj = GetFieldObj(FormName, FieldName);
	if (!obj)
		return null;
	if (obj.length)
	{
		for (var i=0; i<obj.length; i++)
		{
			if (obj[i].checked)
				return obj[i].value;
		}
	}
		return obj.value;
}

function GetValue(ID) {
	var obj;
	if (obj = getObject(ID))
		return obj.value;
}

function GetFieldObj(FormName, FieldName) {
	var F;
	if (typeof FormName == 'string')
		F = document.forms[FormName];
	else
		F = FormName;
	if (F)
		return F.elements[FieldName];
}

function getFirstFieldObj(FormName, IDs) {
	var obj;
	F = document.forms[FormName]
	for (var i = 0; i < IDs.length; i++)
	{
		obj = F.elements[IDs[i]];
		if (obj)
			return obj;		
	}
}

// --- CheckBoxes functions ---

function IsChecked(ID) {
	var obj;
	if (obj = getObject(ID))
		return obj.checked;
	return false;
}

function CheckObject(ID) {
	var obj;
	if (obj = getObject(ID))
		obj.checked = true;
}

function UncheckObject(ID) {
	var obj;
	if (obj = getObject(ID))
		obj.checked = false;
}

function CheckUncheckAll(FieldName1, FieldName2, LBound, HBound, Checked) {
	var i;
	var func = getObjectById;
	for (i = LBound; i <= HBound; i++)
	{
		if (obj = func(FieldName1 + i.toString() + FieldName2))
			obj.checked = Checked;
	}
}

var _PreviousCheckedBox = null;
function CheckboxListClick(e, obj, FieldName1, FieldName2) {
	var Index1, Index2;
	var prevObj = _PreviousCheckedBox;
	_PreviousCheckedBox = obj;
	if (prevObj === null)
		return;
	if (GetEventShiftKey(e) == false)
		return;
	Index1 = obj.id.substring(obj.id.indexOf('[')+1, obj.id.indexOf(']'));
	Index2 = prevObj.id.substring(prevObj.id.indexOf('[')+1, prevObj.id.indexOf(']'));
	Index1 = StrToIntDef(Index1, -1);
	Index2 = StrToIntDef(Index2, -1);
	if (Index1 == -1 || Index2 == -1)
		return;
	if (Index1 < Index2)
		CheckUncheckAll(FieldName1, FieldName2, Index1, Index2, obj.checked);
	else
		CheckUncheckAll(FieldName1, FieldName2, Index2, Index1, obj.checked);
}


function GetValue(ID) {
	var obj;
	if (obj = getObject(ID))
		return obj.value;
}

function Check(FieldName1, FieldName2, LBound, HBound) {
	var i;
	var func = CheckObject;
	for (i = LBound; i <= HBound; i++)
		func(FieldName1 + i + FieldName2);
}

function Uncheck(FieldName1, FieldName2, LBound, HBound) {
	var i;
	var func = UncheckObject;
	for (i = LBound; i <= HBound; i++)
		func(FieldName1 + i + FieldName2);
}

function SwitchCheckbox(ID) {
	var obj;
	if (obj = getObject(ID))
		obj.checked = !(obj.checked);
}

function SwitchState(FieldName1, FieldName2, LBound, HBound) {
	var i;
	var func = SwitchCheckbox;
	for (i = LBound; i <= HBound; i++)
		func(FieldName1 + i + FieldName2);
}

// --- Object size and position functions

var ContentObj = null;
var ActionMenuObj = null;
var ActionMenuDisplayed = null;

function ShowHideActionMenu() {
	if (ActionMenuObj === null)
		ActionMenuObj = getObjectById('xslcActionMenu');
	if (ActionMenuObj === null)
		return false;
	ShowHide([ActionMenuObj], 'IMG', 'ActionMenuToggler', '+', XMLC_PictosPath+'button_expandframe.gif', '-', XMLC_PictosPath+'button_reduceframe.gif');
	if (XMLC_HandleScrollbars = '1')
		SetPageContentSize();
	return false;
}

function SetPageContentSize() {
	var WindowHeight, WindowWidth;
	var OffsetTop, OffsetLeft;
	var X, Y;
	if (ContentObj === null)
	{
		ContentObj = getObjectById('xslcPageContent');
		if (ContentObj === null)
			return;
	}
	if (ActionMenuObj === null)
		ActionMenuObj = getObjectById('xslcActionMenu');
	WindowHeight = GetWindowInnerHeight();
	WindowWidth = GetWindowInnerWidth();
	OffsetTop = GetObjectPosY(ContentObj);
	if (ActionMenuObj != null && isVisible(ActionMenuObj))
		OffsetLeft = GetObjectWidth(ActionMenuObj);
	else
		OffsetLeft = GetObjectPosX(ContentObj);
	X = parseInt(WindowWidth-OffsetLeft);
	Y = parseInt(WindowHeight-OffsetTop);

	// ON 20051206 substract padding made Moz behave correctly for main window											 
	//if (bw.gecko) // bw object removed !																													 
	if (navigator.userAgent.toLowerCase().indexOf('gecko') > -1) // maybe with document.compatMode ? 
	{
		PaddingX = StrToIntDef(ContentObj.style.paddingLeft, 0) + StrToIntDef(ContentObj.style.paddingRight, 0);
		PaddingY = StrToIntDef(ContentObj.style.paddingTop, 0) + StrToIntDef(ContentObj.style.paddingBottom, 0)
		X = X - PaddingX;
		Y = Y - PaddingY;
	}
	if (ActionMenuObj != null)
		SetObjectSize(ActionMenuObj, -1, Y);
	SetObjectSize(ContentObj, X, Y);
}

function MaximizeObjectSize(ID) {
	var WindowHeight, WindowWidth;
	var PaddingBottom, PaddingRight;
	var OffsetTop, OffsetLeft;
	var obj = getObject(ID);
	if (obj === null)
		return;
	WindowHeight = GetWindowInnerHeight();
	WindowWidth = GetWindowInnerWidth();
	OffsetTop = GetObjectPosY(obj);
	OffsetLeft = GetObjectPosX(obj);
	PaddingBottom = 0;
	PaddingRight = 0;
	if (ContentObj)
	{
		PaddingBottom = TranslateStrToStr(ContentObj.style.paddingBottom, 'px', '');
		PaddingRight = TranslateStrToStr(ContentObj.style.paddingRight, 'px', '');
	}
	SetObjectSize(obj, parseInt(WindowWidth-OffsetLeft-PaddingRight), parseInt(WindowHeight-OffsetTop-PaddingBottom));
}

function GetObjectPosX(ID)
{
	var obj = getObject(ID);
	if (obj === null)
		return;
	var result = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			result += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		result += obj.x;
	return result;
}

function GetObjectPosY(ID)
{
	var obj = getObject(ID);
	if (obj === null)
		return;
	var result = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			result += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		result = obj.y;
	return result;
}

// Object must be visible to retreive height and width
function GetObjectHeight(ID)
{
	var obj = getObject(ID);
	if (obj === null)
		return 0;
	if (obj.offsetHeight)
		return obj.offsetHeight;
	if (obj.style.pixelHeight)
		return obj.style.pixelHeight;
}

function GetObjectWidth(ID)
{
	var obj = getObject(ID);
	if (obj === null)
		return 0;
	if (obj.offsetWidth)
		return obj.offsetWidth;
	if (obj.style.pixelWidth)
		return obj.style.pixelWidth;
}

// MoveObject assumes obj is absolutely positionned
function MoveObject(ID, X, Y) {
	var windowWidth;
	var objRight;

	var obj = getObject(ID);
	if (obj === null)
		return;
	if (X != -1)
	{
		objRight = GetObjectWidth(ID)+X;
		windowWidth = GetWindowWidth(window);
		if (objRight > windowWidth)
			X = objRight - windowWidth;
		if (X < 0)
			X = 0;
		obj.style.left = X;
	}
	if (Y != -1)
		obj.style.top = Y;
}

function SetObjectSize(ID, X, Y) {
	var obj = getObject(ID);
	if (obj === null)
		return;
	if (X >= 0)
		obj.style.width = X+'px';
	if (Y >= 0)
		obj.style.height = Y+'px';
}

function SetObjectStyle(ID, options) {
	var obj = getObject(ID);
	if (obj === null)
		return;
	for (rule in options)
		obj.style[rule] = options[rule];
}

// --- Windows functions

function GetWindowHeight(wnd) {
	var WidgetHeight = 28; // Don't care for windows decoration
	if (wnd == null)
		wnd = window;
	if (wnd.document.body.offsetHeight)
		return wnd.document.body.offsetHeight + WidgetHeight;
	else if (wnd.innerHeight)
		return wnd.innerHeight + WidgetHeight;
}

function GetWindowWidth(wnd) {
	var WidgetWidth = 8; // Don't care for windows decoration
	if (wnd == null)
		wnd = window;
	if (wnd.document.body.offsetWidth)
		return wnd.document.body.offsetWidth + WidgetWidth;
	else if (wnd.innerHeight)
		return wnd.innerWidth + WidgetWidth;
}

function GetWindowTop(wnd) {
	if (wnd == null)
		wnd = window;
	if (wnd.screenY)
		return wnd.screenY;
	else if (wnd.screenTop)
		return wnd.screenTop;
}

function GetWindowLeft(wnd) {
	if (wnd == null)
		wnd = window;
	if (wnd.screenX)
		return wnd.screenX;
	else if (wnd.screenLeft)
		return wnd.screenLeft;
}

function GetWindowMaxHeight(wnd) {
	var wndTop;
	if (wnd == null)
		wnd = window;
	wndTop = GetWindowTop(wnd);
	if (screen.availHeight < wndTop)
		wndTop = wndTop - screen.availHeight;
	return screen.availHeight - wndTop;
}

function GetWindowMaxWidth(wnd) {
	var wndLeft;
	if (wnd == null)
		wnd = window;
	wndLeft = GetWindowLeft(wnd);
	if (screen.availWidth < wndLeft)
		wndLeft = wndLeft - screen.availWidth;
	return screen.availWidth - wndLeft;
}

function GetWindowInnerHeight(wnd) {
	var obj;
	var value;
	if (wnd == null)
		wnd = window;
	if (obj = wnd.document)
		if (obj = obj.body)
			if (value = obj.clientHeight)
				return value;
}

function GetWindowInnerWidth(wnd) {
	var obj;
	var value;
	if (wnd == null)
		wnd = window;
	if (obj = wnd.document)
		if (obj = obj.body)
			if (value = obj.clientWidth)
		return value;
}

function TileWindows(Width) {
	var main;
	var ScreenX, ScreenY;
	var ScreenLeft;
	var popupScreenX;
	var WindowLeft;
	ScreenX = screen.availWidth;
	ScreenY = screen.availHeight;
	if (Width == '' || Width == null)
		Width = 200;
	try
	{
		ScreenLeft = 0;
		popupScreenX = ScreenX;
		if (window.opener != null)
		{
			if (window.opener.screenX)
				WindowLeft = window.opener.screenX;
			else if (window.opener.screenLeft)
				WindowLeft = window.opener.screenLeft;
			if (WindowLeft+4 >= ScreenX) // Dual screen, +4 for window decoration offset
			{
				popupScreenX = 2 * ScreenX
				ScreenLeft = ScreenX;
			}
		}
		window.resizeTo(Width, ScreenY);
		window.moveTo(popupScreenX - Width, 0);
		if (main = window.opener)
		{
			if (main.top != null)
				main = main.top;
			if (main == null)
				return;
			main.window.resizeTo(ScreenX - Width , ScreenY);
			main.window.moveTo(ScreenLeft, 0);
		}
	} catch (e) {
		// do nothing
	}
}

function MaximizeWindow(wnd) {
	var DiffWidth = 0;
	var DiffHeight = 0;
	var Left = 0;
	var Top = 0;
	var Width = 800 - DiffWidth;
	var Height = 600 - DiffHeight;
	var WindowLeft = 0;
	var WindowTop = 0;

	if (wnd == null)
		wnd = self.top;
	if (wnd == null)
		return;
	try
	{
		WindowTop = GetWindowTop(wnd);
		WindowLeft = GetWindowLeft(wnd);

		if (screen.availWidth)
			Width = screen.availWidth - DiffWidth;
		if (screen.availHeight)
			Height = screen.availHeight - DiffHeight;
		if (WindowLeft >= screen.availWidth)
			Left = screen.availWidth;
		wnd.moveTo(Top, Left);
		wnd.resizeTo(Width, Height);
	}
	catch (e)
	{
		// do nothing
	}
}

function ResizeWindow(Width, Height, wnd) {
	var maxHeight;
	var maxWidth;
	if (wnd == null)
		wnd = window;
	if ((Width == null || Width == '') && (Height == null || Height == ''))
		return;
	if (Width == null || Width == '')
		Width = GetWindowWidth(wnd);
	if (Height == null || Height == '')
		Height = GetWindowHeight(wnd);

	maxHeight = GetWindowMaxHeight(wnd);
	if (Height > maxHeight)
		Height = maxHeight;
	maxWidth = GetWindowMaxWidth(wnd);
	if (Width > maxWidth)
		Width = maxWidth;
	wnd.resizeTo(Width, Height);
}

function openEmailWindow(URL, Name) {
	openWindow(URL, Name, 'width=900,height=570,resizable,status');
}

function openWindow(URL, Name, Params, YPos, XPos) {
	var win;
	if (XPos == null || XPos == '')
		XPos = 30;
	if (YPos == null || YPos == '')
		YPos = 30;
	var wnd = window;
	if (window.top != null)
		wnd = window.top;
	if (Name == null || Name == '')
		Name = '_blank';
	if (wnd.screenTop)
		YPos = parseInt(YPos) + parseInt(wnd.screenTop);
	else if (wnd.screenY)
		YPos = parseInt(YPos) + parseInt(wnd.screenY);
	if (wnd.screenLeft)
		XPos = parseInt(XPos) + parseInt(wnd.screenLeft);
	else if (wnd.screenX)
		XPos = parseInt(XPos) + parseInt(wnd.screenX);
	if (Params == null || Params == '')
		Params = 'width=900,height=600,resizable';
	Params = 'left=' + XPos + ',top=' + YPos +',' + Params;
	if (XMLC_HandleScrollbars = '1')
		Params = Params+',scrollbars=no';

	win = window.open(URL, Name, Params);
	if (win && win.focus)
		win.focus();
	return win;
}

function Resize(ID, Width, Height) {
	var obj;
	if (obj = getObject(ID))
	{
		if (Width && Width != '' && Width != -1)
		{
			if (obj.style)
			{
				obj.style.pixelWidth = Width;
				obj.style.width = Width+'px';
			}
			if (obj.width)
				obj.width = Width;
		}
		if (Height && Height != '' && Height != -1)
		{
			if (obj.style)
			{
				obj.style.pixelHeight = Height;
				obj.style.height = Height+'px';
			}
			if (obj.height)
				obj.height = Height;
		}
	}
}

function ResizeFrameFromContent(doc, ID, Width, Height) {
	var body;
	var frm;
	var obj;
	var style;
	if (Height == null) Height = '-1';
	if (Width == null) Width = '-1';
	if (Width == '-1' || Height == '1')
	{
		frm = getFrameByName(ID);
		if (frm && frm.getObjectById)
		{
			obj = frm.getObjectById('xslcPageContent');
			if (!obj)
				obj = frm.getObjectById('Content');
			if (!obj)
				return;
			if (frm.GetObjectWidth)
				Width = frm.GetObjectWidth(obj);
			if (frm.GetObjectHeight)
				Height = frm.GetObjectHeight(obj);
		}
		if (Height == '-1' || Width == '-1')
		{
			if (doc == null || doc.body == null)
				doc = GetFrameDoc(ID);
			if (doc == null)
				return;
			body = doc.body;
			style = body.style;
			if (Height == '-1')
			{
				if (style && style.height) Height = style.height;
				if (Height == '' && body.scrollHeight) Height = body.scrollHeight;
				if (Height == '' && body.offsetHeight) Height = body.offsetHeight;
			}
			if (Width == '-1')
			{
				if (style && style.width) Width = style.width;
				if (Width == '' && body.scrollWidth) Width = body.scrollWidth;
				if (Width == '' && body.offsetWidth) Width = body.offsetWidth;
			}
		}
	}
	Resize(ID, Width, Height);
}

function getFrameByName(Name) {
	var frame = window.frames[Name];
	if (frame != null)
		return frame;
	frame = document.getElementsByTagName("FRAMESET").item(Name);
	if (frame != null)
		return frame;
	if (parent)
	{
		var frame = parent.frames[Name];
		if (frame != null)
			return frame;
		var frame = parent.document.getElementsByTagName("FRAMESET").item(Name);
		if (frame != null)
			return frame;
	}
	if (top)
	{
		var frame = top.frames[Name];
		if (frame != null)
			return frame;
		var frame = top.document.getElementsByTagName("FRAMESET").item(Name);
		if (frame != null)
			return frame;
	}
	return null;
}

function GetFrameDoc(ID) {
	var doc = null;
	try {
		if (document.frames)
		{
			if (frm = document.frames[ID])
			{
				if (frm.document)
					doc = frm.document;
			}
		} else {
			if (obj = getObject(ID))
			{
				if (obj.contentDocument)
					return obj.contentDocument;
				else if (obj.contentWindow)
					return obj.contentWindow.document;
				else if (obj.document)
					return obj.document;
			}
		}
		return doc;
	}
	catch (e)
	{
		// do nothing
	}
}

var OpenedFrameID = '';
var PushedButton = '';

function FillFrame(e, FrameID, ContentID, Width, Height, AutoHide, ButtonID) {
	var doc;
	var content;
	var show;
	e = GetEventObj(e);
	if (AutoHide == null)
		AutoHide = false;
	AutoHide = AutoHide && e;
	if (OpenedFrameID != '' || PushedButton != '')
		HideFilledFrame();
	if (doc = GetFrameDoc(FrameID))
	{
		show = !(isVisible(FrameID));
		if (show)
		{
			if (OpenedFrameID != '' && OpenedFrameID != FrameID)
				HideFilledFrame();
			Show(FrameID);
			if (AutoHide)
				OpenedFrameID = FrameID;
			if (ButtonID != null)
				PushedButton = ButtonID;
			if (isEmpty(doc.body))
			{
				if (content = getObject(ContentID))
					SetContent(doc.body, content.innerHTML);
				if (Width != null || Height != null)
		 			ResizeFrameFromContent(doc, FrameID, Width, Height);
			}
		}
		if (AutoHide)
		{
			if (show)
			{
				var fn = function() { HideFilledFrame(); removeEvent(document, 'click', fn); }
				addEvent(document, 'click', fn);
				CancelEvent(e);
			}
			else
			{
				HideFilledFrame();
			}
		}
		if (show)
			return true;
	}
	return false;
}

function HideFilledFrame() {
	if (OpenedFrameID && OpenedFrameID != '')
		Hide(OpenedFrameID);
	if (PushedButton && PushedButton != '')
	{
		BtnUnpushed(getObject(PushedButton), 'TOOL');
		PushedButton = '';
	}
}

function LoadFrameURLObj(obj, FrameID, URL, Force)
{
	var frm;
	var CurrentURL;
	if (typeof Force != 'boolean')
		Force = false;
	if (obj.frames)
	{
		if (frm = obj.frames[FrameID])
		{
			CurrentURL = frm.document.location.href;
			if (Force || CurrentURL.indexOf(URL) == -1) // !!! Test not correct if CurrentURL contains more params
			{
				frm.document.location.href = URL;
			}
			return true;
		}
	}
	if (obj.document)
	{
		if (obj.document.getElementById)
		{
			if (frm = obj.document.getElementById(FrameID))
			{
				if (frm.document)
				{
					if (frm.document.location)
					{
						if (Force || frm.document.location.href != URL)
							frm.document.location.href = URL;
						return true;
					}
				}
			}
		}
	}
	return false;
}

function LoadFrameURL(FrameID, URL, e) {
	if (GetEventShiftKey(e))
	{
		window.open(URL, '_blank');
		return false;
	}
	if (LoadFrameURLObj(parent, FrameID, URL)) return false;
	if (LoadFrameURLObj(top, FrameID, URL)) return false;
	if (LoadFrameURLObj(window, FrameID, URL)) return false;
	parent.document.location.href = URL;
	return false;
}

// --- Cookies functions ---

function getCookie(name) {
	var pos;
	var token = name + "=";
	var tnlen = token.length;
	var cklen = document.cookie.length;
	var i = 0;
	var j;
	while (i < cklen)
	{
		j = i + tnlen;
		if (document.cookie.substring(i, j) == token)
		{
			pos = document.cookie.indexOf (";", j);
			if (pos == -1)
				pos = document.cookie.length;
			return unescape(document.cookie.substring(j, pos));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	}
	return null;
}

function setCookie(name, value) {
	document.cookie = name + '=' + escape(value);
}

function deleteCookie(name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = getCookie(name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function checkCookie(ID) {
	var CookieName = 'COOKIETEST';
	var CookieValueRet = null;

	setCookie(CookieName, 'TESTING_COOKIE');
	CookieValueRet = getCookie(CookieName);
	deleteCookie(CookieName);
	if (CookieValueRet == null)
	{
		if (ID != null && ID != '')
			Show(ID);
		return false;
	}
	else
	{
		return false;
	}
}

function checkTopLevel() {
	if ((top == null) || (top == self))
		return true;
	top.location.href = location.href;
}

// --- Delos functions ---

function ArrayGetItemIndex(List, Value) {
	var Index;
	for (Index = 0; Index < List.length; Index++)
	{
		if (List[Index] == Value)
			return Index;
	}
	return -1;
}

function SetTabStatus(Name, TabName, Active) {
	var ID;
	var TabNamesArray = eval(Name+'TabNames'); // needed for now
	if (typeof(TabNamesArray) != 'object')
		return false;
	var Pos = ArrayGetItemIndex(TabNamesArray, TabName);
	if (Pos == -1)
		return false;
	var LastTab = TabNamesArray.length - 1;

	var URL = XMLC_SkinPath+'tabcontrol/';

	ID = Name + 'Tab' + TabName;
	var Tab = getObjectById(ID);
	ID = Name + 'Tab' + TabName +'Right';
	var TabRight = getObjectById(ID);
	if (Pos == 0)
		ID = Name + 'TabLeft';
	else
		ID = Name + 'Tab' + TabNamesArray[Pos - 1] + 'Right';
	var TabLeft = getObjectById(ID);
	ID = Name + 'TabBottom' + TabName;
	var TabBottom = getObjectById(ID);
	if (Pos == 0)
		ID = Name + 'TabBottomLeft';
	else
		ID = Name + 'TabBottom' + TabNamesArray[Pos - 1] + 'Right';
	var TabBottomLeft = getObjectById(ID);
	ID = Name + 'TabBottom' + TabName + 'Right';
	var TabBottomRight = getObjectById(ID);
	if (Active)
	{
		if (TabLeft)
		{
			if (Pos == 0)
				TabLeft.src = URL+'activetab_left.gif';
			else
				TabLeft.src = URL+'activetab_joint_left.gif';
		}
		if (Tab)
			Tab.className = 'clActiveTab';
		if (TabRight)
		{
			if (Pos == LastTab)
				TabRight.src = URL+'activetab_right.gif';
			else
				TabRight.src = URL+'activetab_joint_right.gif';
		}
		if (TabBottom)
				TabBottom.style.background = 'url('+URL+'activetab_bottom.gif)';
		if (TabBottomLeft)
		{
			if (Pos == 0)
				TabBottomLeft.style.background = 'url('+URL+'tab_bottom_left_first.gif)';
			else
				TabBottomLeft.style.background = 'url('+URL+'activetab_bottom_joint_left.gif)';
		}
		if (TabBottomRight)
		{
			if (Pos == LastTab)
				TabBottomRight.style.background = 'url('+URL+'activetab_bottom_right.gif)';
			else
				TabBottomRight.style.background = 'url('+URL+'activetab_bottom_joint_right.gif)';
		}
	} else {
		if (TabLeft)
		{
			if (Pos == 0)
				TabLeft.src = URL+'tab_left.gif';
			else
				TabLeft.src = URL+'tab_joint_left.gif';
		}
		if (Tab)
			Tab.className = 'clTab';
		if (TabRight)
		{
			if (Pos == LastTab)
				TabRight.src = URL+'tab_right.gif';
			else
				TabRight.src = URL+'tab_joint_right.gif';
		}
		if (TabBottom)
				TabBottom.style.background = 'url('+URL+'main_top.gif)';
		if (TabBottomLeft)
		{
			if (Pos == 0)
				TabBottomLeft.style.background = 'url('+URL+'tab_bottom_left_others.gif)';
			else
				TabBottomLeft.style.background = 'url('+URL+'main_top.gif)';
		}
		if (TabBottomRight)
			TabBottomRight.style.background = 'url('+URL+'main_top.gif)';
	}
}

function DisplayTab(Name, TabName) {
	var ActiveTabName = eval(Name+'CurrentActiveTabName'); // needed for now
	if (Name+TabName == ActiveTabName)
		return false;
	var Body = getObject(Name+'TabPage'+TabName);
	if (Body == null)
		return false;
	if (SetTabStatus(Name, ActiveTabName, false) == false)
		return false;
	if (SetTabStatus(Name, TabName, true) == false)
		return false;
	Show(Body);
	Hide(Name+'TabPage'+ActiveTabName);
	eval(Name+'CurrentActiveTabName = "'+TabName+'"');
	return false;
}

function CheckPassword(Password, Length, MinSpecialChars) {
	var NormalChars = 'abcdefghijklmnopqrstuvwxyz0123456789';
	var Char;
	var Index;
	var SpecialChar = 0;

	if (Password.length < Length)
		return false;
	for (Index = 0; Index <= Password.length; Index++)
	{
		Char = Password.charAt(Index).toLowerCase();
		if (NormalChars.indexOf(Char) == -1)
			SpecialChar++;
		if (SpecialChar >= MinSpecialChars)
			return true;
	}
	return false;
}

function isEmpty(ID) {
	var obj;
	obj = getObject(ID);
	return obj ? obj.firstChild == null : false;
}

function AppendContent(ID, Content) {
	var obj;
	if (obj = getObject(ID))
		obj.innerHTML += Content;
}

function SetContent(ID, Content) {
	var obj;
	if (obj = getObject(ID))
	{
		while (obj.firstChild)
			obj.removeChild(obj.firstChild);
		obj.innerHTML = Content;
	}
}

function SetObjContent(ID, Content) {
	SetContent(ID, Content);
}

function UpdateApplicationMessages(Text) {
	var obj;
	obj = getObjectById('xslcApplicationMessages');
	if (!obj)
		return false;
	if (Text == '')
	{
		Hide(obj);
	} else {
		SetContent(obj, Text);
		Show(obj);
	}
}

function refreshMenu(ID) {
	var frm;
	if (frm = GetFrameDoc('MenuEML'))
	{
		if (ID != null && ID != '')
			if (frm.SetField)
				frm.SetField('MainForm', 'SelectedID', ID);
		if (frm.SubmitForm)
			frm.SubmitForm('MainForm');
	}
}

function boldMenuItem(ID) {
	var frm;
	if (parent.frames)
		if (frm = parent.frames['MenuEML'])
			if (frm.boldItem)
				frm.boldItem(ID);
}

function PopCalendar(PopID, FieldName, EndFieldName, Form, CallbackFunc, show) {
	var e = null;
	if (window.event)
		e = window.event;
	PopCalendar2(e, PopID, FieldName, EndFieldName, Form, CallbackFunc, show);
}

function PopCalendar2(e, PopID, FieldName, EndFieldName, Form, CallbackFunc, show) {
	var URL;
	var Pop;
	var obj;
	Pop = getObjectById(PopID)
	if (!Pop)
		return;
	if (show == null)
		show = !(isVisible(Pop));
	if (!show)
	{
		 Hide(Pop);
		 return;
	}
	if (CallbackFunc == null)
		CallbackFunc = '';
	if (EndFieldName == null)
		EndFieldName = '';
	if (Form == null)
		Form = 'MainForm';
	URL = XMLC_BaseHRef+'CalendarPopup?FieldName='+FieldName;
	URL += '&AutoResize=1';
	URL += '&CALENDAR_DATE='+ GetFieldValue(Form, FieldName);
	URL += '&HTMLForm='+ Form;
	URL += '&PopID=' + PopID;
	if (CallbackFunc != '')
		URL += '&CallbackFunc=' + CallbackFunc;
	if (EndFieldName != '')
		URL += '&EndFieldName=' + EndFieldName;
	obj = getObjectById('XMLC_PartialFrame');
	obj.src = URL;
	var fn = function(e) {
		var obj = GetEventTarget(e);
		while (obj.offsetParent)
		{
			if (obj.offsetParent.id == 'Calendar')
				return true;
			obj = obj.offsetParent;
		}
		Hide(PopID);
		removeEvent(document.body, 'click', fn);
	};
	addEvent(document.body, 'click', fn);
	CancelEvent(e);
}

function PopCalendarResize(PopID) {
	var Width, Height;
	if (document.getElementById)
		obj = document.getElementById('Calendar');
	else if (document.all)
		obj = document.all('Calendar');
	else
		obj = document.body;
	if (obj.style.height)
	{
		Height = obj.style.height;
		Width = obj.style.width;
	}
	else if (obj.scrollHeight)
	{
		Height = obj.scrollHeight;
		Width = obj.scrollWidth;
	}
	else if (obj.offsetHeight)
	{
		Height = obj.offsetHeight;
		Width = obj.offsetWidth;
	}
	parent.Resize(PopID, Width, Height);
}

function PopCalendarUpdateField(PopID, Form, FieldName, Date, EndFieldName, CallbackFunc) {
	if (Form == '')
		Form = 'MainForm';
	SetField(Form, FieldName, Date);
	if (EndFieldName != '')
		SetField(Form, EndFieldName, Date);
	if (CallbackFunc != '')
		eval(CallbackFunc);
	Hide(PopID);
}

function GetStartingRow(Index, PageCount, MaxRows, StandardPaging) {
	var Result;
	if (StandardPaging == null)
		StandardPaging = 0;
	Index = StrToIntDef(Index, 1);
	if (Index < 1)
		Index = 1;
	PageCount = StrToIntDef(PageCount, 0);
	if (PageCount != 0 && Index > PageCount)
		Index = PageCount;
	MaxRows = StrToIntDef(MaxRows, 1);
	if (StandardPaging != '1')
		MaxRows = MaxRows - 1;
	return (Index-1) * (MaxRows);
}

function handlePageNumberKeyPressForm(e, Value, PageCount, MaxRows, RecordName, Form, StandardPaging) {
	var StartingRow;
	var Param;
	var keyCode = GetEventKeyCode(e);
	if (keyCode != 13)
		return true;
	StartingRow = GetStartingRow(Value, PageCount, MaxRows, StandardPaging);
	Param = RecordName+'_StartingRow';
	SetField(Form, Param, StartingRow);
	return false;
}

function handlePageNumberKeyPress(e, Value, PageCount, MaxRows, CommonURL, URLParams, StandardPaging) {
	var StartingRow;
	var CommonURL;
	var keyCode = GetEventKeyCode(e);
	if (keyCode != 13)
		return true;
	StartingRow = GetStartingRow(Value, PageCount, MaxRows, StandardPaging);
	CommonURL = CommonURL+StartingRow+URLParams;
	document.location.href = CommonURL;
	return false;
}

function SwitchProfileOption(ProfileName, CurrentValue) {
	var PartialFrame;
	var Value;
	var URL;
	try
	{
		Value = (CurrentValue == '1') ? '0':'1';
		URL = FormatStr('{0}XMLC_UpdateProfileValue?ProfileName={1}&ProfileValue={2}', [XMLC_BaseHRef, ProfileName, Value]);
		PartialFrame = getFrameByName('XMLC_PartialFrame');
		if (PartialFrame)
			PartialFrame.location.replace(URL);
	} catch(e) {
		// do nothing
	}
}

function lookupPermissions(K_ID, KUSR_ID)
{
	var URL;
	URL = FormatStr('{0}FormKRH?K_ID={1}&KUSR_ID={2}', [XMLC_BaseHRef, K_ID, KUSR_ID]);
	openWindow(URL, 'wndSPM', 'width=450,height=300,scrollbars,resizable');
}

function FillTimeCombo(e, FrameID, ContentID, TimeFieldName) {
	var id;
	var frm;
	var show;
	show = FillFrame(e, FrameID, ContentID, '60', '180', true);
	if (!(show)) return;
	frm = getFrameByName(FrameID);
	if (frm)
	{
		if (frm.SetFocus)
		{
			id = GetField('MainForm', TimeFieldName);
			frm.SetFocus(id);
		}
	}
}

function confirmDeleteEvent(ConfirmText) {
	return(confirm(ConfirmText));
}

function popupAttachProject(Params, DisplayDetach) {
	var wndParams;
	if (DisplayDetach == '1')
		wndParams = 'width=832,height=450,resizable';
	else
		wndParams = 'width=832,height=333';

	var URL = XMLC_BaseHRef+'FormAttachPPRJ?';
	if (Params != '')
	{
		if (Params.charAt(0) == '&')
			Params = Params.slice(1);
		URL = URL+Params;
		if (URL.charAt(URL.length - 1) != '&')
			URL += '&';
	}
	URL += 'Popup=1';
	openWindow(URL, '', wndParams, '', '50');
}

function lookupAttachProject(Form, FieldName, CaptionName, DetachImageName, AutoSubmit, Callback) {
	var URL = XMLC_BaseHRef+'FormAttachPPRJ?';
	if (Form != '')
		URL += 'LookupForm='+Form+'&';
	if (FieldName != '')
		URL += 'LookupFieldName='+FieldName+'&';
	if (CaptionName != '')
		URL += 'LookupCaptionName='+CaptionName+'&';
	if (Callback != '')
		URL += 'LookupCallback='+Callback+'&';
	if (DetachImageName != '')
		URL += 'LookupDetachImageName='+DetachImageName+'&';
	if (AutoSubmit != '')
		URL += 'LookupAutoSubmit='+AutoSubmit+'&';
	URL += 'Lookup=1';
	openWindow(URL, '', 'width=832,height=333', '', '50');
}

function LookupDetachProject(FieldName){
	SetField('MainForm', FieldName, '');
	SetContent('div'+FieldName, '');
	Hide('img'+FieldName);
	Show('divAttach'+FieldName);
}

function PickToolbarDate(e) {
	var cal;
	var doc;
	var obj;
	var URL;
	var StartingDate;
	var wasVisible;
	obj = getObjectById('CalendarMenu');
	if (!obj)
		return;
	wasVisible = isVisible(obj);
	HideFilledFrame();
	if (wasVisible)
		return;
	BtnDropdown(e, 'Calendar', '', -1, -1, true, '0');
	OpenedFrameID = 'CalendarMenu';
	PushedButton = 'Calendar';
	Show(obj);
	StartingDate = GetField('MainForm', 'KTIM_STARTING');
	URL = XMLC_BaseHRef+'XMLC_PopupCalendar?XMLC_PopID=CalendarMenu&XMLC_FieldName=KTIM_STARTING&XMLC_CallbackFunc=SubmitForm()&XMLC_DateValue='+StartingDate;
	LoadFrameURLObj(window, 'CalendarMenu', URL, false);
	var fn = function() { HideFilledFrame(); removeEvent(document, 'click', fn); }
	addEvent(document, 'click', fn);
	CancelEvent(e);
	return true;	
}

function PrepareUpload(Form, KURL_ID) {
	var obj;
	if (KURL_ID != null)
		SetField(Form, 'KURL_ID', KURL_ID);
	obj = GetFieldObj(Form, 'DataFile');
	if (obj != null)
		obj.click();
}

function InternalSubmitUpload(Form, ProgressForm) {
	SubmitForm(Form);
	if (ProgressForm != null && ProgressForm != '')
	{
		Show('divUploadProgress');
		SubmitForm(ProgressForm);
	}
}

function SubmitUpload(Form, ProgressForm, ConfirmMsg) {
	if (ConfirmMsg != null && ConfirmMsg != '')
		if (!confirm(ConfirmMsg))
			return false;
	setTimeout('InternalSubmitUpload("'+Form+'", "'+ProgressForm+'")', 50); // obj.click() is not finished yet.
}

function CancelUpload(Form) {
	SubmitForm(Form, 'ACTION', XMLC_BaseHRef+'XMLC_KillUpload', 'TARGET', 'XMLC_PartialFrame');
}

// --- KD Form functions ---

function submitForm(formName) {
	var arg = arguments;
	var i = 0;
	var question = '';
	if (F = document.forms[formName]) {
		if (checkFields(formName) == false)
			return false;
		var oldAction = F.action;
		var oldTarget = F.target;
		for (i=0; i<arg.length; i++)
		{
			switch (arg[i])
			{
				case 'ACTION': F.action = arg[++i]; break;
				case 'TARGET': F.target = arg[++i]; break;
				case 'CONFIRM': question = arg[++i]; break;
			}
		}
		if (question != '')
		{
			disableUI();
			if (confirm(question))
			{
				enableUI();
				F.submit();
			} else {
				enableUI();
				F.action = oldAction;
				F.target = oldTarget;
			}
		}
		else
			F.submit();
	}
}

function setField(formName, fieldName, fieldValue) {
	var formName_ = formName;
	var fieldName_ = fieldName;
	var fieldValue_ = fieldValue;
	var arg = arguments;
	if (arg.length == 2)
	{
		formName_ = 'MainForm';
		fieldName_ = arg[0];
		fieldValue_ = arg[1];
	}
	SetField(formName_, fieldName_, fieldValue_);
}

function checkFields(formName) {
	var F;
	var i;
	var field;
	var notnull;
	var canSubmit = true;
	var errorMessage = '';
	if (F = document.forms[formName])
	{
		for (i=0; i < F.elements.length; i++)
		{
			field = F.elements[i];
			if ((notnull = getNamedAttribute(field, 'notnull')) && (field.value == ''))
			{
				field.className = 'FieldError';
      	field.valueIsNotValid = true;
      	canSubmit = false;
      	if (errorMessage != '')
      		errorMessage += '\n';
      	errorMessage += errorMessageNotNull + field.name;
			}
		}
		if (!canSubmit)
		{
			alert(errorMessage);
			return false;
		}
	}
	return true;
}

function checkField(field) {
	var notnull;
	field.valueIsNotValid = false;
	if ((notnull = getNamedAttribute(field, 'notnull')) && (field.value == ''))
	{
		 field.className = 'FieldError';
		 field.valueIsNotValid = true;
	}
}

function focusField(formName, fieldName) {
	var F;
	var field;
	var formName_ = formName;
	var fieldName_ = fieldName;
	var arg = arguments;
	if (arg.length == 1)
	{
		formName_ = 'MainForm';
		fieldName_ = arg[0];
	}
	if (F = document.forms[formName_])
	{
		if (field = F.elements[fieldName_])
			field.focus();
	}
}

function deleteRecord(formName, recordName, recordKind) {
	var formName_ = formName;
	var recordName_ = recordName;
	var recordKind_ = recordKind;
	var arg = arguments;
	if (arg.length == 2) {
		formName_ = 'MainForm';
		recordName_ = arg[0];
		recordKind_ = arg[1];
	}
	disableUI();
	if (confirm(questionDeleteRecordBegin + recordKind_ + questionDeleteRecordEnd))
	{
		setField(formName_, recordName_+'.XMLC_Operation', 'Delete');
		submitForm(formName_);
	}
	enableUI();
	return false;
}

function insertRecord(formName, recordName) {
	var formName_ = formName;
	var recordName_ = recordName;
	var arg = arguments;
	if (arg.length == 1)
	{
		formName_ = 'MainForm';
		recordName_ = arg[0];
	}
	setField(formName_, recordName_+'.XMLC_Operation', 'Insert');
	submitForm(formName_);
	return false;
}

// --- Misc functions ---

function navigate(URL) {
	location.href = XMLC_BaseHRef + URL;
	return false;
}

// --- DHTML functions ---

function getObjectStyle(obj) {
	var theObj;
	if (theObj = getObject(obj))
		return theObj.style;
}

function hide(obj) {
	var theObj;
	if (theObj = getObjectStyle(obj))
		theObj.display = 'none';
}

function show(obj) {
	var theObj;
	if (theObj = getObjectStyle(obj))
		theObj.display = 'block';
}

function showhide(obj) {
	var theObj;
	if (theObj = getObjectStyle(obj)) {
		if (theObj.display == 'none')
			show(obj);
		else
			hide(obj);
	}
}

function showhide2(objToShowHideID, objButtonID, imgShow, imgHide) {
	var objToShowHide;
	var objButton;
	var objStyle;
	if (!(objToShowHide = getObject(objToShowHideID)))
		return false;
	if (!(objButton = getObject(objButtonID)))
		return false;
	if (!(objStyle = getObjectStyle(objToShowHide)))
		return false;
	if (objStyle.display == 'none')
	{
		show(objToShowHide);
		objButton.src = imgHide;
	}	else {
		hide(objToShowHide);
		objButton.src = imgShow;
	}
}

function setInfos(infos) {
	if (infos == '')
		infos = 'No information available';
	SetContent('MenuInfos', infos);
}
function fieldOnMouseOut(field) {
	if (!field.focused)
		field.className = 'Field';
	if ((field.valueIsNotValid) && (!field.focused))
		field.className = 'FieldError';
}

function fieldOnMouseOver(field) {
	if (!field.focused)
		field.className = 'FieldOver';
}

function fieldOnFocus(field) {
	field.className = 'FieldFocus';
	field.focused = true;
}

function fieldOnBlur(field) {
	field.className = 'Field';
	field.focused = false;
}

function disableUI() {
	disable(document.body);
}

function enableUI() {
	enable(document.body);
}

function disable(ID) {
	var obj;
	if (obj = getObjectStyle(ID))
	{
		if (obj.opacity)
			obj.opacity = '.80';
		if (obj.filter)
			obj.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
		if (obj.MozOpacity)
			obj.MozOpacity = '.80';
	}
}

function enable(ID) {
	var obj;
	if (obj = getObjectStyle(ID))
	{
		if (obj.opacity)
			obj.opacity = '1';
		if (obj.filter)
			obj.filter = '';
		if (obj.MozOpacity)
			obj.MozOpacity = '1';
	}
}

function disableObject(ID) {
	var obj = getObject(ID);
	if (obj)
		obj.disabled = true;
}

function enableObject(ID) {
	var obj = getObject(ID);
	if (obj)
		obj.disabled = false;
}

function switchEnabledDisabled(Items) {
	var disabledValue;
	var Index;
	var List;
	var obj;
	var func = getObject;
	if (typeof Items == 'string')
		List = new Array(Items);
	else
		List = Items;
	for (Index = 0; Index < List.length; Index++)
	{
		obj = func(List[Index]);
		if (!obj)
			return;
		disabledValue = obj.disabled;
		if (disabledValue)
			obj.removeAttribute('disabled');
		else
			obj.setAttribute('disabled', !disabledValue);
	}
}

// --- LookupComboBox functions ---

var LCBhasResults = false;
var LCBpreviousSearch = '';
var LCBresultCount = 0;
var LCBselectedItem = null;
var LCBlookupTimeout = null;

function handleLookupComboBoxKeyPress(e, id) {
	e = GetEventObj(e);
	var keyCode = GetEventKeyCode(e);
	switch (keyCode)
	{
		case 13: // Enter
		case 27: // Escape
		case 32: // space
		case 38: // Up
		case 40: // Down
			CancelEvent(e);
			break;
		case 35: // End
		case 36: // Home
		case 37: // left
		case 39: // right
				clearTimeout(LCBlookupTimeout);
				break;
		default:
			clearTimeout(LCBlookupTimeout);
			LCBlookupTimeout = setTimeout("AutoHideCombo('"+e+"', '"+id+"'); SubmitSearch('"+id+"', false)", 300);
	}
}

function handleLookupComboBoxKeyDown(e, id) {
	e = GetEventObj(e);
	var keyCode = GetEventKeyCode(e);
	var ctrlKey = GetEventCtrlKey(e);
	switch (keyCode)
	{
		case 9:
			Hide(id+'dropdown');
			break;
		case 8:	 // Backspace
		case 46: // Del
			handleLookupComboBoxKeyPress(e, id);
			break;
		case 13: // enter
			CancelEvent(e);
			SetComboField(id);
			break;
		case 27: // escape
			CancelEvent(e);
			Hide(id+'dropdown');
			break;
		case 32: // space
			 if (ctrlKey)
			 {
				 SubmitSearch(id, true);
				 AutoHideCombo(e, id);
			 }
			 break;
		case 35: // End
			 if (ctrlKey)
			 {
				 CancelEvent(e);
				 SelectLastSearchResult(id);
			 }
			 break;
		case 36: // Home
			 if (ctrlKey)
			 {
				 CancelEvent(e);
				 SelectFirstSearchResult(id);
			 }
			 break;
		case 38: // up
			CancelEvent(e);
			SelectPrevSearchResult(id);
			break;
		case 40: // down;
			CancelEvent(e);
			SelectNextSearchResult(id);
			break;
	}
}

function LookupCopyFields(e, id) {
	var source;
	var dest;
	source = getObjectById(id+'input');
	dest = getObjectById(id+'hidden');
	if (dest != null && source != null)
		dest.value = source.value;
}

function SelectSearchResult(id, Index, Top) {
	var doc;
	var Item;
	if (!LCBhasResults)
		return false;
	doc = getFrameByName(id+'dropdown');
	Item = doc.getObjectById('item'+Index);
	if (Item == null)
		return;
	if (LCBselectedItem)
		LCBselectedItem.className = 'ComboItem';
	Item.className = 'ComboItemOver';
	// if (Item.scrollIntoView)
	//	Item.scrollIntoView(Top);
	LCBselectedItem = Item;
}

function SelectFirstSearchResult(id) {
	SelectSearchResult(id, 1, true);
}

function SelectLastSearchResult(id) {
	SelectSearchResult(id, LCBresultCount, false);
}

function SelectNextSearchResult(id) {
	var Index;
	if (!LCBhasResults)
		return false;
	Index = 1;
	if (LCBselectedItem != null)
	{
		ID = LCBselectedItem.id;
		Index = StrToIntDef(ID.substr('item'.length, 4), 0)+1;
	}
	SelectSearchResult(id, Index, false);
}

function SelectPrevSearchResult(id) {
	var Index;
	if (!LCBhasResults)
		return false;
	Index = 1;
	if (LCBselectedItem != null)
	{
		ID = LCBselectedItem.id;
		Index = StrToIntDef(ID.substr('item'.length, 4), 0)-1;
	}
	SelectSearchResult(id, Index, true);
}

function SubmitSearch(id, Force) {
	var obj;
	var URL;
	var Value;
	clearTimeout(LCBlookupTimeout);
	obj = getObject(id+'input');
	LCBselectedItem = null;
	Value = obj.value;
	if (!Force)
	{
		if (Value == '')
		{
			Hide(id+'dropdown');
			return;
		}
/*
		if (Value.length <= 3)
			return false;
		if (!LCBhasResults && LCBpreviousSearch != '' && Value.indexOf(LCBpreviousSearch) == 0)
			return;
*/
	}
	LCBpreviousSearch = Value;
	URL = GetURL(id, true);
	LoadFrameURLObj(window, id+'dropdown', URL, true);
	Show(id+'dropdown');
}

function FillLookupComboBox(e, id) {
	var doc;
	var URL;
	var obj;
	var value;
	var Width;
	var Height;
	URL = GetURL(id, false);
	if (URL != '')
	{
		// Lookup mode with autocomplete
		if (isVisible(id+'dropdown'))
		{
			Hide(id+'dropdown');
			return;
		}
		LoadFrameURLObj(window, id+'dropdown', URL, true);
		Show(id+'dropdown');
		AutoHideCombo(e, id);
	}
	else
	{
		// simple dropdown mode
		if (isVisible(id+'dropdown'))
			return false; // will hide combo
		FillFrame(e, id+'dropdown', id+'content', null, null, true, null);
		ResizeLookupComboBox(id);
		ScrollSelected(id);
	}
}

function ScrollSelected(id) {
	var frm;
	var item;
	var pos;
	var obj;
	obj = getObject(id+'LookupComboBox');
	pos = obj.getAttribute('selected');
	if (pos == '')
		return;
	frm = window.frames[id+'dropdown'];
	item = frm.getObjectById('item'+pos);
	if (item)
		item.scrollIntoView(true);
}

function ResizeLookupComboBox(id) {
	var frm;
	var obj;
	var Height;
	var Width;
	var minWidth;
	var scrollObj;
	if (window.frames)
		frm = window.frames[id+'dropdown'];
	if (!frm || !frm.getObjectById)
		return;
	obj = getObject('Content');
	Width = frm.GetObjectWidth('items');
	Height = frm.GetObjectHeight('items');
	minWidth = GetObjectWidth(id+'LookupComboBox');
	if (Height > 200)
	{
		Width += 20; // Scrollbar width
		Height = 200;
	}
	if (Width < minWidth)
		Width = minWidth; // Align with combo component
	frm.SetObjectSize('scrollbox', Width, Height);
	SetObjectSize(id+'dropdown', Width, Height);
}

function AutoHideCombo(e, id) {
	var fn = function() { Hide(id+'dropdown'); removeEvent(document, 'click', fn); }
	addEvent(document, 'click', fn);
	CancelEvent(e);
}

function GetURL(id, getSearchedValue) {
	var obj;
	var URL = '';
	if (obj = getObject(id+'LookupComboBox'))
	{
		URL = obj.getAttribute('url');
		if (URL == null)
			return '';
		if (getSearchedValue == true)
			if (obj = getObject(id+'input'))
				URL += '&SearchValue='+obj.value;
		if (obj = getObject(id+'hidden'))
			URL += '&Value='+obj.value;
	}
	return URL;
}

function SetComboFieldValue(id, position, value, caption) {
	var obj;
	obj = getObjectById(id+'LookupComboBox');
	obj.setAttribute('selected', position);
	obj = getObject(id+'hidden');
	if (obj)
		obj.value = value;
	obj = getObject(id+'input');
	if (obj)
		obj.value = caption;
}

function SetComboField(id, position) {
	var caption;
	var frm;
	var item;
	var value;
	frm = getFrameByName(id+'dropdown');
	if (position != null && frm.getObjectById)
		item = frm.getObjectById('item'+position);
	if (item == null)
		item = LCBselectedItem;
	if (item == null && frm.getObjectById)
		item = frm.getObjectById('item1');
	if (item == null)
		return false;
	value = item.getAttribute('value');
	caption = item.getAttribute('caption');
	SetComboFieldValue(id, position, value, caption);
	Hide(id+'dropdown');
}

// --- ActionPanel functions ---
function apHeaderOver(ID) {
	var func = getObjectById;
	func('apHeaderLabel'+ID).className = 'apHeader_over';
	apHeaderImageID = func('apHeaderImage'+ID);
	apContentID = func('apContent'+ID);
	imageSource = 'collapse_over';
	if (apContentID.style.display == 'none')
		imageSource = 'expand_over';
	apHeaderImageID.src = XMLC_SkinPath+'actionpanel/'+imageSource+'.gif';
}

function apHeaderOut(ID) {
	var func = getObjectById;
	func('apHeaderLabel'+ID).className = 'apHeader';
	apHeaderImageID = func('apHeaderImage'+ID);
	apContentID = func('apContent'+ID);
	imageSource = 'collapse';
	if (apContentID.style.display == 'none')
		imageSource = 'expand';
	apHeaderImageID.src = XMLC_SkinPath+'actionpanel/'+imageSource+'.gif';
}

function apHeaderOver_dark(ID) {
	var func = getObjectById;
	func('apHeaderLabel'+ID).className = 'apHeader_over_dark';
	apHeaderImageID = func('apHeaderImage'+ID);
	apContentID = func('apContent'+ID);
	imageSource = 'collapse_over_dark';
	if (apContentID.style.display == 'none')
		imageSource = 'expand_over_dark';
	apHeaderImageID.src = XMLC_SkinPath+'actionpanel/'+imageSource+'.gif';
}

function apHeaderOut_dark(ID) {
	var func = getObjectById;
	func('apHeaderLabel'+ID).className = 'apHeader_dark';
	apHeaderImageID = func('apHeaderImage'+ID);
	apContentID = func('apContent'+ID);
	imageSource = 'collapse_dark';
	if (apContentID.style.display == 'none')
		imageSource = 'expand_dark';
	apHeaderImageID.src = XMLC_SkinPath+'actionpanel/'+imageSource+'.gif';
}

function apShowHide(ID) {
	ShowHide('apContent'+ID, 'IMG', 'apHeaderImage'+ID, '+', XMLC_SkinPath+'actionpanel/collapse_over.gif', '-', XMLC_SkinPath+'actionpanel/expand_over.gif');
}

function apShowHide_dark(ID) {
	ShowHide('apContent'+ID, 'IMG', 'apHeaderImage'+ID, '+', XMLC_SkinPath+'actionpanel/collapse_over_dark.gif', '-', XMLC_SkinPath+'actionpanel/expand_over_dark.gif');
}

// --- WizardBar functions ---
function wbStepOver(obj, infos) {
	obj.className = 'wbStepOver';
	obj.background = XMLC_SkinPath+'wizardbar/wb_step_over.gif';
	SetContent('wbInfos', infos);
}

function wbStepOut(obj, infos) {
	obj.className = 'wbStep';
	obj.background = XMLC_SkinPath+'wizardbar/wb_step.gif';
	SetContent('wbInfos', infos);
}

// --- ProgressBar functions ---

function setInfos(infos) {
	if (infos == '')
		infos = 'No information available';
	SetContent('MenuInfos', infos);
}

function setPgb(pgbID, pgbValue) {
	var pgbObj;
	if (pgbObj = getObject(pgbID))
		pgbObj.width = pgbValue + '%';
	SetContent(pgbID+'_label', pgbValue + '%');
}

function addLog(Value) {
	var logObj;
	var logContent;
	var logScroll;

	logObj = getObjectById('logMain');
	if (logObj === null)
		return;
	logContent = getObjectById('logContent');
	if (logContent == null)
	{
		AppendContent(logObj, Value);
		scrollObj(logObj);
		return;
	}
	else
	{
		AppendContent(logContent, Value);
	}
	logScroll = getObjectById('logScroll');
	if ((logScroll) && (logScroll.scrollIntoView))
	{
		logScroll.scrollIntoView(false);
	}
}

function scrollObj(ID) {
	var doc;
	var body;
	var obj = getObject(ID);
	if (obj.doScroll)
	{
		obj.doScroll('pageDown');
		return;
	}
	if (obj.document)
		doc = obj.document;
	else if (obj.contentDocument)
		doc = obj.contentDocument;
	else if (obj.contentWindow)
		doc = obj.contentWindow.document;
	if (doc == null)
		return;
	body = doc.body;
	if (body == null)
		return;
	if (body.doScroll)
	{
		body.doScroll('pageDown');
		return;
	}
	if (body.scrollBy)
	{
		body.scrollBy(0, 8000);
		return;
	}
}

function showWizardBar(ShowDDALabel) {
	var DDA;
	var topFunc;
	var Menu;
	if (!top || !top.getElementById)
		return;
	DDA = top.getElementById('frmDDAWizardBar');
	if (!DDA)
		return false;
	Menu = top.getElementById('frmXMLRadWithDDA');
	var url = XMLC_BaseHRef+'DDAWizardBar?ProjectName='+ProjectName;
	if (DDA.src.indexOf(url) == -1)
		DDA.src = url;
	if (ShowDDALabel == '1')
		Menu.rows = '*,110';
	else
		Menu.rows = '*,81';
}

function hideWizardBar() {
	var DDA;
	if (top)
	{
		if (top.getElementById)
			DDA = top.getElementById('frmXMLRadWithDDA');
		else if (top.document.all)
			DDA = top.document.all('frmXMLRadWithDDA')
	}
	if (DDA)
		DDA.rows = '*,0';
}

function refreshXMLRADMenu(ProjectName, XMLModule, XMLService, Queries, Query) {
	var frame;
	frame = top.frames['menu'];
	if (frame && frame.refreshMenu)
		frame.refreshMenu(XMLModule, XMLService, Queries, Query);
	else
		reloadXMLRADMenu(ProjectName, XMLModule, XMLService, Queries, Query);
}

function reloadXMLRADMenu(ProjectName, XMLModule, XMLService, Queries, Query) {
	var MainAction;
	var Params = '';
	if (ProjectName != null && ProjectName != '')
	{
		Params = '?ProjectName='+ProjectName;
		if (XMLModule != null && XMLModule != '')
			Params += '&XMLModule='+XMLModule;
		if (XMLService != null && XMLService != '')
			Params += '&XMLService='+XMLService;
		if (Queries != null && Queries != '')
			Params += '&Queries='+Queries;
		if (Query != null && Query != '')
			Params += '&Query='+Query;
	}
	if (!top || !top.frames['menu'])
		document.location.href = XMLC_BaseHRef+'Default'+Params+'&OpenApplicationMode=1';
	else if (Params == '')
		top.frames['menu'].document.location.href = XMLC_BaseHRef+'Menu?OpenApplicationMode=1';
	else
		top.frames['menu'].document.location.href = XMLC_BaseHRef+'Menu'+Params+'&OpenApplicationMode=1';
}
// --- DatePicker functions ---
// ON 20040601 - Uncomment once XMLRAD and Delos share Portal
// var datePickerImages = new Array();
// datePickerImages['normal'] = new Image(16,16);
// datePickerImages['over'] = new Image(16,16);
// datePickerImages['down'] = new Image(16,16);
// datePickerImages['normal'].src = XMLC_SkinPath + 'datepicker/datepicker.gif';
// datePickerImages['over'].src = XMLC_SkinPath + 'datepicker/datepicker_over.gif';
// datePickerImages['down'].src = XMLC_SkinPath + 'datepicker/datepicker_down.gif';
