
/* <![CDATA[ */

  //
  //
  //
  function updateStar(id) {

    var jobID = id.substring(id.lastIndexOf('_') + 1);
    var imgElements = document.getElementsByTagName('img');
    var imgsrc = '';

		for(var i = 0; i < imgElements.length; i++) {
      var elementID = imgElements[i].id;

      if (elementID.substring(0, 5) == 'star_' && elementID.substring(elementID.lastIndexOf('_') + 1) == jobID) {
        imgsrc = (imgElements[i].src ==
          'http://www.jpspacejobs.com/images/star_off.gif') ?
          'http://www.jpspacejobs.com/images/star_on.gif' :
          'http://www.jpspacejobs.com/images/star_off.gif';
        imgElements[i].src = imgsrc;
      }
    }

    var sendStar = (imgsrc == 'http://www.jpspacejobs.com/images/star_off.gif') ? '0' : '1';
    var objXml = new XMLHttpRequest();
    var datasource = "http://www.jpspacejobs.com/vacancies/star.php";
    var params = "id=" + jobID + "&star=" + sendStar;
    objXml.open("GET", datasource + "?" + params, true);
    objXml.send(null);

    /*
    var starcount = parseInt(document.getElementById('starcount').innerHTML);
    if (sendStar == 1) starcount = starcount + 1;
    else starcount = starcount - 1;
    document.getElementById('starcount').innerHTML = starcount.toString();
    */
  }

  //
  //
  //
  function clearStars() {
    var imgElements = document.getElementById('jobslist').getElementsByTagName('img');
		for(var i = 0; i < imgElements.length; i++) {
			if (imgElements[i].id.substr(0, 5) == 'star_') {
			  imgElements[i].src = 'http://www.jpspacejobs.com/images/star_off.gif';
      }
    }

    var objXml = new XMLHttpRequest();
    objXml.open('GET', 'http://www.jpspacejobs.com/vacancies/star.php?clear', true);
    objXml.send(null);
  }

  //
  //
  //
  function toggleDay(day) {
    if (document.getElementById('rest_' + day)) {
      var restDiv = document.getElementById('rest_' + day);
      if (restDiv.style.display == 'none') {
        $(restDiv).slideDown();
        document.getElementById('more_' + day).style.display = 'none';
        document.getElementById('less_' + day).style.display = 'block';
      } else {
        $(restDiv).slideUp();
        document.getElementById('more_' + day).style.display = 'block';
        document.getElementById('less_' + day).style.display = 'none';
      }
    }
  }

  //
  //
  //
  function toggleJobAlertForm() {
    var alertForm = document.getElementById('jobalertform');
    if (alertForm.style.display == 'block') {
      alertForm.style.display = 'none';
      document.getElementById('formerror').innerHTML = '';
    } else {
      alertForm.style.display = 'block';
    }
  }

  //
  //
  //
  function submitJobAlertForm(jobquery) {

    // Disable all the form parts
    // Display a "working" animated gif
    // send request via AJAX
    // Display response

    var objXml = new XMLHttpRequest();
    var datasource = "http://www.jpspacejobs.com/alerts/subscribe/";

    var params = "email=" + encodeURIComponent(document.getElementById('email').value) + "&";
    params += "jobquery=" + encodeURIComponent(jobquery) + "&";
    if (document.getElementById('dailyemail').checked == true) {
      params += "frequency=daily&";
    } else {
      params += "frequency=weekly&";
    }

    objXml.open("GET", datasource + "?" + params, true);

    objXml.onreadystatechange=function() {
      if (objXml.readyState == 4) {
        if (objXml.responseText == 'OK') {
          var confirmText = "<span style='color: #060;'><b>Success:</b> Your subscription request has been recorded.<br />" +
            "Please check your email to confirm and activate the request.</span>";
          document.getElementById('jobalertform').innerHTML = confirmText;
        } else {
          document.getElementById('formerror').innerHTML = objXml.responseText;
        }
      }
    }
    objXml.send(null);
  }

/* ]]> */

