var Lines = { 
	add : function(){
		var ID = this.getID();
		var dataBody = document.getElementById('dataLineBody');
			
		var lastRow = document.getElementById('line-row-'+ID);
		ID++;
		this.setID(ID);
			
		var newRow = document.createElement('tr');
		newRow.id = 'line-row-'+ID;
		if(lastRow)
			newRow.className = lastRow.className == "row1" ? "row0" : "row1";
		else 
			newRow.className = "row0";
			
		var cols = new Array(9);
			
		cols[0] = document.createElement('td');
		cols[0].innerHTML = '<input type="checkbox" id="line-checkbox-'+ID+'" name="line-checkbox-'+ID+'" value=""/>';
			
		cols[1] = document.createElement('td');
		cols[1].innerHTML = '<input type="text" id="line-start-value-'+ID+'" name="line-start-value[]" value="" size="10"/>';
		
		cols[2] = document.createElement('td');
		cols[2].innerHTML = '<input type="text" id="line-end-value-'+ID+'" name="line-end-value[]" value="" size="10"/>';
			
		cols[3] = document.createElement('td');
		
		var color = document.createElement('input');
		color.className = "color {pickerPosition:'top',required:false}";
		color.id = 'line-color-'+ID;
		color.name = 'line-color[]';
		color.size = "7";
		color.value = '';
		var pixer = new jscolor.color(color);
		pixer.pickerPosition = 'top';
		pixer.valueElement.value = '';
		pixer.required = false;
		cols[3].appendChild(color);
		
		cols[4] = document.createElement('td');
		cols[4].innerHTML = '<input type="text"  id="line-display-'+ID+'"name="line-display[]" value="" size="30"/>';
			
		cols[5] = document.createElement('td');
		cols[5].innerHTML = '<input type="text" id="line-thickness-'+ID+'" name="line-thickness[]" value="" size="6"/>';
			
		cols[6] = document.createElement('td');
		cols[6].innerHTML = '<input type="checkbox" id="line-zone-'+ID+'"name="line-zone[]" value="1"/>';
			
		cols[7] = document.createElement('td');
		cols[7].innerHTML = '<input type="checkbox" id="line-top-'+ID+'"name="line-top[]" value="1"/>';
			
		cols[8] = document.createElement('td');
		cols[8].innerHTML = '<input type="text" id="line-alpha-'+ID+'" name="line-alpha[]" value="100" size="3" maxLength="3"/>';
			
		for(var i = 0; i < cols.length; i++ ) newRow.appendChild(cols[i]);
			
		dataBody.appendChild(newRow);	
			
		var info = document.getElementById('emptyLinesInfo');
		if(info) info.style.display = 'none';
	},
	
	remove : function(){
		var ID = Chart.removeRow('line-checkbox-',this.getID(),'dataLineBody','line-row-','emptyLinesInfo');
		this.setID(ID);
	},
	
	getXML : function(){
		var ID = this.getID();
		var result = '';
		for(var i = 1; i <= ID; i++){		
			var row = document.getElementById('line-row-'+i);
			if(row){
				var start     = Chart.quote(document.getElementById('line-start-value-'+i).value);
				var end       = Chart.quote(document.getElementById('line-end-value-'+i).value);
				var color     = Chart.quote(document.getElementById('line-color-'+i).value);
				var display   = Chart.quote(document.getElementById('line-display-'+i).value);
				var thickness = Chart.quote(document.getElementById('line-thickness-' +i).value);
				var zone      = document.getElementById('line-zone-'+i).checked ? "1" : "0";
				var top       = document.getElementById('line-top-' +i).checked ? "1" : "0";
				var alpha     = Chart.quote(document.getElementById('line-alpha-' +i).value);
				
				result += '<line ';
				
				if ( start != "" ) result += ' startValue="' + start + '" ';   
				if ( end != "" ) result += ' endValue="' + end + '" ';
				if ( color != "" ) result += ' color="' + color + '" ';
				if ( display != "" ) result += ' displayvalue="' + display + '" ';
				if ( thickness != "" ) result += ' thickness="' + thickness + '" ';
				if ( zone != "" ) result += ' isTrendZone="' + zone + '" ';
				if ( top != "" ) result += ' showOnTop="' + top + '" ';
				if ( alpha != "" ) result += ' alpha="' + alpha + '" ';
				
				result += '/>';
			}
		}			
		
		return '<trendLines>' + result + '</trendLines>';
	},
	
	checkAll : function(){
		Chart.checkAllRows('line-check-all','line-checkbox-',this.getID());
	},
	
	getID : function(){
		var ID = this.loadID();
		return ID ? ID.value : 0;
	},
	
	setID : function(value){
		var ID = this.loadID();
		if(ID){
			ID.value = value;
		}
	},
	
	loadID : function(){
		return document.getElementById('lastLineID');
	}
}