function binSearch(element, array, start, end) { if (array.length === 0) return 0; start = start || 0; end = end || array.length; var pivot = (start + end) >> 1; if (end - start <= 1) { if (element < array[pivot]) { return pivot; } else { return pivot + 1; } } if (element < array[pivot]) { return binSearch(element, array, start, pivot); } else if (element > array[pivot]) { return binSearch(element, array, pivot, end); } else { return pivot; } } function extractErrorMessage(e) { if (e.data.indexOf("ERROR:") == 0) { return e.data.substring(6, e.data.length); } else { return "An Unexpected Error Occured."; } } function setCookie(cname, cvalue, exdate) { var expires = "expires=" + exdate.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;"; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function padStart(num, size) { var s = num + ""; while (s.length < size) s = "0" + s; return s; } function exportCSV(csv, filename) { var csvToExport = "\ufeff" + csv; //Prefix csv with UTF-8 BOM to allow encoding to be detected var myNav = navigator.userAgent.toLowerCase(); var isIE = (myNav.indexOf('msie') !== -1) ? parseInt(myNav.split('msie')[1]) : false; if (isIE && isIE < 10) { //Internet Explorer 9 and lower var IEwindow = window.open(); IEwindow.document.write(csvToExport); IEwindow.document.close(); IEwindow.document.execCommand('SaveAs', true, filename); IEwindow.close(); } else { blob = new Blob([csvToExport], { type: 'text/csv' }); if (window.navigator && window.navigator.msSaveOrOpenBlob) { //Internet Explorer window.navigator.msSaveOrOpenBlob(blob, filename); } else { //Other browsers var link = document.createElement("a"); link.id = "lnkDwnldLnk"; document.body.appendChild(link); var csvUrl = window.URL.createObjectURL(blob); $("#lnkDwnldLnk") .attr({ 'download': filename, 'href': csvUrl }); $('#lnkDwnldLnk')[0].click(); document.body.removeChild(link); } } }