function showloadbox(obj,small)
{
 var i=1;
 while  (document.getElementById("loadbox"+i) && document.getElementById("loadbox"+i).style.visibility=="visible") i++;
 if (!document.getElementById("loadbox"+i)) createloadbox(i);
 var loadbox=document.getElementById("loadbox"+i)
 if (small)
 {
   loadbox.className="loadboxsmall";
   loadbox.innerHTML='';
   var height=40;
   var width=40;
   loadbox.issmall = true;
 }
 else
 {
   loadbox.className="loadbox";
   var height=60;
   var width=210;
   loadbox.innerHTML='<b>Processing data...</b><br>Please wait...<br><img src="/img/loadinganim.gif">';
   loadbox.issmall = false;
 }

 var X = 0;
 var Y = 0;
 if (obj)
 {
   X = getposOffset(obj, "left")+Math.floor(obj.offsetWidth / 2)-(width/2);
   Y = getposOffset(obj, "top")+Math.floor(obj.offsetHeight / 2)-(height/2)
 }
 else
 {
   X = Math.floor((document.body.scrollWidth-width)/2);
   Y = ((document.body.scrollTop) + (Math.floor(document.body.clientHeight - height) / 3));
 }

 loadbox.style.left=X+"px"
 loadbox.style.top=Y+"px";
 loadbox.style.visibility="visible";
 loadbox.appear=true;
 loadbox.style.opacity="0.1";

 if (ie)
   loadbox.style.filter="alpha(opacity=1)";

 setTimeout("inctrans("+i+")",50);
 return i;
}

function boxerror(i)
{
 var loadbox=document.getElementById("loadbox"+i);
 if (!loadbox.issmall)
 {
   loadbox.innerHTML='<b>Error! Try again in a couple of minutes!</b><br><img src="/img/loadinganim.gif">';
 }
 setTimeout("hidebox("+i+");",3000);
}

function boxretry(i,num)
{
 var loadbox=document.getElementById("loadbox"+i);
 if (loadbox.issmall) return false;
 loadbox.innerHTML='<b>Error! Retry number '+num+'</b><br><img src="/img/loadinganim.gif">';
}


function inctrans(i)
{
var obj=document.getElementById("loadbox"+i);
var objstyle=obj.style;
if (objstyle.opacity<1 && obj.appear)
{
objstyle.opacity=Math.abs(objstyle.opacity)+0.3;
if (ie) objstyle.filter="alpha(opacity="+Math.floor(Math.abs(objstyle.opacity)*100)+")";
setTimeout("inctrans("+i+");",80);
}
}

function dectrans(i)
{
var obj=document.getElementById("loadbox"+i);
var objstyle=obj.style;
if (objstyle.opacity>0.1)
{
objstyle.opacity=Math.abs(objstyle.opacity)-0.3;
if (ie) objstyle.filter="alpha(opacity="+Math.floor(Math.abs(objstyle.opacity)*100)+")";
setTimeout("dectrans("+i+");",80);
}
else
{
objstyle.visibility="hidden";
objstyle.left="-500px";
}
}


function hidebox(ID){
var box=document.getElementById("loadbox"+ID);
box.appear=false;
setTimeout("dectrans("+ID+");",80);
}

function createloadbox(ID){
var divblock=document.createElement("div");
divblock.setAttribute("id", "loadbox"+ID);
divblock.className="loadbox";
document.body.appendChild(divblock);
}


//----------------------------------------------WINDOW ENGINE------------------------------------------------------------------------------------------

var Windows = new Array();
var nowinleft = true;
var NextWinID = 1;

var GreyScreen = [];
GreyScreen.obj = null;
GreyScreen.fadein = false;
GreyScreen.fadeout = false;
GreyScreen.opacity = 0;

var WIN_NOCLOSE     = 1;
var WIN_STARTHIDDEN = 1 << 1;
var WIN_STRETCH     = 1 << 2;
var WIN_TRIM        = 1 << 3;
var WIN_MODAL       = 1 << 4;
var WIN_STATUSBAR   = 1 << 5;
var WIN_INLOADSTATE = 1 << 6;
var WIN_SCROLLBARS  = 1 << 7;
var WIN_REFRESH     = 1 << 8;

function ShowWinBox(wincontents, obj,width,height,header,flags,post_str)
{
  var id = Windows.length;
  var FullWidth = 0;
  var FullHeight = 0;
  // Get Width and Weight of the Window Content Area
  //if (document.body.scrollWidth < document.body.offsetWidth)
  //  FullWidth = document.body.offsetWidth;
  //else
    FullWidth = document.body.scrollWidth;

  if (document.body.scrollHeight < document.body.offsetHeight)
    FullHeight = document.body.offsetHeight;
  else
    FullHeight = document.body.scrollHeight;

  // Calculate X and Y Relative to Object
  var X = 0;
  var Y = 0;
  if (obj)
  {
    X = getposOffset(obj, "left");
    Y = getposOffset(obj, "top");
  }
  else
  {
    X = Math.floor((FullWidth-width-40)/2);
    if (height)
      Y = ((document.body.scrollTop) + (Math.floor(document.body.clientHeight - height-40) / 3));
    else
      Y = document.body.scrollTop + 50;
    if (Y < 10) Y = 10;
  }

  if (!width) width='500';

  // Create VirtualWindow Instance
  Windows[id] = new MakeWindow();
  Windows[id].Init(NextWinID++,wincontents, X, Y, width, height, header, flags, post_str);
  if (post_str)
   {
     AjaxRequest(post_str,'FadeWindowContent(text,'+Windows[id].Id+');',showloadbox(Windows[id].Win,true));
   }
  return Windows[id].Id;

}


function MakeWindow()
{
  this.Id = null;
  this.Win = null;
  this.Order = Infinity;
  this.Minimized = null;
  this.Width = null;
  this.Height = null;
  this.Flags = null;
  this.StatusBar = null;
  this.Content = null;
  this.Request = null
}

function ShowAlphaObj(obj)
{
  //if (!ie) FadeOut(obj,true,false,false,';');
 //  else
  obj.style.visibility = "visible";
}

function HideAlphaObj(obj)
{
  //if (!ie) FadeOut(obj,false,true,false,false,';');
 //  else
  obj.style.visibility = "hidden";
}


MakeWindow.prototype.Init = function(id, wincontents, x, y, width, height, header, flags, post_str)
{
  this.Id = id;
  this.Win = document.createElement("div");
  this.Win.setAttribute("id", "winbox"+id);
  document.body.appendChild(this.Win);
  this.Win.className="winbox";
  this.Win.innerHTML = '';
  this.Order = Infinity;
  this.Minimized = false;
  this.Width = width;
  this.Height = height;
  this.Flags = flags;
  this.Request = (post_str ? post_str : false);

  height +='px';
  width += 'px';

  this.Win.style.left = x + "px";
  this.Win.style.top = y +"px";

  var close='<div class="window_closebtn" style="float:right;" title="Close" onMouseOver="HoldDrag();ShowAlphaObj(document.getElementById(\'window'+id+'_closebtn\'));" onMouseOut="ReleaseDrag();HideAlphaObj(document.getElementById(\'window'+id+'_closebtn\'));"><div id="window'+id+'_closebtn" class="window_closebtn_lit" onclick="CloseWindow('+id+');"></div></div>';
  if (flags & WIN_NOCLOSE)
   close='';

  var sb = '';
  if (flags & WIN_STATUSBAR)
    sb = '_sb';

  var refresh='';
  if (flags & WIN_REFRESH)
    refresh = '<div class="window_refreshbtn" style="float:right;" title="Refresh" onMouseOver="HoldDrag();ShowAlphaObj(document.getElementById(\'window'+id+'_refreshbtn\'));" onMouseOut="ReleaseDrag();HideAlphaObj(document.getElementById(\'window'+id+'_refreshbtn\'));"><div id="window'+id+'_refreshbtn" class="window_refreshbtn_lit" onclick="ReloadWindow('+id+');"></div></div>';



  this.Win.innerHTML = '<table cellspasing="0" cellpadding="0" class="floatwin" onMouseDown="ReOrganizeWindows('+id+')">'
+'<tr id="windrag'+id+'" class="windrag">'
+'<td class="wincorner_tl"></td>'
+'<td class="wincorner_tm"><table cellpadding=0 cellspacing=0 width="100%";><tr><td class="winlogo"></td><td class="winheader">'+header+'</td><td style="text-align:right;">'+close+refresh+'</td></tr></table></td>'
+'<td class="wincorner_tr"></td>'
+'</tr>'
+'<tr>'
+'<td class="wincorner_ml"></td>'
+'<td style="vertical-align:top;" class="wincorner_mm"><div class="wincontent" onMouseDown="ReOrganizeWindows('+id+')" style="width:'+width+'; height:'+height+';" id="wincontent'+id+'">'+wincontents+'</div></td>'
+'<td class="wincorner_mr"></td>'
+'</tr>'
+'<tr>'
+'<td class="wincorner_bl'+sb+'"></td>'
+'<td class="wincorner_bm'+sb+'"><div id="winstatusbar'+id+'" class="winstatusbar"></div></td>'
+'<td class="wincorner_br'+sb+'"></td>'
+'</tr></table>';


  Drag.init(document.getElementById("windrag"+id),this.Win);
  ReleaseDrag();
  this.Content = document.getElementById("wincontent"+id);
  this.StatusBar = document.getElementById("winstatusbar"+id);

  if (flags & WIN_STARTHIDDEN)
  {
    this.Content.style.opacity = 0;
    if (ie) this.Content.style.filter = "alpha(opacity=0)";
    this.Content.style.visibility = "hidden";
  }

  if ((flags & WIN_STATUSBAR) && (flags & WIN_INLOADSTATE))
  {
    this.StatusBar.innerHTML = '<img src="/img/tinyloader.gif" style="vertical-align:middle;"> Loading...';
  }

  ReOrganizeWindows();

  FadeOut(this.Win,true,false);

  if (flags & WIN_MODAL)
    setTimeout("ShowGreyScreen("+id+");",50);

  if (flags & WIN_SCROLLBARS)
  {
    this.Content.style.overflowY = 'scroll';
  }
  else
  if ((flags & WIN_TRIM) && wincontents != '')
  {
    this.Content.style.overflow = 'visible';
    this.Content.style.height = 'auto';
  }
  else
  if (flags & WIN_STRETCH)
  {
    if (this.Content.ScrollHeight > this.Height)
     this.Content.style.height = this.Content.ScrollHeight;
  }

}


function GetWindowById(id)
{
  var i = 0;
  while (Windows[i] && Windows[i].Id != id)  i++;
  if (Windows[i])
    return Windows[i];
  else
   return false;
}

function GetWindowIndexById(id)
{
  var i = 0;
  while (Windows[i] && Windows[i].Id != id)  i++;
  if (Windows[i])
    return i;
  else
   return false;
}

function CloseWindow(id)
{
 var thewin = false;
 if (thewin = GetWindowById(id))
  {
    FadeOut(thewin.Win,false,true,false,false,"DestroyWindow("+id+")");
  }
}

function ReloadWindow(id,post_str)
{
 var thewin = false;
 if (thewin = GetWindowById(id) && (post_str || thewin.Request))
  {
      post_str = (post_str ? post_str : thewin.Request);
      AjaxRequest(post_str,'FadeWindowContent(text,'+thewin.Id+');',showloadbox(thewin.Win,true));
      thewin.Request = post_str;
  }
}

function DestroyWindow(id)
{
  var thewin = null;
  var i = 0;
  i = GetWindowIndexById(id);
  if (i === false) return false;
  thewin = Windows[i];
  thewin.Win.style.display = "none";
  document.body.removeChild(thewin.Win);
  thewin.Win = null;
  thewin = null;
  Windows[i] = null;
  for (var j = i; j < (Windows.length - 1) ; j++)
     Windows[j] = Windows[j+1];
  Windows.length = Windows.length-1;
  HideGreyScreen();
  ReleaseDrag();
}

function ReOrganizeWindows(tofront)
{
  var thewin = null;
  if (!tofront)
    tofront = false;
  else
  {
    tofront = GetWindowIndexById(tofront);
    thewin = Windows[tofront];
    for (var i = tofront; i < (Windows.length - 1) ; i++)
      Windows[i] = Windows[i+1];
    Windows[Windows.length-1] = thewin;
  }

  for (var i = 0; i < (Windows.length) ; i++)
    Windows[i].Win.style.zIndex = 22 + i * 2;
}

function ShowGreyScreen(id)
{
  if (!GreyScreen.obj) GreyScreen.obj = document.getElementById('greyscreen');

  //if (ie) GreyScreen.obj.style.filter = "alpha(opacity="+GreyScreen.opacity+")";
  GreyScreen.obj.style.display = "";
  GreyScreen.obj.style.visibility = "visible";
  GreyScreen.fadein = true;
  GreyScreen.fadeout = false;
  setTimeout("FadeInGreyScreen()",20);

  ResizeGreyScreen();
  var thewinid = GetWindowIndexById(id);
  GreyScreen.obj.style.zIndex = 21+thewinid*2;
}

function HideGreyScreen()
{
  if (GreyScreen.obj)
  {
    var i = Windows.length-1 ;
    var NoWindowLeft = true;
    while ((i > -1) && !(Windows[i].Flags & WIN_MODAL)) i--;

    if (i > -1)
    {
      NoWindowLeft = false;
      GreyScreen.obj.style.zIndex = 21+i*2;
    }

    if (GreyScreen.obj.style.display != "none" && !GreyScreen.fadeout && NoWindowLeft)
    {
      GreyScreen.opacity = 40;
      if (ie) GreyScreen.obj.style.filter = "alpha(opacity="+GreyScreen.opacity+")";
      GreyScreen.obj.style.opacity = GreyScreen.opacity/100;
      GreyScreen.fadein = false;
      GreyScreen.fadeout = true;
      setTimeout("FadeOutGreyScreen()",20);
    }
  }
}

function FadeInGreyScreen()
{
  if (GreyScreen.fadein && GreyScreen.opacity < 60)
  {
    GreyScreen.opacity += 20;
    GreyScreen.obj.style.opacity = GreyScreen.opacity/100;
    if (ie) GreyScreen.obj.style.filter = "alpha(opacity="+GreyScreen.opacity+")";
    setTimeout("FadeInGreyScreen()",80);
  }
  else
    GreyScreen.fadein = false;
}

function FadeOutGreyScreen()
{
  if (GreyScreen.fadeout && GreyScreen.opacity > 20)
  {
    GreyScreen.opacity -= 20;
    GreyScreen.obj.style.opacity = GreyScreen.opacity/100;
    if (ie) GreyScreen.obj.style.filter = "alpha(opacity="+GreyScreen.opacity+")";
    setTimeout("FadeOutGreyScreen()",80);
  }
  else
   {
     GreyScreen.fadeout = false;
     if (!GreyScreen.fadein)
     {
      GreyScreen.obj.style.display = "none";
      GreyScreen.obj.style.visibility = "hidden";
     }
   }
}

function ResizeGreyScreen()
{
  if (GreyScreen.obj)
  {
    var FullWidth=document.body.scrollWidth;
    var FullHeight=0;
    if (document.body.scrollHeight<document.body.offsetHeight)
      var FullHeight=document.body.offsetHeight;
    else
      FullHeight=document.body.scrollHeight;
    GreyScreen.obj.style.width=FullWidth;
    GreyScreen.obj.style.height=FullHeight;
  }
}

function FadeWindowContent(text,id)
{
  FadeOut(GetWindowById(id).Content,true,true,text,false,'ReStretch('+id+');')//,'ReStretch('+id+');');
}

function SetWindowContent(text,id)
{
  GetWindowById(id).Content.innerHTML=text;
}

function FadeStatusBar(text,id)
{
  if (!text) text = '&nbsp;';
  FadeOut(GetWindowById(id).StatusBar,true,true,text);
}

function SetStatusBar(text,id)
{
  GetWindowById(id).StatusBar.innerHTML=text;
}

function ReStretch(id)
{
 var thewin = GetWindowById(id);
 if (thewin.Flags & WIN_STRETCH)
 {
  if (thewin.Content.ScrollHeight > thewin.Height)
   thewin.Content.style.height = thewin.Content.ScrollHeight;
  else
   thewin.Content.style.height = thewin.Height;
 }

 if ((thewin.Flags & WIN_TRIM))
 {
   thewin.Content.style.overflow = 'visible';
   thewin.Content.style.height = 'auto';
 }
}

//----------------------------------------------------------------------------------------------------------------------------------

//---------------------------------------------- DRAG ENGINE --------------------------------------------------------------------------------

var HoldTheDrag = false

function HoldDrag()
{
 HoldTheDrag = true;
}

function ReleaseDrag()
{
  HoldTheDrag = false;
}

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
        if (HoldTheDrag) return false;
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

        o.root.style.opacity="0.7";
        if (ie) o.root.style.filter="alpha(opacity=70)";

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
        if (ie) Drag.obj.root.style.filter="alpha(opacity=70)";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);

		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
        Drag.obj.root.style.opacity=null;
        if (ie) Drag.obj.root.style.filter=null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
		parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
//------------------------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------

function attEvt_ie(obj, event, func)
{
  obj.attachEvent('on' + event, func);
}

function attEvt_moz(obj, event, func)
{
  obj.addEventListener(event, func, false);
}
if (ie)
  attEvt = attEvt_ie;
else
  attEvt = attEvt_moz;

function createMethodRef(object, methodName, arg2)
{
  return function()
  {
    return object[methodName].apply(object, [arg2, arguments]);
  }
}

function ImgPreloader()
 {
  this.ImgObj=false;
  this.AfterAction='';

  this.ImgLoad=OnImgLoad;
  this.PreloadImg=ImgPreload;

  function OnImgLoad()
  {
   //document.images[document.images.length]=this.ImgObj;
   eval(this.AfterAction);
  }

  function ImgPreload(src,exec)
  {
   this.AfterAction=exec;
   this.ImgObj= new Image();
   this.ImgObj.src=src;
   if (this.ImgObj.complete==false)
    attEvt(this.ImgObj,'load',createMethodRef(this,'ImgLoad'));
   else eval(exec);
  }
 }

//----------------------------------------------
function MakeConfirmation(conf_text,width,height,yesexec,yes,noexec,no)
 {
  var nobutton='';
  var id = ShowWinBox('',false,width,height,'Dialog',(WIN_NOCLOSE | WIN_MODAL | WIN_TRIM));
  if (no) nobutton=' <input class="formbtn formbtn_dim" onmouseover="this.className=\'formbtn formbtn_lit\'" onmouseout="this.className=\'formbtn formbtn_dim\'" type=button id="button" value="'+no+'" onclick="'+noexec+';CloseWindow('+id+');">';
  SetWindowContent('<table width="100%" cellpadding=0 cellspacing=0 style="margin-bottom:10px;"><tr><td><div width="100%" style="font-size:12px;margin:10px 10px 5px 10px;" >'+conf_text+'</div></td></tr><tr><td><div width="100%" align="center"><input id="button" class="formbtn formbtn_dim" onmouseover="this.className=\'formbtn formbtn_lit\'" onmouseout="this.className=\'formbtn formbtn_dim\'" type=submit value="'+yes+'" onclick="'+yesexec+';CloseWindow('+id+');">'+nobutton+'</div></td></tr></table>',id);
  return id;
 }


function ShowPic(obj,name,src,width,height)
{
 var loadbox=showloadbox(obj,true);
 var ImgPrel = new ImgPreloader();
 ImgPrel.PreloadImg(src,'showpic2(false,"'+name+'","'+src+'",'+width+','+height+');hidebox('+loadbox+')');
}


function showpic2(obj,name,src,width,height)
{
 var id = ShowWinBox('',false,width,height,name,WIN_MODAL);
 SetWindowContent('<a href="" onclick="CloseWindow('+id+');return false;" title="[click to close]"><img class="image" width="'+width+'" height="'+height+'" src="'+src+'"></a>',id);
}

///--------------------- Fader -------------------------


FadeObjects= new Array();

function FadeOut(obj,fin,fout,text,exec2,exec1)
 {
  var i=0;
  if (!text) text = false;

  while (FadeObjects[i] && FadeObjects[i]!=null && FadeObjects[i].obj!=obj) i++;
  if (!FadeObjects[i] || FadeObjects[i]==null)
   {
    FadeObjects[i]=[];
    FadeObjects[i].obj=obj;
   }
   else
   if ((FadeObjects[i].fadein==fin) && (FadeObjects[i].fadeout==fout) && (FadeObjects[i].text==text) && (FadeObjects[i].exec2==exec2) && (FadeObjects[i].exec1==exec1))
     return false;
   FadeObjects[i].opacity = 0;
   FadeObjects[i].fadein=fin;
   FadeObjects[i].fadeout=fout;
   FadeObjects[i].text=text;
  if (exec2)
   FadeObjects[i].exec2=exec2;
  else
   FadeObjects[i].exec2=false;

  if (exec1)
   FadeObjects[i].exec1=exec1;
  else
   FadeObjects[i].exec1=false;
  if (fout)
  {
    if (obj.style.opacity == null || obj.style.opacity === '')
    {
      obj.style.opacity = 1;
      FadeObjects[i].opacity = 100;
      if (ie) obj.style.filter = "alpha(opacity=100)";
    }
  }
  else if(fin)
  {
    if (obj.style.opacity == null || obj.style.opacity === '')
    {
      obj.style.opacity=0;
      FadeObjects[i].opacity = 0;
      if (ie) obj.style.filter="alpha(opacity=0)";
    }
  }

  if (fout && obj.style.opacity > 0)
  {
   FadeObjects[i].opacity = parseInt(obj.style.opacity*100);
   if (FadeObjects[i].timer!=null)
    clearTimeout(FadeObjects[i].timer);
   FadeObjects[i].timer=setTimeout("fadeoutobj("+i+");",65)*100;
  }
  else
  if (fin)
  {
   FadeObjects[i].opacity = parseInt(obj.style.opacity*100);
   if (FadeObjects[i].timer!=null)
    clearTimeout(FadeObjects[i].timer);
   if (text!=false)
    obj.innerHTML=text;
   FadeIn(i);
  }
 }

function FadeIn(i)
 {
   FadeObjects[i].obj.style.visibility="visible";
   if (FadeObjects[i].exec1) eval(FadeObjects[i].exec1);
   if (FadeObjects[i].timer!=null)  clearTimeout(FadeObjects[i].timer);
   FadeObjects[i].timer=setTimeout("fadeinobj("+i+");",65);
 }

function KillFadeObject(i)
{
  FadeObjects[i] = null;
}

function fadeinobj(i)
 {
  var obj = FadeObjects[i].obj;
  var objstyle = obj.style;
  if (FadeObjects[i].opacity <= 100)
   {
    objstyle.opacity = FadeObjects[i].opacity/100;
    if (ie) objstyle.filter="alpha(opacity="+FadeObjects[i].opacity+")";
    FadeObjects[i].opacity += 20;
    FadeObjects[i].timer=setTimeout("fadeinobj("+i+");",65);
   }
  else
  {
   FadeObjects[i].opacity = 0;
   if (ie) objstyle.filter = null;
   objstyle.opacity = null;
   if (FadeObjects[i].exec2) eval(FadeObjects[i].exec2);
   clearTimeout(FadeObjects[i].timer)
   KillFadeObject(i);
  }
 }

function fadeoutobj(i)
 {
  var obj=FadeObjects[i].obj;
  var objstyle=obj.style;
  if (FadeObjects[i].opacity > 0)
   {
    objstyle.opacity = FadeObjects[i].opacity/100;
    if (ie) objstyle.filter="alpha(opacity="+FadeObjects[i].opacity+")";
    FadeObjects[i].opacity -= 20;
    FadeObjects[i].timer=setTimeout("fadeoutobj("+i+");",65);
   }
  else
   {
    FadeObjects[i].opacity = 0;
    objstyle.opacity = 0;
    if (ie) objstyle.filter="alpha(opacity=0)";
    if (FadeObjects[i].fadein && FadeObjects[i].fadeout)
     {
      if (FadeObjects[i].text!=false)
       FadeObjects[i].obj.innerHTML=FadeObjects[i].text;
      if (FadeObjects[i].exec1) eval(FadeObjects[i].exec1);
      FadeObjects[i].fadeout=false;
      FadeObjects[i].timer=setTimeout("fadeinobj("+i+");",65);
     }
    else
    {
     clearTimeout(FadeObjects[i].timer);
     objstyle.visibility="hidden";
     if (ie) objstyle.filter = null;
     objstyle.opacity = null;
     if (FadeObjects[i].exec1) eval(FadeObjects[i].exec1);
     KillFadeObject(i);
    }
   }
 }
//----------------------------------------INFO BOX--------------------------------------------------

var InfoBox= new Array();
var InfoBoxLeftPosCorr=9;//------------------------------------
var InfoBoxTopPosCorr=2; //----------------------
var InfoBoxTimerID=false;
var prevobj=false;

function InfoBoxDraw()
{
 var i=1;
 var CanDoTimeout=false;
 InfoBoxTimerID=false;
 while (InfoBox[i] && InfoBox[i].block)
 {
 if (InfoBox[i].showing)
 {
  if (InfoBox[i].growingout)
   {
    InfoBox[i].width=InfoBox[i].width+(InfoBox[i].speed*InfoBox[i].whcoef);
    if (InfoBox[i].toleft) InfoBox[i].leftcorr=InfoBox[i].leftcorr-(InfoBox[i].speed*InfoBox[i].whcoef);
    if (InfoBox[i].toup) InfoBox[i].upcorr=InfoBox[i].upcorr-InfoBox[i].speed;
    InfoBox[i].height=InfoBox[i].height+InfoBox[i].speed;
    if (InfoBox[i].height>=InfoBox[i].newheight)
     {
      InfoBox[i].growingout=false;
      InfoBox[i].contentbox.innerHTML=InfoBox[i].content;
     }
    else
    CanDoTimeout=true;
   }
  if (InfoBox[i].growingin)
   {
    InfoBox[i].width=InfoBox[i].width-(InfoBox[i].speed*InfoBox[i].whcoef);
    if (InfoBox[i].toleft) InfoBox[i].leftcorr=InfoBox[i].leftcorr+(InfoBox[i].speed*InfoBox[i].whcoef);
    if (InfoBox[i].toup) InfoBox[i].upcorr=InfoBox[i].upcorr+InfoBox[i].speed;
    InfoBox[i].height=InfoBox[i].height-InfoBox[i].speed;
    if (InfoBox[i].height<=10)
     {
      InfoBox[i].width=0;
      InfoBox[i].height=0;
      InfoBox[i].growingin=false;
      InfoBox[i].growingout=false;
      InfoBox[i].showing=false;
      InfoBox[i].block.style.visibility="hidden";
      InfoBox[i].leftarrow.style.visibility="hidden";
      InfoBox[i].rightarrow.style.visibility="hidden";
     }
    else
     CanDoTimeout=true;
   }
   if (InfoBox[i].toleft)
    {
     InfoBox[i].block.style.left=Math.floor(InfoBox[i].leftcorr);
    }
   if (InfoBox[i].toup)
    {
     InfoBox[i].block.style.top=Math.floor(InfoBox[i].upcorr);
    }
  InfoBox[i].block.style.width=Math.floor(InfoBox[i].width)+browserleftcorrection;
  InfoBox[i].block.style.height=InfoBox[i].height;
}
 i++;
}
 //clearTimeout(InfoBoxTimerID);
 if (CanDoTimeout)
 {
 InfoBoxTimerID=setTimeout(InfoBoxDraw,10);
 }

}



function getinfobox(obj)
{
var i=1;
while (InfoBox[i] && InfoBox[i].obj!=obj) i++;
if (!InfoBox[i] || !InfoBox[i].block)
{
 InfoBox[i]=[];
 InfoBox[i].obj=obj;
 var divblock=document.createElement("div");
 divblock.setAttribute("id", "infobox"+i);
 document.body.appendChild(divblock);
 divblock.className='infobox';
 InfoBox[i].block=divblock;
 InfoBox[i].block.innerHTML='<div id="infobox'+i+'content" class="infoboxcontent" onmouseover="StopInfoBoxHide('+i+');" onclick="HideInfoBox('+i+');" onmouseout="InfoBoxTimeout('+i+')"></div>';
 InfoBox[i].contentbox=document.getElementById("infobox"+i+"content");
 var divblock=document.createElement("img");
 divblock.setAttribute("id", "arrowR"+i);
 divblock.src="/img/arrow_right.gif";
 document.body.appendChild(divblock);
 divblock.className='arrowR';
 InfoBox[i].rightarrow=divblock;
 var divblock=document.createElement("img");
 divblock.setAttribute("id", "arrowL"+i);
 divblock.src="/img/arrow_left.gif";
 document.body.appendChild(divblock);
 divblock.className='arrowL';
 InfoBox[i].leftarrow=divblock;
 InfoBox[i].toleft=false;  //------------
 InfoBox[i].toup=false;  //--------------
}
return i;
}

function ShowInfoBox(boxcontent,obj,tipwidth,height,toleft,topcorr)
{
var i=getinfobox(obj);
StopInfoBoxHide(i);
HideAllBoxes();
if (!topcorr) topcorr = 0;
if ((InfoBox[i].obj!=obj) || !InfoBox[i].showing)
 {
  //prevobj=i;
  if (!toleft) toleft = false;
  InfoBox[i].contentbox.innerHTML='';
  x=getposOffset(obj, "left")-browserleftcorrection;
  y=getposOffset(obj, "top")-4;  
  y += topcorr;
  if (((x-23+browserleftcorrection-tipwidth)<0) || !toleft)
   InfoBox[i].toleft=false;
  else
   InfoBox[i].toleft=(InfoBox[i].toleft || true);

  if ((y-height+13)<0)
   InfoBox[i].toup=false;
  else
   InfoBox[i].toup=(InfoBox[i].toup && true);
  InfoBox[i].speed=Math.floor(Math.sqrt(tipwidth+height)*0.3);
  if (InfoBox[i].toleft)
   {
    InfoBox[i].block.style.left=x+InfoBoxLeftPosCorr;
    InfoBox[i].leftarrow.style.visibility="hidden";
    InfoBox[i].rightarrow.style.visibility="visible";
    InfoBox[i].rightarrow.style.left=x-15+InfoBoxLeftPosCorr+browserleftcorrection+browserwidthcorrection;
   }
  else
   {
    InfoBox[i].block.style.left=x+9-InfoBoxLeftPosCorr+obj.offsetWidth;
    InfoBox[i].rightarrow.style.visibility="hidden";
    InfoBox[i].leftarrow.style.visibility="visible";
    InfoBox[i].leftarrow.style.left=x-InfoBoxLeftPosCorr+obj.offsetWidth+2;
   }
   if (InfoBox[i].toup)
    {
     InfoBox[i].block.style.top=y+8+InfoBoxTopPosCorr;
    }
   else
    {
     InfoBox[i].block.style.top=y-3+InfoBoxTopPosCorr;
    }
  InfoBox[i].rightarrow.style.top=y+5+InfoBoxTopPosCorr;
  InfoBox[i].leftarrow.style.top=y+5+InfoBoxTopPosCorr;
  InfoBox[i].block.style.width=0;
  InfoBox[i].block.style.height=0;
  if (boxcontent!='')
   InfoBox[i].content=boxcontent;
  InfoBox[i].growingin=false;
  InfoBox[i].growingout=true;
  InfoBox[i].showing=true;
  InfoBox[i].width=InfoBox[i].height=0;
  InfoBox[i].newwidth=tipwidth;
  InfoBox[i].newheight=height;
  InfoBox[i].leftcorr=x+browserleftcorrection-InfoBoxLeftPosCorr;
  InfoBox[i].upcorr=y+21+InfoBoxTopPosCorr;
  InfoBox[i].whcoef=(InfoBox[i].newwidth/InfoBox[i].newheight);
  InfoBox[i].block.style.visibility="visible";
  if (!InfoBoxTimerID)
  InfoBoxDraw();
  return InfoBox[i];
 }
else
 {
  if (InfoBox[i].growingin)
  {
  InfoBox[i].growingin=false;
  InfoBox[i].growingout=true;
  if (!InfoBoxTimerID)
   InfoBoxDraw();
  }
  return InfoBox[i];
 }
}

function GetBoxByObj(obj)
{
var i=1;
while (InfoBox[i] && InfoBox[i].obj!=obj) i++;
if (!InfoBox[i] || !InfoBox[i].block) return false;
else return i;
}


function SetInfoBoxText(obj,text)
{
var i=1;
if (i=GetBoxByObj(obj))
 {
  if (InfoBox[i].contentbox.innerHTML!='')
   InfoBox[i].contentbox.innerHTML=text;
  else
   InfoBox[i].content=text;
 }
}

function StopInfoBoxHide(i)
{
if (InfoBox[i].hidetimer) clearTimeout(InfoBox[i].hidetimer);
 if (InfoBox[i].growingin)
  {
  InfoBox[i].growingin=false;
  InfoBox[i].growingout=true;
  if (!InfoBoxTimerID)
   InfoBoxDraw();
  }
}

function HideInfoBox(i)
{
  InfoBox[i].contentbox.innerHTML='';
  InfoBox[i].growingout=false;
  InfoBox[i].growingin=true;
  if (!InfoBoxTimerID)
   InfoBoxDraw();
}

function HideAllBoxes()
{
for (var i=0;i<InfoBox.length;i++)
if (InfoBox[i] && InfoBox[i].showing) HideInfoBox(i);
}


function InfoBoxTimeout2(obj)
{
 var i=1;
 if (i=GetBoxByObj(obj))
  {
   if (!InfoBox[i].growingin)
   InfoBox[i].hidetimer=setTimeout("HideInfoBox("+i+")",300);
  }
}


function InfoBoxTimeout(i)
{
  InfoBox[i].hidetimer=setTimeout("HideInfoBox("+i+")",200);
}



