/*
 - w e b s p r e a d - - - - - - - - - - - - - - - - - - - - - - - - - - -
 utiliza    :: format.js v. 1.0
 			   			 métodos [rInput(Object, Event, String)]
						   funcoes.js v. 1.0
						   métodos [selecionacombo(Object, String)]
 versão     :: 3.0 beta
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - s y s w o r k s -
 */

var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=navigator.appName=='Netscape'&&!isDOM?1:0;
var isIE4=isIE&&!isDOM?1:0;
var isOp=window.opera?1:0;
var isWin=navigator.platform.indexOf('Win')!=-1?1:0;
var isDyn=isDOM||isIE||isNS4;

function spread(name) {
	this.config = {
		expand			: false,
		scroll			: true,
		diff				: 0,
		backcolor1	: 'sprlista0',
		backcolor2	: 'sprlista1',
		backcolor3	: 'sprlista2',
		name				: name,
		images			: 'images',
		inputName 	: 'name_col_line'
	}
	this.process = {
		create	: false,
		edit		: false,
		maxRows : 0,
		aux			: null
	}
	this.tr = {
		readonly			: false,
		disabled			: false,
		cursor				: '',
		comment				: '[F8] Nova Linha - [F9] Excluir Linha Corrente',
		styles				: '',
		onClick				: '',
		onDblClick				: '',
		onContextMenu	: '',
		onKeyPress		: '',
		onKeyDown			: '',
		onBlur				: '',
		onChange			: ''
	}
	this.span;
	this.header;
	this.body;
	this.scroll;
	this.hidden;
	this.nodes = [];
	this.first_line = true;
        this.event_delete_line = "";
        this.event_add_line = "";
};

function column(title, type, maxlength, size, aux, order, titleAlign) {
	this.title					= title;
	this.type						= type;
	this.maxlength			= maxlength;
	this.size						= size;
	this.col						= 0;
	this.readonly				= null;
	this.disabled				= null;
	this.cursor					= null;
	this.comment				= null;
	this.value					= (!aux) ? "" : aux;
	this.defaultValue		= '';
	this.styles					= null;
	this.onClick				= null;
	this.onDblClick				= null;
	this.onContextMenu	= null;
	this.onKeyPress			= null;
	this.onKeyDown			= null;
	this.onBlur					= null;
	this.onChange				= null;
	this.order				 = null;
	this.titleAlign			 = "left";
};

function makeInputName(inputName, name, line, col) {
	var re;
	var ret = inputName;

	re = /name/g;
	ret = ret.replace(re,name);
	re = /line/g;
	ret = ret.replace(re,line);
	re = /col/g;
	ret = ret.replace(re,col);

	return ret;
}

function createInput(name, obj, line, col) {
	var ret;
	var cName;
	var cor;
	var evento;
	var o = eval(name);
	var inputType;

	var cursor;
	var comment;
	var readonly;
	var disabled;
	var styles;

	var type					= obj.type;
	var maxlength			= obj.maxlength;
	var size					= obj.size;
	var type					= obj.type;
	var value					= obj.value;
	var defaultValue	= (!obj.defaultValue) ? "" : obj.defaultValue;

	var spreadName		= name;
	var name					= makeInputName(o.config.inputName, name, (line+1), (col+1));
	var evento				= createEvent(spreadName, obj, (line+1));

	if (obj.cursor != null) cursor = obj.cursor;
	else cursor = o.tr.cursor;
	if (obj.comment != null) comment = obj.comment;
	else comment = o.tr.comment;
	if (obj.readonly != null) readonly = obj.readonly;
	else readonly = o.tr.readonly;
	if (obj.disabled != null) disabled = obj.disabled;
	else disabled = o.tr.disabled;
	if (obj.styles != null) styles = obj.styles;
	else styles = o.tr.styles;

	if (readonly == true) readonly = ' readonly ';
	else readonly = '';
	if (disabled == true) disabled = ' disabled ';
	else disabled = '';

	if (o.config.expand && o.process.aux) {
		if (type.toUpperCase() != 'HIDDEN' &&
				type.toUpperCase() != 'CHECK' &&
				type.toUpperCase() != 'OPTIONV' &&
				type.toUpperCase() != 'BUTTON' ){
			o.process.aux = false;
		} else {
			size = size + o.config.diff;
		}
	} else {
		size = size + o.config.diff;
	}

	ret = "";
	if (type.toUpperCase() == 'LABEL') {
		ret += '<div ';
	} else if (type.toUpperCase() == 'COMBO') {
		ret += '<select ';
	} else if (type.toUpperCase() == 'IMAGE') {
		ret += '<image ';
		ret += ' src="'+value+'"';
	} else {
		if (type.toUpperCase() == 'CHECK') {
			inputType = 'checkbox';
		} else if (type.toUpperCase() == 'OPTIONV') {
			inputType = 'radio';
		} else if (type.toUpperCase() == 'MONEY'  ||
							 type.toUpperCase() == 'NUMBER' ||
							 type.toUpperCase() == 'DATE'   || type.toUpperCase() == 'INTEGER'){
			inputType = 'text';
		} else {
			inputType = type;
		}
		ret += '<input ';
		ret += ' type="'+inputType+'"';
	}
	if (type.toUpperCase() == 'HIDDEN') {
		ret += ' id="hid_'+name+'"';
		//ret += ' name="hid_'+name+'"';
	} else {
		ret += ' id="'+name+'"';
		ret += ' name="'+name+'"';
	}
	ret += evento; //evento
	ret += ' style="';
	ret += 'cursor: '+cursor+';'; //cursor
	if (type.toUpperCase() != 'IMAGE' &&
		  type.toUpperCase() != 'CHECK' &&
		  type.toUpperCase() != 'OPTIONV') {
		if (type.toUpperCase() == 'LABEL') {
			ret += 'width: 100%; '; //tam.
		} else {
			ret += 'width: '+size+'px; '; //tam.
		}
	}
	if (type.toUpperCase() == 'MONEY'  ||
		  type.toUpperCase() == 'DATE'   ||
			type.toUpperCase() == 'NUMBER' ||
			type.toUpperCase() == 'HOUR' || type.toUpperCase() == 'INTEGER'){
		ret += 'text-align: right;'; //align
	}
	ret += styles+'"'; //custom stylesheets
	if (type.toUpperCase() != 'BUTTON' ){
		ret += ' class="transparent" ';
		ret += ' maxlength="'+maxlength+'"';
	}
	ret += ' defaultValue="'+defaultValue+'" ';
	ret += ' tipo="'+type+'"';
	ret += ' spreadName="'+spreadName+'" ';
	ret += ' defaultValue="'+defaultValue+'" ';
	ret += ' title="'+comment+'" ';
	ret += readonly;
	ret += disabled;
	if (type.toUpperCase() != 'COMBO') {
		ret += ' value="'+value+'" ';
		ret += ">";
	} else {
		ret += ">";
		ret += value;
		ret += "</select>";
	}

	return ret;
};

function createEvent(name, obj, line) {
	var ret;
	var onChange;
	var onKeyPress;
	var onBlur;
	var onClick;
	var onDblClick;
	var onContextMenu;
	var onKeyDown;
	var re;
	var rep;
	var oSpread = eval(name);

	if (obj.onChange != null) onChange = obj.onChange;
	else onChange = oSpread.tr.onChange;
	if (obj.onKeyPress != null) onKeyPress = obj.onKeyPress;
	else onKeyPress = oSpread.tr.onKeyPress;
	if (obj.onBlur != null) onBlur = obj.onBlur;
	else onBlur = oSpread.tr.onBlur;
	if (obj.onClick != null) onClick = obj.onClick;
	else onClick = oSpread.tr.onClick;
	if (obj.onDblClick != null) onDblClick = obj.onDblClick;
	else onDblClick = oSpread.tr.onDblClick;
	if (obj.onContextMenu != null) onContextMenu = obj.onContextMenu;
	else onContextMenu = oSpread.tr.onContextMenu;
	if (obj.onKeyDown != null) onKeyDown = obj.onKeyDown;
	else onKeyDown = oSpread.tr.onKeyDown;

	for (var i = 0; i < 2; i++) {
		if (i == 0) {
			re = /&id/g;
			rep = '(this.parentNode.parentNode.sectionRowIndex+1)';
		} else {
			re = /&name/g;
			rep = '"' + name + '"';
		}

		onChange 			= onChange.replace(re,rep);
		onKeyPress 		= onKeyPress.replace(re,rep);
		onBlur 				= onBlur.replace(re,rep);
		onClick 			= onClick.replace(re,rep);
		onDblClick 			= onDblClick.replace(re,rep);
		onContextMenu = onContextMenu.replace(re,rep);
		onKeyDown 		= onKeyDown.replace(re,rep);
	}

	if (obj.type.toUpperCase() == 'MONEY'){
		onChange = 'fNumber(this,2);' + onChange;
		onKeyPress = onKeyPress + 'return rInput(this,event,"N");';
	}
	if (obj.type.toUpperCase() == 'INTEGER'){
		onChange = 'fInteger(this,2);' + onChange;
		onKeyPress = onKeyPress + 'return fInteger(this,event);';
	}
	if (obj.type.toUpperCase() == 'NUMBER'){
		onKeyPress = onKeyPress + 'return rInput(this,event,"N");';
	}
	if (obj.type.toUpperCase() == 'DATE'){
		onBlur = onBlur + 'vData(this);';
		onKeyPress = onKeyPress + 'return rInput(this,event,"D");';
	}
	if (obj.type.toUpperCase() == 'HOUR'){
		onBlur = onBlur + 'vHora(this);';
		onKeyPress = onKeyPress + 'return rInput(this,event,"H");';
	}

	ret  = '';
	ret += ' onChange=\'' + onChange + '\'' //onChange
	ret += ' onKeyPress=\'' + onKeyPress + '\'' //onKeyPress
	ret += ' onBlur=\'' + onBlur + '\'' //onBlur
	ret += ' onClick=\'' + onClick + '\'' //onClick
	ret += ' onDblClick=\'' + onDblClick + '\'' //onDblClick
	ret += ' onContextMenu=\'' + onContextMenu + '\'' //onRightClick
	ret += ' onKeyDown=\'' + onKeyDown + 'return chars("'+name+'", this, event);\'' //onKeyDown
	return ret;
};

function chars(name, o, e) {
	var i;
	var whichCode;
	var oSpread = eval(name);
	var line = o.parentNode.parentNode.sectionRowIndex;
	var col  = o.parentNode.cellIndex;
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if (validKey(oSpread,line,col,whichCode)) {
		oSpread.process.edit = true;
		return true;
	} else {
		return false;
	}
};

function validKey(oSpread,line,col,whichCode) {
	var stop;
	var type;
	var maxLine = oSpread.process.maxRows;
	var aux;

	(isIE) ? type = oSpread.body.rows[line].cells[col].childNodes[0].tipo : type = oSpread.body.rows[line].cells[col].childNodes[0].getAttribute("tipo");

	if (!oSpread.config.readonly) {
		if (whichCode == 119) {
			oSpread.addLine();
                        if (oSpread.getEventAddLine() != "") {
                          eval(oSpread.getEventAddLine());
                        }
			return false;
		} else if (whichCode == 120) {
			if (maxLine == 1) {
				oSpread.create();
				try {
					oSpread.body.rows[0].cells[col].childNodes[0].focus()
				} catch (e) {}
			} else {
				oSpread.deleteLine(line+1);
				try {
					if ((line+1) >= (maxLine-1)) aux = maxLine-2;
					else aux = line;

					oSpread.body.rows[aux].cells[col].childNodes[0].focus()
				} catch (e) {}
			}
                        if (oSpread.getEventDeleteLine() != "") {
                            eval(oSpread.getEventDeleteLine());
                        }
			return false;
		}
	}
	if (whichCode == 13) {
		if (oSpread.process.edit) {
			if ((col+1) != oSpread.body.rows[line].cells.length) {
				oSpread.body.rows[line].cells[col+1].childNodes[0].focus();
			} else {
				stop = true;
				for (i = 0; i < oSpread.body.rows[line].cells.length; i++) {
					with (oSpread.body.rows[line].cells[i].childNodes[0]) {
						try {
							if (isIE) {
								if (value != defaultValue) {
									stop = false;
									break;
								}
							} else {
								if ((type == 'select-one' && value != getAttribute("defaultValue")) || (type != 'select-one' && value != defaultValue)) {
									stop = false;
									break;
								}
							}
						} catch (e) {}
					}
				}

				if (!oSpread.config.readonly) {
					if (!stop) {
						if ((line+1) == maxLine) {
							oSpread.addLine();
						}
						try {
							oSpread.body.rows[line+1].cells[0].childNodes[0].focus()
						} catch (e) {}
					} else if ((line+1) != maxLine) {
						if (stop) {
							oSpread.deleteLine(line+1);
							try {
								oSpread.body.rows[line].cells[0].childNodes[0].focus()
								oSpread.body.rows[line].cells[0].childNodes[0].select()
							} catch (e) {}
						} else {
							try {
								oSpread.body.rows[line+1].cells[0].childNodes[0].focus()
								oSpread.body.rows[line+1].cells[0].childNodes[0].select()
							} catch (e) {}
						}
					}
				} else if ((line+1) != maxLine) {
					try {
						oSpread.body.rows[line+1].cells[0].childNodes[0].focus()
						oSpread.body.rows[line+1].cells[0].childNodes[0].select()
					} catch (e) {}
				}
			}
			oSpread.process.edit = false;
			return false;
		} else {
			oSpread.process.edit = true;
			return false;
		}
	}

	if (type.toUpperCase() != "COMBO") {

		//*** seta pra baixo
		if (whichCode == 40) {
			stop = true;
			for (i = 0; i < oSpread.body.rows[line].cells.length; i++) {
				with (oSpread.body.rows[line].cells[i].childNodes[0]) {
					try {
						if (isIE) {
							if (value != defaultValue && tipo != 'image') {
								stop = false;
								break;
							}
						} else {
							if ((type == 'select-one' && value != getAttribute("defaultValue")) || (type != 'select-one' && value != defaultValue)) {
								stop = false;
								break;
							}
						}
					} catch (e) {}
				}
			}

			if (!oSpread.config.readonly) {
				if (!stop) {
					if ((line+1) == maxLine) {
						oSpread.addLine();
					}
					try {
						oSpread.body.rows[line+1].cells[col].childNodes[0].focus()
						oSpread.body.rows[line+1].cells[col].childNodes[0].select()
					} catch (e) {}
				} else if ((line+1) != maxLine) {
					if (stop) {
						oSpread.deleteLine(line+1);
						try {
							oSpread.body.rows[line].cells[col].childNodes[0].focus()
							oSpread.body.rows[line].cells[col].childNodes[0].select()
						} catch (e) {}
					} else {
						try {
							oSpread.body.rows[line+1].cells[col].childNodes[0].focus()
							oSpread.body.rows[line+1].cells[col].childNodes[0].select()
						} catch (e) {}
					}
				}
			} else if ((line+1) != maxLine) {
				try {
					oSpread.body.rows[line+1].cells[col].childNodes[0].focus()
					oSpread.body.rows[line+1].cells[col].childNodes[0].select()
				} catch (e) {}
			}

			oSpread.process.edit = false;
			return false;
		}

		//*** seta pra cima
		if (whichCode == 38) {
			if ((line+1) != 1) {
				try {
					oSpread.body.rows[line-1].cells[col].childNodes[0].focus()
					oSpread.body.rows[line-1].cells[col].childNodes[0].select()
				} catch (e) {}

				stop = false;
				for (i = 0; i < oSpread.body.rows[line].cells.length; i++) {
					with (oSpread.body.rows[line].cells[i].childNodes[0]) {
						try {
							if (isIE) {
								if (value != defaultValue && tipo != 'image') {
									stop = true;
									break;
								}
							} else {
								if ((type == 'select-one' && value != getAttribute("defaultValue")) || (type != 'select-one' && value != defaultValue)) {
									stop = true;
									break;
								}
							}
						} catch (e) {}
					}
				}

				if (!oSpread.config.readonly) {
					if (!stop) {
						oSpread.deleteLine(line+1);
					}
				}
			}

			oSpread.process.edit = false;
			return false;
		}
	}

	if (!oSpread.process.edit) {
		//*** seta pra direita
		if (whichCode == 39) {
			if ((col+1) != oSpread.body.rows[line].cells.length) {
				try {
					oSpread.body.rows[line].cells[col+1].childNodes[0].focus()
					oSpread.body.rows[line].cells[col+1].childNodes[0].select()
				} catch (e) {}
			} else {
				stop = true;
				for (i = 0; i < oSpread.body.rows[line].cells.length; i++) {
					with (oSpread.body.rows[line].cells[i].childNodes[0]) {
						try {
							if (isIE) {
								if (value != defaultValue) {
									stop = false;
									break;
								}
							} else {
								if ((type == 'select-one' && value != getAttribute("defaultValue")) || (type != 'select-one' && value != defaultValue)) {
									stop = false;
									break;
								}
							}
						} catch (e) {}
					}
				}

				if (!oSpread.config.readonly) {
					if (!stop) {
						if ((line+1) == maxLine) {
							oSpread.addLine();
						}
						try {
							oSpread.body.rows[line+1].cells[0].childNodes[0].focus()
							oSpread.body.rows[line+1].cells[0].childNodes[0].select()
						} catch (e) {}
					} else if ((line+1) != maxLine) {
						if (stop) {
							oSpread.deleteLine(line+1);
							try {
								oSpread.body.rows[line].cells[0].childNodes[0].focus()
								oSpread.body.rows[line].cells[0].childNodes[0].select()
							} catch (e) {}
						} else {
							try {
								oSpread.body.rows[line+1].cells[0].childNodes[0].focus()
								oSpread.body.rows[line+1].cells[0].childNodes[0].select()
							} catch (e) {}
						}
					}
				} else if ((line+1) != maxLine) {
					try {
						oSpread.body.rows[line+1].cells[0].childNodes[0].focus()
						oSpread.body.rows[line+1].cells[0].childNodes[0].select()
					} catch (e) {}
				}
			}
			return false;
		}

		//*** seta pra esquerda
		if (whichCode == 37) {
			if ((col+1) != 1) {
				try {
					oSpread.body.rows[line].cells[col-1].childNodes[0].focus()
					oSpread.body.rows[line].cells[col-1].childNodes[0].select()
				} catch (e) {}
			} else {
				if ((line+1) != 1 )
				{
					try {
						oSpread.body.rows[line-1].cells[oSpread.body.rows[line].cells.length-1].childNodes[0].focus()
						oSpread.body.rows[line-1].cells[oSpread.body.rows[line].cells.length-1].childNodes[0].select()
					} catch (e) {}

					stop = false;
					for (i = 0; i < oSpread.body.rows[line].cells.length; i++) {
						with (oSpread.body.rows[line].cells[i].childNodes[0]) {
							try {
								if (isIE) {
									if (value != defaultValue) {
										stop = true;
										break;
									}
								} else {
									if ((type == 'select-one' && value != getAttribute("defaultValue")) || (type != 'select-one' && value != defaultValue)) {
										stop = true;
										break;
									}
								}
							} catch (e) {}
						}
					}

					if (!oSpread.config.readonly) {
						if (!stop) {
							oSpread.deleteLine(line+1);
						}
					}
				}
			}
			return false;
		}
	}

	return true;
};

spread.prototype.addCol =
function(title,type,maxlength,size, aux) {
	this.nodes[this.nodes.length] = new column(title, type, maxlength, size, aux)
};

spread.prototype.create =
function() {
	var j;
	var aux1;
	var aux2;
	var aux3;

	if (this.span == undefined) {
		alert("Span não configurada para spread '" + this.obj + "' !")
		this.process.create = false;
		return false;
	}

	aux1  =	'<table border="0" cellspacing="0" cellpadding="0">';
	aux1 +=	'	<tr>';
	aux1 +=	'		<td>';
	aux1 +=				'<table border="0" cellspacing="0" cellpadding="0">';
	aux1 +=	'				<tr>';
	aux1 +=	'					<td><div></div></td>';
	aux1 +=	'				</tr>';
	aux1 +=	'				<tr>';
	aux1 +=	'					<td><div></div></td>';
	aux1 +=	'				</tr>';
	aux1 +=	'			</table>';
	aux1 +=	'		</td>';
	aux1 +=	'		<td><div></div></td>';
	aux1 +=	'	</tr>';
	aux1 +=	'	<tr>';
	aux1 +=	'		<td><div style="display: none" id="' + "hid_" + this.config.name + '"></div></td>';
	aux1 +=	'	</tr>';
	aux1 +=	'</table>';
	this.span.innerHTML = aux1;

	with (this.span.childNodes[0].rows[0].cells[0]) {
		this.header = childNodes[0].rows[0].cells[0].childNodes[0];
		this.body 	= childNodes[0].rows[1].cells[0].childNodes[0];
	}
	this.scroll	= this.span.childNodes[0].rows[0].cells[1].childNodes[0];
	this.hidden = this.span.childNodes[0].rows[1].cells[0].childNodes[0];

	with (this) {
		if (config.scroll) {
			if (isIE) {
				body.style.overflowY = 'scroll';
			} else {
				body.style.overflow = 'scroll';
			}
			body.className = 'divScroll';
			body.style.width = span.style.width;
			body.style.height = span.style.height;
		}

		body.table = document.createElement("table");

		try {
			if (!isIE) {
				span.parentNode.style.height = parseFloat(span.style.height) + 16;
				span.parentNode.style.verticalAlign = "top";
			}
		} catch (e) {}
	}

	this.config.diff = 0

	with (this.body.table) {
		border = 0;
		cellspacing = 1;
		cellpadding = 0;
	}

	if (this.config.expand == true)	{
		this.body.table.style.width = '100%';
		aux3 = '100%';
	}

	this.body.innerHTML = "<table border='0' cellspacing='1' cellpadding='1' style='width: " + aux3 + "'>" +
							this.body.table.innerHTML +
							"</table>";

	this.body = this.body.childNodes[0];

	this.hidden.innerHTML = 	"<table></table>";
	this.hidden = this.hidden.childNodes[0];

	this.process.create	= true;

	if (this.config.readonly) {
		this.tr.comment = '';
	}

	this.addTitle();
	if (this.first_line) {
		this.addLine();
	}
};

spread.prototype.setFirstLine =
function(first) {
  this.first_line = first;
};

spread.prototype.getEventDeleteLine =
function() {
  return this.event_delete_line;
};

spread.prototype.setEventDeleteLine =
function(evento) {
  this.event_delete_line = evento;
};

spread.prototype.getEventAddLine =
function() {
  return this.event_add_line;
};

spread.prototype.setEventAddLine =
function(evento) {
  this.event_add_line = evento;
};

spread.prototype.addTitle =
function() {
	if (this.process.create) {
		var j;
		var aux1;
		var aux2;
		var aux3;

		this.header.table = document.createElement("table");

		with (this.header.table) {
			border = 0;
			cellspacing = 1;
			cellpadding = 0;
		}

		if (this.config.expand) {
			this.header.table.style.width = '100%';
			aux2 = '100%'
		}

		with (this.header.table) {
			insertRow(-1);

			j = rows.length-1;
			aux1 = true;
			aux3 = 0;
			//rafa
			for (i = 0; i < this.nodes.length; i++) {
				type = this.nodes[i].type;
				if (type.toUpperCase() != 'HIDDEN') {
					rows[j].insertCell(-1);
					rows[j].cells[aux3].className = this.config.backcolor1;
					rows[j].cells[aux3].style.cursor = 'pointer';
					rows[j].cells[aux3].innerHTML = this.nodes[i].title;
					rows[j].cells[aux3].onClick = this.nodes[i].order;
					rows[j].cells[aux3].style.textAlign = this.nodes[i].titleAlign;
					if (this.nodes[i].comment != null) rows[j].cells[aux3].title = this.nodes[i].comment;
					else if (this.tr.comment != null) rows[j].cells[aux3].title = this.tr.comment;

					if (this.config.expand && aux1) {
						if (type.toUpperCase() != 'HIDDEN' &&
							  type.toUpperCase() != 'CHECK' &&
								type.toUpperCase() != 'OPTIONV' &&
								type.toUpperCase() != 'BUTTON' ){
							aux1 = false;
						} else {
							rows[j].cells[aux3].style.width = this.nodes[i].size + this.config.diff;
						}
					} else {
						rows[j].cells[aux3].style.width = this.nodes[i].size + this.config.diff;
					}
					aux3++;
				}
			}
			if (this.config.scroll) {
				rows[j].insertCell(-1);
				rows[j].cells[aux3].style.width = '14px';
			}
		}

		this.header.innerHTML = "<table border='0' cellspacing='1' cellpadding='1' style='width: " + aux2 + "'>" +
								this.header.table.innerHTML +
								"</table>";
	}
}

spread.prototype.addScroll =
function() {
}

spread.prototype.addLine =
function(n) {
	if (this.process.create) {
		var i;
		var j;
		var aux1;
		var aux2;

		if (n != undefined) {
			this.body.insertRow(n);
			this.hidden.insertRow(n);
			j = n;
		} else {
			this.body.insertRow(-1);
			this.hidden.insertRow(-1);
			j = this.body.rows.length-1;
		}

		aux1 = 0;
		aux2 = 0;

		this.process.aux = true;

		with (this.body) {
			for (i = 0; i < this.nodes.length; i++) {
				type = this.nodes[i].type;
				if (type.toUpperCase() == 'HIDDEN') {
					this.hidden.rows[j].insertCell(-1);
					this.hidden.rows[j].cells[aux1].innerHTML += createInput(this.config.name, this.nodes[i], j, aux1);
					this.nodes[i].col = aux1;
					aux1++;
				} else {
					rows[j].insertCell(-1);
					rows[j].cells[aux2].innerHTML = createInput(this.config.name, this.nodes[i], j, aux2);
					rows[j].cells[aux2].style.width = this.header.table.rows[0].cells[aux2].style.width;
					if (type.toUpperCase() == 'CHECK' ||
							type.toUpperCase() == 'OPTIONV') {
						rows[j].cells[aux2].align = 'center';
					}
					this.nodes[i].col = aux2;
					aux2++;
				}
			}

			rows[j].className = ((j+1) % 2) == 1 ? this.config.backcolor2 : this.config.backcolor3;
			this.process.maxRows = rows.length;
		}

//		this.zebrar()
	}
}

spread.prototype.deleteLine =
function(n) {
	if (this.process.create) {
		if (n != undefined) {
			this.body.deleteRow(n-1);
			this.hidden.deleteRow(n-1);
		}

		this.process.maxRows = this.body.rows.length;
		this.zebrar()
	}
}

spread.prototype.editCol =
function(n,conf,val) {
	try {
		eval("this.nodes["+(n-1)+"]."+conf+" = '"+val+"';")
	} catch(e) {
		alert("Não foi possível atualizar a configuração para \n Coluna :: "+n+" \n Parâmetro :: "+conf+" \n Valor :: "+val)
	}
}

spread.prototype.addValue =
function(n, line, value, aux) {
	var type;
	var col;
	try {
		type = this.nodes[n-1].type;
		col  = this.nodes[n-1].col;

		if (type.toUpperCase() == 'HIDDEN') {
				this.hidden.rows[line-1].cells[col].childNodes[0].value = value;
		} else {
			with (this.body.rows[line-1].cells[col]) {
				if (type.toUpperCase() == 'LABEL') {
					childNodes[0].innerHTML = value;
				} else if (type.toUpperCase() == 'COMBO') {
					selecionacombo(childNodes[0], value);
				} else if (type.toUpperCase() == 'CHECK' ||
									 type.toUpperCase() == 'OPTIONV') {
					childNodes[0].value = value;
					if (aux) {
						childNodes[0].setAttribute("checked","true");
					} else {
						if (!isIE) {
							childNodes[0].removeAttribute("checked");
						} else {
							childNodes[0].checked = aux;
						}
					}
				} else {
					childNodes[0].value = value;
				}
			}
		}
	} catch(e) {}
}

spread.prototype.getValue =
function(n, line) {
	var type;
	var col;
	try {
		type = this.nodes[n-1].type;
		col  = this.nodes[n-1].col;
		if (type.toUpperCase() == 'HIDDEN') {
			return this.hidden.rows[line-1].cells[col].childNodes[0].value;
		} else {
			with (this.body.rows[line-1].cells[col]) {
				if (type.toUpperCase() == 'CHECK' ||
					type.toUpperCase() == 'OPTIONV') {
				if (childNodes[0].checked == true)
					return childNodes[0].value;
				else
					return null;
				} else if (type.toUpperCase() == 'LABEL') {
					return childNodes[0].innerHTML;
				} else {
					return childNodes[0].value;
				}
			}
		}
	} catch(e) {
		alert("Não foi possível retornar o valor desejado ! \n [n: " + n + "; line: " + line + "]");
	}
}

spread.prototype.getObject =
function(n, line) {
	var type;
	var col;
	try {
		type = this.nodes[n-1].type;
		col  = this.nodes[n-1].col;
		if (type.toUpperCase() == 'HIDDEN') {
			return this.hidden.rows[line-1].cells[col].childNodes[0];
		} else {
			return this.body.rows[line-1].cells[col].childNodes[0];
		}
	} catch(e) {
		alert("Não foi possível retornar o valor desejado ! \n [n: " + n + "; line: " + line + "]");
	}
}

spread.prototype.zebrar =
function() {
	if (this.process.create) {
		var i;
		var j;
		var newName;
		var re;
		var ret;

		for (i = 0; i < this.process.maxRows; i++) {
			this.setLineStyle(i+1,"color","");
			this.setLineStyle(i+1,"backgroundColor","");
			this.setLineStyle(i+1,"fontWeight","");
			if ((i % 2) == 0) {
				this.body.rows[i].className = this.config.backcolor2;
			} else {
				this.body.rows[i].className = this.config.backcolor3;
			}

			for (j = 0; j < this.body.rows[i].cells.length; j++) {
				newName = makeInputName(this.config.inputName, this.config.name, (i+1), (j+1));

				this.body.rows[i].cells[j].childNodes[0].name = newName;
				this.body.rows[i].cells[j].childNodes[0].id   = newName;
			}
		}
		with (document.getElementById("hid_" + this.config.name).childNodes[0]) {
			for (var k=0; k < rows.length; k++){
				for (var m=0; m < rows[k].cells.length; m++){
					var nome = "hid_" + this.config.name + "_" + (m+1) + "_" + (k+1);
					rows[k].cells[m].childNodes[0].name = nome
					rows[k].cells[m].childNodes[0].id = nome;
				}
			}
		}
	}
}

spread.prototype.toXml =
function() {
	var xml = "";
	var type;

	xml += "<" + this.config.name + ">\n";
	for (i = 0; i < this.process.maxRows; i++) {
		xml += "  <row>\n";
		with (this.body.rows[i]) {
			for (j = 0; j < cells.length; j++) {
				xml += "    <cell>";
				var type = cells[j].childNodes[0].getAttribute("tipo");
				if (type.toUpperCase() == 'LABEL') {
					xml += cells[j].childNodes[0].innerHTML;
				} else if (type.toUpperCase() == 'CHECK') {
					if (!isIE) {
						if (cells[j].childNodes[0].check != null) {
							xml += 1;
						} else {
							xml += 0;
						}
					} else {
						if (cells[j].childNodes[0].check) {
							xml += 1;
						} else {
							xml += 0;
						}
					}
				} else {
					xml += cells[j].childNodes[0].value;
				}
				xml += "</cell>\n";
			}
		}
		with (this.hidden.rows[i]) {
			for (j = 0; j < cells.length; j++) {
				xml += "    <hidden>";
				xml += cells[j].childNodes[0].value;
				xml += "</hidden>\n";
			}
		}
		xml += "  </row>\n";
	}
	xml += "</" + this.config.name + ">";

	return xml;
}

spread.prototype.toCsv =
function() {
	var csv = "";
	var type;

	for (i = 0; i < this.process.maxRows; i++) {
		with (this.body.rows[i]) {
			for (j = 0; j < cells.length; j++) {
				var type = cells[j].childNodes[0].getAttribute("tipo");
				if (type.toUpperCase() == 'LABEL') {
					csv += '"' + fJava(cells[j].childNodes[0].innerHTML) + '";';
				} else if (type.toUpperCase() == 'CHECK') {
					if (!isIE) {
						if (cells[j].childNodes[0].check != null) {
							csv += '1;';
						} else {
							csv += '0;';
						}
					} else {
						if (cells[j].childNodes[0].check) {
							csv += '1;';
						} else {
							csv += '0;';
						}
					}
				} else {
					csv += '"' + fJava(cells[j].childNodes[0].value) + '";';
				}
			}
		}
		with (this.hidden.rows[i]) {
			for (j = 0; j < cells.length; j++) {
				csv += '"' + fJava(cells[j].childNodes[0].value) + '";';
			}
		}
		csv += "\n";
	}

	return csv;
}

spread.prototype.setLineStyle =
function(line,property,value) {
	with (this.body.rows[line-1]) {
		eval("style." + property + " = '" + value + "'");
	}
}