// Main script file for Delos 7G
// Contain XCheck.js, XForms.js, XRollover.js, XShowHide.js

// --- Javascript string variables (used to localize messages) ---
var errorMessageNotNull = 'You must fill this field: ';
var questionDeleteRecordBegin = 'Are you sure you want to delete this ';
var questionDeleteRecordEnd = ' ?\nClick OK to confirm.';

// --- Browser detection script functions ---
function checkBrowser(){
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?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();

if (!document.getElementById) {
	document.getElementById = getObjectById;
}

function getObjectById(ID) {
	var obj;
	if (bw.dom)
		return document.getElementById(ID);
	else if (bw.ie4)
		return document.all(ID);
	else if (bw.ns4)
		return eval('document.' + ID);
}

function getElementByID(ID) {
	return getObjectById(ID);
}

function getNamedAttribute(field, name) {
	var att = null
	if (field.attributes)
	{
		if (field.attributes.getNamedItem)
			att = field.attributes.getNamedItem(name);
	} else {
		att = eval(field + "." + name);
	}
	return att;
}

// --- Forms keypress functions ---
function handleFormKeyPress(form) {
	var keyCode = GetEventKeyCode();
	if (keyCode == 13)
		form.submit();
}

function ConfirmDelete(formName, DeleteAction, Prompt) {
	D = document.forms[formName];
	if (confirm(Prompt)) {
		D.action = DeleteAction;
		D.submit();
	}
}

// --- Showhide functions ---
function ShowHideOld(DivID) {
	var arg = arguments;
	var DivObject;
	var i = 0;
	var ImageID;
	var ImageObject;
	var ImagePlus;
	var ImageMinus;
	var Width = -1;
	var Height = -1;
	var MaxWidth = 0;
	var MaxHeight = 0;
	var Show = true;
	var Alpha	= -1;
	
	if (DivObject = getObjectById(DivID)) {
		Show = (DivObject.style.visibility == 'hidden');
		if (Show) {
			DivObject.style.visibility = 'visible';
			DivObject.style.display = '';
		}
		else {
			DivObject.style.visibility = 'hidden';
			DivObject.style.display = 'none';
		}	
		for (i=0; i<arg.length; i++) {
			switch(arg[i])
			{
				case 'IMG': ImageID = arg[++i]; break;
				case '+': ImagePlus = arg[++i]; break;
				case '-': ImageMinus = arg[++i]; break;
				case 'WIDTH': Width = arg[++i]; break;
				case 'HEIGHT': Height = arg[++i]; break;
				case 'MAXWIDTH': MaxWidth = 1; break;
				case 'MAXHEIGHT': MaxHeight = 1; break;
				case 'ALPHA': Alpha = arg[++i]; break;
			}
		}
		if (ImageObject = getObjectById(ImageID)) {
			if (Show)
				ImageObject.src = ImageMinus;
			else 
				ImageObject.src = ImagePlus;
		}
		if (Height != -1) DivObject.style.height = Height + 'px';
		if (Width != -1) DivObject.style.width = Width + 'px';
		if (MaxHeight == 1) DivObject.style.height = (document.body.clientHeight - DivObject.offsetTop - 15) + 'px';
		if (MaxWidth == 1) DivObject.style.width = (document.body.clientWidth - DivObject.offsetLeft - 15) + 'px';
		if (Alpha != -1) DivObject.style.filter = 'alpha(opacity='+Alpha+')';
	}
}

function ShowHide(Items) {
  var Alpha = -1;
  var arg = arguments;
  var obj;
  var Height = -1;
  var i;
  var ImageID;
  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') ImageID = 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;

  for (Index = 0; Index < List.length; Index++) {
    if (obj = getObjectById(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 (img = getObjectById(ImageID))
    {
      if (Show == '1')
        img.src = ImageMinus;
      else
        img.src = ImagePlus;
    }
  }
}

function Show(ID) {
	var obj;
	if (obj = getObjectById(ID)) {
		obj.style.visibility = 'visible';
		obj.style.display = '';
	}
}

function Hide(ID) {
	var obj;
	if (obj = getObjectById(ID)) {
		obj.style.visibility = 'hidden';
		obj.style.display = 'none';
	}
}

function isVisible(ID) {
	var obj;
	var result;
	result = true;
	if (obj = getObjectById(ID))
		result = obj.style.display == 'none' ? false : true;
	return result;
}

function TileWindows(Width) {
	var main;
	var ScreenX, ScreenY, Width;
	ScreenX = screen.availWidth;
	ScreenY = screen.availHeight;
	if (Width == '' || Width == null)
		Width = 200;
	try
	{
		window.resizeTo(Width, ScreenY);
		window.moveTo(ScreenX - Width, 0);
		if (window.opener != null)
		{
			main = window.opener;
			if (main.top != null)
				main = main.top;
			if (main == null)
				return;
			main.window.moveTo(0, 0);
			main.window.resizeTo(ScreenX - Width , ScreenY);
		}
	} catch (e) { 
		// do nothing 
	}
}

function MaximizeWindow(wnd) {
	if (wnd == null)
		wnd = self.top;
	if (wnd == null)
		return;
	try {
		wnd.moveTo(0, 0);
		wnd.resizeTo(screen.availWidth , screen.availHeight);
	} catch (e) {
		// do nothing
	}
}

// --- 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
		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')
	{
		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 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 = getObjectById(ID))
	{
		obj.focus();
		if (Begin == false)
		{
			if (obj.createTextRange)
			{
				txt = obj.createTextRange();
				txt.collapse(false);
				txt.select();
			}
		}
		if (Select == true)
		{
			obj.select();
		}
	}
}

function SelectText(ID) {
	var obj, txt;
	if (obj = getObjectById(ID))
	{
		if (obj.createTextRange)
		{
			txt = obj.createTextRange();
			txt.select();
		}
	}
}

function MoveCaret(ID, Pos) {
	var obj;
	if (obj = getObjectById(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;
}

// Event functions

function GetEventObj(e) {
	if (e) return e;
	else return window.event;
}

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;
}

// --- Form functions ---

function SubmitForm(FormName) {
	var arg = arguments;
	var i = 0;
	var ConfirmQuestion = '';
	if (F = document.forms[FormName])
	{		
		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))
				F.submit();
		} else {
			F.submit();
		}
	}
}

function SetField(FormName, FieldName, FieldValue) {
	if (F = document.forms[FormName])
		if (E = F.elements[FieldName])
			E.value = FieldValue;
}

function GetFieldValue(FormName, FieldName) {
	return GetField(FormName, FieldName);
}

function GetField(FormName, FieldName) {
	var value = '';
	if (F = document.forms[FormName])
		if (E = F.elements[FieldName])
			value = E.value;
	return value;
}

function GetValue(ID) {
	var obj;
	if (obj = getObjectById(ID))
		return obj.value;
}

// --- CheckBoxes functions ---

function CheckObject(ID) {
	var obj;
	if (obj = getObjectById(ID))
		obj.checked = true;
}

function UncheckObject(ID) {
	var obj;
	if (obj = getObjectById(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 = getObjectById(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 = getObjectById(ID))
		obj.checked = !(obj.checked);
}

function SwitchState(FieldName1, FieldName2, LBound, HBound) {
	var i;
	for (i = LBound; i <= HBound; i++)
		SwitchCheckbox(FieldName1 + i + FieldName2);
}

// ---

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;
	return window.open(URL, Name, Params); 
}

function confirmDeleteEvent(ConfirmText) {
	return(confirm(ConfirmText));
}

function Resize(ID, Width, Height) {
	var obj;
	if (obj = getObjectById(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.getElementById)
		if (obj = doc.getElementById('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;
	if (frame = window.frames[Name])
		return frame;
	if (frame = document.getElementsByTagName("FRAMESET").item(Name))
		return frame;
	else if (frame = parent.document.getElementsByTagName("FRAMESET").item(Name))
		return frame;
	else if (frame = top.document.getElementsByTagName("FRAMESET").item(Name))
		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 = getObjectById(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 = '';

function FillFrame(FrameID, ContentID, Width, Height, AutoHide) {
	var doc, content, shown;
	if (AutoHide == null) AutoHide = false;
	if (doc = GetFrameDoc(FrameID))
	{
		show = !(isVisible(FrameID));
		if (show)
		{
			if (OpenedFrameID != '')
				Hide(OpenedFrameID);
			Show(FrameID);
			OpenedFrameID = FrameID;
			if (doc.body.innerHTML == '')
			{
				if (content = getObjectById(ContentID))
					doc.body.innerHTML = content.innerHTML;
				ResizeFrameFromContent(doc, FrameID, Width, Height);
			}
		}
		else
		{
			Hide(FrameID);
		}
		if (AutoHide && window.event) // !!! Should support Mozilla
		{
			if (show)
			{
				document.body.onclick = HideFilledFrame;
				CancelEvent();
			}
			else
			{
				document.body.onclick = null;
			}
		}
		if (show)
			return true;
	}
	return false;
}

function HideFilledFrame() {
	if (OpenedFrameID && OpenedFrameID != '')
		Hide(OpenedFrameID);
	document.body.onclick = null;
}

function LoadFrameURLObj(obj, FrameID, URL, Force)
{
  var frm;
  var CurrentURL;
  if (Force == null || Force == '')
    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) {
  if (LoadFrameURLObj(parent, FrameID, URL)) return;
  if (LoadFrameURLObj(top, FrameID, URL)) return;
  if (LoadFrameURLObj(window, FrameID, URL)) return;
  parent.document.location.href = URL;
}

// --- Delos functions ---

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) {
  if (CallbackFunc == null) CallbackFunc = '';
	if (EndFieldName == null) EndFieldName = '';
	if (Form == null) Form = 'MainForm';
  if (show == null) show = !(isVisible(PopID));
  if (show)
  {
    if (Pop = getElementByID(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();
    }
  }
  else
  {
    Hide(PopID);
    document.body.onclick = null;
  }
}


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(FrameID, ContentID, TimeFieldName) {
  var id;
  var frm;
  var show;
  show = FillFrame(FrameID, ContentID, '60', '180', true);
  if (!(show)) return;
  if (frm = document.frames[FrameID])
  {
    if (frm.SetFocus)
    {
      id = GetField('MainForm', TimeFieldName);
      frm.SetFocus(id);
    }
  }
}

// --- 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))
			{
				F.submit();
				enableUI();
			} else {
				F.action = oldAction;
				F.target = oldTarget;
				enableUI();
			}
		}
		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 getObject(obj) {
	if (typeof obj == 'string') {
		if (result = getObjectById(obj))
			return result;
	}
	else {
		return obj;
	}
}

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('body');
}

function enableUI() {
	enable('body');
}

function disable(obj) {
	if (bw.ie5plus)
		if (theObj = getObjectStyle(obj))
			theObj.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
}

function enable(obj) {
	if (bw.ie5plus)
		if (theObj = getObjectStyle(obj))
			theObj.filter = '';
}

// --- 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 = getObject('wbInfos'))
		wbInfosObj.innerHTML = infos;
}

function wbStepOut(obj, infos) {
	obj.className = 'wbStep';
	obj.background = XMLC_SkinPath+'wizardbar/wb_step.gif';
	if (wbInfosObj = getObject('wbInfos'))
		wbInfosObj.innerHTML = infos;
}

// --- ProgressBar functions ---
function setPgb(pgbID, pgbValue) {
	if (pgbObj = getObjectById(pgbID))
		pgbObj.width = pgbValue + '%';
	if (lblObj = getObjectById(pgbID+'_label'))
		lblObj.innerHTML = pgbValue + '%';
}
function addLog(Value) {
	if (logObj = getObjectById('logMain')) {
		logObj.innerHTML = logObj.innerHTML + Value;
		logObj.doScroll('pageDown');
	}
}

// --- 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';

