﻿/*********************************************************************************************/
// PATCH FUNCTION: patched because the link tooltip should display the text, not the link (in case javacript)
/*********************************************************************************************/
if (typeof eXcell_link !== 'undefined') {
    eXcell_link.prototype.getTitle = function() {
        var z = this.cell.firstChild;
        return ((z && z.tagName) ? z.innerHTML : "")
    };
}
/*********************************************************************************************/
// PATCH FUNCTION: patched to add extra events
/*********************************************************************************************/

dhtmlXGridObject.prototype._in_header_master_checkbox=function(t,i,c){
	t.innerHTML=c[0]+"<input type='checkbox' />"+c[1];
	var self=this;
	t.firstChild.onclick=function(e){
		self._build_m_order();
		var j=self._m_order?self._m_order[i]:i;
		var val=this.checked?1:0;
		
		// added event
		self.xDefOnMCClick(j);
		
		self.forEachRowA(function(id){
			var c=this.cells(id,j);
			if (c.isCheckbox()) c.setValue(val);
			// added event
			self.xDefOnMCClickRowChanged(id,j);
		});
		(e||event).cancelBubble=true;
	}
}

/*********************************************************************************************/
// PATCH FUNCTION: patched to handle insflag
/*********************************************************************************************/

dGrid.prototype._process_json_row = function(r, data){
    r._attrs=data.attrs;
    if (r._attrs) {
        if (!r._attrs['INSFLAG']) { r._attrs={INSFLAG:"Q"};}
    } else {
        r._attrs={INSFLAG:"Q"};
    }
    
    for (var j = 0;j<r.childNodes.length;j++)r.childNodes[j]._attrs={};
    this._fillRow(r, (this._c_order ? this._swapColumns(data.data) : data.data));
    return r;
};



/*********************************************************************************************/
// PATCH FUNCTION: REPLACED BECAUSE IT DOESN'T WORK IN IE7
/*********************************************************************************************/

dhtmlXGridObject.prototype._postRowProcessing = function(r,donly){ 
	if (r._attrs["class"])
		r._css=r.className=r._attrs["class"];

	if (r._attrs.locked)
		r._locked=true;

	if (r._attrs.bgColor)
		r.bgColor=r._attrs.bgColor;
	var cor=0;	
	
	for (var i = 0; i < r.childNodes.length; i++){
		var c=r.childNodes[i];
		var ii=c._cellIndex;
		//style attribute
		var s = c._attrs.style||r._attrs.style;

		if (s)
			c.style.cssText+=";"+s;

		if (c._attrs["class"])
			c.className=c._attrs["class"];
		s=c._attrs.align||this.cellAlign[ii];


		if (s)
		    // modified because c.align=s causes the actual outerHTML to be "middle" in IE7
			// c.align=s;
			c.style.textAlign=s;
		c.vAlign=c._attrs.valign||this.cellVAlign[ii];
		var color = c._attrs.bgColor||this.columnColor[ii];


		if (color)
			c.bgColor=color;

		if (c._attrs["colspan"] && !donly){ 
			this.setColspan(r.idd, i+cor, c._attrs["colspan"]);
			//i+=(c._attrs["colspan"]-1);
			cor+=(c._attrs["colspan"]-1);
		}

		if (this._hrrar&&this._hrrar[ii]&&!donly){
			c.style.display="none";
		}
	};
	this.callEvent("onRowCreated", [
		r.idd,
		r,
		null
	]);
};

/*********************************************************************************************/
// PATCH FUNCTION: Make sure the masked numeric columns will display '0' (instead of empty).
/*********************************************************************************************/
eXcell_edn.prototype.setValue = function(val) {
    if (!val || val.toString()._dhx_trim() == "") {
        this.cell._clearCell = true;
        return this.setCValue("0", 0);
    } else
        this.cell._clearCell = false;
    this.setCValue(this.grid._aplNF(val, this.cell._cellIndex));
}
