function PCSGrid(GridClientID,GridID,FloatLoader,HighlightRowID,HighlightRowColor,HoverHeaderID,HoverHeaderEnabled){
	this.GridClientID = GridClientID;
	this.GridID = GridID;
	this.Grid = document.getElementById(this.GridClientID);
	this.Loader = new PCSLoader(GridClientID);
	this.OnResize=false;
	this.OnDrag=false;
	this.Resizing=false;
	this.WasDragging=false;
	this.Dragging=false;
	this.DragCell=null;
	this.CurrentCell=null;
	this.CurWidth=0;
	this.CurHeight=0;
	this.xoff=0;
	this.yoff=0;
	this.HoverHeaderID=HoverHeaderID;
	this.HoverHeaderEnabled=HoverHeaderEnabled
	this.HoverHeaderActive=false;
	this.HoverHeaderVisible=false;
	this.HoverHeaderShowTimer=null;
	this.HoverHeaderHideTimer=null;
	this.HoverHeaderOff=0;
	this.InitRows();
	this.HighlightRowID=HighlightRowID;
	this.HighlightRowColor=HighlightRowColor;
	this.HighlightRows = new Array;	
}
PCSGrid.prototype.ToggleSortImage=function(cell, toggleOff)
{	
	if(this.Resizing || (this.Dragging && this.WasDragging)){
		return;
	}
	var img = cell.getElementsByTagName('img')[0];
	var row = cell.parentElement;
	if (toggleOff){
		if(img) img.style.display = 'none';
		cell.sortOrder = '-1';
		return;
	}
	
	if (!img){
		img = document.createElement("IMG");
		img.src='../images/icon_sortasc.gif';
		img.style.display='inline';
		img.className='sortimage';
		cell.sortOrder = this.GetSortOrder(row);
		cell.insertBefore(img,cell.firstChild);
		return;
	}
	
	if (img.style.display == 'none'){
		img.src = '../images/icon_sortasc.gif';
		img.style.display = 'inline';
		cell.sortOrder = this.GetSortOrder(row);
		return;
	}
	
	if (img.src.indexOf('images/icon_sortasc.gif') > -1){
		img.src = '../images/icon_sortdesc.gif';
		img.style.display = 'inline';
	}else{
		img.src = '../images/icon_sortasc.gif';
		img.style.display = 'inline';
	}	
}
PCSGrid.prototype.GetSortOrder=function(row){
	var iSort = 0;
	for(var i=0;i<row.cells.length;i++){
		cell = row.cells[i];
		if (cell.field){
			if (cell.sortOrder == '-1') continue;
			if (iSort <= (cell.sortOrder *= 1)){
				iSort = (cell.sortOrder *= 1) + 1;
			}
		}
	}
	return iSort;
}
PCSGrid.prototype.RowClick=function(row){
	giCurrentRowFullID = row.id;
	if (!giCurrentRowID){	
		if (row.id.indexOf(':') > -1){
			var rowid = row.id.split(':');
			giCurrentRowID = rowid[rowid.length - 1];
		}else{
			giCurrentRowID = row.id;
		}	
	}
	var props = row.props;
	var handleHighlight;
	var handleMouse;
	var clickCommand;
	var handleClick;
	var checkID;
	var handleCheck;
	var temp='';
	if (props){
		temp = props.split('`');
		handleHighlight = (temp[0]==1);
		handleMouse = (temp[1]==1);
		clickCommand = temp[2];
		handleClick=(!temp[2]==0);
		checkID = temp[3];
		handleCheck=(!temp[3]==0);
	}
	if (handleClick){
		if (clickCommand == 1){
			gc(this)
		}else{
			if (bypassGridClick){
				bypassGridClick = false;
				return;
			}
			eval(clickCommand)
		}
	}
	if (handleCheck){
		gridClickCheck(checkID);
	}
}

PCSGrid.prototype.Refresh=function(){
	var callbackArguments;
	var callbackArgument='';
	if (arguments.length > 1)
		callbackArguments = new Array(arguments.length - 1);
	else
		callbackArguments = new Array(0);

	for (var i=1;i<arguments.length;i++){
		callbackArguments[i-1] = arguments[i];
	}
	callbackArgument=callbackArguments.join(String.fromCharCode(123));
	Callback.Constructor(this.GridID,function(args,context){window[context].Content(args)},this.GridID).AjaxCallback('refresh',callbackArgument);
}
PCSGrid.prototype.SetSort=function(strValue,row){
	var strSort = '';
	var tables = document.getElementsByTagName('TABLE');
	var row;
	var cell;
	var img;
	var iArray = -1;
	var aSort = new Array();
	//var grid = row.parentElement.parentElement;
	
	if (!strValue) strValue = ''
	
	if (strValue != 'release')
	{
		for(var i=0;i<tables.length; i++)
		{
			if(tables[i].className.toLowerCase() == 'gridmain' || tables[i].id.toLowerCase().indexOf('gridmain') > -1)
			{
				row=tables[i].rows[0]
				for(ii=0;ii<row.cells.length;ii++)
				{
					cell = row.cells[ii];
					if (cell.field)
					{
						img = cell.getElementsByTagName('IMG')[0]
						if (img)
						{
							if (img.style.display != 'none')
							{
								iArray += 1;
								aSort[iArray] = cell.sortOrder + ' ' + cell.field + '`' + (img.src.indexOf('asc') > -1 ? 'ASC' : 'DESC');	
							}
						}
					}
				}
			}
		}
		if (aSort.length > 0)
		{
			aSort.sort()
			for (i=0; i<aSort.length; i++)
			{
				strSort = strSort + (strSort == '' ? '' : '|');
				strSort = strSort + aSort[i].substr(aSort[i].indexOf(' ') + 1, aSort[i].length);
			}				
		}	
	}
	Callback.Constructor('Form1',refreshNav,'GridMain',null,null,'Sorting...').Standard_SetSort(strSort);
}
PCSGrid.prototype.Content=function(val){
	if(!document.getElementById(this.GridClientID)) return;
	setHTML(val,document.getElementById(this.GridClientID),true);
	this.InitRows();
}
PCSGrid.prototype.HighlightRow=function(rowid,color){
	this.HighlightRowID = rowid
	if(color) this.HighlightRowColor = color;
	this.Reset();
}
PCSGrid.prototype.AddHighlightRow=function(rowid,color){
	this.HighlightRows.push(rowid);
	if(color) this.HighlightRowColor = color;
	this.Reset();
}
PCSGrid.prototype.RemoveHighlightRow=function(rowid){
	for(var i=0; i<this.HighlightRows.length; i++){
		if(this.HighlightRows[i]==rowid){
			this.HighlightRows.splice(i,1);
			break;
		}
	}
	this.Reset();
}
PCSGrid.prototype.ClearHighlightRows=function(){
	this.HighlightRows=null;
	this.HighlightRows=new Array();
	this.Reset();
}
PCSGrid.prototype.HasHighlightRow=function(rowid){
	for(var i=0; i<this.HighlightRows.length; i++){
		if(this.HighlightRows[i]==rowid){
			return true;
			break;
		}
	}
	return false;
}
PCSGrid.prototype.Reset=function(){
	this.InitRows();
}
PCSGrid.prototype.InitRows=function(){
	var grid = document.getElementById(this.GridClientID);
	if(!grid || !grid.rows) return;
	var row;
	var GridClientID=this.GridClientID;
	var GridID = this.GridID
	var RowID;
	for(var i=0;i<grid.rows.length;i++){
		row = grid.rows[i];
		RowID = row.id
		if (row.id.indexOf(':') > -1){
			var rowid = row.id.split(':');
			RowID = rowid[rowid.length - 1];
		}else{
			RowID = row.id;
		}
		row.KeyID=RowID;
		row.style.backgroundColor = row.bgColor;
		if(RowID == this.HighlightRowID){
			row.style.backgroundColor = this.HighlightRowColor;
		}
		
		if(this.HighlightRows){
			if(this.HighlightRows.length > 0 && this.HasHighlightRow(RowID)){
				row.style.backgroundColor = this.HighlightRowColor;
			}
		}
		
		if(row.className.indexOf('gi')==0){
			var props = row.props;
			var temp;
			var cells = row.cells;	
			var handleMouse=false;
			if (props){
				temp = props.split('`');
				handleMouse = (temp[1]==1);
			}
			if (cells){
				if (cells[0]){
					cells[0].style.borderLeft='none';
				}
			}
			row.onmouseover=function(){ gov(this,null,this.props.split('`')[1]==1); };
			row.onmouseout=function(){ got(this); };
			row.onclick=function(){ window[GridID].RowClick(this); };
			row.ondblclick=function(){ window[GridID].RowClick(this); };
		}else if(row.className.indexOf('gh')==0){
			var cell;
			if(this.HoverHeaderEnabled){
				row.onmouseenter=function(){window[GridID].BeginShowHoverHeader()};
				row.onmouseleave=function(){window[GridID].BeginHideHoverHeader()};
			}
			for(var ii=0;ii<row.cells.length;ii++){
				cell = row.cells[ii];
				cell.className=row.className;
				cell.prevClassName=row.className;
				cell.onmousemove=function(){ window[GridID].MonitorMouseHeader(); }; 
				cell.onmousedown=function(){ window[GridID].HeaderMouseDown(); };
				cell.onmouseup=function(){ window[GridID].HeaderMouseUp(); };
				if (cell.field){
					cell.title='Right Click to Set Sort'
					cell.onmouseover=function(){ this.className='gho'; };
					cell.onmouseout=function(){ this.className=this.prevClassName; };
					cell.onclick=function(){ window[GridID].ToggleSortImage(this,false); };
					cell.ondblclick=function(){ window[GridID].ToggleSortImage(this,true); };
					cell.oncontextmenu=function(){
						cancelBubble=true;
						window[GridID].SetSort(null,this.parentElement);
						event.returnValue=false;
					};
					cell.unselectable='on';
				}
			}
			row.className = '';
		}
	}
	row=null;
	cell=null;
	grid=null;
	this.resetColumnWidths();
	
	if(this.HoverHeaderEnabled){
		var hoverheader = document.getElementById(this.HoverHeaderID);
		if(hoverheader){
			hoverheader.onmouseenter=function(){
				clearTimeout(window[GridID].HoverHeaderHideTimer);
				clearTimeout(window[GridID].HoverHeaderShowTimer);
				window[GridID].HoverHeaderHideTimer=null;
				window[GridID].HoverHeaderVisible=true;
				window[GridID].HoverHeaderActive=true;
			}
			hoverheader.onmouseleave=function(){
				window[GridID].HoverHeaderActive=false;
				window[GridID].BeginHideHoverHeader();
			}
		}
	}
}
PCSGrid.prototype.BeginShowHoverHeader=function(){
	var g = this;
	clearTimeout(this.HoverHeaderHideTimer);
	this.HoverHeaderHideTimer=null;
	if(!document.getElementById(this.HoverHeaderID)) return;
	if(this.HoverHeaderVisible || document.getElementById(this.HoverHeaderID).style.display=='block') return;
	this.HoverHeaderShowTimer = setTimeout(function(){g.ShowHoverHeader()},1500);
}
PCSGrid.prototype.ShowHoverHeader=function(){
	
	var hoverheader = document.getElementById(this.HoverHeaderID);
	if(!hoverheader) return;
	var grid = document.getElementById(this.GridClientID);
	var xy = this.GetCoordinates(grid)
	
	hoverheader.style.left=xy[0];
	hoverheader.style.top=xy[1]+1;
	hoverheader.style.height='25px';
	hoverheader.style.clip='rect(auto,auto,0px,auto)';
	hoverheader.style.width=grid.offsetWidth;
	hoverheader.style.display='block';
	
	this.HoverHeaderVisible=true;
	this.HoverHeaderActive=false;
	this.HoverHeaderShowTimer=null;
	
	this.HoverHeaderOff=0;
	this.SlideHeaderOpen(hoverheader,xy);
}
PCSGrid.prototype.SlideHeaderOpen=function(hoverheader,xy){
	var g=this;
	if(this.HoverHeaderOff<25) {
		if(this.HoverHeaderOff>=18){
			this.HoverHeaderOff++;
			hoverheader.style.top=parseInt(hoverheader.style.top) - 1;
		}else{
			this.HoverHeaderOff+=2;
			hoverheader.style.top=parseInt(hoverheader.style.top) - 2;
		}
		hoverheader.style.clip='rect(auto,auto,' + this.HoverHeaderOff + 'px,auto)';
		setTimeout(function(){g.SlideHeaderOpen(hoverheader,xy)},1);
		return;
	}
}

PCSGrid.prototype.BeginHideHoverHeader=function(){
	var g = this;
	if(!this.HoverHeaderVisible){
		clearTimeout(this.HoverHeaderShowTimer);
		this.HoverHeaderShowTimer=null;
	}
	if(this.HoverHeaderActive) return;
	this.HoverHeaderHideTimer = setTimeout(function(){g.HideHoverHeader()},500);
}
PCSGrid.prototype.HideHoverHeader=function(){
	var hoverheader = document.getElementById(this.HoverHeaderID);
	if(!hoverheader) return;
	if(this.HoverHeaderActive){
		this.HoverHeaderHideTimer=null;
		return;
	}
	this.HoverHeaderVisible=false;
	this.HoverHeaderActive=false;
	hoverheader.style.display='none';
}
PCSGrid.prototype.MonitorMouseHeader=function(){
	if(this.Resizing || this.Dragging) return;
	var posx = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	var posy = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	//Get the outermost cell
	var cell = event.srcElement;
	while(cell.parentElement.tagName != 'TR'){
		cell = cell.parentElement;
	}
	var cellxy = this.GetCoordinates(cell)
	var cellxl = cellxy[0];
	var cellxr = cellxl + cell.clientWidth;
	if(posx <= cellxr && posx >= cellxr - 2){
		this.DragCell = cell;
		cell.style.cursor='e-resize';
		this.OnResize=true;
	}else if(posx <= cellxl + 2 && posx >= cellxl){
		if(!cell.previousSibling) return;
		this.DragCell = cell.previousSibling;
		cell.style.cursor='e-resize';
		this.OnResize=true;
	}else{
		this.OnResize=false;
		this.OnDrag=true;
		this.DragCell=cell;
		this.WasDragging=false;
		cell.style.cursor='default';
	}

}
PCSGrid.prototype.HeaderMouseDown=function(){
	if(!this.DragCell) return;
	var g = this;
	this.addEvent(document,'mouseup',function(){g.StopDrag()});
	this.StartDrag();
}
PCSGrid.prototype.HeaderMouseUp=function(){
	this.StopDrag();
}
PCSGrid.prototype.UpdateRecordsPerPage=function(val){
	if((!val || val==0) && event){
		val=event.srcElement.value;
	}
	var RegExp = /^(\d*)$/;
	if(!val.match(RegExp)){
		alert('Invalid numeric format!');
		return;
	}
	if(val==0){
		alert('Value must be > 0!');
		return;
	}
	doPostback('Standard_UpdateRecordsPerPage',val);
}
PCSGrid.prototype.StartDrag=function(){
	var cell = this.DragCell;
	var cellxy = this.GetCoordinates(cell)
	var g = this;
	this.CurWidth = cell.clientWidth;
	if(this.OnResize){
		this.Resizing=true;
		this.WasDragging=true;
		this.addEvent(document,'mousemove', function(){return g.Drag();});
		var ex=event.clientX+document.body.scrollLeft;
		this.xoff=(cellxy[0]+cell.clientWidth)-ex;
		this.xoff = (cellxy[0]+cell.clientWidth) + this.xoff;
		cell.style.cursor='e-resize';
	}else if(this.OnDrag){
		this.WasDragging=false;
		this.Dragging=false;
		//UnComment this to support column reordering
//		this.Dragging=true;
//		this.addEvent(document,'mousemove', function(){return g.Drag();});
//		this.xoff=event.clientX+document.body.scrollLeft;
//		this.yoff=event.clientY+document.body.scrollTop;
	}
	return false;
}
PCSGrid.prototype.StopDrag=function(){
	if(!(this.Dragging || this.Resizing)) return;
	var g = this;
	var targetCell = event.srcElement;
	while(targetCell.parentElement.tagName != 'TR'){
		targetCell = targetCell.parentElement;
	}
	this.Dragging=false;
	this.Resizing=false;
	this.removeEvent(document,'mousemove', function(){return g.Drag();});
	this.removeEvent(document,'mouseup',function(){g.StopDrag()});
	this.DragCell.style.cursor='default';
	targetCell.style.cursor='default';
	if(this.OnResize){
	
		this.persistColumnWidths();
	
	}else if(this.OnDrag){
		
		newIndex = targetCell.cellIndex 
		
		if (newIndex == null) return 
		if (this.DragCell.cellIndex == newIndex) return 
		
		this.WasDragging=true;
		
		var tableRows = this.Grid.rows;
		var maxIndex = tableRows[0].cells.length;
		var cellIndex = this.DragCell.cellIndex;
			
		for (var x=0; x < tableRows.length; x++) { 
			tds = tableRows[x].cells 
			
			var cell = tableRows[x].removeChild(tds[cellIndex]) 
			if (newIndex >= maxIndex || newIndex + 1 >= maxIndex) { 
				tableRows[x].appendChild(cell) 
			} else { 
				tableRows[x].insertBefore(cell, tds[newIndex]) 
			} 
		} 
		
	}
}
PCSGrid.prototype.Drag=function(){
	var mx = event.clientX + document.body.scrollLeft;
	if(this.Resizing){
		this.Resize(mx-this.xoff);
	}else if(this.Dragging){
		//this.MoveColumn(mx-this.xoff,my-this.yoff);
	}
	return false;
}
PCSGrid.prototype.Resize=function(x){
	var cell = this.DragCell;
	cell.style.cursor='e-resize';
	if(this.CurWidth+x <= 0) return;
	cell.style.width = (this.CurWidth+x)+'px';
	var table = cell.parentElement.parentElement;
	for(var i=1;i<table.rows.length;i++){
		var row = table.rows[i];
		var childcell = row.cells[cell.cellIndex];
		if(childcell.style) childcell.style.width = (this.CurWidth+x)+'px';
		var child = row.cells[cell.cellIndex].firstChild;
		if(child){
			var n = this.FindCellNOBR(child);
			//get size diff
			if(n){
				if(n.style){
					var z=(this.CurWidth+x) - parseInt(n.style.width)
					n.style.width = (parseInt(n.style.width) + z - (childcell.hl ? 18 : 0)) + 'px';
				}else{
					n.width = ((this.CurWidth+x) - (childcell.hl ? 18 : 0))+ 'px';
				}
			}
		}
	}
}
PCSGrid.prototype.FindCellNOBR=function(child){
	if(child.tagName=='NOBR') return child;
	for(var i=0;i<child.childNodes.length;i++){
		if(child.childNodes.item(i).tagName=='NOBR'){
			return child.childNodes.item(i);
		}
		var n = this.FindCellNOBR(child.childNodes.item(i));
		if(n) return n;
	}
}
PCSGrid.prototype.ToggleChecks=function(val){
	var gm = this.Grid;
	for(var i=0;i<gm.all.length;i++){
		if(gm.all[i].tagName=='INPUT'){
			if(gm.all[i].type == 'checkbox'){
				gm.all[i].checked=val;
			}
		}
	}
}
PCSGrid.prototype.GetSelectedChecks=function(arg){
	var gm = this.Grid;
	var args = new Array;
	var id;
	//if(arg) args.push(currentID)
	var xtraColumns=(arguments.length > 0)
	for(var i=0;i<gm.all.length;i++){
		if(gm.all[i].tagName=='INPUT'){
			if(gm.all[i].type == 'checkbox'){
				if(gm.all[i].checked && gm.all[i].id != 'chkSelectAll'){
					id = replaceAll(gm.all[i].id,'chk','')
					if(xtraColumns){
						for(var ii=0;ii<arguments.length;ii++){
							id += '|' + eval('gm.all[i].' + arguments[ii]);
						}
					}
					args.push(id);
				}
			}
		}
	}
	return args
}
function gc(target,argument){
	if(!argument){
		var el = event.srcElement;
		var i=0;
		while(el.tagName.toLowerCase() != 'tr'){
			i++
			el = el.parentElement;
			if(i>10) return;
		}
		argument=el.id;
	}
	doPostback(target,argument);
}
function gcdd(){
	doPostback('drilldown',giCurrentRowID)
}
function gridClickCheck(id, highlight){
	if (bypassGridClick){
		bypassGridClick = false;
		setDirty();
		return;
	}
	if (!id) return;
	var chkbox = document.getElementById(id);
	if (!chkbox) return;
	chkbox.checked = chkbox.checked ? false : true;
	QueryString['scroll'] = document.body.scrollTop;
	setDirty();
	if (highlight){
		chkbox.parentElement.parentElement.bgColor = (chkbox.checked ? '#C1CDD8' : '#ffffff'); 	
	}
}

function gov(row, color, mouse){
	if (!color) color = RowHighlightColor;	
	PrevColor = (row.style.backgroundColor == FlashColor ? OrigColor : row.style.backgroundColor);
	row.OrigColor=PrevColor;
	row.style.backgroundColor = color;
	if (mouse == null || mouse){
		//setTimeout(function(){row.style.cursor = 'hand'},1);
		row.style.cursor = 'hand'
	}else{
		row.style.cursor = 'default';
	}
	giCurrentRowFullID = row.id;
	if (row.id.indexOf(':') > -1){
		var rowid = row.id.split(':');
		giCurrentRowID = rowid[rowid.length - 1];
	}else{
		giCurrentRowID = row.id;
	}
}
function got(row, color){
	//This line is here ONLY for custom grid actions that change the row color while we are moused over
	//Ex: Mouseover causes gray row, click a checkbox that turns row blue.. row must stay blue or whatever other color
	//the row was changed to, when you mouseoff
	if (row.style.backgroundColor != RowHighlightColor)
	{
		PrevColor = row.style.backgroundColor;
	}
	//*********************************************************************************
	if (!color) color = PrevColor;
	row.style.backgroundColor = color;
	row.style.cursor = 'default';
}
function bgc(arg,row){
	bypassGridClick= (arg == 1 ? true : false);
	if (arg == 1) row.style.cursor='default';
	if(!giCurrentRowID && row.parentElement.id)
	{
		//giCurrentRowID=row.parentElement.id;
		if (row.parentElement.id.indexOf(':') > -1){
			var rowid = row.parentElement.id.split(':');
			giCurrentRowID = rowid[rowid.length - 1];
		}else{
			giCurrentRowID = row.parentElement.id;
		}	
	}
}

PCSGrid.prototype.GetCoordinates= function (el){
    var parent=null;
    var coords=[];
    var box;
    if (el.getBoundingClientRect){
        box=el.getBoundingClientRect();
        var scrollTop=document.documentElement.scrollTop || document.body.scrollTop;
        var scrollLeft=document.documentElement.scrollLeft || document.body.scrollLeft;
        var x=box.left+scrollLeft;
        var y=box.top+scrollTop-1;
        return [x,y];
    } else if (document.getBoxObjectFor){
        box=document.getBoxObjectFor(el); 
        coords=[box.x-2,box.y-2];
    } else {
        coords=[el.offsetLeft,el.offsetTop];
        parent=el.offsetParent;
        if (parent!=el){
            while (parent){
                coords[0]+=parent.offsetLeft;
                coords[1]+=parent.offsetTop;
                parent=parent.offsetParent;
            }
        }
    }
    if (window.opera){
        parent=el.offsetParent;
        while (parent && parent.tagName!="BODY" && parent.tagName!="HTML"){
            coords[0]-=parent.scrollLeft;
            coords[1]-=parent.scrollTop;
            parent=parent.offsetParent;
        }
    }else {
        parent=el.parentNode;
        while (parent && parent.tagName!="BODY" && parent.tagName!="HTML"){
            coords[0]-=parent.scrollLeft;
            coords[1]-=parent.scrollTop;
            parent=parent.parentNode;
        }   
    }
    return coords;
}

PCSGrid.prototype.addEvent=function(obj, evType, fn)
{
	var evTypeRef = '__' + evType;
	if (obj[evTypeRef]){
		if (this.array_search(fn, obj[evTypeRef]) > -1) return;
	}else{
		obj[evTypeRef] = [];
		if (obj['on'+evType]) obj[evTypeRef][0] = obj['on'+evType];
		obj['on'+evType] = this.handleEvent;
	}
	obj[evTypeRef][obj[evTypeRef].length] = fn;
}

PCSGrid.prototype.removeEvent=function(obj, evType, fn)
{
	var evTypeRef = '__' + evType;
	if (obj[evTypeRef]){
		var i = this.array_search(fn, obj[evTypeRef]);
		if (i > -1) {
			delete obj[evTypeRef][i];
		}
	}
}

PCSGrid.prototype.hasEvent=function(obj, evType, fn)
{
	var evTypeRef = '__' + evType;
	if (obj[evTypeRef]){
		var i = this.array_search(fn, obj[evTypeRef]);
		if (i > -1) {
			return true;
		}
	}
}

PCSGrid.prototype.handleEvent=function(e)
{
	e = e || window.event;
	var evTypeRef = '__' + e.type, retValue = true;

	for (var i = 0, j = this[evTypeRef].length; i < j; i++){
		if (this[evTypeRef][i]){
			this.__fn = this[evTypeRef][i];
			retValue = this.__fn(e) && retValue;
		}
	}

	if (this.__fn) try { delete this.__fn; } catch(e) { this.__fn = null; }

	return retValue;
}

PCSGrid.prototype.array_search=function(val, arr)
{
	var i = arr.length;
	while (i--){
		if (arr[i] && arr[i].toString() == val.toString()){
			break;
		}
	}
	return i;
}
PCSGrid.prototype.persistColumnWidths=function(){
	//return;
	var cell=null;
	var header = document.getElementById(this.GridClientID).rows[0];
	var aWidths = new Array();
	for(var i=0;i<header.cells.length;i++){
		cell = header.cells[i];
		aWidths[i]=cell.style.width;
	}
	var val = aWidths.join('|');
	this.writeCookie(this.GridID + '_ColumnWidths',val);
	header=null;
	cell=null;
}
PCSGrid.prototype.resetColumnWidths=function(){
	//return;
	var cols='';
	var aWidths;
	var cell=null;
	cols = this.readCookie(this.GridID + '_ColumnWidths');
	if(cols=='') return;
	aWidths = cols.split('|');
	var header = document.getElementById(this.GridClientID).rows[0];
	if(aWidths.length == header.cells.length){
		for(var ii=0;ii<header.cells.length;ii++){
			cell=header.cells[ii];
			cell.style.width = aWidths[ii];
			var table = cell.parentElement.parentElement;
			for(var i=1;i<table.rows.length;i++){
				var row = table.rows[i];
				var childcell = row.cells[cell.cellIndex];
				childcell.style.width = aWidths[ii];
				var child = row.cells[cell.cellIndex].firstChild;
				if(child){
					var n = this.FindCellNOBR(child);
					if(n){
						var w = (parseInt(aWidths[ii]) - (childcell.hl ? 18 : 0)) + 'px';
						try{
							if(n.style){
								n.style.width = w;
							}else{
								n.width = w;
							}
						}catch(e){}
					}
				}
			}			
		}
	}
	header=null;
	cell=null;
}
PCSGrid.prototype.writeCookie=function(cookieName,cookieValue,nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=365;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires="+expire.toGMTString();
}
PCSGrid.prototype.readCookie=function(cookieName)
{
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}