/*--
*Description: Actions specific to the Jobamatic job details page
*Uses: JHttpRequest.js

*Steps:
1. 
2. 
3. 
4. 
--*/

JEventUtil.addEvent(window,'load',init,false);

function Controller(){
  //inherit http methods from ClassRPC
  ClassRPC.call(this);
  
  this.countEmailApply = countEmailApply;
  this.countWebApply = countWebApply;
}


function countEmailApply(job_post_id){
  var response = null;
  
  var _url = '/a/jbb/count-email-apply/'+job_post_id;
  var _callback = function(http){
    response = http.responseText;
  }

  this.rpc(_url, _callback, false);

  return;
}

function countWebApply(job_post_id){
  var response = null;
  
  var _url = '/a/jbb/count-web-apply/'+job_post_id;
  var _callback = function(http){
    response = http.responseText;
  }

  this.rpc(_url, _callback, false);

  return;
}



function init(){
  oController = new Controller();
  
  //get job post id from url
  var pathname_pieces = document.location.pathname.split('/');
  var job_post_id = pathname_pieces[pathname_pieces.length-1];

  //Try to asign event handlers. These elements show up on page conditionally so we can't assume they will always be there.
  try{
    JEventUtil.addEvent(document.getElementById('a_email_apply'),'click',function(e){oController.countEmailApply(job_post_id)},false);
  }catch(e){};
  
  try{
    JEventUtil.addEvent(document.getElementById('a_web_apply'),'click',function(e){oController.countWebApply(job_post_id)},false);
  }catch(e){};
}
