var script = '/xmlrequest.php'
var cacheIE = false
var focused = ''

// edit this function - called to initiate XML request
function startXMLHTTPRequest(oForm, oSelect)
{
  focused = oSelect.name
  parameters = 'branchID=' + oForm.branchID.options[oForm.branchID.selectedIndex].value
  if (typeof(oForm.salaryID) != 'undefined' && oForm.typeID.options[oForm.typeID.selectedIndex].value != '') {
    parameters += '&typeID=' + oForm.typeID.options[oForm.typeID.selectedIndex].value
  }
  xmlHTTPRequestCall()
}

// edit this function - called to parse and use response text
function xmlHTTPRequestAction(response)
{
  aReturn = eval(response)
  aTypeOptions = new Array(new Option('-select type-', ''))
  aSalaryOptions = new Array(new Option('-select salary-', ''))
  if (typeof(aReturn) == 'object') {
    // parse job types
    types = aReturn[0]
    for (i = 0; i < types.length; i++) {
      for (key in types[i]) {
        value = types[i][key]
        aTypeOptions[i+1] = new Option(value, key)
      }
    }
    // parse salary types
    if (aReturn.length == 2) {
      salaries = aReturn[1]
      for (i = 0; i < salaries.length; i++) {
        for (key in salaries[i]) {
          value = salaries[i][key]
          aSalaryOptions[i+1] = new Option(value, key)
        }
      }
    }
  }
  if (focused == 'branchID') {
    oType = document.getElementById('job-search-type')
    oType.options.length = 0
    if (typeof(aTypeOptions) == 'object') {
      for (i = 0; i < aTypeOptions.length; i++) {
        oType.options[i] = aTypeOptions[i]
      }
    }
  }
  
  if (document.getElementById('job-search-salary')) {
    oSalary = document.getElementById('job-search-salary')
    oSalary.options.length = 0
    if (typeof(aSalaryOptions) == 'object') {
      for (i = 0; i < aSalaryOptions.length; i++) {
        oSalary.options[i] = aSalaryOptions[i]
      }
    }
  }
}

/*******************************/
/* DO NOT EDIT BELOW THIS LINE */
/*******************************/
var http = false
var parameters = ''

function xmlHTTPRequestCall()
{
  // get unix timestamp to use to avoid caching
  if (!cacheIE) {
    today = new Date()
    millseconds = Date.UTC(today.getFullYear(), today.getMonth(), today.getDate(), today.getHours(), today.getMinutes(), today.getSeconds(), today.getMilliseconds())
    parameters = '?t=' + millseconds + '&' + parameters
  } else {
    parameters = '?' + parameters
  }
  if (!http) {
    http = getHTTPObject()
  }
  if (!http) {
    alert('Your browser does not support this functionality')
    return false
  }
  http.open('GET', script + parameters, true);
  http.onreadystatechange = checkResponse;
  http.send(null);
}

function checkResponse()
{
  if (http.readyState == 4) {
    response = http.responseText
    if (http.status != 200) {
      alert('Error: could not call script')
      return false
    }
    xmlHTTPRequestAction(response)
  }
}

function getHTTPObject()
{
  xmlhttp = false
  /*@cc_on
  @if (@_jscript_version >= 5)
     try {
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
     } catch (e) {
       try {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
       } catch (E) {
         xmlhttp = false
       }
    }
  @else
     xmlhttp = false
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest()
    } catch (e) {
      xmlhttp = false
    }
  }
  return xmlhttp
}