// Title: Tigra Tables PRO
// URL: http://www.softcomplex.com/products/tigra_tables_pro/
// Version: 2.1
// Date: 03-09-2004 (mm-dd-yyyy)
// Technical Support: support@softcomplex.com (specify product title and order ID)
// Notes: Registration needed to use this script legally.
// Visit official site for details.
// ----------------------------------------------------------------------------------

// A path to Tigra Tables PRO files from the PAGE containinig the table
var path_to_files='http://images.ibsys.com/sh/scripts/informars/ttp_files/';
// Please, don't change below this line
// ==================================================================================

var d = document, TTablePRO = [], NUM = 'NUM', STR = 'STR',DATE='DATE',CURRENCY='CURRENCY';

function TCastSTR(s_){return s_.replace(/<[^>]+>/ig,'')+'';}
function TCastNUM(s_){if(isNaN(s_*1))return 0;else return s_*1;}
function TCastDATE(s_,s_format){
if(typeof(set_date_by_format)!='function') return s_+'';
if(s_format) return set_date_by_format(s_format,s_);
else return set_date_by_format('Y-m-d',s_);
}
function TCastCURRENCY(s_){return s_.replace(/[^0-9\-\.]/g, '')*1;}

function TQSRT(l, h) {
	if(this.a_f_body && !this.a_f_body.length)return true;
	var x = this.a_cont_d[(h + l) >> 1][this.o_sort.n_col], i = l, j = h, t = [];
	do {
		while (i <= h && (this.a_cont_d[i][this.o_sort.n_col]< x)) i ++;
		while (j >= l && (x< this.a_cont_d[j][this.o_sort.n_col])) j --;
		if (i <= j) {
			t = this.a_body[i];
			this.a_body[i] = this.a_body[j];
			this.a_body[j] = t;
			t = this.a_cont_d[i];
			this.a_cont_d[i] = this.a_cont_d[j];
			this.a_cont_d[j] = t;
			i++;
			j--
		}
	} while (i < j);
	if (l < j) this.exeQSRT(l, j);
	if (i < h) this.exeQSRT(i, h);
}

function TTable(a_capt, a_cont, o_look) {
	var c = 0, filters = ['substring','match','regexp'], i, 
	a_css = ['main', 'captCell', 'captText', 'head', 'foot', 'pagnCell', 'pagnText', 'pagnPict', 'filtCell', 'filtPatt', 'filtSelc'];
	this.a_capt = []; this.a_head = []; this.a_body = [];this.a_sel_capt=[], this.a_foot = [];this.a_cont_d=[],this.a_cont=[],this.n_hid_rows = 0;
	this.a_part = ['Capt()', 'HdFt("head")', 'Body()', 'HdFt("foot")', 'Page()', 'Filt()'];
	this.id = TTablePRO.length;
	TTablePRO[this.id] = this;
	this.n_fcol = null;
	this.s_fpat = '';
	this.s_light = '';
	this.s_click = '';
	this.a_index=[];
	this.a_index_d=[];
	this.a_marked=[];
	this.changeCont = TTPChange_content;
	this.buildCapt = TTPBuildCapt;
	this.buildHdFt = TTPBuildFreeze;
	this.buildBody = TTPBuildBody;
	this.buildPage = TTPBuildPage;
	this.buildFilt = TTPBuildFilt;
	this.build     = TTPBuild;
	this.f_show      = TTPShow;
	this.buildCell = TTPBuildCell;
	this.exeSort   = TTPExeSort;
	this.exeQSRT   = TQSRT;
	this.exePage   = TTPExePage;
	this.exeFilt   = TTPExeFilt;
	this.callFilt  = TTPCallFilt;
	this.callSort  = TTPCallSort;
	this.attachForm = TTPAttach_form;
	this.go = TTPGo;
	this.o_css = [];
	this.s_filthtml='';
	this.b_date=false;
	this.f_onclick = o_look.onclick;
	this.n_key = o_look.key || 0;
	with (o_look) {
			for (i in a_css) 
				this.o_css[a_css[i]] = css != null && css[a_css[i]] ? ' class="' + css[a_css[i]] + '"' : '';
			this.o_css.body = [];
			this.n_padding = params[0] || 0;
			this.n_spacing = params[1] || 0;
		this.o_color = colors || {};
			this.a_struc = structure;
			if (!paging) var paging = [];
			this.o_paging = {
			's_pf' : paging.pf || '&laquo;&laquo;',
			's_pp' : paging.pp || '&laquo;',
			's_pn' : paging.pn || '&raquo;',
			's_pl' : paging.pl || '&raquo;&raquo;',
				's_tt' : paging.tt || '&nbsp;',
				'b_sh' : paging.sh,
				'n' : paging.by && paging.by > 0 ? paging.by : a_cont.length,
				'c' : 0
			};
			if (!sorting) var sorting = [];
			this.o_sort = {
			's_as' : sorting.as || '',
			's_ds' : sorting.ds || '',
			's_no' : sorting.no || '',
				'n_col' : sorting.cl,
				'b_ord' : sorting.or
			};
			this.btn_ok=filter.btn_ok || 'filter';
			this.btn_no=filter.btn_no || 'clear';
			this.a_filters = filters;
			this.filter = filter.type;
			this.n_filters = 3;
			for (i = filters.length-1; i >=0; i--){
					if (!((1 << i) & filter.type)) {
						this.a_filters[i] = 0; 
						this.n_filters --;
					}
					else this.n_ftype = i;
			}
			if(this.filter==0) this.n_ftype='';
		var n_head = freeze[0] * 1, n_foot = freeze[1] * 1;
	}
	this.b_markmulty = o_look.multy_mark;
	this.n_rows = a_cont.length - n_head - n_foot;
	this.n_cols = a_capt.length;
	
	for (var i in a_capt) {
		this.o_css.body[i] = !o_look.css || !o_look.css.body ? '' : 
			typeof(o_look.css.body) != 'object' ? o_look.css.body : 
				o_look.css.body[i] ? ' class="' + o_look.css.body[i] + '"' : '';
		this.a_sel_capt[i]={'name': a_capt[i].name.replace(/<[^>]+>/ig,'')};
		this.a_capt[i] = {
			'name' : a_capt[i].name,
			'b_hide_filter' : a_capt[i].hide_filter,
			'type' : a_capt[i].type,
			'b_hide' : a_capt[i].hide,
			'cast' : typeof(window['TCast' + a_capt[i].type]) == 'function' 
				? window['TCast' + a_capt[i].type] 
				: typeof(a_capt[i].type)  == 'function'
					? a_capt[i].type
					: function (s_) {return s_},
			'f_css' : typeof(a_capt[i].format) == 'function' 
				? a_capt[i].format 
				: function () {return null}
		};
		if(a_capt[i].hide)this.n_hid_rows++;
		if(a_capt[i].type==DATE){
			if(!this.b_date){
				this.getparseDate = (typeof(get_date_by_format)=='function'?get_date_by_format:function(s_){return s_+'';});
				this.b_date=true;
			};
			this.a_capt[i].format_input = a_capt[i].format_input || '';
			this.a_capt[i].format_output = a_capt[i].format_output || '';
		}
	}
	for (i = 0; i < a_cont.length; i ++) for (j = 0; j < a_cont[0].length; j ++) 
		if (a_cont[i][j] + '' == ''||a_cont[i][j]==null) a_cont[i][j] = '&nbsp;';
	for (i = 0; i < n_head; i ++) this.a_head[i] = a_cont[c++];
	for (i = 0; i < this.n_rows; i ++){
		this.a_cont_d[i]=[];
		for (var _j = 0; _j < this.n_cols; _j ++) {
			var s_ = a_cont[c][_j]+'';
			if(this.a_capt[_j]['type']==DATE){
				this.a_cont_d[i][_j]= this.a_capt[_j].cast(s_,this.a_capt[_j].format_input);
				a_cont[i][_j] = this.getparseDate(this.a_cont_d[i][_j],this.a_capt[_j].format_output);
			}
			else this.a_cont_d[i][_j] = this.a_capt[_j].cast(s_);
		}
		this.a_body[i] = a_cont[c++];
		this.a_cont[i]=this.a_cont_d[i];
		this.a_body[i][this.a_body[i].length] = i;
	}
	for (i = 0; i < n_foot; i ++) this.a_foot[i] = a_cont[c++];
	this.go();
}
function TTPChange_content(a_cont,n_p_by){
	var c = 0;
	this.a_cont = [];this.a_cont_d = [];this.a_body = [];this.a_index = [];this.o_sort.n_col = null;
	this.a_f_body = [];
	this.o_paging.n = n_p_by && n_p_by > 0 ? n_p_by: a_cont.length;
	this.o_paging.c = 0;
	if(this.o_paging.n > a_cont.length)this.o_paging.n = a_cont.length;
	this.n_rows = a_cont.length - this.a_head.length - this.a_foot.length;
	for (i = 0; i < a_cont.length; i ++) for (j = 0; j < a_cont[0].length; j ++) 
		if (a_cont[i][j] + '' == ''||a_cont[i][j]==null) a_cont[i][j] = '&nbsp;';
	for (i = 0; i < this.a_head.length; i ++) this.a_head[i] = a_cont[c++];
	for (i = 0; i < this.n_rows; i ++){
		this.a_cont_d[i]=[];
		this.a_body[i] = [];
		for (var _j = 0; _j < this.n_cols; _j ++) {
			var s_ = a_cont[c][_j]+'';
			var s_i = 0;
			if(this.a_capt[_j]['type']==DATE){
				this.a_cont_d[i][_j]= this.a_capt[_j].cast(s_,this.a_capt[_j].format_input);
				//a_cont[i][_j] = this.getparseDate(this.a_cont_d[i][_j],this.a_capt[_j].format_output);
				s_i = this.getparseDate(this.a_cont_d[i][_j],this.a_capt[_j].format_output);
			}
			else this.a_cont_d[i][_j]= this.a_capt[_j].cast(s_);
			this.a_body[i][_j] = s_i?s_i:a_cont[i][_j];
		}
		c++;
		this.a_cont[i]=this.a_cont_d[i];
		this.a_body[i][this.a_body[i].length] = i;
	}
	for (i = 0; i < this.a_foot.length; i ++) this.a_foot[i] = a_cont[c++];
	this.f_show();
}

function TTPBuildCapt() {
	var a_ = ['<tr>'], i, b_order, s_img, n_cnt = 1;
	for (i in this.a_capt) if (!this.a_capt[i].b_hide)
		if (this.a_capt[i].type) {
			b_order = Boolean(this.o_sort.n_col == i && this.o_sort.b_ord != 1);
			s_img = this.o_sort[this.o_sort.n_col != i ? 's_no' : this.o_sort.b_ord ? 's_ds' : 's_as'];
			s_lnk = 'TTablePRO[' + this.id + '].exeSort(' + i + ',' + b_order + ')';
			a_[n_cnt++] = this.buildCell(['<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr valign="middle">', '<td width="99%"', this.o_css.captText, '><a title="Sort this column" href="javascript:', s_lnk, '"', this.o_css.captText, '>', this.a_capt[i].name, '</a></td><td><a href="javascript:', s_lnk, '">', s_img, '</a></td></tr></table>'].join(''), this.o_css.captCell);
		}
		else a_[n_cnt++] = this.buildCell(['<table cellpadding="0" width="100%" cellspacing="0" border="0"><tr valign="middle"><td width="99%"', this.o_css.captText, '>', this.a_capt[i].name, '</td></tr></table>'].join(''), this.o_css.captCell);
	a_[n_cnt++] = '</tr>';
  return a_.join('');
}

function TTPBuildFilt() {
	if (this.s_filthtml) 
		return this.s_filthtml;
	if (this.n_filters == 0) return '';
	var a_ = ['<tr><td', this.o_css.filtCell, ' colspan="', this.n_cols-this.n_hid_rows, '" ><form id="TTForm' + this.id + '" name="TTForm' + this.id + '" onsubmit="return TTablePRO[', this.id, '].exeFilt(1);"><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td', this.o_css.filtCell, ' align=right nowrap>use <input', this.o_css.filtPatt, ' type="text" name="filtPatt" size="10', this.s_fpat ? '" value="' + this.s_fpat : '', '"> as '], n_cnt = 13;
	if (this.n_filters > 1) {
		a_[n_cnt++] = '<select' + this.o_css.filtSelc + ' name="filtType">';
		for (var i = 0; i < this.a_filters.length; i++) if (this.a_filters[i]) 
			a_[n_cnt++] = ['<option value=', i, (i == this.n_ftype*1 ? ' selected' : ''), ">", this.a_filters[i]].join('');
		a_[n_cnt++] = "</select>";
	}
	else a_[n_cnt++] = this.a_filters[this.n_ftype];
	a_[n_cnt++] = ' on column <select' + this.o_css.filtSelc + ' name="filtCol">';
	for (var i in this.a_capt) if (!this.a_capt[i].b_hide && !this.a_capt[i].b_hide_filter)
		a_[n_cnt++] = '<option value=' + i + (this.n_fcol*1 == i ? ' selected' : '') + ">" + this.a_sel_capt[i].name;
	a_[n_cnt++] = '</select><a href="#" onclick="javascript:TTablePRO[' + this.id + '].exeFilt(1)">'+this.btn_ok+'</a> <a href="#" onclick="javascript:TTablePRO[' + this.id + '].exeFilt()">'+this.btn_no+'</a></td></tr></table></td></form></tr>';
	this.s_filthtml=a_.join('');
	return this.s_filthtml;
}


function TTPBuildPage() {
	var n_a = Math.ceil(this.n_rows / this.o_paging.n) - 1;
	if (n_a <= 0 && !this.o_paging.b_sh) return '';
	var a_ = ['<tr><td colspan=', this.n_cols-this.n_hid_rows, this.o_css.pagnCell, '><table cellspacing="0" cellpadding="0" border="0" width="100%"><tr>'], n_cnt = 4;
	this.o_paging.c = this.o_paging.c * 1;
	var s_ = '<td nowrap><a' + this.o_css.pagnPict + ' href="javascript:TTablePRO[' + this.id + '].exePage(';
	if (this.o_paging.c > 0) {
		if (this.o_paging.s_pf) a_[n_cnt ++] = s_ + '0)" title="First page">' + this.o_paging.s_pf + '</a></td>';
		if (this.o_paging.s_pp) a_[n_cnt ++] = s_ + (this.o_paging.c - 1) + ')" title="Previous page">' + this.o_paging.s_pp + '</a></td>';
	}
	a_[n_cnt++] = '<td width="99%"' + this.o_css.pagnText + '>' + this.o_paging.s_tt.replace('%ind', this.o_paging.c+1).replace('%pgs', n_a+1).replace('%rcs', this.n_rows) + '</td>';
	if (this.o_paging.c < n_a) {
		if (this.o_paging.s_pn) a_[n_cnt ++] = s_ + (this.o_paging.c + 1) + ')" title="Next page">' + this.o_paging.s_pn + '</a></td>';
		if (this.o_paging.s_pl) a_[n_cnt ++] = s_ + n_a + ')" title="Last page">' + this.o_paging.s_pl + '</a></td>';
	}
	a_[n_cnt++] = '</tr></table></td></tr>';
	return a_.join('');
}

function TTPBuildCell(value, s_CSS, s_add) {
	return '<td' + s_CSS + (s_add ? ' ' + s_add : '') + '>' + value + '</td>';
}
	
function TTPBuildFreeze(s_what) {
	var s_ = '', i, j,a_={'head':this.a_head, 'foot':this.a_foot};;
	for (i in a_[s_what]) {
		s_ += '<tr>';
		for (j in this.a_capt) if (!this.a_capt[j].b_hide) 
			s_ += this.buildCell(a_[s_what][i][j], this.o_css[s_what]);
		s_ += '</tr>';
	}
	return s_;
}

function TTPBuild () {
	var i, s_ = "<table cellpadding=" + this.n_padding + " cellspacing=" + this.n_spacing + this.o_css.main + " width=100% border=0>";
	for (i in this.a_struc) s_ += eval('this.build' + this.a_part[this.a_struc[i]]);
	s_ += "</table>";
	return s_ ;
}
function TTPAttach_form(e_form,filtCol,filtPatt,filtType){
	this.e_form=e_form;
	this.filtCol = e_form.elements[filtCol];
	this.filtPatt = e_form.elements[filtPatt];
	this.filtType = e_form.elements[filtType];
}
function TTPExeFilt(i_) {
	if (i_) {
		if(!this.e_form) return false;
		this.n_fcol = !this.filtCol 
			? 0
			: this.filtCol.type.indexOf('select-') > -1
				? this.filtCol.options[this.filtCol.selectedIndex].value
				: this.filtCol.value;
		this.s_fpat = this.filtPatt.value;
		this.n_ftype = this.filtType && this.filtType.type.indexOf('select-') > -1
			? this.filtType.options[this.filtType.selectedIndex].value
			: this.n_ftype;
	}
	else {
		this.n_fcol = null;
		this.s_fpat = '';
	}
	this.o_paging.c = 0;
	this.f_show();
	return false;
}

function TTPExePage(n) {
	this.o_paging.c = n; 
	this.f_show();
}

function TTPExeSort(n_col, n_ord) {
	var n_col_old = this.o_sort.n_col;
	this.o_sort.n_col = n_col;
	this.o_sort.b_ord = n_ord;
	this.o_paging.c = 0;
	this.f_show(true, n_col_old);
}

function TTPCallSort(n_col_old) {
	var i,j=0;
	if (n_col_old == this.o_sort.n_col){
		this.a_body = this.a_body.reverse();
		this.a_cont_d = this.a_cont_d.reverse();
	}
	else {
		if(!this.a_index[this.o_sort.n_col]){
			this.exeQSRT(0, this.a_cont_d.length - 1);
			this.a_index[this.o_sort.n_col]=[];
			this.a_index_d[this.o_sort.n_col]=[];
			for (i = 0; i < this.a_body.length; i ++){
				this.a_index[this.o_sort.n_col][i]=this.a_body[i];
				this.a_index_d[this.o_sort.n_col][i]=this.a_cont_d[i];
			}
			this.a_index[this.o_sort.n_col]['b_ord']=this.o_sort.b_ord;
		}else{
			if (this.a_index[this.o_sort.n_col]['b_ord']!=this.o_sort.b_ord){
				this.a_body = this.a_index[this.o_sort.n_col].reverse();
				this.a_cont_d = this.a_index_d[this.o_sort.n_col].reverse();
			}else{
				this.a_body = this.a_index[this.o_sort.n_col];
				this.a_cont_d = this.a_index_d[this.o_sort.n_col];
			}
		}
		if (this.o_sort.b_ord){
			this.a_body = this.a_body.reverse();
			this.a_cont_d = this.a_cont_d.reverse();
		}
	}
}

function TTPCallFilt() {
	if (!this.s_fpat || this.n_fcol == null) return this.a_body;
	var a_body = [],s_;
	if (this.n_ftype == 2) var r_ = eval('/' + this.s_fpat + '/');
	for (i = 0; i < this.a_body.length; i ++){
		if(this.a_capt[this.n_fcol]==DATE) s_ = this.a_body[i][this.n_fcol] + '';
		else s_ = this.a_cont_d[i][this.n_fcol]+'';
		if (
				(this.n_ftype == 2 && s_.search(r_) != -1) ||
				(this.n_ftype == 1 && s_ == this.s_fpat) ||
				(this.n_ftype == 0 && s_.indexOf(this.s_fpat) != -1)
			) a_body[a_body.length] = this.a_body[i];
	}
	return a_body;
}

d.write('<SC','RIPT LANGUAGE="JavaScript" src="', path_to_files, 'table.do.', d.implementation||d.styleSheets ? 'ok' : 'no', '.js"></SCR','IPT>')