function openPopupCalendar(strInputID, e)
	{
	var x=y=0;
    if (e != '')
		{
        x = e.screenX+15;
        y = e.screenY+10;
		}
	var strDate = document.getElementById(strInputID + '_date').value;
	if (strDate != '')
		{
		var arrDate = strDate.split("-");
		var strSelectedDate = arrDate[0] + arrDate[1] + arrDate[2] ;
		}
	var win = window.open('/includes/popup_calendar.asp?target=' + strSelectedDate + '&inp=' + strInputID,'winPopupCalendar','screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ',toolbar=no,resizable=yes,scrollbars=no,width=280,height=230,status=no,menubar=no,copyhistory=no');
	win.focus();
	return false;
	}






function moveRow(rowID, sDirection, sTableName)
	{
	var oTbody = document.getElementById(sTableName).getElementsByTagName("tbody");
	var oRows = oTbody[0].getElementsByTagName("tr");


	/* sDirection:  u = up, d = down */
	/* determine the rowIDs of the two rows we need to pull */
	if (sDirection == "u")
		{
		if (rowID == 0)
			{ return false; }
		else
			{ var iTargetRow  = (rowID - 1); }
		}
	else if (sDirection == "d")
		{
		if (rowID == (oRows.length-1))      /* because .length is not zero-indexed */
			{ return false; }
		else
			{ var iTargetRow  = (rowID + 1); }
		}


	/* go through the table, find out how many rows there are and nab the current one when we find it */
	for (var ii = 0; ii < oRows.length; ii++)
		{
		if (oRows[ii].id.indexOf("tr__") >= 0)
			{
			if (ii == rowID)
				{ var oThisRow = oRows[ii]; }

			if (ii == iTargetRow)
				{ var oTargetRow = oRows[ii]; }
			}
		}


	if (oThisRow && oTargetRow)
		{
		var oThisCells = oThisRow.getElementsByTagName("td");
		var oThisCells__copy = oThisRow.getElementsByTagName("td");

		var oTargetCells = oTargetRow.getElementsByTagName("td");
		var oTargetCells__copy = oTargetRow.getElementsByTagName("td");

		var sRegexPattern = /(moveRow\()[0-9].*?(,.*?\))/gi

		for (ii = 0; ii < oThisCells.length; ii++)
			{
			var aa = oThisCells[ii].innerHTML.replace(sRegexPattern , "$1" + iTargetRow + "$2")
			var bb = oTargetCells[ii].innerHTML.replace(sRegexPattern , "$1" + rowID + "$2");
			oThisCells[ii].innerHTML = bb;
			oTargetCells[ii].innerHTML = aa;
			}
		}


	document.getElementById("btnPositions").style.visibility = "visible";
	return true;
	}






function insertTab(e, oInput)
	{
	if (e != null)
		{
		if (oInput.selectionStart)
			{ insertTabMoz(e, oInput); }
		else
			{ insertTabIE(e, oInput); }
		}
	return true;
	}
function insertTabMoz(e, oInput)
	{
	if (e.keyCode==9)
		{
		e.preventDefault();
		var sInput = oInput.value;
		var iLeft = oInput.selectionStart;
		var iRight = oInput.selectionEnd;
		var sLeft = sInput.slice(0, iLeft);
		var sRight = sInput.slice(iRight, sInput.length);
		sInput = sLeft + "\t" + sRight;
		oInput.value = sInput;
		oInput.setSelectionRange( iLeft+1 , iLeft+1);
		e.stopPropagation();
		}
	}
function insertTabIE(e, oInput)
	{
	if (e.srcElement)
		{
		if (e.keyCode == 9)
			{
			if (document.selection != null)
				{
				document.selection.createRange().text = '\t';
				e.returnValue = false;
				}
			else
				{ e.srcElement.value += '    '; }
			}
		}
	}




function preventEnter(e, oInput)
	{
	if (e.keyCode == 13)
		{ return false; }
	else
		{ return true; }
	}








function checkValueLength(e, oInput, maxLength)
	{
	var key, keychar;
	if (window.event)
		{ key = window.event.keyCode; }
	else if (e)
		{ key = e.which; }
	else
	   { return true; }

	/* for keycodes: http://www.cambiaresearch.com/cambia3/snippets/javascript/reference/javascript_charcodes.aspx */
	/* these are control keys so they shouldn't raise the pop-up alert because they've probably been used for EDITING the content */
	var bShowAlert = true;
	var aKeys = new Array(8,16,17,18,19,20,27,33,34,35,36,37,38,39,40,91,92,93,112,113,114,115,116,117,118,119,120,121,122,123,144,145)
	for (var ii=0; ii < aKeys.length; ii++)
		{
		if (key == aKeys[ii])
			{bShowAlert = false};
		}

	var oCounter = document.getElementById(oInput.id + "__length");
	var iLength = (oInput.value.length);
	var iLengthRemaining = (maxLength - iLength);

	//oCounter.value = iLengthRemaining;
	oCounter.innerHTML = iLengthRemaining;
	if (iLengthRemaining < 0)
		{ oCounter.className = "spanValueWarning";}
	else
		{ oCounter.className = "spanValue"; }

	if ((bShowAlert == true) && (iLengthRemaining < 0))
		{
		if (confirm("You have reached the maximum length allowed for this input (" + maxLength + " character" + ((maxLength > 1) ? "s" : "") + ").\nClick \"OK\" to continue, or \"Cancel\" to trim the entry to the maximum length.") == false)
			{
			oInput.value = oInput.value.substring(0, maxLength);
			//oCounter.value = 0;
			oCounter.innerHTML = 0;
			oCounter.className = "spanValue";
			}
		}

	return true;
	}





function toggleCheckselectItem(sCheckboxId)
	{
	var oCheckbox = document.getElementById(sCheckboxId);
	var oLi = oCheckbox.parentNode.parentNode;
	if (oCheckbox.checked == true)
		{ oLi.className = "selected"; }
	else
		{ oLi.className = "normal"; }
	return true;
	}

