/*####################################################################################
#
# CLASS:
#  	Ajax
#
# PURPOSE:
#  	a class for all DHTML and simple Ajax functionality
#
####################################################################################*/

/*####################################################################
#
# FUNCTION:
# 	Ajax
#
# DESCRIPTION:
# 	Contructor
#
####################################################################*/
function Ajax()
	{
	// Variables
	this.DHTML = false;
	this.DOM = false;
	this.MSIE4 = false;
	this.NS4 = false;
	
	// Methods
	this.getElement		= AJAX_getElement;
	this.getDiv			= AJAX_getDiv;
	this.showDiv		= AJAX_showDiv;
	this.hideDiv		= AJAX_hideDiv;
	this.moveDiv		= AJAX_moveDiv;
	this.moveDeltaDiv	= AJAX_moveDeltaDiv;
	this.loadURLToFrame	= AJAX_loadURLToFrame;
	this.hideFrame		= AJAX_hideFrame;
	this.showCover		= AJAX_showCover;
	this.copyAjaxToDiv	= AJAX_copyAjaxToDiv;
	this.copyDivToDiv	= AJAX_copyDivToDiv;
	this.messageBox		= AJAX_messageBox;
	this.setHTML		= AJAX_setHTML;
	
	// Constructor
	if (document.getElementById)
		{
		this.DHTML = true;
		this.DOM = true;
		}
	else
		{
		if (document.all)
			{
			this.DHTML = true;
			this.MSIE4 = true;
			}
		else
			{
			if (document.layers)
				{
				this.DHTML = true;
				this.NS4 = true;
				}
			}
		}
	}
	
	
/*####################################################################
#
# FUNCTION:
# 	AJAX_getElement
#
# DESCRIPTION:
# 	gets Element by ID, Name, tagname
#
####################################################################*/
function AJAX_getElement (Mode, Identifier, ElementNumber) {
  var Element, ElementList;
  if (this.DOM) {
    if (Mode.toLowerCase() == "id") {
      Element = document.getElementById(Identifier);
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") {
      ElementList = document.getElementsByName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.getElementsByTagName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (this.MSIE4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      Element = document.all(Identifier);
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.all.tags(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (this.NS4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      Element = document[Identifier];
      if (!Element) {
        Element = document.anchors[Identifier];
      }
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "layerindex") {
      Element = document.layers[Identifier];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  return false;
}	


/*####################################################################
#
# FUNCTION:
# 	AJAX_getDiv
#
# DESCRIPTION:
# 	gets Element by ID, Name, tagname
#
####################################################################*/
function AJAX_getDiv(anID)
	{
  if (this.NS4) {
    obj = this.getElement("id", anID);
  } else {
    obj = this.getElement("id", anID).style;
  }
	return obj;
	}

/*####################################################################
#
# FUNCTION:
# 	AJAX_moveDiv
#
# DESCRIPTION:
# 	moves div to x,y
#
####################################################################*/
function AJAX_moveDiv(anID, x, y)
	{
	obj = this.getDiv(anID);
	obj.left = x + "px";
	obj.top = y + "px";
	}

/*####################################################################
#
# FUNCTION:
# 	AJAX_moveDeltaDiv
#
# DESCRIPTION:
# 	moves div to x,y
#
####################################################################*/
function AJAX_moveDeltaDiv(anID, x, y)
	{
	obj = document.getElementById(anID).style; //this.getDiv(anID);
	if (false) //this.NS4) 
		{
		xnew = parseInt(obj.pageX) + x;
		ynew = parseInt(obj.pageY) + y;
		obj.pageX = xnew + "px";
		obj.pageY = ynew + "px";
		}
	else	
		{
		xnew = parseInt(obj.left) + x;
		ynew = parseInt(obj.top) + y;
		obj.left = xnew + "px";
		obj.top = ynew + "px";
		}
	}


/*####################################################################
#
# FUNCTION:
# 	AJAX_showDiv
#
# DESCRIPTION:
# 	shows div
#
####################################################################*/
function AJAX_showDiv(anID)
	{
  if (this.NS4) {
    obj = this.getElement("id", anID);
    obj.display = "block";
  } else {
    obj = this.getElement("id", anID).style;
    obj.visibility = "visible";
    obj.display = "block";
  }


	}

/*####################################################################
#
# FUNCTION:
# 	AJAX_hideDiv
#
# DESCRIPTION:
# 	hides div
#
####################################################################*/
function AJAX_hideDiv(anID)
	{
  if (this.NS4) {
    obj = this.getElement("id", anID);
    if(obj) obj.display = "none";
  } else {
    obj = this.getElement("id", anID).style;
    if(obj) obj.display = "none";
  }
	}

/*####################################################################
#
# FUNCTION:
# 	AJAX_loadURLToFrame
#
# DESCRIPTION:
# 	Shows Cover, loads an URL in the AJAX-Frame and opens Message-Frame (or another)
#
####################################################################*/
function AJAX_loadURLToFrame(url, target)
	{
	target = target?target:'divAJAX_Message';
	this.showCover(true);
	top.frames.divAJAX_IO.document.location = url;
	this.showDiv(target);
	}
	
/*####################################################################
#
# FUNCTION:
# 	AJAX_hideFrame
#
# DESCRIPTION:
# 	Hides Cover and MessageFrame (or another)	
#
####################################################################*/
function AJAX_hideFrame(target)
	{
	target = target?target:'divAJAX_Message';
	this.showCover(false);
	this.hideDiv(target);
	}
	
/*####################################################################
#
# FUNCTION:
# 	AJAX_copyDivToDiv
#
# DESCRIPTION:
# 	copies HTML from one div to another
#
####################################################################*/
function AJAX_copyDivToDiv(source, target, show)
	{
	this.getElement("id", target).innerHTML = this.getElement("id", source).innerHTML;
	if(show==true)
		{
		this.showCover(1);
		this.showDiv(target);
		}
	}

/*####################################################################
#
# FUNCTION:
# 	AJAX_copyAjaxToDiv
#
# DESCRIPTION:
# 	copies HTML from AJAX-Frame to MessageFrame (or another)
#
####################################################################*/
function AJAX_copyAjaxToDiv(target)
	{
	target = target?target:'divAJAX_Message';
	html = top.frames.divAJAX_IO.document.body.innerHTML;
	targetFrame = this.getElement("id", target);
	targetFrame.innerHTML = html;
	}

/*####################################################################
#
# FUNCTION:
# 	AJAX_hideDiv
#
# DESCRIPTION:
# 	hides div
#
####################################################################*/
function AJAX_messageBox(title, text)
	{
	targetFrame = this.getElement("id", "divAJAX_Default_Title");
	targetFrame.innerHTML = title;
	targetFrame = this.getElement("id", "divAJAX_Default_Text");
	targetFrame.innerHTML = text;
	this.showCover(true);
	this.showDiv('divAJAX_Default');
	}
	
/*####################################################################
#
# FUNCTION:
# 	cover
#
# DESCRIPTION:
# 	show/hides AJAX_showCover
#
####################################################################*/
function AJAX_showCover(onoff)
	{
	if(onoff==true)
		{
		this.showDiv('divAJAX_Cover');
		}
	else	
		{
		this.hideDiv('divAJAX_Cover');
		}
	}

/*####################################################################
#
# FUNCTION:
# 	AJAX_setHTML
#
# DESCRIPTION:
# 	hides div
#
####################################################################*/
function AJAX_setHTML(aDiv, html)
	{
	targetFrame = this.getElement("id", aDiv);
	targetFrame.innerHTML = html;
	}
	
	
