/* Career Opportunities Functions for PMI website.

Author: Brendan O'Connor
Date: September 18, 2004

Sept. 30 - Added carOpp className to increase row height. RSuen

Author: Ray Hope
Date: August 2, 2007

 */

function drawCareerOpportunities( aTable )
{
  var today = new Date()
  var thisDay = today.getDate()
  var thisMonth = today.getMonth()
	var thisYear = today.getFullYear()
  var count = 0
  var currentDate = thisYear + "/" + monthDayFormat((thisMonth+1))+"/" +monthDayFormat((thisDay))
  
  deleteRows(getObject(aTable));
 
	for (var j = 0; j < carOppDB.length; j++) 
  {
    if ( carOppDB[j].aEndDate >= currentDate )
    {
      newCarOppRow = getObject(aTable).insertRow(count)
 	    appendCarOppDetailCell(newCarOppRow, j);
      count++
    }
  }
  if ( count == 0 )
  {
    // add message
    newCarOppRow = getObject(aTable).insertRow(count)
    appendCarOppNoCurrentCells(newCarOppRow);
  }  
} 

function appendCarOppNoCurrentCells(Trow)
{
  var newCell = Trow.insertCell(Trow.cells.length)
  newCell.colSpan = 4;
  newCell.className = "TwoToneDetail";
  newCell.innerHTML = "<br>No opportunities currently available, please check back later.<br><br>"
}

function appendCarOppDetailCell(Trow, rowId) 
{
  var cellData = "";
  var testDate = "";
	
  with ( carOppDB[rowId] )
  {
    var newCell = Trow.insertCell(Trow.cells.length)
  	newCell.className = "TwoToneDetail"
    newCell.noWrap = true;
    testDate = new Date( aEndDate )
  	newCell.innerHTML = testDate.toDateString();
    
    var newCell = Trow.insertCell(Trow.cells.length)
  	newCell.className = "TwoToneDetail"
    newCell.title = aBody
    if ( aDetailLink == "" )
    {
 			newCell.innerText = aPosition
    }
    else
    {     	
    	newCell.innerHTML = "<a class='OnTwoTone' href='" + aDetailLink + "' class='detailLink' target='_blank'>" + aPosition + " &nbsp;</a>"
    }    
     	
    var newCell = Trow.insertCell(Trow.cells.length)
  	newCell.className = "TwoToneDetail"
    if ( aHomePageLink == "" )
    {
 			newCell.innerText = aCompany
    }
    else
    {
     	newCell.title = "Company's Home Page"
    	newCell.innerHTML = "<a class='OnTwoTone' href='" + aHomePageLink + "' class='detailLink' target='_blank'>" + aCompany + " &nbsp;</a>"
    }

    var newCell = Trow.insertCell(Trow.cells.length)
  	newCell.className = "TwoToneDetail"
    testDate = new Date( aBeginDate )
    newCell.noWrap = true;
  	newCell.innerHTML = testDate.toDateString();
  }
}

function sortCarOpp( aType )
{  
  order = false
 
  switch (aType) 
  {
    case 0 :       
      carOppDB.sort(sortByBeginDate)
      break
		default :
			carOppDB.sort(sortByBeginDate)      
  }
}

function sortByBeginDate(a, b) 
{ // Sort logic
  return (order) ? (( a.aEndDate > b.aEndDate ) ? -1 : 1) : (( a.aEndDate < b.aEndDate ) ? -1 : 1)
}