//THE OBJECT DEFINITION FOR THE DOMTABBEDMENU CLASS
var _DOMTabbedMenu_objects = [];

function DOMTabbedMenu(thisVar,myName,prnt,cls,tpos,hgt,wdt,thgt,twdt,dflttab) {
	//* denotes absolutely must have
	//thisVar	=>	*the string name of the variable this menu object is stored in
	//myName	=>	*the name/id of this div object in the page. For DOM reference.
	//prnt		=>	*the id of the object on the screen that will be the menus parent object.
	//cls		=>	the class name which describes the style of the menu
	//tpos		=>	*the location of the tabs with respect to the content area
	//				 values are: top,bottom,left,right
	//hgt		=>	*the height of the menu. Must be in px measurements. Will override height in the class
	//wdt		=>	*the width of the menu. Must be in px measurements. Will override width in the class
	//thgt		=>	*the height of the tabs. Must be in px measurements. Will override height in the class
	//twdt		=>	*the width of the tabs. Must be in px measurements. Will override width in the class
	//dflttab	=>	the tab that is selected to start. defaults to the first one.

	if (!thisVar) {
		alert("The instance variable nees to be set to use this menu properly.");
	} else {

		//set the JS variable used for this instance of the menu
		//passed in as a string
		this.instance = thisVar;
		_DOMTabbedMenu_objects.push(this.instance);

		//Set the name of this menu
		if (!myName || (myName=="")) {
			var x=0;
			while ($$DOM(getTheObjectName(prnt)+x+"")) {x++;}
			this.name = getTheObjectName(prnt)+x+"";
		} else {
			this.name = myName;
		}
		this.id = this.name;

		//Set the other properties
		this.parent = (prnt)?prnt:"";
		if (cls) {
			this.clsName = (cls.charAt(0)==".")?cls.substring(1,cls.length):cls;
		} else {
			this.clsName = "";
		}

		this.tabsPosition = (tpos)?tpos.toLowerCase():"top";
		this.width = (wdt)?wdt:"";
		this.height = (hgt)?hgt:"100px";
		this.tabHeight = (thgt)?thgt:"100px";
		this.tabWidth = (twdt)?twdt:"";
		this.selectedTab = (dflttab)?dflttab:0;
		this.loadText = "<i>Loading...</i>";

		//Other Properties
		this.autoHideContentObjects = true;

		//Internal Properties
		this.hasBeenDrawn = false;
		this.tabAreaName = this.name + "_tabs_top";
		this.bodyAreaName = this.name + "_main";
		this.tabs = [];

		//Location Enumeration
		this.location = new Object();
		this.location.OBJECT = 0;	//data => the object name with the data
		this.location.AJAX = 1;		//data => url where the data is
		this.location.URL = 2;		//data => creates an iframe and loads the url into it

		//Properties for AutoSize
		this.windowWidth = getWindowWidth();
		this.windowHeight = getWindowHeight();
		this.windowOffsetWidth = this.windowWidth - parseInt(this.width);
		this.windowOffsetHeight = this.windowHeight - parseInt(this.height);
		this.autoResize = false;
		this.minimumWidth = -1;
		this.minimumHeight = -1;
		this.maximumWidth = -1;
		this.maximumHeight = -1;

		//Properties for autoFitToWindow
		this.fit2Win = false;
		this.originalOffsetWidth = this.windowOffsetWidth;
		this.originalOffsetHeight = this.windowOffsetHeight;
		this.autoFitOffsetWidth = 40;
		this.autoFitOffsetHeight = 50;
		this.originalResizeStatus = false;
	}
}

DOMTabbedMenu.prototype.enableAutoResize = function(bool) {
	if (bool) {
		if (!this.autoResize) {
			//set resize listener
			if (window.addEventListener)
				window.addEventListener("resize", eval(this.instance + ".doAutoResize"), false) //FS-Netscape
			else
				window.attachEvent("onresize", eval(this.instance + ".doAutoResize")); //IE

			this.autoResize = true;
		}
	} else {
		if (this.autoResize) {
			//remove resize listener
			if (window.removeEventListener)
				window.removeEventListener("resize", eval(this.instance + ".doAutoResize"), false) //FS-Netscape
			else
				window.detachEvent("onresize", eval(this.instance + ".doAutoResize")); //IE

			this.autoResize = false;
		}
	}
}

DOMTabbedMenu.prototype.doAutoResize = function() {
	var w,h,menu;
	for (var i=0;i<_DOMTabbedMenu_objects.length;i++) {
		menu = eval(_DOMTabbedMenu_objects[i]);

		if (menu.autoResize && menu.hasBeenDrawn && (menu.tabs.length>=0)) {
			w = getWindowWidth() - menu.windowOffsetWidth;
			h = getWindowHeight() - menu.windowOffsetHeight;
			
			if (menu.minimumWidth != -1 && w < menu.minimumWidth) w = menu.minimumWidth;
			if (menu.minimumHeight != -1 && h < menu.minimumHeight) h = menu.minimumHeight;
			if (menu.maximumWidth != -1 && w > menu.maximumWidth) w = menu.maximumWidth;
			if (menu.maximumHeight != -1 && h > menu.maximumHeight) h = menu.maximumHeight;

			menu.resize(w+"px", h+"px");
		}
	}
}

DOMTabbedMenu.prototype.autoFitToWindow = function(bool) {
	if (bool) {
		this.fit2Win = true;
		this.windowOffsetWidth = this.autoFitOffsetWidth;
		this.windowOffsetHeight = this.autoFitOffsetHeight;
		this.originalResizeStatus = this.autoResize;
		this.enableAutoResize(true);
		this.doAutoResize();
	} else {
		this.fit2Win = false;
		this.windowOffsetWidth = this.originalOffsetWidth;
		this.windowOffsetHeight = this.originalOffsetHeight;
		this.doAutoResize();
		this.enableAutoResize(this.originalResizeStatus);
	}
}

DOMTabbedMenu.prototype.drawTMenu = function() {
	if (this.hasBeenDrawn) {
		$$DOM(this.parent).removeChild($$DOM(this.name));
		this.hasBeenDrawn = false;
	}

	var nme, nmeB, nmeT, table, tbody, tr, td, td2;

	switch (this.tabsPosition) {
		case "top":
		  //build main div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.name);
  			nme.setAttribute("id",this.name);
  			$$DOM(this.parent).appendChild(nme);
  			$$DOM(this.name).style.height = this.height;
  			$$DOM(this.name).style.width = this.width;
  			$$DOM(this.name).style.borderWidth = "0px";
  			$$DOM(this.name).style.margin = "0px";

		  //build tab div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.tabAreaName);
  			nme.setAttribute("id",this.tabAreaName);
  			$$DOM(this.name).appendChild(nme);
  			$$DOM(this.tabAreaName).style.border = "black 0px solid";
  			$$DOM(this.tabAreaName).style.height = this.tabHeight;
  			$$DOM(this.tabAreaName).style.width = this.width;

		  //build body div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.bodyAreaName);
  			nme.setAttribute("id",this.bodyAreaName);
  			$$DOM(this.name).appendChild(nme);
  			$$DOM(this.bodyAreaName).className = this.clsName;
  			$$DOM(this.bodyAreaName).style.height = this.height;
  			$$DOM(this.bodyAreaName).style.width = this.width;
  			$$DOM(this.bodyAreaName).style.overflow = "auto";
			$$DOM(this.bodyAreaName).innerHTML = "&nbsp;";

			break;
		case "bottom":
		  //build main div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.name);
  			nme.setAttribute("id",this.name);
  			$$DOM(this.parent).appendChild(nme);
  			$$DOM(this.name).style.height = this.height;
  			$$DOM(this.name).style.width = this.width;
  			$$DOM(this.name).style.borderWidth = "0px";
  			$$DOM(this.name).style.margin = "0px";

		  //build body div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.bodyAreaName);
  			nme.setAttribute("id",this.bodyAreaName);
  			$$DOM(this.name).appendChild(nme);
  			$$DOM(this.bodyAreaName).className = this.clsName;
  			$$DOM(this.bodyAreaName).style.height = this.height;
  			$$DOM(this.bodyAreaName).style.width = this.width;
  			$$DOM(this.bodyAreaName).style.overflow = "auto";
			$$DOM(this.bodyAreaName).innerHTML = "&nbsp;";

		  //build tab div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.tabAreaName);
  			nme.setAttribute("id",this.tabAreaName);
  			$$DOM(this.name).appendChild(nme);
  			$$DOM(this.tabAreaName).style.border = "black 0px solid";
  			$$DOM(this.tabAreaName).style.height = this.tabHeight;
  			$$DOM(this.tabAreaName).style.width = this.width;

			break;
		case "left":
		  //build the menu objects
			nme = document.createElement("div");
  			nme.setAttribute("name",this.name);
  			nme.setAttribute("id",this.name);

			table = document.createElement("table");
  			table.setAttribute("name",this.name + "_main_table");
  			table.setAttribute("id",this.name + "_main_table");

			tbody = document.createElement("tbody"); //required for IE

			tr = document.createElement("tr");

			td = document.createElement("td");
  			td.setAttribute("name",this.name + "_td_left");
  			td.setAttribute("id",this.name + "_td_left");

			td2 = document.createElement("td");
  			td2.setAttribute("name",this.name + "_td_right");
  			td2.setAttribute("id",this.name + "_td_right");

			nmeT = document.createElement("div");
  			nmeT.setAttribute("name",this.tabAreaName);
  			nmeT.setAttribute("id",this.tabAreaName);

			nmeB = document.createElement("div");
  			nmeB.setAttribute("name",this.bodyAreaName);
  			nmeB.setAttribute("id",this.bodyAreaName);

		  //attach the objects to the document
  			$$DOM(this.parent).appendChild(nme);
			nme.appendChild(table);
			table.appendChild(tbody);
			tbody.appendChild(tr);
			tr.appendChild(td);
			tr.appendChild(td2);
  			td.appendChild(nmeT);
  			td2.appendChild(nmeB);

		  //set the object properties
  			$$DOM(this.name).style.height = this.height;
  			$$DOM(this.name).style.width = this.width;
  			$$DOM(this.name).style.borderWidth = "0px";
  			$$DOM(this.name).style.margin = "0px";

			$$DOM(this.name + "_main_table").style.margin = "0px";
			$$DOM(this.name + "_main_table").cellPadding = "0";
			$$DOM(this.name + "_main_table").cellSpacing = "0";

  			$$DOM(this.tabAreaName).style.border = "black 0px solid";
  			$$DOM(this.tabAreaName).style.height = this.height;
  			$$DOM(this.tabAreaName).style.width = this.tabWidth;

  			$$DOM(this.bodyAreaName).className = this.clsName;
  			$$DOM(this.bodyAreaName).style.height = this.height;
  			$$DOM(this.bodyAreaName).style.width = Math.abs((parseInt(this.width) - parseInt(this.tabWidth))) + "px";
  			$$DOM(this.bodyAreaName).style.overflow = "auto";
			$$DOM(this.bodyAreaName).innerHTML = "&nbsp;";

			break;

		case "right":
		  //build main div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.name);
  			nme.setAttribute("id",this.name);
  			$$DOM(this.parent).appendChild(nme);
  			$$DOM(this.name).style.height = this.height;
  			$$DOM(this.name).style.width = this.width;
  			$$DOM(this.name).style.borderWidth = "0px";
  			$$DOM(this.name).style.margin = "0px";

		  //build the table for the left and right menus
			table = document.createElement("table");
  			table.setAttribute("name",this.name + "_main_table");
  			table.setAttribute("id",this.name + "_main_table");
			nme.appendChild(table);

			tr = document.createElement("tr");
			tbody = document.createElement("tbody"); //required for IE
			table.appendChild(tbody);
			tbody.appendChild(tr);

			td = document.createElement("td");
  			td.setAttribute("name",this.name + "_td_left");
  			td.setAttribute("id",this.name + "_td_left");
			tr.appendChild(td);

			td2 = document.createElement("td");
  			td2.setAttribute("name",this.name + "_td_right");
  			td2.setAttribute("id",this.name + "_td_right");
			tr.appendChild(td2);

			$$DOM(this.name + "_main_table").style.margin = "0px";
			$$DOM(this.name + "_main_table").cellPadding = "0";
			$$DOM(this.name + "_main_table").cellSpacing = "0";
			$$DOM(this.name + "_td_left").valign = "top";
			$$DOM(this.name + "_td_right").valign = "top";

		  //build body div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.bodyAreaName);
  			nme.setAttribute("id",this.bodyAreaName);
  			$$DOM(this.name + "_td_left").appendChild(nme);
  			$$DOM(this.bodyAreaName).className = this.clsName;
  			$$DOM(this.bodyAreaName).style.height = this.height;
  			$$DOM(this.bodyAreaName).style.width = Math.abs((parseInt(this.width) - parseInt(this.tabWidth))) + "px";
  			$$DOM(this.bodyAreaName).style.overflow = "auto";
			$$DOM(this.bodyAreaName).innerHTML = "&nbsp;";

		  //build tab div
			nme = document.createElement("div");
  			nme.setAttribute("name",this.tabAreaName);
  			nme.setAttribute("id",this.tabAreaName);
  			$$DOM(this.name + "_td_right").appendChild(nme);
  			$$DOM(this.tabAreaName).style.border = "black 0px solid";
  			$$DOM(this.tabAreaName).style.height = this.height;
  			$$DOM(this.tabAreaName).style.width = this.tabWidth;

			break;
	}

	this.hasBeenDrawn = true;
}

DOMTabbedMenu.prototype.resize = function(w,h) {
	var obj = $$DOM(this.id);

	if ((this.tabsPosition=="top")||(this.tabsPosition=="bottom")) {

		if (w!=null) {
			obj.style.width = w;
			$$DOM(this.tabAreaName).style.width = w;
			$$DOM(this.bodyAreaName).style.width = w;
		}
		if (h!=null) {
			obj.style.height = h;
			$$DOM(this.bodyAreaName).style.height = h;
		}
		if (this.tabs[this.selectedTab].location == this.location.URL) {
			if ($$DOM(this.bodyAreaName).firstChild) {
				if ($$DOM(this.bodyAreaName).firstChild.nodeName.toLowerCase()=="iframe") {
					if (w!=null) $$DOM(this.bodyAreaName).firstChild.style.width=w;
					if (h!=null) $$DOM(this.bodyAreaName).firstChild.style.height=h;
				}
			}
		}

	} else if ((this.tabsPosition=="left")||(this.tabsPosition=="right")) {
		if (w!=null) {
			obj.style.width = w;
			$$DOM(this.bodyAreaName).style.width = Math.abs((parseInt(this.tabWidth) - parseInt(w))) + "px";
		}
		if (h!=null) {
			obj.style.height = h;
			$$DOM(this.tabAreaName).style.height = h;
			$$DOM(this.bodyAreaName).style.height = h;
		}
		if (this.tabs[this.selectedTab].location == this.location.URL) {
			if ($$DOM(this.bodyAreaName).firstChild) {
				if ($$DOM(this.bodyAreaName).firstChild.nodeName.toLowerCase()=="iframe") {
					if (w!=null) $$DOM(this.bodyAreaName).firstChild.style.width = $$DOM(this.bodyAreaName).style.width;
					if (h!=null) $$DOM(this.bodyAreaName).firstChild.style.height = h;
				}
			}
		}

	}

	if (w!=null) this.width=w;
	if (h!=null) this.height=h;

}

DOMTabbedMenu.prototype.applyClass = function(clsNm) {
	if (clsNm) this.clsName = clsNm;
  	$$DOM(this.name).className = clsNm;
}

DOMTabbedMenu.prototype.addTab = function(lctn,dt,txt,clsNm,tMOVtext,tMOVclass,display) {
	/*
	lctn = the location TYPE of the info for this tab, innerHTML of a DOM object, an AJAX page, or a URL
	dt = if is DOM object, this is the name/id of the object / if is AJAX or URL  then this is the address
	txt = text displayed on the tab when its not selected
	clsNm = class of the tab when its not selected
	tMOVtext = text displayed on the tab when it is selected
	tMOVclass = class of the tab when it is selected
	display = whether or not to show this tab; value = show|hide
	*/
	var tab = new Object();
	tab.id = this.tabs.length + "_tab" + "_" + this.instance;
	tab.name = tab.id;
	tab.location = (lctn)?lctn:this.location.OBJECT;
	tab.data = (dt)?dt:"";

	if ((tab.location==this.location.OBJECT) && this.autoHideContentObjects) {
		if (tab.data!="") {
			$$DOM(tab.data).style.display = "none";
			$$DOM(tab.data).style.visibility = "hidden";
		}
	}

	tab.HTMLtext = (txt)?txt:"";
	tab.className = (clsNm)?clsNm:"";
	tab.mouseOverClass = (tMOVclass)?tMOVclass:"";
	tab.mouseOverText = (tMOVtext)?tMOVtext:txt;
	
	if (display) {
		display = display.toLowerCase();
		tab.show = (display=="show");
	} else {
		tab.show = true;
	}

	this.tabs.push(tab);
}

DOMTabbedMenu.prototype.drawTabs = function() {
	var tobj = $$DOM(this.tabAreaName);

	//clear the tab area
	while (tobj.firstChild) {
		tobj.removeChild(tobj.firstChild);
	}
	tobj.innerHTML = "";


	var tbl, tbdy, tr, td, tblID, tdID, i;
	tblID = this.tabAreaName + "_table";

	tbl = document.createElement("table");
	tbl.setAttribute("name",tblID);
	tbl.setAttribute("id",tblID);

	tbdy = document.createElement("tbody");

	if ((this.tabsPosition=="top")||(this.tabsPosition=="bottom")) {
		tr = document.createElement("tr");

		//create the table td's
		for (i=0;i<this.tabs.length;i++) {
			if (this.tabs[i].show) {
				td = document.createElement("td");
				td.setAttribute("name",this.tabs[i].id);
				td.setAttribute("id",this.tabs[i].id);
				td.setAttribute("align","center");
				td.setAttribute("valign","middle");
	  			tr.appendChild(td);
			}
		}

		tbdy.appendChild(tr);

	} else if ((this.tabsPosition=="left")||(this.tabsPosition=="right")) {

		//create the table td's
		for (i=0;i<this.tabs.length;i++) {
			if (this.tabs[i].show) {
				tr = document.createElement("tr");

				td = document.createElement("td");
				td.setAttribute("name",this.tabs[i].id);
				td.setAttribute("id",this.tabs[i].id);
				td.setAttribute("align","center");
				td.setAttribute("valign","middle");

	  			tr.appendChild(td);

				tbdy.appendChild(tr);
			}
		}

	}

	tbl.appendChild(tbdy);
	$$DOM(this.tabAreaName).appendChild(tbl);
	$$DOM(tblID).style.margin = "0px";
	$$DOM(tblID).cellPadding = "0";
	$$DOM(tblID).cellSpacing = "0";


	//add the properties to each td
	for (i=0;i<this.tabs.length;i++) {
		if (this.tabs[i].show) {
	  		$$DOM(this.tabs[i].id).className = this.tabs[i].className;
	  		$$DOM(this.tabs[i].id).style.height = this.tabHeight;
	  		$$DOM(this.tabs[i].id).style.width = this.tabWidth;
			$$DOM(this.tabs[i].id).innerHTML = this.tabs[i].HTMLtext;


			if (this.tabs[i].mouseOverClass!="") {

				$$DOM(this.tabs[i].id).onmouseover = function() {
					var mObj = eval(getThisInstanceName(this));
					var index = getThisIndexNumber(this);

					if (index!=mObj.selectedTab) {
						this.className = mObj.tabs[index].mouseOverClass;
						this.innerHTML = mObj.tabs[index].mouseOverText;
					}
				};

				$$DOM(this.tabs[i].id).onmouseout = function() {
					var mObj = eval(getThisInstanceName(this));
					var index = getThisIndexNumber(this);

					if (index!=mObj.selectedTab) {
						this.className = mObj.tabs[index].className;
						this.innerHTML = mObj.tabs[index].HTMLtext;
					}
				};

				$$DOM(this.tabs[i].id).onclick = function() {
					var index = getThisIndexNumber(this);
					var MObj = eval(getThisInstanceName(this));

					MObj.selectTab(index);
				};
			}
		}
	}

	this.selectTab(this.selectedTab);

	if (this.fit2Win) this.doAutoResize();
}

DOMTabbedMenu.prototype.selectTab = function(index) {
	if (this.tabs[index].show) {
		if (index==null) {
			index = this.selectedTab;
		} else {
			this.selectedTab = index;
		}

		var bodyObj = $$DOM(this.bodyAreaName);


		//SET THE SELECTED TAB
		//clear the set the tabs
		for (var x=0;x<this.tabs.length;x++) {
			if (this.tabs[x].show) {
				if (x==index) {
					$$DOM(this.tabs[x].id).className = this.tabs[x].mouseOverClass;
					$$DOM(this.tabs[x].id).innerHTML = this.tabs[x].mouseOverText;
				} else {
					$$DOM(this.tabs[x].id).className = this.tabs[x].className;
					$$DOM(this.tabs[x].id).innerHTML = this.tabs[x].HTMLtext;
				}
			}
		}

		//reset overflow
		bodyObj.style.overflow = "auto";

		//clear the tab body
		while (bodyObj.firstChild) {
			bodyObj.removeChild(bodyObj.firstChild);
		}
		bodyObj.innerHTML = "";
		bodyObj.className = this.clsName;

		//depending on the clicked tab's location type, write content
		var dataObj = this.tabs[index].data;

		if (dataObj=="") {
			bodyObj.innerHTML="";
		} else {
			switch (this.tabs[index].location) {
				case 0:
					dataObj = $$DOM(dataObj);
					bodyObj.innerHTML = dataObj.innerHTML;
					addClassName(bodyObj,dataObj.className);

					break;
				case 1:
					bodyObj.innerHTML = this.loadText;
					returnAJAXHTML(dataObj,bodyObj);

					break;
				case 2:
					var nme = document.createElement("iframe");
	  				nme.setAttribute("name",bodyObj.id + "_iframe");
	  				nme.setAttribute("id",bodyObj.id + "_iframe");
	  				$$DOM(bodyObj).appendChild(nme);
	  				$$DOM(bodyObj.id + "_iframe").style.width = bodyObj.style.width;
	  				$$DOM(bodyObj.id + "_iframe").style.height = bodyObj.style.height;
	  				$$DOM(bodyObj.id + "_iframe").style.border = "black 0px solid";
					bodyObj.style.overflow = "visible";
	  				$$DOM(bodyObj.id + "_iframe").src = dataObj;

					break;
			}
		}
	}
}

DOMTabbedMenu.prototype.updateTabHTML = function(whichTab,html,append) {
	var bodyObj = $$DOM(this.bodyAreaName);
	if (isNaN(whichTab))
		var tab = $$DOM(whichTab)
	else
		var tab = $$DOM(this.tabs[whichTab].data);

	if (append) {
		tab.innerHTML+=html;
		bodyObj.innerHTML = tab.innerHTML;
	} else {
		tab.innerHTML=html;
		bodyObj.innerHTML = tab.innerHTML;
	}
}

DOMTabbedMenu.prototype.getFirstTab = function() {return this.tabs[0];}

DOMTabbedMenu.prototype.getLastTab = function() {return this.tabs[this.tabs.length-1];}

DOMTabbedMenu.prototype.getTabById = function(id) {
	for (var i=0;i<this.tabs.length;i++) {
		if (this.tabs[i].id==id)
			return this.tabs[this.tabs.length-1];
	}
}

DOMTabbedMenu.prototype.GetObject = function(tagName,objID) {
	var objs = document.getElementById(this.id).getElementsByTagName(tagName);
	for (var i=0;i<objs.length;i++) {
		if (objs[i].id==objID || objs[i].name==objID) return objs[i];
	}
	return null;
}
//END DOMTABBEDMENU CLASS DEFINITION


///////////////////////////////////////////////////////////
/********HELPER FUNCTIONS FOR THE TABBED MENU OBJECT******/
//Quick functions for location DOM objects
function $$DOM(obj) {
	if (typeof(obj)=="string") obj=find_DOM_Object(obj);
	return obj;
}

function find_DOM_Object(objectId) {
	if (document.getElementById) {return (document.getElementById(objectId));}
	else if (document.all) {return (document.all[objectId]);}
	else if (document.layers) {return (document.layers[objectId]);}
	else {return (document.getElementById(objectId));}
}

function getThisInstanceName(id) {
	var a = getTheObjectName($$DOM(id)).split("_");
	return a[a.length-1];
}

function getThisIndexNumber(id) {
	var a = getTheObjectName($$DOM(id));
	return parseInt(a);
}

function getTheObjectName(obj) {
	obj = $$DOM(obj);
	if (obj.id!="") {
		return obj.id;
	} else if (obj.name!="") {
		return obj.name;
	} else {
		return "";
	}
}

function SetObjectClassName(obj,cls) {
	$$DOM(obj).className = cls;
}

function returnAJAXHTML(url,name) {
	name = $$DOM(name);

	var _xmlHttp = getTheAJAXObject();

	if (_xmlHttp==null) {
		alert("Your browser does not support this action.\nIf using IE, ActiveX Objects may not be allowed.");
		return;
	}

	_xmlHttp.onreadystatechange = function() {
		if (_xmlHttp.readyState==4 || _xmlHttp.readyState=="complete")
		{
			name.innerHTML="";
			name.innerHTML=_xmlHttp.responseText;
		}
	};

	_xmlHttp.open("GET",url,true);
	_xmlHttp.send(null);
}

function getTheAJAXObject() {
	var objXMLHttp=null
	try {// Firefox, Opera 8.0+, Safari
		objXMLHttp=new XMLHttpRequest();
	}
	catch (e) {// Internet Explorer
		try {
			objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				return null;
			}
		}
	}
	return objXMLHttp;
}

function getWindowWidth() {
	if (self.innerHeight) { // all except Explorer
		return self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight) {// Explorer 6 Strict Mode
		return document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		return document.body.clientWidth;
	}
}

function getWindowHeight() {
	if (self.innerHeight) { // all except Explorer
		return self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {// Explorer 6 Strict Mode
		return document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		return document.body.clientHeight;
	}
}

function addClassName(obj,cls) {
	if (obj && cls) {
		if (cls.indexOf(".")==0) cls=cls.substring(1,cls.length);
		$$DOM(obj).className += " "+cls;
	}
}

function removeClassName(obj,cls) {
	if (obj && cls && ($$DOM(obj).className!="")) {
		if (cls.indexOf(".")==0) cls=cls.substring(1,cls.length);
		var classes = $$DOM(obj).className.split(" ");
		for (var i=0;i<classes.length;i++) {
			if (classes[i].toLowerCase()==cls.toLowerCase()) classes[i]="";
		}
		$$DOM(obj).className = classes.join(" ");
	}
}
