/*
 * Copyright (c) 2012 Francisco Salavert (ICM-CIPF)
 * Copyright (c) 2012 Ruben Sanchez (ICM-CIPF)
 * Copyright (c) 2012 Ignacio Medina (ICM-CIPF)
 *
 * This file is part of JS Common Libs.
 *
 * JS Common Libs is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * JS Common Libs is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JS Common Libs. If not, see <http://www.gnu.org/licenses/>.
 */

var Utils = {
    //properties
    characters: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",

    number: {
        sign: function (x) {
            return x ? x < 0 ? -1 : 1 : 0;
        }
    },
    //Methods
    formatNumber: function (position) {
        return position.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
    },
    formatText: function (text, spaceChar) {
        text = text.replace(new RegExp(spaceChar, "gi"), " ");
        text = text.charAt(0).toUpperCase() + text.slice(1);
        return text;
    },
    isFunction: function (s) {
        return typeof(s) === 'function' || s instanceof Function;
    },
    parseDate: function (strDate) {
        return strDate.substring(0, 4) + " " + strDate.substring(4, 6) + " " + strDate.substring(6, 8) + ", " + strDate.substring(8, 10) + ":" + strDate.substring(10, 12) + ":" + strDate.substring(12, 14);
    },
    genId: function (prefix) {
        prefix = prefix || '';
        prefix = prefix.length == 0 ? prefix : prefix + '-';
        return prefix + this.randomString();
    },
    randomString: function (length) {
        length = length || 10;
        var str = "";
        for (var i = 0; i < length; i++) {
            str += this.characters.charAt(this.getRandomInt(0, this.characters.length - 1));
        }
        return str;
    },
    getRandomInt: function (min, max) {
        // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/random
        // Using Math.round() will give you a non-uniform distribution!
        return Math.floor(Math.random() * (max - min + 1)) + min;
    },
    endsWithIgnoreCase: function (str, test) {
        var regex = new RegExp('^.*\\.(' + test + ')$', 'i');
        return regex.test(str);
    },
    endsWith: function (str, test) {
        return str.length >= test.length && str.substr(str.length - test.length) == test;
    },
    addQueryParamtersToUrl: function (paramsWS, url) {
        var chr = "?";
        if (url.indexOf("?") != -1) {
            chr = "&";
        }
        var query = "";
        for (var key in paramsWS) {
            if (paramsWS[key] != null)
                query += key + "=" + paramsWS[key].toString() + "&";
        }
        if (query != "")
            query = chr + query.substring(0, query.length - 1);
        return url + query;
    },
    randomColor: function () {
        var color = "";
        for (var i = 0; i < 6; i++) {
            color += ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f'][Math.floor(Math.random() * 16)]);
        }
        return "#" + color;
    },
    colorLuminance: function (hex, lum) {
        // validate hex string
        hex = String(hex).replace(/[^0-9a-f]/gi, '');
        hex = String(hex).replace(/#/gi, '');
        if (hex.length < 6) {
            hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
        }
        lum = lum || 0;

        // convert to decimal and change luminosity
        var rgb = "#", c, i;
        for (i = 0; i < 3; i++) {
            c = parseInt(hex.substr(i * 2, 2), 16);
            c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
            rgb += ("00" + c).substr(c.length);
        }

        return rgb;
    },
    getSpeciesFromAvailable: function (availableSpecies, speciesCode) {
        for (var i = 0; i < availableSpecies.items.length; i++) {
            var phylos = availableSpecies.items[i].items;
            for (var j = 0; j < phylos.length; j++) {
                var species = phylos[j];
                if (this.getSpeciesCode(species.text) == speciesCode) {
                    return species;
                }
            }
        }
    },
    getSpeciesCode: function (speciesName) {
        var pair = speciesName.split(" ");
        var code;
        if (pair.length < 3) {
            code = (pair[0].charAt(0) + pair[1]).toLowerCase();
        } else {
            code = (pair[0].charAt(0) + pair[1] + pair[pair.length - 1].replace(/[/_().\-]/g, '')).toLowerCase();

        }
        return code;

    },
    basicValidationForm: function (scope) {
        var validated = true;
        var msg = "";
        if (scope.$.outdir.selectedFile === undefined || scope.$.outdir.selectedFile.type != "FOLDER") {
            msg += "Error: Please select an output folder.\n";
            validated = false;
        }
        if (scope.$.inputFile.selectedFile === undefined || scope.$.inputFile.selectedFile.type != "FILE") {
            msg += "Error: Please select an input file.\n";
            validated = false;
        }
        if (scope.$.jobName.value == "") {
            msg += "Error: Please add a job name.\n";
            validated = false;
        }
        if (!validated) {
            alert(msg)
        }
        return validated;
    },
    getUrl: function (fileId) {
        return OpencgaManager.files.download({
            id: fileId,
            query: {
                sid: Cookies("bioinfo_sid")
            },
            request: {
                url: true
            }
        });
    },
    getFileContent: function (callback, fileId) {
        OpencgaManager.files.content({
            id: fileId,
            query: {
                sid: Cookies("bioinfo_sid")
            },
            request: {
                success: function (response) {
                    callback(response);
                },
                error: function () {
                    this.message = 'Server error, try again later.';
                }
            }
        })
    },
    loadExampleFile: function (callback, toolName, exampleFileName) {

        var me = this;
        OpencgaManager.files.contentExample({
            query: {
                toolName: toolName,
                fileName: exampleFileName
            },
            request: {
                //method: 'POST',
                success: function (response) {
                    callback(response);
//                            debugger
//                            me.loadedMainSelectChanged(false,true);
                },
                error: function () {
                    alert('Server error, try again later.');
                }
            }
        })
    },
    downloadExampleFile: function (toolName, fileName) {
        var url = OpencgaManager.files.downloadExample({
            query: {
                toolName: toolName,
                fileName: fileName
            },
            request: {
                url: true
            }
        });
        var link = document.createElement('a');
        link.href = url;
        //link.setAttribute("download", "download.zip");
        var event = new MouseEvent('click', {
            'view': window,
            'bubbles': true,
            'cancelable': true
        });
        link.dispatchEvent(event);
    },
    argsParser: function (form, args) {
        if (form.toolName == args.tool) {
            for (var key in args) {
                if (typeof(args[key]) == "object") {
                    if (form.$[key] !== undefined)
                        form.$[key].selectedFile = args[key];
                }
                else {
                    var elems = form.shadowRoot.querySelectorAll('input[name="' + key + '"]');
                    if (form.$[key] !== undefined) {
                        switch (form.$[key].type) {
                            case "checkbox":
                                form.$[key].checked = args[key];
                            default:
                                form.$[key].value = args[key];
                        }
                    }
                    for (var i = 0; i < elems.length; i++) {
                        var elem = elems[i];
                        if (elem.value == args[key])
                            elem.checked = true;
                    }

                }
            }
        }
    },
    getLinks: function (terms) {
        var links = [];
        for (var i = 0; i < terms.length; i++) {
            var term = terms[i];
            links.push(Utils.getLink(term));
        }
        return links;
    },
    getLink: function (term) {
        var link = "http://www.ebi.ac.uk/QuickGO/GTerm?id=";
        if (term.indexOf("(") >= 0) {
            var id = term.split("(");
            if (id.length > 1)
                id = id[1];
            id = id.split(")")[0];

        }
        else
            id = term;
        if (id.indexOf("IPR") == 0)
            link = "http://www.ebi.ac.uk/interpro/entry/";
        link = link + id;
        return link;
    },
    myRound: function (value, decimals) {
        decimals = typeof decimals !== 'undefined' ? decimals : 2;
        value = parseFloat(value);
        /** rounding **/
        if (Math.abs(value) >= 1)
            value = value.toFixed(decimals);
        else
            value = value.toPrecision(decimals);
        value = parseFloat(value);
        return value;
    },
    formatNumber: function (value, decimals) {
        value = Utils.myRound(value, decimals);

        if (Math.abs(value) > 0 && Math.abs(value) < 0.001)
            value = value.toExponential();
        return value;
    },
    getSpecies: function (specieValue, species) {
        for (var i = 0; i < species.length; i++) {
            var specie = species[i];
            if (specie.value == specieValue) {
                return specie;
            }
        }
        return null;
    },
    test: function () {
        return this;
    },
    cancelFullscreen: function () {
        if (document.cancelFullScreen) {
            document.cancelFullScreen();
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        } else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen();
        }
    },
    launchFullScreen: function (element) {
        if (element.requestFullScreen) {
            element.requestFullScreen();
        } else if (element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
        } else if (element.webkitRequestFullScreen) {
            element.webkitRequestFullScreen();
        }
    },
    parseJobCommand: function (item) {
        var commandObject = {};
        var commandArray = item.commandLine.split(/ -{1,2}/g);
        var tableHtml = '<table cellspacing="0" style="max-width:400px;border-collapse: collapse;border:1px solid #ccc;"><tbody>';
        tableHtml += '<tr style="border-collapse: collapse;border:1px solid #ccc;font-weight:bold;">';
        tableHtml += '<td style="min-width:50px;border-collapse: collapse;border:1px solid #ccc;padding: 5px;background-color: whiteSmoke;">Parameter</td>';
        tableHtml += '<td style="border-collapse: collapse;border:1px solid #ccc;padding: 5px;background-color: whiteSmoke;">Value</td>';
        tableHtml += '</tr>';
        for (var i = 1; i < commandArray.length; i++) {
            //ignore first argument
            var paramenter = commandArray[i];
            var paramenterArray = paramenter.split(/ {1}/g);
            var name = '';
            var value = '';
            if (paramenterArray.length < 2) {
                name = paramenterArray[0];
                value = '<span color:darkgray;font-weight:bold;>This paramenter is a flag</span>';
            } else {
                name = paramenterArray[0];
                value = paramenterArray[1];
            }
            commandObject[name] = value;
            /* clean values for viz*/
            value = value.replace(/\/httpd\/bioinfo\/opencga\/analysis\/.+\/examples\//, '');
            value = value.replace('/httpd/bioinfo/opencga/accounts/', '');
            value = value.replace(/,/g, ", ");

            tableHtml += '<tr style="border-collapse: collapse;border:1px solid #ccc;">';
            tableHtml += '<td style="border-collapse: collapse;border:1px solid #ccc;padding: 5px;background-color: whiteSmoke;color:steelblue;font-weight:bold;white-space: nowrap;">' + name + '</td>';
            tableHtml += '<td style="border-collapse: collapse;border:1px solid #ccc;padding: 5px;background-color: whiteSmoke;">' + value + '</td>';
            tableHtml += '</tr>';
        }
        tableHtml += '</tbody></table>';
        return {html: tableHtml, data: commandObject};
    },
    htmlTable: function (object) {
        var tableHtml = '';
        tableHtml += '<table cellspacing="0" style="border-collapse: collapse;border:1px solid #ccc;"><tbody>';
        for (var key in object) {
            tableHtml += '<tr style="border-collapse: collapse;border:1px solid #ccc;">';
            tableHtml += '<td style="border-collapse: collapse;border:1px solid #ccc;padding: 5px;background-color: whiteSmoke;color:steelblue;font-weight:bold;white-space: nowrap;">' + key + '</td>';
            tableHtml += '<td style="border-collapse: collapse;border:1px solid #ccc;padding: 5px;background-color: whiteSmoke;">' + object[key] + '</td>';
            tableHtml += '</tr>';
        }
        tableHtml += '</tbody></table>';
        return tableHtml;
    },
    camelCase: function (input) {
        return input.toLowerCase().replace(/[.-_\s](.)/g, function (match, group1) {
            return group1.toUpperCase();
        })
    },
    msg: function (title, msg) {
        var div = $('<div class="ocb-msg-hidden"><div>' + title + '</div><div>' + msg + '</div></div>')[0];
        $('body').append(div);
        setTimeout(function () {
            $(div).addClass('ocb-msg-shown');
        }, 10);
        setTimeout(function () {
            $(div).removeClass('ocb-msg-shown');
        }, 2000);
        setTimeout(function () {
            $(div).remove();
        }, 2200);
    },
    repeat: function (string, count) {
        'use strict';
        if (string == null) {
            throw new TypeError('can\'t convert ' + string + ' to object');
        }
        var str = '' + string;
        count = +count;
        if (count != count) {
            count = 0;
        }
        if (count < 0) {
            throw new RangeError('repeat count must be non-negative');
        }
        if (count == Infinity) {
            throw new RangeError('repeat count must be less than infinity');
        }
        count = Math.floor(count);
        if (str.length == 0 || count == 0) {
            return '';
        }
        // Ensuring count is a 31-bit integer allows us to heavily optimize the
        // main part. But anyway, most current (august 2014) browsers can't handle
        // strings 1 << 28 chars or longer, so:
        if (str.length * count >= 1 << 28) {
            throw new RangeError('repeat count must not overflow maximum string size');
        }
        var rpt = '';
        for (; ;) {
            if ((count & 1) == 1) {
                rpt += str;
            }
            count >>>= 1;
            if (count == 0) {
                break;
            }
            str += str;
        }
        return rpt;

    },
    clone: function (obj) {
        return JSON.parse(JSON.stringify(obj));
    }

};


Utils.images = {
    add: "data:image/gif;base64,R0lGODlhEAAQAIcAAD2GNUKNNkOPOESMO0WNPEmPP0iNQUmPQlOVTFWWTVCZQVeeRV6cVmGeWGSgVWSgV2aiWGejW2WrVWirU2uqWGqsW2yqWm61WG+1WG+1WXS3W3S3XHC4WXK5W3O6XHG+X3asZ3iuaHe8YHi0ZH+yany6ZH28Zn2+Z3m9bn25an25a3+5bUD/QHDBY3nBZHrGa3zDa37BaX7Hb4K1boO1boa3cYi4d4y7doq5eYm+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5h+CL958/nxj1XivVF+e6C9TVhPmFdbROgEhwNU1d4m09UaJuInLjhct3DgDUh5ee7j14PLxulLvYP/0seadPkub88Wib0eB3bDkmxgbRoFPpxeCuKvjsyQIzOyqImT7/y8Mh++NveW7jLFmrx6m1NlWxz6PHA7otQ7tloAmYJE9isOeeCJRtIrULLLUTjsqG7+//xs72z7jZgCTNONlVJKEiuobW0jqSaoiet19dFQATJcc2FSFEciNoLYwOHcPDASvdjM5cQntxlbR9gqacoFSK84VsnOrkH11Zdmp0FFXjobSeCFgXSDS0Eo11ge7yGXSaU092UUlCaEpC8FK4tDcu4rzZ2a/S+bWI94HSAgFigDQD24Cvp4gIOp0juBJvC2L07B1Uc/Mtg9k7sHMbywZrA3lLECV4AtaCpAp79CcmzXHlhOBrAJrGyNbOVBY7qTO1C9r5EKyPSttAiJEs01SuQStFkrdp6gKd5AzHjixVxCDxp+1paZRUxoc4Kp36bndYbS53U5WlCq0CMYIPMY7GI0mNpiqmGK0oK4jIveGkPgRqfTBt3A8Pqtvrq52HtglnGh9XIaKUkCQ6nj6RyWBsmdXCtFI/bu2Fq5c+3roGzIAgWokCDNACOhfOLb781Ip+vd+RC2dXWibROkxKvvp1z376yZe7d4HpMdz8/YVjiQYyoA30Ti6la2++0n/n83vTW/e3ix1gcgzXgPchBoC/AFu/UBF5InryAAAAAElFTkSuQmCC",
    bluebox: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wMHAwTE5pcivoAAALsSURBVDjLXZPPaxxlGMc/77wz+3N2k822tWsTIrQFe/BWEKxKCV5UohdFhJ60p6rgUfpP6C0K4kHx0ENEkV7aElHwUikhFVosRGoTm83+3pnZnXfed2beHtItIQ98+Z6+H57nga8AsNYKDkYcEofcHvKZEEJYcSTszPzqL3fmf3+w/+a51tytby9d6D0N5U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meBFhWBU5oUgpZikrSnzZ9v3nW/ndKEbziXUAwfOOe/7Puc9z/MCq1DwMmB1NX/rzfCNnsc/gK08lPgnnT8Cs33BULg0HI4YKdkHX9DqKwKArXXv1bTMTFcoyruC89E8MxaDw659t6rKhIUwRBLdP2t2v/5bBwQA+5pH8ibnIj3BucgWIQRASw8RERTGYFUtsGmWYUXKmqmr7t4UAnal54GQ8lq8MBlyOU0CEnA67MiwqfvHbhZ+Smgg6o9eV2L8Nhk6wI2lZeggrpvE+TTjxgxxQ4IbmJsJYSa00JQiotnguacJ8zIZOmDosAnzTpowt8tGj0s0ejZqprnDKmPHSNebjHDkUPatt4cTTbZ+LsmO79XK52dZxTNp9/ovAEDnaM62lo8HHrd9SVfiOelVryrSq9vrEx0s8sW2tuEzDgDgT875bcIsjy6owwAwHhjnYT5bGTL29PiHyuwAMO873aL/Ct5PiPjwXe5vq7KJW2hdJxENMFInGCkhIblLj80WRoyxGxZmh1XJGlSIlV8s6A8kuVDXn+MF6JHC7GBkBSNlOSRgiihMsQhAgJGGNNU1atc2HPG6O8YSBABwt2/nGyFlGSCSB4UIBMuyoQKMFNiUjIApRH5t8YfpFOOrO/JrhZBVUiJLxq2ipIkY8Z36uivpC6txqb3YbhqhIingFlLmxmLSKyXAGAaYqh13aFjfcHJwfE2ClSitK9psc85PMVC3M999orX4Kcf/wuPb27VW7A+O2QVVA1M1CQAAAABJRU5ErkJggg==",
    newitem: "data:image/png;base64,[encoded data, 4676 characters]"
};


Utils.genBamVariants = function (seq, size, x, y) {
    var length = seq.length;
    var s = size / 6;
    //if(x==null){x=0;}
    //if(y==null){y=0;}
    var d = "";
    for (var i = 0; i < length; i++) {
        switch (seq.charAt(i)) {
            case "A" :
                d += "M" + ((2.5 * s) + x) + "," + (y) +
                "l-" + (2.5 * s) + "," + (6 * s) +
                "l" + s + ",0" +
                "l" + (0.875 * s) + ",-" + (2 * s) +
                "l" + (2.250 * s) + ",0" +
                "l" + (0.875 * s) + "," + (2 * s) +
                "l" + s + ",0" +
                "l-" + (2.5 * s) + ",-" + (6 * s) +
                "l-" + (0.5 * s) + ",0" +
                "l0," + s +
                "l" + (0.75 * s) + "," + (2 * s) +
                "l-" + (1.5 * s) + ",0" +
                "l" + (0.75 * s) + ",-" + (2 * s) +
                "l0,-" + s +
                " ";
                break;
            case "T" :
                d += "M" + ((0.5 * s) + x) + "," + (y) +
                "l0," + s +
                "l" + (2 * s) + ",0" +
                "l0," + (5 * s) +
                "l" + s + ",0" +
                "l0,-" + (5 * s) +
                "l" + (2 * s) + ",0" +
                "l0,-" + s +
                " ";
                break;
            case "C" :
                d += "M" + ((5 * s) + x) + "," + ((0 * s) + y) +
                "l-" + (2 * s) + ",0" +
                "l-" + (1.5 * s) + "," + (0.5 * s) +
                "l-" + (0.5 * s) + "," + (1.5 * s) +
                "l0," + (2 * s) +
                "l" + (0.5 * s) + "," + (1.5 * s) +
                "l" + (1.5 * s) + "," + (0.5 * s) +
                "l" + (2 * s) + ",0" +
                "l0,-" + s +
                "l-" + (2 * s) + ",0" +
                "l-" + (0.75 * s) + ",-" + (0.25 * s) +
                "l-" + (0.25 * s) + ",-" + (0.75 * s) +
                "l0,-" + (2 * s) +
                "l" + (0.25 * s) + ",-" + (0.75 * s) +
                "l" + (0.75 * s) + ",-" + (0.25 * s) +
                "l" + (2 * s) + ",0" +
                " ";
                break;
            case "G" :
                d += "M" + ((5 * s) + x) + "," + ((0 * s) + y) +
                "l-" + (2 * s) + ",0" +
                "l-" + (1.5 * s) + "," + (0.5 * s) +
                "l-" + (0.5 * s) + "," + (1.5 * s) +
                "l0," + (2 * s) +
                "l" + (0.5 * s) + "," + (1.5 * s) +
                "l" + (1.5 * s) + "," + (0.5 * s) +
                "l" + (2 * s) + ",0" +
                "l0,-" + (3 * s) +
                "l-" + (s) + ",0" +
                "l0," + (2 * s) +
                "l-" + (s) + ",0" +
                "l-" + (0.75 * s) + ",-" + (0.25 * s) +
                "l-" + (0.25 * s) + ",-" + (0.75 * s) +
                "l0,-" + (2 * s) +
                "l" + (0.25 * s) + ",-" + (0.75 * s) +
                "l" + (0.75 * s) + ",-" + (0.25 * s) +
                "l" + (2 * s) + ",0" +
                " ";
//                d += "M" + ((5 * s) + x) + "," + ((0 * s) + y) +
//                    "l-" + (2 * s) + ",0" +
//                    "l-" + (2 * s) + "," + (2 * s) +
//                    "l0," + (2 * s) +
//                    "l" + (2 * s) + "," + (2 * s) +
//                    "l" + (2 * s) + ",0" +
//                    "l0,-" + (3 * s) +
//                    "l-" + (1 * s) + ",0" +
//                    "l0," + (2 * s) +
//                    "l-" + (0.5 * s) + ",0" +
//                    "l-" + (1.5 * s) + ",-" + (1.5 * s) +
//                    "l0,-" + (1 * s) +
//                    "l" + (1.5 * s) + ",-" + (1.5 * s) +
//                    "l" + (1.5 * s) + ",0" +
//                    " ";
                break;
            case "N" :
                d += "M" + ((0.5 * s) + x) + "," + ((0 * s) + y) +
                "l0," + (6 * s) +
                "l" + s + ",0" +
                "l0,-" + (4.5 * s) +
                "l" + (3 * s) + "," + (4.5 * s) +
                "l" + s + ",0" +
                "l0,-" + (6 * s) +
                "l-" + s + ",0" +
                "l0," + (4.5 * s) +
                "l-" + (3 * s) + ",-" + (4.5 * s) +
                " ";
                break;
            case "d" :
                d += "M" + ((0 * s) + x) + "," + ((2.5 * s) + y) +
                "l" + (6 * s) + ",0" +
                "l0," + (s) +
                "l-" + (6 * s) + ",0" +
                "l0,-" + (s) +
                " ";
                break;
            default:
                d += "M0,0";
                break;
        }
        x += size;
    }
    return d;
};
