﻿/* 
DataGrid Common Script 
Version 4.1.1000.1
Copyright (c) Galaxy Software Services. All Rights Reserved.
The JavaScript functions in this file are intended for the internal use of the Stirrup.ASPXTemplate Web Controls only.
*/
var __ATCurDataGrid;
var __ATRowClassName = "NormalRow";
function __ATGetGridElement(){
	var objRow=__ATGetParentElementByTagName(event.srcElement,"TR");
	var objGrid=__ATGetParentElementByTagName(objRow,"TABLE");
	return objGrid
}
var colorPreSelRow = "";
function __ATSelectGridRow(){
	var objRow=__ATGetParentElementByTagName(event.srcElement,"TR");
	__ATCurDataGrid = __ATGetGridElement();
	if(__ATCurDataGrid.EditItemIndex>-1) return false;
	if(__ATCurDataGrid.SelectedIndex>-1){
		var objPreSelRow=__ATCurDataGrid.rows[__ATCurDataGrid.SelectedIndex];
		if(objPreSelRow.style.getAttribute("backgroundColor")!=""){
			objPreSelRow.style.setAttribute("backgroundColor",colorPreSelRow);
		}
		else{
			var strCss = objPreSelRow.getAttribute("__IClassName");
			if(strCss==null){
				objPreSelRow.className = "NormalRow";}
			else{
				objPreSelRow.className = strCss;
				objPreSelRow.removeAttribute("__IClassName");}
		}
	}
	if(objRow.style.getAttribute("backgroundColor")!=""){
		colorPreSelRow = objRow.style.getAttribute("backgroundColor");
		objRow.style.backgroundColor="navajowhite";}
	else{
		if(objRow.getAttribute("__IClassName")==null) objRow.setAttribute("__IClassName",objRow.className);
		objRow.className = "SelectedRow";}
	__ATCurDataGrid.setAttribute("SelectedIndex",objRow.rowIndex);
	var intSelIdx =objRow.rowIndex;
	var intHRows = __ATCurDataGrid.getAttribute("HeaderRows");
	if(intHRows!=null) intSelIdx=intSelIdx-intHRows;
	__ATCreateHiddenElement(__ATCurDataGrid.id + "_SelectedIndex",intSelIdx);
}

function __ATFireGridSelectCommand(vobjGrid){
	if(vobjGrid==null) vobjGrid = __ATGetGridElement();
	if(vobjGrid.SelectedIndex>-1){
		var objCurSelRow=vobjGrid.rows[vobjGrid.SelectedIndex];
		if(objCurSelRow._Select==null) return false;
		window.execScript(objCurSelRow._Select, "JavaScript");	
	}
}

function __ATFireGridEditCommand(vobjGrid){
	if(vobjGrid==null) vobjGrid = __ATGetGridElement();
	if(vobjGrid.SelectedIndex>-1){
		var objCurSelRow=vobjGrid.rows[vobjGrid.SelectedIndex];
		if(objCurSelRow._Edit==null) return false;
		window.execScript(objCurSelRow._Edit, "JavaScript");	
	}
}

function __ATFireGridUpdateCommand(vobjGrid){
	if(vobjGrid==null) vobjGrid = __ATGetGridElement();
	if(vobjGrid.EditItemIndex>-1){
		var objCurSelRow=vobjGrid.rows[vobjGrid.EditItemIndex];
		if(objCurSelRow._Update==null) return false;
		window.execScript(objCurSelRow._Update, "JavaScript");	
	}
}

function __ATFireGridCancelCommand(vobjGrid){
	if(vobjGrid==null) vobjGrid = __ATGetGridElement();
	if(vobjGrid.EditItemIndex>-1){
		var objCurSelRow=vobjGrid.rows[vobjGrid.EditItemIndex];
		if(objCurSelRow._Cancel==null) return false;
		window.execScript(objCurSelRow._Cancel, "JavaScript");	
	}
}

function __ATFireGridDeleteCommand(vobjGrid){
	if(vobjGrid==null) vobjGrid = __ATGetGridElement();
	if(vobjGrid.SelectedIndex>-1){
		var objCurSelRow=vobjGrid.rows[vobjGrid.SelectedIndex];
		if(objCurSelRow._Delete==null) return false;
		window.execScript(objCurSelRow._Delete, "JavaScript");	
	}
}

function __ATGetParentElementByTagName(vobj,vstrTagName) {
	while (vobj.tagName!=vstrTagName.toUpperCase()) {
		vobj=vobj.parentElement;
		if(vobj==null) return;
	}		
	return vobj
}

function __ATHighlightGridRow(vobjRow, vblnHighLight, vstrHighlightRowClassName){
	__ATCurDataGrid=__ATGetParentElementByTagName(vobjRow,"TABLE");
	var strCss = vobjRow.getAttribute("__IClassName");
	if(strCss==null) vobjRow.setAttribute("__IClassName",vobjRow.className);
	
	if (vblnHighLight){
		vobjRow.className = vstrHighlightRowClassName;
	}
	else{
		if(vobjRow.rowIndex==__ATCurDataGrid.SelectedIndex){
			vobjRow.className = "SelectedRow";}
		else{
			if(strCss==null){
				vobjRow.className = "NormalRow";}
			else{
				vobjRow.className = strCss;
				if(strCss!=null) vobjRow.removeAttribute("__IClassName");
			}
		}
	}
}

function __ATIsSelectGridRow(vobjGrid){
	if(vobjGrid==null) vobjGrid = __ATCurDataGrid;
	if(vobjGrid==null) return false;
	if(vobjGrid.SelectedIndex>-1){
		return true;}
	else{
		return false;}
}