var hasChart = false; var hasDelayedQuote = false; var tableData; function checkData(cb) { if (tableData.length <= 0){ if(hasChart == false){ document.getElementById("dataDiv").innerHTML = "
No data available"; } else { document.getElementById("dataDiv").style.display = "none"; } } else { document.getElementById("dataDiv").style.display = "block"; } } function getTable() { var syms = document.getElementById("peersSelect").value; var cb = new ContentBuffer(); cb.load({ url: "resources/asp/getBufferedPeers.asp?syms=" + syms, debug: true, onload: checkData }); } function updateTable(sort, sortDir) { tableData = j1; if (sort){ tableData = qsort(tableData, "raw_"+sort); } else { tableData = qsort(tableData, "raw_name"); for(i = 0; i < tableData.length; i++) { if(tableData[i].raw_ticker == symbol) { var temp = tableData[i]; tableData.splice(i, 1); tableData.splice(0,0,temp); break; } } sort = "name"; } if (sortDir == "d"){ tableData = tableData.reverse(); } else { sortDir = "a"; } var table = document.createElement("table"); var thead = document.createElement("thead"); var tbody = document.createElement("tbody"); var tr = document.createElement("tr"); var td; var th; var i, x, y, prop, img; var heads = new Array(); heads.push({id: "name", label: "Company Name/Symbol", align: "left"}); heads.push({id: "recommend", label: "Current Consensus
Recommendation", align: "left"}); heads.push({id: "price", label: "Price", align: "right"}); heads.push({id: "curChange", label: "Today's Change", align: "right", span: 2}); heads.push({id: "cap", label: "Market
Cap", align: "right"}); heads.push({id: "pe", label: "P/E", align: "right"}); heads.push({id: "growth", label: "5 Yr EPS
Growth", align: "right"}); var cols = new Array(); cols.push({id: "name", align: "left"}); cols.push({id: "recommend", align: "left"}); cols.push({id: "price", align: "right"}); cols.push({id: "curChange", align: "right"}); cols.push({id: "pctChange", align: "right"}); cols.push({id: "cap", align: "right"}); cols.push({id: "pe", align: "right"}); cols.push({id: "growth", align: "right"}); //table head for(i = 0; i < heads.length; i++) { th = document.createElement("th"); if(sort == heads[i].id){ img = (sortDir=="d"?" ":" "); } else{ img = ""; } th.innerHTML = '
'+heads[i].label + '
'+ img + '
'; if(heads[i].align){ th.align = heads[i].align; } if(heads[i].span){ th.colSpan = heads[i].span; } th.vAlign = "bottom"; th.className = "smblk solid"; tr.appendChild(th); } thead.appendChild(tr); //look at all the rows i can put out for(i = 0; i < tableData.length; i++) { tr = document.createElement("tr"); if(tableData[i].raw_ticker == symbol){ tr.className = " hiliteRow"; } else{ tr.className = (i%2?"oddRow":"evenRow"); } for(x = 0; x < cols.length; x++) { td = document.createElement("td"); if(cols[x].align){ td.align = cols[x].align; } if(cols[x].id == "name") { td.innerHTML = tableData[i]["name"].substring(0, 28) + " "; if(hasDelayedQuote){ td.innerHTML += '' + tableData[i]["ticker"] + ''; } else{ td.innerHTML += tableData[i]["ticker"]; } } else if(cols[x].id == "recommend"){ td.innerHTML = getRecommendGraphic(tableData[i]["recommend"]); } else{ td.innerHTML = tableData[i][cols[x].id]; } if(hasChart && cols[x].id == "name"){ td.innerHTML = getCheckBox(tableData[i]["ticker"]) + " " + td.innerHTML; } if(sort == cols[x].id && tableData[i].raw_ticker == symbol){ td.className = " hiliteRowSort"; } else if(sort == "curChange" && tableData[i].raw_ticker == symbol && cols[x].id == "pctChange"){ td.className = " hiliteRowSort"; } else if(sort == cols[x].id){ td.className = (i%2?"oddRowSort":"evenRowSort"); } else if(sort == "curChange" && cols[x].id == "pctChange"){ td.className = (i%2?"oddRowSort":"evenRowSort"); } tr.appendChild(td); } tbody.appendChild(tr); } table.cellSpacing = "0"; table.cellPadding = "0"; table.id = "searchResults"; table.appendChild(thead); table.appendChild(tbody); if(document.getElementById("peerPerformanceTable").firstChild) { document.getElementById("peerPerformanceTable").removeChild(document.getElementById("peerPerformanceTable").firstChild); } document.getElementById("peerPerformanceTable").appendChild(table); } function output(d) { var t = ""; for(var x = 0; x < d.length; x++) { for(var i in d[x]) { t += i + ": " + d[x][i] + "\n"; } } return t; } //sorts like a mighty pirate of yore //...with one good leg function qsort(argh, field) { var l = new Array(); var e = new Array(); var g = new Array(); if(argh.length <= 1){ return argh; } else { var pivot = argh[Math.floor(argh.length/2)][field]; for(var i = 0; i < argh.length; i++) { if(argh[i][field] < pivot){ l.push(argh[i]); } else if(argh[i][field] == pivot){ e.push(argh[i]); } else{ g.push(argh[i]); } } return qsort(l, field).concat(e).concat(qsort(g, field)); } } function getCheckBox(sym) { sym = sym.toLowerCase(); var ta = arr.concat(arr2); var checked = false; for(var x = 0; x < ta.length; x++) { if(ta[x].toLowerCase() == sym){ checked = true; break; } } if(sym == symbol.toLowerCase()){ var temp = 'disabled="true" checked="true"'; } else{ var temp = 'onclick="upChart(this, \''+sym+'\');"'; } if(checked){ temp += ' checked="true"'; } return ''; } function upChart(box, sym) { if(!hasChart){ return; } if(box.checked) { if(arr2.length >= 4) { box.checked = false; return; } arr2.push(sym.toLowerCase()); } else { for(var x = 0; x < arr2.length; x++) { if(arr2[x] == sym.toLowerCase()){ arr2.splice(x,1); } } } loadChart(); } function getRecommendGraphic(t) { if(typeof(t) == "undefined"){ t = "none"; } return ''+t+''; }