// Main script file for Delos 7G
// Contain XCheck.js, XForms.js, XRollover.js, XShowHide.js

// xslc.js version = used to check generated HTML and xslc.js on the client
var xslc_version = '7.0.0.1000';
function CheckPortalVersion(ClientVersion, MessageID, Callback) {
  if (ClientVersion == xslc_version)
  {
    if (MessageID != null && MessageID != '')
      Hide(MessageID);
    if (Callback != null && Callback != '')
      eval(Callback);
  }
}

// --- Browser detection script functions ---
function checkBrowser(){
  this.agent = navigator.userAgent.toLowerCase();
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.gecko=(this.agent.indexOf('gecko')>-1)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie55=((this.ver.indexOf("MSIE 5.5")>-1 || this.ie6) && this.dom)?1:0;
	this.ie5=((this.ver.indexOf("MSIE 5")>-1 || this.ie5 || this.ie6) && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.ie4plus=(this.ie6 || this.ie5 || this.ie4);
	this.ie5plus=(this.ie6 || this.ie5)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns5);
	return this;
}

bw = new checkBrowser();

function getObjectById(ID) {
	var obj;
	if (document.getElementById)
		return document.getElementById(ID);
	else if (document.all)
		return document.all(ID);
	else
		return eval('document.' + ID);
}

if (!document.getElementById)
	document.getElementById = getObjectById;

function getElementByID(ID) {
	return getObjectById(ID);
}

function getObject(obj) {
	if (typeof obj == 'string')
	{
		if (result = getObjectById(obj))
			return result;
	} 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 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 ShowHide(Items) {
  var Alpha = -1;
  var arg = arguments;
  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);

  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';
      if (Show == '1')
      {
        obj.style.visibility = 'visible';
        obj.style.display = '';
      }
      else
      {
        obj.style.visibility = 'hidden';
        obj.style.display = 'none';
      }
      if (Height != -1) obj.style.height = Height + 'px';
      if (Width != -1) obj.style.width = Width + 'px';
      if (MaxHeight == 1) obj.style.height = (document.body.clientHeight - obj.offsetTop - 15) + 'px';
      if (MaxWidth == 1) obj.style.width = (document.body.clientWidth - obj.offsetLeft - 15) + 'px';
      if (Alpha != -1) obj.style.filter = 'alpha(opacity='+Alpha+')';
    }
    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) {
	var obj;
	if (obj = getObject(ID)) {
		obj.style.visibility = 'visible';
		obj.style.display = '';
	}
}

function Hide(ID) {
	var obj;
	if (obj = getObject(ID)) {
		obj.style.visibility = 'hidden';
		obj.style.display = 'none';
	}
}

function isVisible(ID) {
	var obj;
	var result;
	result = true;
	if (obj = getObject(ID))
		result = obj.style.display == 'none' ? false : true;
	return result;
}

// --- Rollover functions ---

function SwapImages(btn, Prefix, Suffix, Folder) {
	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.setAttribute('background', Path + 'main' + Suffix + '.gif', 0);
		if (cell = row.cells[2])
			if (obj = cell.childNodes[0])
				obj.setAttribute('src', Path + 'right' + Suffix + '.gif', 0);
  }
	else if (btn.all)
	{
		if (obj = btn.all.BtnLeft)	obj.src = Path + 'left' + Suffix + '.gif';
		if (obj = btn.all.BtnMain)	obj.background = Path + 'main' + Suffix + '.gif';
		if (obj = btn.all.BtnRight) obj.src = Path + 'right' + Suffix + '.gif';
	}
}

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) {
	var obj;
	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);
	FillFrame(e, ID+'Menu', ID+'Content', Width, Height, true, ID);
	X = GetObjectPosX(ID);
	Y = GetObjectPosY(ID)+GetObjectHeight(ID);
	MoveObject(ID+'Menu', X, Y);
}

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) {
	var obj;
	if (obj = getObjectById(ID))
		obj.className = Class;
}

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))
	{
		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;
	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;
	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 Trim(S) {
	if (!S)
		return '';
	while (S.substring(0, 1) == ' ')
		S = S.substring(1, S.length);
	while (S.substring(S.length-1, S.length) == ' ')
		S = S.substring(0, S.length-1);
	return S;
}

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 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 = targ.parentNode;
	return obj;
}

// --- Form functions ---

function SubmitForm(FormName) {
	var arg = arguments;
	var i = 0;
	var ConfirmQuestion = '';
	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])
		{
			case 'ACTION': F.action = arg[++i]; break;
			case 'TARGET': F.target = arg[++i]; break;
			case 'CONFIRM': ConfirmQuestion = arg[++i]; break;
		}
	}
	if (ConfirmQuestion != '')
	{
		if (confirm(ConfirmQuestion) == false)
			return false;
	}
	if (F.onsubmit && typeof(F.onsubmit) == 'function')
		if (F.onsubmit() == false)
			return false;

	F.submit();
	return true;
}

function handleFormKeyPress(FormName, e) {
	var obj;
	var keyCode = GetEventKeyCode(e);
	if (keyCode == 13)
		SubmitForm(FormName);
}

function ConfirmDelete(FormName, DeleteAction, Prompt) {
	var F = document.forms[FormName];
	if (confirm(Prompt)) {
		F.action = DeleteAction;
		F.submit();
	}
}

function SetFormAction(FormName, Action) {
	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 value = '';
	E = GetFieldObj(FormName, FieldName);
	if (E)
    return E.value;
}

function GetValue(ID) {
	var obj;
	if (obj = getObject(ID))
		return obj.value;
}

function GetFieldObj(FormName, FieldName) {
	if (F = document.forms[FormName])
		return F.elements[FieldName];
}

// --- 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;
	for (i = LBound; i <= HBound; i++)
	{
		if (obj = getObjectById(FieldName1 + i.toString() + FieldName2))
			obj.checked = Checked;
	}
}
function GetValue(ID) {
	var obj;
	if (obj = getObject(ID))
		return obj.value;
}

function Check(FieldName1, FieldName2, LBound, HBound) {
	for (i = LBound; i <= HBound; i++)
		CheckObject(FieldName1 + i + FieldName2);
}

function Uncheck(FieldName1, FieldName2, LBound, HBound) {
	for (i = LBound; i <= HBound; i++)
		UncheckObject(FieldName1 + i + FieldName2);
}

function SwitchCheckbox(ID) {
	var obj;
	if (obj = getObject(ID))
		obj.checked = !(obj.checked);
}

function SwitchState(FieldName1, FieldName2, LBound, HBound) {
	var i;
	for (i = LBound; i <= HBound; i++)
		SwitchCheckbox(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;

	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);
	if (bw.gecko) // ON 20051206 substract padding made Moz behave correctly for main window
	{
    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;
}

function GetObjectHeight(ID)
{
	var obj = getObject(ID);
	if (obj == null)
		return;
	if (obj.offsetHeight)
		return obj.offsetHeight;
	else if (obj.style.pixelHeight)
		return obj.style.pixelHeight;
}

function GetObjectWidth(ID)
{
	var obj = getObject(ID);
	if (obj == null)
		return;
	if (obj.offsetWidth)
		return obj.offsetWidth;
	else 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;
	objRight = GetObjectWidth(ID)+X;
	WindowWidth = GetWindowWidth(window);
	if (objRight > WindowWidth)
		X = WindowWidth - objRight;
	if (X < 0)
		X = 0;
	obj.style.top = Y;
	obj.style.left = X;
}

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';
}

// --- 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)
		result = wnd.document.body.offsetWidth + WidgetWidth;
	else if (wnd.innerHeight)
		result = wnd.innerWidth + WidgetWidth;
	return result;
}

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) {
	if (wnd == null)
		wnd = window;
	if (wnd.document)
		if (wnd.document.body)
			if (wnd.document.body.clientHeight)
		return wnd.document.body.clientHeight;
}

function GetWindowInnerWidth(wnd) {
	if (wnd == null)
		wnd = window;
	if (wnd.document)
		if (wnd.document.body)
			if (wnd.document.body.clientWidth)
		return wnd.document.body.clientWidth;
}

function TileWindows(Width) {
	var main;
	var ScreenX, ScreenY, Width;
	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 > ScreenX)
			{
				popupScreenX = 2 * ScreenX
				ScreenLeft = ScreenX;
			}
		}
		window.resizeTo(Width, ScreenY);
		window.moveTo(popupScreenX - Width, 0);
		if (window.opener != null)
		{
			main = window.opener;
			if (main.top != null)
				main = main.top;
			if (main == null)
				return;
			main.window.moveTo(ScreenLeft, 0);
			main.window.resizeTo(ScreenX - Width , ScreenY);
		}
	} 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) {
	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 != -1)
		{
			if (obj.style)
			{
				obj.style.pixelWidth = Width;
				obj.style.width = Width;
			}
			if (obj.width)
				obj.width = Width;
		}
		if (Height != '' && Height != -1)
		{
			if (obj.style)
			{
				obj.style.pixelHeight = Height;
				obj.style.height = Height;
			}
			if (obj.height)
				obj.height = Height;
		}
	}
}

function ResizeFrameFromContent(doc, ID, Width, Height) {
	var Height, Width;
	if (doc == null) return;
	if (doc.body == null) return;
	if (Height == null) Height = '';
	if (Width == null) Width = '';

	if (Height == '')
	{
		if (doc.body.style && doc.body.style.height) Height = doc.body.style.height;
		if (Height == '' && doc.body.scrollHeight) Height = doc.body.scrollHeight;
		if (Height == '' && doc.body.offsetHeight) Height = doc.body.offsetHeight;
	}
	if (doc.getObjectById)
		if (obj = doc.getObjectById('Content'))
			if (obj.clientWidth)
			  Width = obj.clientWidth;
	if (Width == '')
	{
		if (doc.body.style && doc.body.style.width) Width = doc.body.style.width;
		if (Width == '' && doc.body.scrollWidth) Width = doc.body.scrollWidth;
		if (Width == '' && doc.body.offsetWidth) Width = doc.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, content, 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;
			PushedButton = ButtonID;
			if (doc.body.innerHTML == '')
			{
				if (content = getObject(ContentID))
					doc.body.innerHTML = content.innerHTML;
				ResizeFrameFromContent(doc, FrameID, Width, Height);
			}
		}
		if (AutoHide)
		{
			if (show)
			{
				document.body.onclick = HideFilledFrame;
				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 = '';
	}
	document.body.onclick = null;
}

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))
    return true;
  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;
	}
}

// --- 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');
	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');
	if (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 UpdateApplicationMessages(Text) {
	var obj;
	if (Text == '')
	{
		Hide('xslcApplicationMessages');
		return false;
	}
	obj = getObjectById('xslcApplicationMessages');
	if (obj)
	{
		obj.innerHTML = Text;
		Show('xslcApplicationMessages');
	}
}

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) {
	if (CallbackFunc == null)
		CallbackFunc = '';
	if (EndFieldName == null)
		EndFieldName = '';
	if (Form == null)
		Form = 'MainForm';
	if (show == null)
		show = !(isVisible(PopID));
	if (show)
	{
		if (Pop = getObjectById(PopID))
		{
			CalendarURL = XMLC_BaseHRef+'CalendarPopup?FieldName='+FieldName;
			CalendarURL += '&AutoResize=1';
			CalendarURL += '&CALENDAR_DATE='+ GetFieldValue(Form, FieldName);
			CalendarURL += '&HTMLForm='+ Form;
			CalendarURL += '&PopID=' + PopID;
			if (CallbackFunc != '')
				CalendarURL += '&CallbackFunc=' + CallbackFunc;
			if (EndFieldName != '')
				CalendarURL += '&EndFieldName=' + EndFieldName;
			Pop.src = CalendarURL;
			Show(PopID);
			document.body.onclick = function () { Hide(PopID); document.body.onclick = null; };
			CancelEvent(e);
		}
	}
	else
	{
		Hide(PopID);
		document.body.onclick = null;
	}
}

function GetStartingRow(Index, PageCount, MaxRows) {
  Index = StrToIntDef(Index, 1);
  if (Index < 1)
    Index = 1;
  PageCount = StrToIntDef(PageCount, 0);
  if (PageCount != 0 && Index > PageCount)
    Index = PageCount;
  MaxRows = StrToIntDef(MaxRows, 1);
  return (Index-1) * (MaxRows-1);
}

function handlePageNumberKeyPressForm(e, Value, PageCount, MaxRows, RecordName, Form, Click) {
  var StartingRow;
  var keyCode = GetEventKeyCode(e);
  if (keyCode != 13)
    return true;
  StartingRow = GetStartingRow(Value, PageCount, MaxRows);
  Param = RecordName+'_StartingRow';
  SetField(Form, Param, StartingRow);
  eval(Click);
  return false;
}

function handlePageNumberKeyPress(e, Value, PageCount, MaxRows, CommonURL, URLParams) {
  var StartingRow;
  var keyCode = GetEventKeyCode(e);
  if (keyCode != 13)
    return true;
  StartingRow = GetStartingRow(Value, PageCount, MaxRows);
  CommonURL = CommonURL+StartingRow+URLParams;
  document.location.href = CommonURL;
  return false;
}

function lookupPermissions(K_ID, KUSR_ID)
{
	var URL;
	URL = XMLC_BaseHRef + 'FormKRH?K_ID=' + K_ID + '&KUSR_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;
  if (frm = document.frames[FrameID])
  {
    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';

  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) {
  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){
  var obj;
  SetField('MainForm', FieldName, '');
  obj = getObjectById('div'+FieldName);
  if (obj)
    obj.innerHTML = '';
  Hide('img'+FieldName);
  Show('divAttach'+FieldName);
}

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) {
	formName_ = formName;
	fieldName_ = fieldName;
	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 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) {
	field.valueIsNotValid = false;
	if ((notnull = getNamedAttribute(field, 'notnull')) && (field.value == ''))
	{
		 field.className = 'FieldError';
		 field.valueIsNotValid = true;
	}
}

function focusField(formName, fieldName) {
	formName_ = formName;
	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) {
	formName_ = formName;
	recordName_ = recordName;
	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) {
	formName_ = formName;
	recordName_ = recordName;
	var arg = arguments;
	if (arg.length == 1)
	{
		formName_ = 'MainForm';
		recordName_ = arg[0];
	}
	setField('MainForm', recordName_+'.XMLC_Operation', 'Insert');
	submitForm('MainForm');
	return false;
}

// --- Misc functions ---

function navigate(URL) {
	location.href = XMLC_BaseHRef + URL;
	return false;
}

// --- DHTML functions ---

function getObjectStyle(obj) {
	if (theObj = getObject(obj))
		return theObj.style;
}

function hide(obj) {
	if (theObj = getObjectStyle(obj))
		theObj.display = 'none';
}

function show(obj) {
	if (theObj = getObjectStyle(obj))
		theObj.display = 'block';
}

function showhide(obj) {
	if (theObj = getObjectStyle(obj)) {
		if (theObj.display == 'none')
			show(obj);
		else
			hide(obj);
	}
}

function showhide2(objToShowHideID, objButtonID, imgShow, imgHide) {
	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'; }
	if (theObj = getObject('MenuInfos'))
		theObj.innerHTML = 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 Index;
  var List;
  var obj;
  if (typeof Items == 'string')
    List = new Array(Items);
  else
    List = Items;
  for (Index = 0; Index < List.length; Index++)
  {
    obj = getObject(List[Index]);
	if (obj)
		obj.disabled = !obj.disabled;
}
}

// --- ActionPanel functions ---
function apHeaderOver(ID) {
	getObjectById('apHeaderLabel'+ID).className = 'apHeader_over';
	apHeaderImageID = getObjectById('apHeaderImage'+ID);
	apContentID = getObjectById('apContent'+ID);
	imageSource = 'collapse_over';
	if (apContentID.style.display == 'none')
		imageSource = 'expand_over';
	apHeaderImageID.src = XMLC_SkinPath+'actionpanel/'+imageSource+'.gif';
}

function apHeaderOut(ID) {
	getObjectById('apHeaderLabel'+ID).className = 'apHeader';
	apHeaderImageID = getObjectById('apHeaderImage'+ID);
	apContentID = getObjectById('apContent'+ID);
	imageSource = 'collapse';
	if (apContentID.style.display == 'none')
		imageSource = 'expand';
	apHeaderImageID.src = XMLC_SkinPath+'actionpanel/'+imageSource+'.gif';
}

function apHeaderOver_dark(ID) {
	getObjectById('apHeaderLabel'+ID).className = 'apHeader_over_dark';
	apHeaderImageID = getObjectById('apHeaderImage'+ID);
	apContentID = getObjectById('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) {
	getObjectById('apHeaderLabel'+ID).className = 'apHeader_dark';
	apHeaderImageID = getObjectById('apHeaderImage'+ID);
	apContentID = getObjectById('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';
	if (wbInfosObj = getObjectById('wbInfos'))
		wbInfosObj.innerHTML = infos;
}

function wbStepOut(obj, infos) {
	obj.className = 'wbStep';
	obj.background = XMLC_SkinPath+'wizardbar/wb_step.gif';
	if (wbInfosObj = getObjectById('wbInfos'))
		wbInfosObj.innerHTML = infos;
}

// --- ProgressBar functions ---

function setInfos(infos) {
	if (infos == '')
		infos = 'No information available';
	if (theObj = getObjectById('MenuInfos'))
		theObj.innerHTML = infos;
}

function setPgb(pgbID, pgbValue) {
	if (pgbObj = getObject(pgbID))
		pgbObj.width = pgbValue + '%';
	if (lblObj = getObjectById(pgbID+'_label'))
		lblObj.innerHTML = pgbValue + '%';
}

function addLog(Value) {
	if (logObj = getObjectById('logMain'))
	{
		logObj.innerHTML = logObj.innerHTML + Value;
		scrollObj(logObj);
	}
}

function scrollObj(ID) {
  	var obj = getObject(ID);
	if (logObj.doScroll)
		logObj.doScroll('pageDown');
	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;
	if (doc.body == null)
		return;
	if (doc.body.doScroll)
	{
		doc.body.doScroll('pageDown');
		return;
	}
	if (doc.body.scrollBy)
	{
		doc.body.scrollBy(0, 8000);
		return;
	}
}

function showWizardBar(ShowDDALabel) {
	var DDA
	if (top.getElementById)
		DDA = top.getElementById('frmDDAWizardBar');
	else if (top.document.all)
		DDA = top.document.all('frmDDAWizardBar')

	if (!DDA)
		return false;
	var url = XMLC_BaseHRef+'DDAWizardBar?ProjectName='+ProjectName;
	if (DDA.src.indexOf(url) == -1)
		DDA.src = url;

	if (top.getElementById)
		Menu = top.getElementById('frmXMLRadWithDDA');
	else if (top.document.all)
		Menu = top.document.all('frmXMLRadWithDDA')
	Menu = getParentObjectById('frmXMLRadWithDDA');
	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';
