
function load_file(file_name)
{
  var request;
  request = window.XMLHttpRequest ? new XMLHttpRequest () :
                                    new ActiveXObject ('Microsoft.XMLHTTP');
  request.open("GET", file_name, false);
  request.send(null);
  return request.responseText;
}

function parse_csv_data(data)
{
  var parsed_data = new Array ();
  var lines_array = data.split ('\n');
  //skip first row (header row)
  for (var i=1; i<lines_array.length; i++)
  {
    line = lines_array[i];
    line = line.replace(/[\r\n]/g, '');
    var reg_expression = /,?"[^"$]*["$]|,?[^,$]*/g;
    var line_array = new Array ();
    while (true)
    {
      match = reg_expression.exec(line);
      if (match == null || match[0].length == 0)
      {
        reg_expression.lastIndex = 0;
        break;
      }
      var cell = match[0];
      cell = cell.replace(/"/g, '');
      cell = cell.replace(/^,/, '');
      if (cell.length == 0)
        cell = null;
      line_array.push(cell);
    }
    if (line_array.length > 0)
      parsed_data.push(line_array);
  }
  return parsed_data;
}

