//
// Copyright (c) 2002 ComponentOne L.L.C. All rights reserved.
// Version 1.1.20024.1
//
var c1g_Props = [];
var c1g_curGrid;
var c1g_dragMode = false;
var c1g_resizeMode = false;
var c1g_DHTML = (document.getElementById || document.all || document.layers);


function c1g_state()
{
	this.allowColSizing = false;
	this.allowColMoving = false;
	this.columns = null;
	this.curGrid = null;
	this.disabled = false;	
	this.dstIdx = -1;
	this.fixedColIndex = -1;
	this.grid = null;
	this.grid00 = null;
	this.grid01 = null;
	this.grid10 = null;
	this.grid11 = null;
	this.grpCount = 0;	
	this.grpDstIdx = -1;
	this.grpSrcIdx = -1;	
	this.groupedRows = new Array();
	this.groupHitTest = new Array();
	this.groupInfo = null;
	this.isLTR = true;	
	this.isLayoutInitiated = false;
	this.keepSize = false;	
	this.objDragItem = null;
	this.objResizeItem = null;
	this.offsetWidth = 0;
	this.rows = null;
	this.resizedColumns = new Array();	
	this.scrollContainer = null;
	this.spliting = false;	
	this.srcIdx = -1;
	this.imgColDown = null;    
	this.imgColUp = null;
	this.scrollX = 0;
	this.scrollY = 0;
	this.uniqueId = null;
}



function c1g_baseInit(gridid, uniqueid, fixcolidx, spliting, keepSize, groupcnt, selectedidx, allowcolsizing, allowcolmoving, columns)
{
	var props = new c1g_state();
	c1g_Props[gridid] = props;
	props.grid = c1g_getElementById(gridid);
	      
	props.allowColSizing = allowcolsizing;
	props.allowColMoving = allowcolmoving;
	props.disabled = c1g_getattr(props.grid, "disabled");
	props.columns = columns;
	props.fixedColIndex = fixcolidx;
	props.groupCount = groupcnt;
	props.isLTR = c1g_isLTR(gridid);
	props.keepSize = keepSize;
	props.spliting = spliting;
	props.uniqueId = uniqueid;

	if (props.spliting)
	{
		props.grid00 = c1g_getSubTable(gridid, 0, 0);
		props.grid01 = c1g_getSubTable(gridid, 0, 1);
		props.grid10 = c1g_getSubTable(gridid, 1, 0);
		props.grid11 = c1g_getSubTable(gridid, 1, 1);
	}
}


function c1g_col(allowgroup, allowmove, allowsize)
{
    var o = new Object();
    
    o.allowGroup = (allowgroup == 1);
    o.allowMove = (allowmove == 1);
    o.allowSize = (allowsize == 1);
    o.idx = -1;
    o.x = -1;
    o.y = -1;
    o.xx = -1;
    o.yy = -1;
    o.srcElem = null;
    
    return o;
}

function c1g_refreshGrid(id)
{
	if (typeof(c1g_reinit) != "undefined")
		c1g_reinit(id);
	
	if (typeof(c1g_reLayout) != "undefined")
	{
		if (c1g_Props[id].spliting)
			c1g_reLayout(id);
	}
}

function c1g_isLTR(gridid)
{
	var grid = document.getElementById(gridid);
	return !(c1g_getattr(grid, "dir") == "rtl");
}

function rsearch(str, strToLook)
{
	for(a=str.length;a>=0;a--) {
		
		if(str.substr (a,1) == strToLook)
			return a;
	}
			
	return -1;
}

function c1g_getGridID(srcElem)
{
    var id = null;
    
    while (srcElem && !id)
    {
        if (srcElem.tagName == "TABLE")
        {
            var testId = c1g_getattr(srcElem, "id");
            
            //test for GroupContainer
            var len = testId.length;
            if (len > 15)
            {
                var tmp = testId.substr(len - 15, 15);
                if (tmp == "_GroupContainer")
                    testId = testId.substr(0, len - 15);
            } 
            
            if (testId)
                for (var tmp in c1g_Props)
                    if (testId == tmp)
                    {
                        id = tmp;
                        break
                    }
        }
        
        srcElem = c1g_getParent(srcElem);
    }
    
    return id;

	/*var str = c1g_getattr(srcElem, "id");
	while (srcElem && !(str && srcElem.tagName == "TABLE"))
	{
		srcElem = c1g_getParent(srcElem);
		if (srcElem)
			str = c1g_getattr(srcElem, "id");
	}
	if (!srcElem) return;
	//str = c1g_getattr(srcElem, "C1id");
	str = srcElem.style["C1id"];
	return str;*/
}

function c1g_getByName(name)
{
	var o = document.getElementById(name);
	if (!o)
	{
		for (var i = 0; i < document.forms.length; i++)
		if (typeof(document.forms[i].elements[name]) != "undefined")
		{
			o = document.forms[i].elements[name]
			break;				
		}
	}
	
	return o;
}

function c1g_getParent(srcElem)
{
	if( srcElem.parentElement )
		return srcElem.parentElement;
	else
		return srcElem.parentNode;
}

/*function c1g_getUniqueID(gridId)
{
	//return gridId;
  var grid = new c1g_getObj(gridId);
  //return c1g_getattr(grid.obj, "uniqueID");
  return grid.obj.style["uniqueID"];
}*/

function c1g_getattr(obj, att)
{
    if (obj.getAttribute)
        return obj.getAttribute(att);
    if (obj.attributes) {
        var a = obj.attributes[att];
        if (a) return a.value;
    } else
        return obj[att];
}

function c1g_getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
	    this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
	    this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = document.layers[name];
        this.style = document.layers[name];
	}
}

function c1g_findPosX(o)
{
	if (typeof(o) != 'object' || o == null)
		return 0;
	else
		return o.offsetLeft + c1g_findPosX(o.offsetParent);
}

function c1g_findPosY(o)
{
	if (typeof(o) != 'object' || o == null)
		return 0;
	else
		return o.offsetTop + c1g_findPosY(o.offsetParent);
}

function c1g_getElementById(tagId) 
{
	var obj;
	if(document.all)
		obj=document.all[tagId];
	else
		obj=document.getElementById(tagId);
	if(obj && obj.length && obj[0].id==tagId)
		obj=obj[0];
	return obj;
}

function c1g_getSubDiv(gn, row, col)
{
	var div = null;
	div=c1g_getElementById(gn + "_grid" + row + col + "div");
	if (!div)
		div=c1g_getElementById(gn + "_R1_grid" + row + col + "div");

	return div;
}

function c1g_getSubTable(gn, row, col)
{
	var div=c1g_getSubDiv(gn, row, col);
	if (div)
	{
		var a = div.getElementsByTagName("TABLE");
		if (a)
			return a[0];
	}

	return null;
}

function c1g_onNoSplitScroll(e)
{
    var tmp = e.srcElement.id.split("_");
    var o = c1g_getElementById("__" + tmp[0] + "_Scroll");
    if (o)
	{
        var scroller = c1g_getElementById(tmp[0] + "_scrolldiv");
		if (scroller)
			o.value = scroller.scrollLeft + "," + scroller.scrollTop;
	}
}

function c1g_findItem(clct, propName, item)
{
    var len = clct.length;
    for (var i = 0; i < len; i++)
        if (clct[i][propName] == item)
            return clct[i];
    
    return null;
}



function c1g_canMove(props, elem)
{
    var col = c1g_findItem(props.columns, "srcElem", elem);
    return (col) ? col.allowMove : true;
}


function c1g_canSizing(props, elem)
{
    var col = c1g_findItem(props.columns, "srcElem", elem);
    return (col) ? col.allowSize : true;
}


function c1g_isDefined(o)
{
    return (o && (typeof(o) != "undefined"));
}


function c1g_parentByTagName(src, tag)
{
    while (c1g_isDefined(src) && (src.tagName != tag))
        src = src.parentElement;

    return src;
}