/*
* first column is not sortable.
* After sorting reindex rows so that it always starts with 1 and ends with n
*/
$.tablesorter.addWidget({
	id: 'columnIndex',
	format: function (table)
		{
			$("tr:visible",table.tBodies[0])
				.find('td:first a').each(function (e) {$(this).text(e + 1);});
		}
	}
);

/*
* month_year string needs to be sorted numericaly.
* A span holds the integer yearmonth. (e.g. Maj 2009 -> 200905)
* Instead of the string return this value.
*/
$.tablesorter.addParser({
  // set a unique id
  id: 'months',
  is: function(s) {
      // return false so this parser is not auto detected
      return false;
  },
  format: function(s) {
    // format your data for normalization
    if( 'h' == s.substring(12,13)){
      //for ie 17 == strlen('<span class=hide>')
    	begin = 17;
    }
    else{
      //19 == strlen('<span class="hide">')
    	begin = 19;
    }
    end = begin+6;
    mySubstr = s.substring(begin, end);
		return mySubstr;
  },
  // set type, either numeric or text
  type: 'numeric'
  }
);

/*
* convert slo number (that is . as thousand) to ang number
* remove all '.'
*/
$.tablesorter.addParser({
  // set a unique id
  id: 'sloInt',
  is: function(s) {
      // return false so this parser is not auto detected
      return false;
  },
  format: function(s) {
      // format your data for normalization
    var shouldBeInt = s.replace(/\./g, '');
		var i = parseInt(shouldBeInt);
		return (isNaN(i)) ? 0 : i;
  },
  // set type, either numeric or text
  type: 'numeric'
  }
);

/*
* Remove % from input and return float
*/
$.tablesorter.addParser({
  // set a unique id
  id: 'procent',
  is: function(s) {
      // return false so this parser is not auto detected
      return false;
  },
  format: function(s) {
      // format your data for normalization
    var shouldBeInt = s.replace(/,/g, '.').replace(/%/,'');
		var i = parseFloat(shouldBeInt);
		return (isNaN(i)) ? 0 : i;
  },
  // set type, either numeric or text
  type: 'numeric'
	}
);