
//Wait function is used to pause execution of code
//for the passed in milliseconds 
function wait(milliseconds)
{
	d = new Date() //today's date
	while (1)
	{
		mill=new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if( diff > milliseconds ) {break;}
	}
}
function resizeWindow(x,y)
{
	window.resizeTo(x,y);
}
function checkParent()
{
	if (window.opener.closed)
	{
		window.close();
	}
}
function popupWin(url, w, h)
{
	var windowprops;
	var scrollIt = "yes";
	var targetName = "";
	var left = (screen.width - w) / 2;
	var top = (screen.height - h) / 2;
	if(popupWin.arguments.length>3)
		scrollIt = popupWin.arguments[3];
	if(popupWin.arguments.length>4)
		targetName = popupWin.arguments[4];
		
	windowprops = "width="+w+",height="+h+",left="+left+",top="+top+",location=0,toolbar=no,menubar=no,scrollbars="+scrollIt+",resizable=yes";
	window.open(url, targetName, windowprops);
}
function checkParent()
{
	if (window.opener.closed)
	{
		window.close();
	}
	setTimeout("checkParent()", 2000);
}
function setTxBox(obj, strTB)
{
	document.getElementById(strTB).innerText = obj.options[obj.selectedIndex].text;
}
function getRadioButtonVal(obj)
{
	for(var i=0; i < obj.length; i++)
	{
		if(obj[i].checked)
		{
			return obj[i].value;
		}
	}
}
function getMonthName(iMo, bolAbbrev)
{
	var sMonth = "";
	switch (iMo)
	{
		case 1:
			if (bolAbbrev)
				sMonth = "Jan";
			else
				sMonth = "January";
			break;
		case 2:
			if (bolAbbrev)
				sMonth = "Feb";
			else
				sMonth = "February";
			break;
		case 3:
			if (bolAbbrev)
				sMonth = "Mar";
			else
				sMonth = "March";
			break;
		case 4:
			if (bolAbbrev)
				sMonth = "Apr";
			else
				sMonth = "April";
			break;
		case 5:
			if (bolAbbrev)
				sMonth = "May";
			else
				sMonth = "May";
			break;
		case 6:
			if (bolAbbrev)
				sMonth = "Jun";
			else
				sMonth = "June";
			break;
		case 7:
			if (bolAbbrev)
				sMonth = "Jul";
			else
				sMonth = "July";
			break;
		case 8:
			if (bolAbbrev)
				sMonth = "Aug";
			else
				sMonth = "August";
			break;
		case 9:
			if (bolAbbrev)
				sMonth = "Sep";
			else
				sMonth = "September";
			break;
		case 10:
			if (bolAbbrev)
				sMonth = "Oct";
			else
				sMonth = "October";
			break;
		case 11:
			if (bolAbbrev)
				sMonth = "Nov";
			else
				sMonth = "November";
			break;
		case 12:
			if (bolAbbrev)
				sMonth = "Dec";
			else
				sMonth = "December";
			break;
	}
	return sMonth;
}
//http://www.codeproject.com/useritems/JavaScript_Tips.asp
function StringBuilder()
{
	this.buffer = [];
}
StringBuilder.prototype.Append = function(str)
{
	this.buffer[this.buffer.length] = str;
};
StringBuilder.prototype.ConvertToString = function()
{
	return this.buffer.join('');
};
function $()
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
   }
   return elements;
}
function SwapRows(rowElem, dirUp, ignoreFirstRow)
{
	var rowElemToSwap = (dirUp) ? rowElem.previousSibling : rowElem.nextSibling;
	// Firefox returns a blank text node for the sibling
	while (rowElemToSwap && rowElemToSwap.nodeType != 1)
	{
		rowElemToSwap = (dirUp) ? rowElemToSwap.previousSibling :
		rowElemToSwap.nextSibling;
	}
	if (rowElemToSwap && !(ignoreFirstRow && rowElemToSwap.rowIndex == 0))
	{
		var rowCells = rowElem.cells;
		var colInner;
		for (var i = 0, loopCnt = rowCells.length; i < loopCnt; i++)
		{
			colInner = rowCells[i].innerHTML;
			rowCells[i].innerHTML = rowElemToSwap.cells[i].innerHTML;
			rowElemToSwap.cells[i].innerHTML = colInner;
		}
	}
}
function HashTable()
{
	this.hashArr = new Array();
	this.length = 0;
}
HashTable.prototype.get = function(key)
{
	return this.hashArr[key];
};
HashTable.prototype.put = function(key, value)
{
	if (typeof(this.hashArr[key]) == 'undefined')
	{
		this.length++;
	}
	this.hashArr[key] = value;
};
HashTable.prototype.remove = function(key)
{
	if (typeof(this.hashArr[key]) != 'undefined')
	{
		this.length--;
		var value = this.hashArr[key];
		delete this.hashArr[key];
		return value;
	}
};
HashTable.prototype.has = function(key)
{
	return (typeof(this.hashArr[key]) != 'undefined');
};
Array.prototype.has = function(value)
{
	var i;
	for (var i = 0, loopCnt = this.length; i < loopCnt; i++)
	{
		if (this[i] === value)
		{
			return true;
		}
	}
	return false;
};
function LoseFocus(ddlElem)
{
	ddlElem.blur();
}
function LoseFocusById(id)
{
	//blur() is not working so we'll set focus to the passed in control id that's not a form element. ie a table
	//$(id).blur();
	$(id).focus();
}
function ToggleDisplay(elemId)
{
	var elem = document.getElementById(elemId);
	elem.style.display = (elem.style.display != 'none') ? 'none' : '';
}
//http://www.codeproject.com/useritems/JavaScript_Tips_-_Part_2.asp

//Start - Place a div over a drop down box using iframe
//http://esdi.excelsystems.com/wsexmp/divdrp.pgm?wsnum=00110
function positionIFrame(divid, frmid)
{
	var div = document.getElementById(divid);
	var frm = document.getElementById(frmid);
	frm.style.left = div.style.left;
	frm.style.top = div.style.top;
	frm.style.height = div.offsetHeight;
	frm.style.width = div.offsetWidth;
	frm.style.display = "block";	
}
//findPosX and findPosY are included only to put the div over the dropdownbox.
//They are not necessary in order to position the iFrame under the div
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 positionDiv(divid, frmid, selectId)
{	
	var div = document.getElementById(divid);
	div.style.left=findPosX(document.getElementById(selectId))+ 5 + "px";
	div.style.top=findPosY(document.getElementById(selectId))+ 5 + "px";
	positionIFrame(divid, frmid);
}
//End - Place a div over a drop down box using iframe

//Must have filter applied to the objects style
function fadeObj(objName)
{
	var obj = $(objName);
	obj.style.display = 'none';
	obj.filters[0].Apply();
	obj.style.display = '';
	obj.filters[0].Play();
}

