window.onload = functionList; function functionList() { sortList(); jobInfo(); } var sortwhichway=1; function compare_rows(column,type) { return function compare(row1, row2) { var value1=""; var value2=""; if (type=='0') { value1 = row1.cells[column].lastChild.nodeValue; if (value1 == null) value1=row1.cells[column].innerHTML; if (value1.substring(0,4)=="user") { value1=parseInt(value1.substring(4)); if (isNaN(value1)) value1=-1000000; } value2 = row2.cells[column].lastChild.nodeValue; if (value2 == null) value2=row2.cells[column].innerHTML; if (value2.substring(0,4)=="user") { value2=parseInt(value2.substring(4)); if (isNaN(value2)) value2=-1000000; } } else { value1 = parseInt(row1.cells[column].lastChild.nodeValue); value2 = parseInt(row2.cells[column].lastChild.nodeValue); if (isNaN(value1)) value1=-1000000; if (isNaN(value2)) value2=-1000000; } if (value1 < value2) return 1*sortwhichway; else if (value1 > value2) return -1*sortwhichway; else return 0; }; } function compare_rows2(column,type) { return function compare(row1, row2) { var value1=""; var value2=""; if (type=='0') { value1 = row1.cells[column].innerHTML; value2 = row2.cells[column].innerHTML; } else { value1 = parseInt(row1.cells[column].lastChild.nodeValue); value2 = parseInt(row2.cells[column].lastChild.nodeValue); if (isNaN(value1)) value1=-1000000; if (isNaN(value2)) value2=-1000000; } if (value1 < value2) return 1*sortwhichway; else if (value1 > value2) return -1*sortwhichway; else return 0; }; } function sort_table(table_id, column, temptype, keeplastrow) { // if type is 1, column will get sorted in integer ascending order var type=temptype; if (type==undefined) { type='0'; } sortwhichway=sortwhichway*-1; var tabletosort = document.getElementById(table_id); var domrows = tabletosort.getElementsByTagName("tr"); var newtablerows = []; var newtableparent = tabletosort.parentNode; for (var i=0; i < domrows.length; i++) newtablerows[i] = domrows[i]; var header_row = newtablerows.shift(); // footer? var table_foot = document.createElement("tfoot"); if (keeplastrow=='1') { var last_row=newtablerows.pop(); table_foot.appendChild(last_row); } var num_rows = newtablerows.length; newtablerows.sort(compare_rows(column,type)); var new_table = document.createElement("table"); var table_head=document.createElement("thead"); table_head.appendChild(header_row); var table_body = document.createElement("tbody"); for (var i=0; i < num_rows; i++) table_body.appendChild(newtablerows[i]); var even=false; for (var i=0; i< num_rows; i++) { var row=newtablerows[i]; if (even) row.className="tablerow1"; else row.className="tablerow2"; even=!even; } new_table.appendChild(table_head); new_table.appendChild(table_body); new_table.appendChild(table_foot); new_table.setAttribute("id", table_id); new_table.setAttribute("class", tabletosort.getAttribute("class")); new_table.setAttribute("border", tabletosort.getAttribute("border")); new_table.setAttribute("bordercolor", tabletosort.getAttribute("bordercolor")); new_table.setAttribute("cellpadding", tabletosort.getAttribute("cellpadding")); newtableparent.replaceChild(new_table, tabletosort); } function sort_table2(table_id, column, temptype, temphighlight, tempaltsort) { // if type is 1, column will get sorted in integer ascending order var type=temptype if (type==undefined) { type='0'; } var highlight=temphighlight; if (highlight==undefined) { highlight='0'; } var altsort=tempaltsort; if (altsort==undefined) { altsort='0'; } sortwhichway=sortwhichway*-1; var tabletosort = document.getElementById(table_id); var domrows; var thead, tbody, tfoot; var heads, bodies, feet; heads=tabletosort.getElementsByTagName("thead"); bodies=tabletosort.getElementsByTagName("tbody"); feet=tabletosort.getElementsByTagName("tfoot"); if (heads.length>0) thead=heads[0] else thead=document.createElement("thead"); if (bodies.length>0) tbody=bodies[0] else tbody=document.createElement("tbody"); if (feet.length>0) tfoot=feet[0] else tfoot=document.createElement("tfoot"); domrows = tbody.getElementsByTagName("tr"); var newtablerows = []; var newtableparent = tabletosort.parentNode; for (var i=0; i < domrows.length; i++) newtablerows[i] = domrows[i]; var num_rows = newtablerows.length; if (altsort=='0') newtablerows.sort(compare_rows(column,type)); else newtablerows.sort(compare_rows2(column,type)); var new_table = document.createElement("table"); new_table.setAttribute("cellspacing", "0"); var table_body = document.createElement("tbody"); for (var i=0; i < num_rows; i++) table_body.appendChild(newtablerows[i]); var even=false; if (highlight=='0') { for (var i=0; i< num_rows; i++) { var row=newtablerows[i]; if (even) row.className="tablerow1"; else row.className="tablerow2"; even=!even; } } table_body.setAttribute("style", tbody.getAttribute("style")); table_body.setAttribute("class", tbody.getAttribute("class")); table_body.setAttribute("id", tbody.getAttribute("id")); new_table.appendChild(thead); new_table.appendChild(tfoot); new_table.appendChild(table_body); new_table.setAttribute("id", table_id); new_table.setAttribute("class", tabletosort.getAttribute("class")); new_table.setAttribute("style", tabletosort.getAttribute("style")); newtableparent.replaceChild(new_table, tabletosort); } function sortList() { // Sort Vacancies Page -- Need to allow script to be global. var jobTitle = document.getElementById('jobTitle'); var categoryList = document.getElementById('category'); jobTitle.onclick = sortByTitle; categoryList.onclick = sortByCategory; function sortByTitle() { sort_table2('list','2','0','0','1'); } function sortByCategory() { sort_table2('list','1','0','0','1'); } sortByTitle(); } function jobInfo() { var listId = document.getElementById('list'); var listTh = listId.getElementsByTagName('th'); var listTd = listId.getElementsByTagName('td'); var listTdDiv; var listTdA; //Set Arrow BGs on th if js enabled for (i=0;i