/*-----------------*/
//http://javascript.about.com/library/blsort3.htm
var dateRE = /^(\d{2})[\/\- ](\d{2})[\/\- ](\d{4})/;
function dmyOrdA(a, b){
a = a.replace(dateRE,"$3$2$1");
b = b.replace(dateRE,"$3$2$1");
if (a>b) return 1;
if (a <b) return -1;
return 0; }
function dmyOrdD(a, b){
a = a.replace(dateRE,"$3$2$1");
b = b.replace(dateRE,"$3$2$1");
if (a>b) return -1;
if (a <b) return 1;
return 0; }
function mdyOrdA(a, b){
a = a.replace(dateRE,"$3$1$2");
b = b.replace(dateRE,"$3$1$2");
if (a>b) return 1;
if (a <b) return -1;
return 0; }
function mdyOrdD(a, b){
a = a.replace(dateRE,"$3$1$2");
b = b.replace(dateRE,"$3$1$2");
if (a>b) return -1;
if (a <b) return 1;
return 0; } 
/*-----------------*/

window.onload = Firend;
function Firend(){
 if (document.tell != null) {
  if (document.tell.submit.value = "Tell A Firend") {
	document.tell.submit.value = "Tell A Friend";	
  }
 }
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function sortTable(id, col, rev) {

if (col == 4) {
	dateFixerALL(id);
}
	
  // Get the table or table section to sort.
  var tblEl = document.getElementById(id);

  // The first time this function is called for a given table, set up an
  // array of reverse sort flags.
  if (tblEl.reverseSort == null) {
    tblEl.reverseSort = new Array();
    // Also, assume the team name column is initially sorted.
    tblEl.lastColumn = 1;
  }

  // If this column has not been sorted before, set the initial sort direction.
  if (tblEl.reverseSort[col] == null)
    tblEl.reverseSort[col] = rev;

  // If this column was the last one sorted, reverse its sort direction.
  if (col == tblEl.lastColumn)
    tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  // Remember this column as the last one sorted.
  tblEl.lastColumn = col;

  // Set the table display style to "none" - necessary for Netscape 6 
  // browsers.
  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";

  // Sort the rows based on the content of the specified column using a
  // selection sort.

//if (col == 3) { alert("3");}

  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;

  for (i = 0; i < tblEl.rows.length - 1; i++) {

    // Assume the current row has the minimum value.
    minIdx = i;
    minVal = getTextValue(tblEl.rows[i].cells[col]);
//	minVal = minVal.replace("/","")
	

    // Search the rows that follow the current one for a smaller value.
    for (j = i + 1; j < tblEl.rows.length; j++) {
      testVal = getTextValue(tblEl.rows[j].cells[col]);
      cmp = compareValues(minVal, testVal);
      // Negate the comparison result if the reverse sort flag is set.
      if (tblEl.reverseSort[col])
        cmp = -cmp;
      // Sort by the second column (team name) if those values are equal.
      if (cmp == 0 && col != 1)
        cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                            getTextValue(tblEl.rows[j].cells[1]));
      // If this row has a smaller value than the current minimum, remember its
      // position and update the current minimum value.
      if (cmp > 0) {
        minIdx = j;
        minVal = testVal;
      }
    }

    // By now, we have the row with the smallest value. Remove it from the
    // table and insert it before the current row.
    if (minIdx > i) {
      tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
      tblEl.insertBefore(tmpEl, tblEl.rows[i]);
    }
  }

  //dateReFixer('offTblBdy');
  
  // Make it look pretty.
  makePretty(tblEl, col);

  // Set team rankings.
  //setRanks(tblEl, col, rev);

  // Restore the table's display style.
  tblEl.style.display = oldDsply;

  	if (col == 4) {
	  dateReFixerALL('offTblBdy');
	}

  return false;
}
//-----------------------------------------------------------------------------
function sortTableSTART(id, col, rev) {
  var tblEl = document.getElementById(id);
  if (tblEl.reverseSort == null) {
    tblEl.reverseSort = new Array();
    tblEl.lastColumn = 1;
  }

  if (tblEl.reverseSort[col] == null)
    tblEl.reverseSort[col] = rev;

  if (col == tblEl.lastColumn)
    tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  tblEl.lastColumn = col;
  
  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";
  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;
  for (i = 0; i < tblEl.rows.length - 1; i++) {
    minIdx = i;
    minVal = getTextValue(tblEl.rows[i].cells[col]);	
    for (j = i + 1; j < tblEl.rows.length; j++) {
      testVal = getTextValue(tblEl.rows[j].cells[col]);
      cmp = compareValues(minVal, testVal);
      if (tblEl.reverseSort[col])
        cmp = -cmp;
      if (cmp == 0 && col != 1)
        cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                            getTextValue(tblEl.rows[j].cells[1]));
      if (cmp > 0) {
        minIdx = j;
        minVal = testVal;
      }
    }
    if (minIdx > i) {
      tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
      tblEl.insertBefore(tmpEl, tblEl.rows[i]);
    }
  }
  makePretty(tblEl, col);
  //setRanks(tblEl, col, rev);
  dateReFixerEnd('offTblBdy');
  tblEl.style.display = oldDsply;
  return false;	
}
//-----------------------------------------------------------------------------
function sortTable10(id, col, rev) {
dateFixer(id);
  var tblEl = document.getElementById(id);
  if (tblEl.reverseSort == null) {
    tblEl.reverseSort = new Array();
    tblEl.lastColumn = 1;
  }

  if (tblEl.reverseSort[col] == null)
    tblEl.reverseSort[col] = rev;


  if (col == tblEl.lastColumn)
    tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  tblEl.lastColumn = col;

  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";

  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;

  for (i = 0; i < tblEl.rows.length - 1; i++) {

    minIdx = i;
    minVal = getTextValue(tblEl.rows[i].cells[col]);

    for (j = i + 1; j < tblEl.rows.length; j++) {
      testVal = getTextValue(tblEl.rows[j].cells[col]);
      cmp = compareValues(minVal, testVal);

      // Negate the comparison result if the reverse sort flag is set.
      if (tblEl.reverseSort[col])
        cmp = -cmp;

      if (cmp == 0 && col != 1)
        cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                            getTextValue(tblEl.rows[j].cells[1]));

      if (cmp > 0) {
        minIdx = j;
        minVal = testVal;
      }
    }

    if (minIdx > i) {
      tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
      tblEl.insertBefore(tmpEl, tblEl.rows[i]);
    }
  }

  tblEl.style.display = oldDsply;
  
  if (tblEl.rows.length > 15) {
   for (i = 15; i < tblEl.rows.length; i++) {
	  tblEl.rows[i].style.display = "none";
   }
  }
  
  fixLinks('offTblBdy');

  return false;
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Functions to get and compare values during a sort.
//-----------------------------------------------------------------------------

// This code is necessary for browsers that don't reflect the DOM constants
// (like IE).
if (document.ELEMENT_NODE == null) {
  document.ELEMENT_NODE = 1;
  document.TEXT_NODE = 3;
}

function getTextValue(el) {

  var i;
  var s;

  // Find and concatenate the values of all text nodes contained within the
  // element.
  s = "";
  for (i = 0; i < el.childNodes.length; i++)
    if (el.childNodes[i].nodeType == document.TEXT_NODE)
      s += el.childNodes[i].nodeValue;
    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
             el.childNodes[i].tagName == "BR")
      s += " ";
    else
      // Use recursion to get text within sub-elements.
      s += getTextValue(el.childNodes[i]);

  return normalizeString(s);
}

function compareValues(v1, v2) {

  var f1, f2;

  // If the values are numeric, convert them to floats.
  v1 = v1.replace("/","");
  v2 = v2.replace("/","");

  f1 = parseFloat(v1);
  f2 = parseFloat(v2);
  if (!isNaN(f1) && !isNaN(f2)) {
    v1 = f1;
    v2 = f2;
  }

  // Compare the two values.
  if (v1 == v2)
    return 0;
  if (v1 > v2)
    return 1
  return -1;
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s) {

  s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
  s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space.
  s = s.replace("$","");

  return s;
}

//-----------------------------------------------------------------------------
// Functions to update the table appearance after a sort.
//-----------------------------------------------------------------------------

// Style class names.
var rowClsNm = "alternateRow";
var colClsNm = "sortedColumn";

// Regular expressions for setting class names.
var rowTest = new RegExp(rowClsNm, "gi");
var colTest = new RegExp(colClsNm, "gi");

function makePretty(tblEl, col) {

  var i, j;
  var rowEl, cellEl;

  // Set style classes on each row to alternate their appearance.
  for (i = 0; i < tblEl.rows.length; i++) {
   rowEl = tblEl.rows[i];
   rowEl.className = rowEl.className.replace(rowTest, "");
    if (i % 2 != 0)
      rowEl.className += " " + rowClsNm;
    rowEl.className = normalizeString(rowEl.className);
    // Set style classes on each column (other than the name column) to
    // highlight the one that was sorted.
    for (j = 2; j < tblEl.rows[i].cells.length; j++) {
      cellEl = rowEl.cells[j];
      cellEl.className = cellEl.className.replace(colTest, "");
      if (j == col)
        cellEl.className += " " + colClsNm;
      cellEl.className = normalizeString(cellEl.className);
    }
  }

  // Find the table header and highlight the column that was sorted.
  var el = tblEl.parentNode.tHead;
  rowEl = el.rows[el.rows.length - 1];
  // Set style classes for each column as above.
  for (i = 2; i < rowEl.cells.length; i++) {
    cellEl = rowEl.cells[i];
    cellEl.className = cellEl.className.replace(colTest, "");
    // Highlight the header of the sorted column.
    if (i == col)
      cellEl.className += " " + colClsNm;
      cellEl.className = normalizeString(cellEl.className);
  }
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------

function setRanks(tblEl, col, rev) {

  // Determine whether to start at the top row of the table and go down or
  // at the bottom row and work up. This is based on the current sort
  // direction of the column and its reversed flag.

  var i    = 0;
  var incr = 1;
  if (tblEl.reverseSort[col])
    rev = !rev;
  if (rev) {
    incr = -1;
    i = tblEl.rows.length - 1;
  }

  // Now go through each row in that direction and assign it a rank by
  // counting 1, 2, 3...

  var count   = 1;
  var rank    = count;
  var curVal;
  var lastVal = null;

  // Note that this loop is skipped if the table was sorted on the name
  // column.
  while (col > 1 && i >= 0 && i < tblEl.rows.length) {

    // Get the value of the sort column in this row.
    curVal = getTextValue(tblEl.rows[i].cells[col]);

    // On rows after the first, compare the sort value of this row to the
    // previous one. If they differ, update the rank to match the current row
    // count. (If they are the same, this row will get the same rank as the
    // previous one.)
    if (lastVal != null && compareValues(curVal, lastVal) != 0)
        rank = count;
    // Set the rank for this row.
    tblEl.rows[i].rank = rank;

    // Save the sort value of the current row for the next time around and bump
    // the row counter and index.
    lastVal = curVal;
    count++;
    i += incr;
  }

  // Now go through each row (from top to bottom) and display its rank. Note
  // that when two or more rows are tied, the rank is shown on the first of
  // those rows only.

  var rowEl, cellEl;
  var lastRank = 0;

  // Go through the rows from top to bottom.
  for (i = 0; i < tblEl.rows.length; i++) {
    rowEl = tblEl.rows[i];
    cellEl = rowEl.cells[0];
    // Delete anything currently in the rank column.
    while (cellEl.lastChild != null)
      cellEl.removeChild(cellEl.lastChild);
    // If this row's rank is different from the previous one, Insert a new text
    // node with that rank.
    if (col > 1 && rowEl.rank != lastRank) {
      cellEl.appendChild(document.createTextNode(rowEl.rank));
      lastRank = rowEl.rank;
    }
  }
}

//-----------------------------------------------------------------------------------------
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function refixDate(fx) {
	flen = String(fx).length;
	start = String(fx).indexOf("|")+1;
	return String(fx).substring(flen, flen-(flen-start));
}
function fixDate(fx) {
	var nD = new Date(fx); 	
	return nD.valueOf() +" | "+ fx;
}

function fixLinks(id) { //	from sortable10 only
	var elemx = document.getElementById(id);
	for (var ii = 0; ii < elemx.rows.length; ii++) {
		var xurl = elemx.rows[ii].cells[0].childNodes[0].href;
		xlen = xurl.length;
		xstart = xurl.indexOf("/");
		var xlurl = xurl.substring(xlen, xlen-(xlen-xstart));
		elemx.rows[ii].cells[0].childNodes[0].href = "redirector.asp?l="+xurl;
		elemx.rows[ii].cells[0].childNodes[0].target="_top";
	}
}

function salaryFixer(id) {
	var elem = document.getElementById(id);
	if (elem == null) {
		return false;
	}

	for (var i = 0; i < elem.rows.length; i++) {
		xcurVal = getTextValue(elem.rows[i].cells[3]);
		xcurVal = xcurVal.replace(",","");
		if (xcurVal.indexOf("$") == -1) {
			elem.rows[i].cells[3].innerHTML = "$"+xcurVal;
		} else {
			elem.rows[i].cells[3].innerHTML = xcurVal;
		}
	}
	//alert(elem.rows.length);
	pathArray = top.location.pathname.split( '/' );
    if (pathArray[pathArray.length-1] == 'allJobs.asp') {
		var elem = document.getElementsByTagName("body")[0];
		var myTHs = elem.getElementsByTagName("th");
			for (var i = 0; i < myTHs.length; i++) {
				if (myTHs[i].className == "dateTH") {
					myTHs[i].style.display = "block";
				}
			}
    	dateFixerSTART(id);	
		sortTableSTART(id, 4, true);
		top.document.getElementById('ajaxLoading').style.display = "none";
	}
}


function dateReFixerEnd(id) { //	from sortable only
	var elem3 = document.getElementById(id);
	for (var iq3 = 0; iq3 < elem3.rows.length; iq3++) {
		var str3 = elem3.rows[iq3].cells[4].innerHTML;
		elem3.rows[iq3].cells[4].innerHTML = refixDate(str3);
	}
}

function dateFixerALL(id) { //
	var elem5 = document.getElementById(id);
	for (var iq5 = 0; iq5 < elem5.rows.length; iq5++) {
		var str5 = elem5.rows[iq5].cells[4].innerHTML;
		elem5.rows[iq5].cells[4].innerHTML = fixDate(str5);
		elem5.rows[iq5].cells[4].style.display = "block";
	}
}

function dateReFixerALL(id) { //	from sortable only
	var elem3 = document.getElementById(id);
	for (var iq3 = 0; iq3 < elem3.rows.length; iq3++) {
		var str3 = elem3.rows[iq3].cells[4].innerHTML;
		elem3.rows[iq3].cells[4].innerHTML = refixDate(str3);
	}
}

function dateReFixer(id) {
var elem2 = document.getElementById(id);
var myTDs2 = elem2.getElementsByTagName("td");
var myint2 = 0
for (var ix = 0; ix < myTDs2.length; ix++) {
	if (myTDs2[ix].className == "dateTD") {
		myint2++;
		var str2 = trim(myTDs2[ix].innerHTML);
		myTDs2[ix].innerHTML = refixDate(str2);
	}
}
}

function dateFixerSTART(id) {
var elem = document.getElementById(id);
var myTDs = elem.getElementsByTagName("td");
var myint = 0
	for (var i = 0; i < myTDs.length; i++) {
		if (myTDs[i].className == "dateTD") {
			myint++;
			myTDs[i].style.display = "block";
			var str = trim(myTDs[i].childNodes[0].innerHTML);
			myTDs[i].innerHTML = fixDate((str));
		}
	}
}
function dateFixer(id) {
	if (!document.getElementById || !document.getElementsByTagName) {
		return false; }
	else {
		 
		var elem = document.getElementById(id);
        var myTDs = elem.getElementsByTagName("td");
		var myint = 0
		for (var i = 0; i < myTDs.length; i++) {
			if (myTDs[i].className == "dateTD") {
				myint++;
				var str = trim(myTDs[i].childNodes[0].innerHTML);
				myTDs[i].innerHTML = fixDate((str));
			}
		}
	}
}

setTimeout("salaryFixer('offTblBdy');",300);