function AjaxGridTable(){
    this.Name=null;
    this.RowArray=new Array();
    this.ColumnArray=new Array();
    this.GetRowById=_getRow;
    this.AddRow=_addRow;
    this.AddColumn=_addColumn;
    this.PageSize=null;
    this.NumberOfPages=null;
    this.InsertRowAfter=_insertRow;
    this.RemoveRow=_removeRow;
    
    function _removeRow(rowid){
		var rows=new Array();
		for(var i=0;i<this.RowArray.length;i++){
			if(this.RowArray[i].ID!=rowid){
				rows[rows.length]=this.RowArray[i];				
			}
		}
		this.RowArray=rows;
    }
    function _insertRow(row,afterrowid){
		var next=false;
		var rows=new Array();
		for(var i=0;i<this.RowArray.length;i++){
			if(next){
				rows[rows.length]=row;
			}
			if(this.RowArray[i].ID==afterrowid){
				next=true;
			}else{
				next=false;
			
			}
			rows[rows.length]=this.RowArray[i];
		}
		this.RowArray=rows;
    }
    function _addRow(row){
        this.RowArray[this.RowArray.length]=row;
    }
    function _addColumn(col){
        this.ColumnArray[this.ColumnArray.length]=col;
    }
    function _getRow(id){
        for(var r=0;r<this.RowArray.length;r++){
            if(this.RowArray[r].ID==id){
                return this.RowArray[r];
            }
        }
    }
}

function AjaxGridColumn(){
    this.ColumnName=null;
    this.SortBy=false;
    this.SortDirection=1;
    this.Title=null;
    this.IsPrimaryKey=false;
    this.Width=150;
    this.Align='Left';
    this.Type='System.String';
    this.Editable=false;
    this.Visible=true;
    this.AllowEditable=false;
    this.EditModeListItems=null; //Array
    this.Formatter=null;    
}
function AjaxGridRow(){
    this.ID=null;
    this.CssClass=null;
    this.Selected=false;
    this.MergeAllCells=false;
    this.HasChildren=false;
    this.ItemArray=new Array();
    this.AddItem=_addItem;
    this.DisableHover=false;
    this.PrimaryKeyValue=null;
    this.Editable=false;
    this.EditModeListItems=null; //Array
    
    function _addItem(item){
		this.ItemArray[this.ItemArray.length]=item;
    }
}
function ListItemCollection(){
	this.Items=new Array();
	this.AddItem=_additem;
	this.Count=_count;
	
	function _additem(item){
		this.Items[this.Items.length]=item;
	}
	function _count(){
		return this.Items.length;
	}
	
}
function AjaxListItem(text,value){
	this.Text=text;
	this.Value=value;
	this.Disabled=false;
	this.CssClass='';
}

var enumSelectionMode={
	Single:1,
	Multiple:2
}
var enumSortDirection={
	Asc:1,
	Desc:2
}
var structSortDirection=new Object();
structSortDirection.Ascending='Ascending';
structSortDirection.Descending='Descending';

function _mousePass(divobj,cls){
	divobj.className=cls;
}
function EndImage(){
	this.ImagePath=null;
	this.HoverImagePath=null;
	this.SelectedImagePath=null;
	this.DisabledImagePath=null;
}
//------------------

var AjaxControls=new AjaxControls();

document.onmousemove = AjaxControls.OnMouseMove;
document.onclick=AjaxControls.CloseOpenSelectBox;

function AjaxControls(){
	this.OnMouseMove=_OnMouseMove;
	this.SetActiveControl=_set;
	this.DisposeActiveControl=_dispose;
	this.SetOpenSelectBox=_setopenselect;
	this.CloseOpenSelectBox=_closeopenselect;
	
	var _openselect=null;	
	var _activeControl=null;
	
	function _setopenselect(selectObj){
		_openselect=selectObj;
	}
	function _closeopenselect(e){
		var src;
		if(document.all){
			src=window.event.srcElement;
		}else{
			if(e==null){
				if(_openselect!=null){
					_openselect.Close();
				}
				return;
			}
			src=e.target;
		}
		if(src==null)
			return;
		if(!src.getAttribute('isSelect')){
			if(_openselect!=null)
				_openselect.Close();
		}else{
			if(_openselect!=null){
			    if (src.id != _openselect.ID + '_mid' && src.id != _openselect.ID + '_rightimg') {
					_openselect.Close();
				}
			}
		}
	}
	
	function _set(ctrl){
		_activeControl=ctrl;
	}
	function _dispose(){
		_activeControl=null;
	}
	    
	function _OnMouseMove(e) {
		var target,tempX,tempY;
		if (document.all) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft
			tempY = event.clientY + document.body.scrollTop
			target=event.srcElement;
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX
			tempY = e.pageY
			target=e.target;
		}  
		if(_activeControl!=null){
			disableSelection(target);
			_activeControl.OnMouseMove(tempX,tempY);
		}
	}

	function disableSelection(element) {
		element.onselectstart = function() {
			return false;
		};
		element.unselectable = "on";
		element.style.MozUserSelect = "none";
		element.style.cursor = "default";
	}

}

function _FormatCurrency(dec){
	var x,x1,x2;
	var nStr= parseFloat(dec).toFixed(2);
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return '$ '+x1 + x2;
}
//------------------------------- transition effects ----------
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	try{
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}catch(ex2){}
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	//if(document.getElementById(id).style.opacity==null || document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	//} //else {
//		opacity(id, 100, 0, millisec);
//	}
}

function SetAlpha(divid,opacity){
	var object = document.getElementById(divid).style; 
	try{
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}catch(ex){}
}