function openHelpBig(key)
{
	window.showModalDialog('/meetmaker/help/helppopup.aspx?helpid=' + key + '&size=big','','dialogWidth: 540px;dialogHeight: 500px;status: no;unadorned: yes;scroll: yes;help: no;resizable: no')
}

function openHelpSmall(key)
{
	window.showModalDialog('/meetmaker/help/helppopup.aspx?helpid=' + key,'','dialogWidth: 340px;dialogHeight: 300px;status: no;unadorned: yes;scroll: yes;help: no;resizable: no')
}

// Dirty variable for forms that use grids
var __isDirty = false;

// Cell button click event for reg edit on meetreg.aspx
function RegEditChgLvlBtnClick(gridId, cellId)
{
	//Determine the row we are on and get RegDetailID value
	var cell = igtbl_getCellById(cellId);
	if(cell)
	{
		var idcell = cell.Row.getCell(21);	//RegDetailID
		if(idcell)
		{
			//window.open('changelevel.aspx?id=' + idcell.getValue());
			//Open edit level popup for selected regdetailid
			var vReturnValue = window.showModalDialog('changelevel.aspx?id=' + idcell.getValue(),'','dialogWidth: 340px;dialogHeight: 300px;status: no;unadorned: yes;scroll: yes;help: no;resizable: no')
			//if (typeof(vReturnValue) != "undefined")
			if(vReturnValue != null)
			{ 
				window.location = 'meetreg.aspx?a=cl&rdid=' + idcell.getValue() + '&newid=' + vReturnValue;
				return true;
			}
		}
	}
}

//Set __isDirty column of a grid row
function setIsDirty(gridId, cellId)
{
	var cell = igtbl_getCellById(cellId);
	var row = cell.getRow();
	row.getCellFromKey('__isDirty').value = true;
	__isDirty = true;
}

// Set isDirty variable
function OnAfterCellUpdate(gridId, cellId)
{
	__isDirty = true;
}


// Set isDirty variable
function OnAfterCellUpdateRegGrid(gridId, cellId)
{
	__isDirty = true;

	//See if this is the register column
	var cell = igtbl_getCellById(cellId);
	if(cell.Column.Key=="Register")
	{
		var feeCell = cell.Row.getCell(24)	//Reg Fee
	}
	else if(cell.Column.Key=="TeamMember")
	{
		var feeCell = cell.Row.getCell(25)	//Team Fee
	}
	if(feeCell)
	{
		if(cell.getValue())
		{
			if(cell.Column.Key=="Register")
			{
				//Add fee to total
				document.getElementById("FeeTotal").innerHTML = parseFloat(document.getElementById("FeeTotal").innerHTML) + feeCell.getValue();
			}
			//Add count
			updateCellFooter(cellId, parseFloat(getCellFooterValue(cellId)) + 1);
		}
		else
		{
			if(cell.Column.Key=="Register")
			{
				//Minus fee from total
				document.getElementById("FeeTotal").innerHTML = parseFloat(document.getElementById("FeeTotal").innerHTML) - feeCell.getValue();
			}			
			//Minus count
			updateCellFooter(cellId, parseFloat(getCellFooterValue(cellId)) - 1);
		}
		//Transfer value from hidden control to visible control in currency format
		document.getElementById("FeeTotalCurr").innerHTML = formatCurrency(parseFloat(document.getElementById("FeeTotal").innerHTML));
	}
}

//Updates cell footer
function updateCellFooter(cellId, value)
{
    var cell=igtbl_getElementById(cellId);
    if(cell.parentNode.parentNode.nextSibling)
    {
        var footer=cell.parentNode.parentNode.nextSibling.childNodes[0].childNodes[cell.cellIndex];
        footer.innerText=value;
    }
}

//Returns current cell footer value
function getCellFooterValue(cellId)
{
    var cell=igtbl_getElementById(cellId);
    if(cell.parentNode.parentNode.nextSibling)
    {
        var footer=cell.parentNode.parentNode.nextSibling.childNodes[0].childNodes[cell.cellIndex];
        return footer.innerText;
    }
}

// Infragistics' grid event handler. Fired after user adds a new row.
// Fixes incorrect row positioning after a new row is added.
function OnAfterRowInsert(gridId, rowId) 
{
	var gridObject = igtbl_getGridById(gridId);
	if (gridObject != null)
	{
		var divElement = gridObject.DivElement;
		if (divElement != null)
		{
			divElement.scrollLeft = 0;
			if (divElement.scrollHeight > divElement.offsetHeight)
				divElement.scrollTop = divElement.scrollHeight;
		}
	}
	return false;
}

// Just for roster grids
function OnAfterRowInsertRoster(gridId, rowId) 
{
	var gridObject = igtbl_getGridById(gridId);
	if (gridObject != null)
	{
		// If gymnast or coach was just added add all three levels
		
		// Get the band object based on the passed-in row ID.
		var band = igtbl_getBandById(rowId);
	    
		// Do something specific based on the band's key
		if(band.Key == "Participants")
		{
			igtbl_addNew(gridId, 1);
			igtbl_addNew(gridId, 2);
			igtbl_setActiveRow(gridId, igtbl_getElementById(rowId));
		}

		var divElement = gridObject.DivElement;
		if (divElement != null)
		{
			divElement.scrollLeft = 0;
			if (divElement.scrollHeight > divElement.offsetHeight)
				divElement.scrollTop = divElement.scrollHeight;
		}
	}
	return false;
}

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}