function getRequestObj()
{
	var xmlHttpReq = false;
	
	// Mozilla/Safari
	if(window.XMLHttpRequest)
	{
		xmlHttpReq = new XMLHttpRequest();
	}
	
	//IE
	else if(window.ActiveXObject)
	{
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlHttpReq;
}


function genRequestURL(genForm)
{
	var form = document.forms[genForm];
	var query = "";
	for (var i=0; i<form.elements.length; i++)
	{
		if(query.length > 0)
		{
			query += "&";
		}
		query += form.elements[i].name + "=" + escape(form.elements[i].value);
	}
	return query;
}


/*
 * Given a textarea object, a start point, and a number of characters to select
 * cause the characters to be selected (highlighted)
 */
function selectRange(fieldToSelect, selStart, selLength)
{
	if (fieldToSelect.createTextRange)
	{
		// IE uses createTextRange
		var srange = fieldToSelect.createTextRange();
		srange.moveStart("character", selStart);
		srange.moveEnd("character", selLength - fieldToSelect.value.length);
		srange.select();
	}
	else if (fieldToSelect.setSelectionRange)
	{
		fieldToSelect.setSelectionRange(selStart, fieldToSelect.value.length);
	}
	
	fieldToSelect.focus();
}




// JavaScript object to add events to objects.
// To use this, pass in an object, the event to add (leave off the letters "on" - so 'onsubmit' 
// becomes 'submit'), and the name of the function to execute when the
// event is triggered:
// var form = document.forms['order'];
// Event.add(form, 'submit', alert('Submitted!')); 
//

var ajEvent = {
	add: function(obj,type,fn)
	{
		if (obj.attachEvent)
		{
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn](window.event); }
			obj.attachEvent('on'+type,obj[type+fn]);
		}
		else
		{
			obj.addEventListener(type,fn,false);
		}
	},
	remove: function(obj,type,fn)
	{
		if (obj.detachEvent) 
		{
			obj.detachEvent('on'+type,obj[type+fn]);
			obj[type+fn] = null;
		}
		else
		{
			obj.removeEventListener(type,fn,false);
		}
	}
}

/* JavaScript to hide or display a section of a page.  This is often useful when we have a section of a 
 * form that we need to have displayed when a user checks a box, or something like that:
 *
 * 
 */ 

var Layer = {
    getLayerStyle:function(whichLayer) 
	{
		if (document.getElementById)
		{
			// this is the way the standards work
			var style2 = document.getElementById(whichLayer).style;
		}
		else if (document.all)
		{
			// this is the way old msie versions work
			var style2 = document.all[whichLayer].style;
		}
		else if (document.layers)
		{
			// this is the way nn4 works
			var style2 = document.layers[whichLayer].style;
		}
		return style2;
    },
    enable: function(whichLayer)
	{
       this.getLayerStyle(whichLayer).display = "";
    },
    disable: function (whichLayer)
	{
       this.getLayerStyle(whichLayer).display = "none";
    }
}



// Function to add a row to a table
// Must pass in a table object and an object containing the data to add
function addRowToTable(tbl, data)
{
	var lastRow = tbl.rows.length;
	// if there's no header row in the table, then iteration = lastRow + 1
	var row = tbl.insertRow(lastRow);
	for (var colnum=0; colnum < data.length; colnum++)
	{
		var cell = row.insertCell(colnum);
		var textNode = document.createTextNode(data[colnum]);
		cell.appendChild(textNode);
	}
}

// Function to remove a row from a table
// Must pass in a table object...
function removeRowFromTable(tbl, rownum)
{
	if (rownum == null)
	{
		var rownum = tbl.rows.length;
	}
	if (rownum > 1)
	{
		tbl.deleteRow(rownum - 1); // Make sure we don't delete the table heading.
		return true;
	}
	else
	{
		return false; // Return false when there are no more rows to delete.
	}
}

function selectTableRow(row)
{
	var cols = row.getElementsByTagName("td");
	var value=cols[0].innerHTML;
	return(value);
}

function changeColor(column, inout, color)
{
	if (inout == 1)
	{
		this.origValue = column.innerHTML;
		// column.innerHTML += " (click to toggle)";
		this.bgColor = column.style.backgroundColor ;
		column.style.backgroundColor = color; //'#bcd4ec';
	}
	else
	{
		// column.innerHTML = this.origValue;
		column.style.backgroundColor = this.bgColor;
	}
}