// Main script file for Delos 7G
// Contain XCheck.js, XForms.js, XRollover.js, XShowHide.js

// --- Browser detection script functions -----------------------------------------------------------------
function checkBrowser(){
  this.ver=navigator.appVersion;
  this.dom=document.getElementById?1:0;
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && 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.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
  return this;
}

bw = new checkBrowser();

// --- Forms keypress functions ---------------------------------------------------------------------------
function handleFormKeyPress(form) { if (13 == event.keyCode) form.submit(); }
function ConfirmDelete(formName, DeleteAction, Prompt) {
  D = document.forms[formName];
  if (confirm(Prompt)) {
    D.action = DeleteAction;
    D.submit();
  }
}

// --- Showhide functions ---------------------------------------------------------------------------------
function ShowHide(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 = document.getElementById(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++) {
      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 (ImageObject = document.getElementById(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 ShowHidePFO(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 = document.getElementById(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++) {
      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 (ImageObject = document.getElementById(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 Show(ID) {
  var obj;
  if (obj = document.getElementById(ID)) {
      obj.style.visibility = 'visible';
      obj.style.display = '';
  }
}

function Hide(ID) {
  var obj;
  if (obj = document.getElementById(ID)) {
      obj.style.visibility = 'hidden';
      obj.style.display = 'none';
  }
}

// --- Rollover functions ---------------------------------------------------------------------------------
function BtnOver(Row) {
  var arg = arguments;
  var XMLC_SkinPath2 = XMLC_SkinPath;
  if (arg[1] == 'TOOL') { XMLC_SkinPath2 = XMLC_SkinPath + 'tool'; }
  if (Obj = Row.all.BtnLeft)  Obj.src = XMLC_SkinPath2+'button_left_over.gif';
  if (Obj = Row.all.BtnMain)  Obj.background = XMLC_SkinPath2+'button_main_over.gif';
  if (Obj = Row.all.BtnRight) Obj.src = XMLC_SkinPath2+'button_right_over.gif';
}

function BtnOut(Row) {
  var arg = arguments;
  if (arg[1] == 'TOOL') {
    if (Obj = Row.all.BtnLeft)  Obj.src = XMLC_SkinPath+'toolbutton.gif';
    if (Obj = Row.all.BtnMain)  Obj.background = XMLC_SkinPath+'toolbutton.gif';
    if (Obj = Row.all.BtnRight) Obj.src = XMLC_SkinPath+'toolbutton.gif';
  }
  else {
    if (Obj = Row.all.BtnLeft)  Obj.src = XMLC_SkinPath+'button_left.gif';
    if (Obj = Row.all.BtnMain)  Obj.background = XMLC_SkinPath+'button_main.gif';
    if (Obj = Row.all.BtnRight) Obj.src = XMLC_SkinPath+'button_right.gif';
  }
}

function BtnDown(Row) {
  var arg = arguments;
  var XMLC_SkinPath2 = XMLC_SkinPath;
  if (arg[1] == 'TOOL') { XMLC_SkinPath2 = XMLC_SkinPath + 'tool'; }
  if (Obj = Row.all.BtnLeft)  Obj.src = XMLC_SkinPath2+'button_left_down.gif';
  if (Obj = Row.all.BtnMain)  Obj.background = XMLC_SkinPath2+'button_main_down.gif';
  if (Obj = Row.all.BtnRight) Obj.src = XMLC_SkinPath2+'button_right_down.gif';
}

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 PreloadImages() {
  var d=document;
  if (!d.LoadedImages)
    d.LoadedImages=new Array();
  var i, j=d.LoadedImages.length, a=PreloadImages.arguments;
  for (i=0; i<a.length; i++) {
    if (a[i].indexOf("#")!=0) { 
      d.LoadedImages[j] = new Image; 
      d.LoadedImages[j++].src = XMLC_SkinPath+a[i];
    }
  }
}

PreloadImages('button_left_over.gif', 'button_left_down.gif', 
'button_main_over.gif', 'button_main_down.gif', 
'button_right_over.gif', 'button_right_down.gif', 
'button_spacer.gif');

// --- 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++) {
      if (arg[i] == 'ACTION') { F.action = arg[++i]; }
      if (arg[i] == 'TARGET') { F.target = arg[++i]; }
      if (arg[i] == 'CONFIRM') { ConfirmQuestion = arg[++i]; }
    }
  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;
    }
  };
}

// --- CheckBoxes functions --------------------------------------------------------------------------
function GetValue(ID) {
  if (bw.ns4) { return eval("document.Formul."+ID+".value"); }
  else { return document.getElementById(ID).value; }
}

function CheckObject(ID) {
  if (bw.ns4) { eval("document.Formul."+ID+".checked  = true;"); }
  else { document.getElementById(ID).checked  = true; }
}

function UncheckObject(ID) {
   if (bw.ns4) { eval("document.Formul."+ID+".checked  = false;"); }
   else { document.getElementById(ID).checked  = false; }
}

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 elt;
  if (bw.ns4) { eval("elt = document.Formul."+ID+";"); }
  else { elt = document.getElementById(ID); }
  elt.checked = !(elt.checked);
}

function SwitchState(FieldName1, FieldName2, LBound, HBound) {
  for (i = LBound; i <= HBound; i++)
    SwitchCheckbox(FieldName1 + i + FieldName2);
}

function openEmailWindow(URL, Name) {
  if (Name == null)
    Name = '_blank';
  return window.open(URL, Name, 'left=200,top=200,width=800,height=600,resizable'); 
}