// JavaScript Document

// XML2CSV utility

function xml2csv(obj){
  url = obj.getProperty("URL");
  url = "xml2csv/" + url
  location.href = url;
}



// Ajax Set Combo Options 
var setComboData = Class.create();
setComboData.prototype = {
	initialize: function(id, sel, key, val) {
		this.combo_id = id;
		if (sel) {
			this.xml_sel = sel;
		} else {
			this.xml_sel = false;
		}
		if (key) {
			this.xml_key = key;
		} else {
			this.xml_key = "key";
		}
		if (val) {
			this.xml_val = val;			
		} else {
			this.xml_val = "value";			
		}
	},
	ajaxUpdate: function(ajaxResponse) {
		text = ajaxResponse.getElementsByTagName(this.xml_key).item(0).text;
		value = ajaxResponse.getElementsByTagName(this.xml_val).item(0).text;
		comboObj = document.getElementById(this.combo_id);
		pos = comboObj.length;
		comboObj.options[pos]=new Option(value,text);
		if ((this.xml_sel) && (this.xml_sel==text)) {
			comboObj.options[pos].selected=true;
		}
	}
};

// define custom sort
var awSortTotal = function(src){		
	// get column index
	var i = src.getProperty("item/index");	
	// get array of row indices
	var rows = this.getProperty("row/values");			
	// re-arrange rows
	t = rows.pop();
	rows.reverse();		
	rows.push(t);
	// assign new rows array
	this.setProperty("row/values", rows);			
	// store column index
	this.setProperty("sort/index", i);			
	// store sort direction
	var sortDir = this.getProperty("sort/direction");

	if (sortDir =="descending") {
		this.setProperty("sort/direction", "ascending");
	} else {
		this.setProperty("sort/direction", "descending");			
	}
	this.refresh();
}


// Tools
   function trim(str) {
	 s = str.replace(/^(\s)*/, '');
	 s = s.replace(/(\s)*$/, '');
	 return s;
   }