/*
 * JQuery CSV loader plugin
 * Copyright (c) 2009 Redpill Linpro
 * Dual licensed under the MIT and GPL licenses.
 *
 */
 
 (function($){
 
 
 $.getCSV = function (url,callback,options) {
    options = $.extend($.getCSV.defaults,options);
    var cb = function(data) {
        
        //we make a list of list of the file
        var nlreg = new RegExp(options.newline,"g");
        var reg = new RegExp(options.delimiter,"g");
        var middle = options.str_chr+','+options.str_chr;
        var endlist = options.str_chr+'],['+options.str_chr;
        var list = ['[['+options.str_chr,
                        data.replace(/(\r\n)|(\n)/g,endlist).replace(reg,middle),
                   options.str_chr+']]'];
        
        list = eval(list.join(""));
        
        if (callback) {
            callback(list);
        }
    }
 
    $.get(url,cb);
 
 }
 
 $.getCSV.defaults = { 
                        delimiter: ';',
                        str_chr: "'"
                     };
 
 
 })(jQuery)
 
