function xml_specification() {
	this.loading_group = Array();
 	this.loading_spec = Array();
	
	this.show_head = function() {
		res = "";
		for (var group_id in in_group) {
			res += in_group[group_id][0];
			res += "|" + in_group[group_id][1] + "| ";
			str_f = "action_specification('edit_group'," + group_id + ")";
			res += '(<a href="#" onClick="' + str_f + '">edit</a>) <br/>';
			for (var spec_id in in_spec) {
				if (in_spec[spec_id][0] == group_id) {
					res += "&nbsp;&nbsp;" + in_spec[spec_id][1];
					res += "|" + in_spec[spec_id][2] + "|";	
					str_f = "action_specification('edit_spec'," + spec_id + ")";
					res += '(<a href="#" onClick="' + str_f + '">edit</a>) <br/>';
				}
			}
		}
		res += '<br/>';
		str_f = "action_specification('add_group',0)";
		res += '(<a href="#" onClick="' + str_f + '">Add group</a>) <br/>';

		str_f = "action_specification('add_spec',0)";
		res += '(<a href="#" onClick="' + str_f + '">Add specification</a>) <br/>';
		return res;
	}
	this.add_group = function() {
		len = in_group.length;
		len += 1;
		return this.show_edit_group(len);
	}
	
	this.add_spec = function() {
		len = in_spec.length;
		len += 1;
		return this.show_edit_spec(len);
	}
	

	this.show_edit_group = function(group_id) {
		this.load_group(group_id);
		res = "";
		res += 'Title <input name="group_title" type="text" value="'+this.loading_group["title"]+'"/><br/>';
		res += 'Weight <input name="group_weight" type="text" value="'+this.loading_group["weight"]+'"/><br/>';
		//res += 'Mark Delete <input name="group_delete" type="text" value="'+this.loading_group["delete"]+'"/><br/>';
		if (this.loading_group["delete"]) {
			check = 'checked';
		} else {
			check = '';
		}
		res += '<input name="group_delete" type="checkbox" value="1" '+check+' /> Mark Delete <br/>';

		str_f = "action_specification('save_group'," + group_id + ")";
		res += '<a href="#" onClick="' + str_f + '">save</a><br/>';
		return res;
	}
	
	this.show_edit_spec = function(spec_id) {
		this.load_spec(spec_id);
		res = "";
		res += 'Title <input name="spec_title" type="text" value="'+this.loading_spec["title"]+'"/><br/>';
		res += 'Weight <input name="spec_weight" type="text" value="'+this.loading_spec["weight"]+'"/><br/>';
		if (this.loading_spec["delete"]) {
			check = 'checked';
		} else {
			check = '';
		}
		res += '<input name="spec_delete" type="checkbox" value="1" '+check+' /> Mark Delete <br/>';
		res += 'Group <select name="group_id">';
		for (var group_id in in_group) {
			if (this.loading_spec["group_id"] == group_id) {
				sel = "selected='1'";
			} else {
				sel = "";
			}
			res += '<option value="'+group_id+'" '+sel+'>'+in_group[group_id][0]+'</option>';
		}
		res += '</select><br/>';
		str_f = "action_specification('save_spec'," + spec_id + ")";
		res += '<a href="#" onClick="' + str_f + '">save</a><br/>';
		return res;
	}
	

	this.load_spec = function(spec_id) {
		if (spec_id < in_spec.length) {
			this.loading_spec["group_id"] = in_spec[spec_id][0];
			this.loading_spec["title"] = in_spec[spec_id][1];
			this.loading_spec["weight"] = in_spec[spec_id][2];
			this.loading_spec["delete"] = in_spec[spec_id][3];
		} else  {
			this.loading_spec["group_id"] = 1;
			this.loading_spec["title"] = "";
			this.loading_spec["weight"] = 0;
			this.loading_spec["delete"] = false;
		}
	}

	
	this.save_spec = function(spec_id) {
		if (spec_id < in_spec.length) {
			in_spec[spec_id][0] = document.all["group_id"].value;
			in_spec[spec_id][1] = document.all["spec_title"].value;
			in_spec[spec_id][2] = document.all["spec_weight"].value;
			in_spec[spec_id][3] = document.all["spec_delete"].checked;
		} else {
			in_spec[spec_id] = Array (document.all["group_id"].value, document.all["spec_title"].value, document.all["spec_weight"].value, document.all["spec_delete"].checked);
		}
		return "Save spec <br/>" + this.show_head();
	}
	

	this.load_group = function(group_id) {
		if (group_id < in_group.length) {
			this.loading_group["title"] = in_group[group_id][0];
			this.loading_group["weight"] = in_group[group_id][1];
			this.loading_group["delete"] = in_group[group_id][2];
		} else {
			this.loading_group["title"] = "";
			this.loading_group["weight"] = "0";
			this.loading_group["delete"] = false;
		}
	}

	
	this.save_group = function(group_id) {
		if (group_id < in_group.length) {
			in_group[group_id][0] = document.all["group_title"].value;
			in_group[group_id][1] = document.all["group_weight"].value;
			in_group[group_id][2] = document.all["group_delete"].checked;
		} else {
			in_group[group_id] = Array(document.all["group_title"].value, document.all["group_weight"].value, document.all["group_delete"].checked);
		}
		return "Save group data <br/>" + this.show_head();
	}
	
	this.gen_xml = function() {
		xml = "";
		//sort
		//alert(in_group.length);
		/*
		for (i = 1; i <= in_group.length - 1; i++) {
			for (j = i + 1; j <= in_group.length; j++) {
				if (in_group[i-1][1] > in_group[j-1][1]) {
					mas = in_group[i-1];
					in_group[i-1] = in_group[j-1];
					in_group[j-1] = mas;   
				}
			}
		}		
		*/
		for (var group_id in in_group) {
			if (!in_group[group_id][2]) { 
				xml += '<group';
				xml += ' title = "' + in_group[group_id][0] + '"';
				xml += ' weight = "' + in_group[group_id][1] + '"';
				xml += '>';
				for (var spec_id in in_spec) {
					if (in_spec[spec_id][0] == group_id) {
						xml += '<spec';
						xml += ' title = "' + in_spec[spec_id][1] + '"';
						xml += ' weight = "' + in_spec[spec_id][2] + '"';
						xml += '/>';
					}
				}
				xml += '</group>';
			}
		}
		return xml;
	}	
}



