function getPosition(theElement)
	{
		var positionX = 0;
		var positionY = 0;
		while (theElement != null)
			{
				positionX += theElement.offsetLeft;
				positionY += theElement.offsetTop;
				theElement = theElement.offsetParent;
			}
		return [positionX, positionY];
	}
	
	/*  commented out because event stack order is different IE vs mozilla; use next version instead
function addLoadEvent(fn)
	{
	if (typeof window.addEventListener != 'undefined')
		{
		window.addEventListener('load', fn, false);
		}
	else if (typeof document.addEventListener != 'undefined')
		{
		document.addEventListener('load', fn, false);
		}
	else if (typeof window.attachEvent != 'undefined')
		{
		window.attachEvent('onload', fn);
		}
	else
		{
		var oldfn = window.onload;
		if (typeof window.onload != 'function')
			{
				window.onload = fn;
			}
		else
			{
			window.onload = function()
				{
					oldfn();
					fn();
				};
			}	
		}
	}*/
	
function addLoadEvent(fn)
{
	if (!window.loadEvents) {
		window.loadEvents = [];
		var loadFn = function() { for (var i=0,f;(f=window.loadEvents[i]);i++) f(); }
		if (window.addEventListener) 
			window.addEventListener('load', loadFn, false)
		else if (window.attachEvent) 
			window.attachEvent('onload', loadFn);
	}
	
	window.loadEvents.push(fn);
}
	
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
	



function getElementsByClassName(oElm, strTagName, strClassName)
		{
			//popularly used function to return array of elements which have certain class 
			var arrElements = oElm.getElementsByTagName(strTagName);
		    var arrReturnElements = new Array();
		    strClassName = strClassName.replace(/\-/g, "\\-");
		    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
		    var oElement;
		    for(var i=0; i<arrElements.length; i++)
		    	{
			       oElement = arrElements[i];  				
			       if(oRegExp.test(oElement.className))
			        {
			            arrReturnElements.push(oElement);
			        }  
		   		}
		    return (arrReturnElements)
		}
	


		
function addEvent(element, type, handler) {
	// assign each event handler a unique ID
	if (!handler.$$guid) handler.$$guid = addEvent.guid++;
	// create a hash table of event types for the element
	if (!element.events) element.events = {};
	// create a hash table of event handlers for each element/event pair
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		// store the existing event handler (if there is one)
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}
	// store the event handler in the hash table
	handlers[handler.$$guid] = handler;
	// assign a global event handler to do all the work
	element["on" + type] = handleEvent;
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	// delete the event handler from the hash table
	if (element.events && element.events[type]) {
		delete element.events[type][handler.$$guid];
	}
};

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(window.event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) == false) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};


//internet script to get properties even if they haven't been set using javascript!!
function getStyle(el,styleProp)
	{
		var x = el;
		if (x.currentStyle)
			var y = x.currentStyle[styleProp];
		else if (window.getComputedStyle)
			var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
		return y;
	}
	
function insertAtCursor(myField, myValue) 
	{
		if (document.selection && myField.type && myField.type != "text") 
			{
				myField.focus();
				sel = document.selection.createRange();
				sel.text = myValue;
			}
		
		else if ((myField.selectionStart || myField.selectionStart == '0')) 
			{
				var startPos = myField.selectionStart;
				var endPos = myField.selectionEnd;
				myField.value = myField.value.substring(0, startPos)
								+ myValue
								+ myField.value.substring(endPos, myField.value.length);
			} 
		else 
			{
				myField.value += myValue;
			}
	}

	
function getScreenWidth()
	{
		var x;
		if (self.innerHeight) // all except Explorer
		{
			x = self.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			x = document.documentElement.clientWidth;
		}
		else if (document.body) // other Explorers
		{
			x = document.body.clientWidth;
		}
		
		return x;
	}	
	
function getScreenHeight()
	{
		var y;
		if (self.innerHeight) // all except Explorer
		{
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			y = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			y = document.body.clientHeight;
		}

		return y;
	}	
	
function triggerEvent(fieldRef, event)
	{
		var onEvent = "on" + event;
	 	if(fieldRef.fireEvent)
		 	{   
		 		fieldRef.fireEvent(onEvent);
			}		
		else	
			{
				var evt = document.createEvent("HTMLEvents");
				evt.initEvent(event, true, true);
				fieldRef.dispatchEvent(evt);
			}
	}
	
	
function jscss(a,o,c1,c2)
	{	
		switch (a)
		{
			case 'swap':
				o.className=!jscss('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
				break;
			case 'add':
				if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
				break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
				break;
			case 'check':
				return new RegExp('\\b'+c1+'\\b').test(o.className)
				break;
		}
	}
		
function arrayToList(arrayName)
	{
		 // turns a list of array values (such as from a series of checkboxes) into a comma-delimited list.		 	
		valueToReturn="";
		for(var i=0;i<arrayName.length;i++)
			{		 		
				// only add it to the list if checked!
				if(arrayName[i].checked)
					{
						valueToReturn=valueToReturn + arrayName[i].value + ",";
					}
				 //a multi-select box comes in as array of options
				 if(arrayName[i].selected)
					{
						valueToReturn=valueToReturn + arrayName[i].value + ",";
					}
				 //multiple select boxes might also be an issue, have to check their values as well
				 if (arrayName[i].type && arrayName[i].type != "multiple-select" &&
				 		arrayName[i].options && arrayName[i].selectedIndex != -1)
					{
						valueToReturn = valueToReturn + arrayName[i].options[arrayName[i].selectedIndex].value + ",";
					}			 	 			
				 if(arrayName[i].type && arrayName[i].type=="text" && arrayName[i].value)
					{
						valueToReturn += arrayName[i].value;
					}				  	 	
			}
		// hack off the last comma
		if(valueToReturn.length > 0 && valueToReturn.substr(valueToReturn.length-1,1) == ",")
			{
				valueToReturn=valueToReturn.substring(0,valueToReturn.length-1);	
			}
		 return valueToReturn;
	}				
		
function getFieldValue(fieldRef)
	{
		var theValue;	
		// if it's an array of checkboxes or radio buttons,
		// or a multi-select
		if (fieldRef.type && (fieldRef.type == "select-multiple"))
			{	
				theValue=arrayToList(fieldRef.options);				
			}
		else if (!fieldRef.value)
			{
				theValue=arrayToList(fieldRef);				
			}
		else if (fieldRef.type && (fieldRef.type == "checkbox" || fieldRef.type == "radio"))
			{
				if(fieldRef.checked)
					{
						theValue = fieldRef.value;
					}
				else
					{
						theValue = "";
					}
			}		
		else
			{
				theValue=fieldRef.value;
			}
		return theValue;
	}
		
			
	
/*
	This example function takes four parameters:

		a 
		defines the action you want the function to perform. 
		o 
		the object in question. 
		c1 
		the name of the first class 
		c2 
		the name of the second class 
		Possible actions are:
		
		swap 
		replaces class c1 with class c2 in object o. 
		add 
		adds class c1 to the object o. 
		remove 
		removes class c1 from the object o. 
		check 
		test if class c1 is already applied to object o and returns true or false. 
*/
