function showPopup(show)
{
  if(show){
      document.getElementById('popup').style.visibility="visible";
  }else {
      document.getElementById('popup').style.visibility="hidden";
  }
}

function isEmployee()
{
  //alert('is employee');
  window.open ("http://employee.bnsf.com");
}

function isExternalCandidate()
{
  //alert('is external candidate');
  createCookie2('Alt_Reg_Link',"Alt Registration Link",1);
  //alert('after create');
  window.open ("https://careers.bnsf.com/sap(bD1lbiZjPTM5MiZkPW1pbg==)/bc/bsp/sap/hrrcf_unrg_srch/application.do?rcfContext=EXTRNL", "jobsearch", "scrollbars=yes,resizable=yes");
}

function checkCookie() {
  sapCookie=readCookie('JSESSIONID');
  //alert(sapCookie + " sapCookie");
  if(sapCookie!=null){
    sapCookieValue = sapCookie.indexOf("wdsapp");
    }else{
    sapCookieValue = null;
  }
  //alert(sapCookieValue + " sapCookieValue");
  empCookie=readCookie('EMP_PORTALID');
    if (empCookie!=null && sapCookieValue!=null) {
        showPopup(true);
  }else{
    window.open ("https://careers.bnsf.com/sap/bc/webdynpro/sap/hrrcf_a_unreg_job_search?sap-client=392", "jobsearch", "scrollbars=yes,resizable=yes");
  }
}

function newcan() {
  sapCookie=readCookie('JSESSIONID');
  //alert(sapCookie + " sapCookie");
  if(sapCookie!=null){
    sapCookieValue = sapCookie.indexOf("wdsapp");
    }else{
    sapCookieValue = null;
  }
  //alert(sapCookieValue + " sapCookieValue");
  empCookie=readCookie('EMP_PORTALID');
    if (empCookie!=null && sapCookieValue!=null) {
        showPopup(true);
  }else{
    window.open ("https://careers.bnsf.com/sap%28bD1lbiZjPTM5MiZkPW1pbg==%29/bc/bsp/sap/hrrcf_cand_reg/application.do?sap-return-url=%2fsap%2fbc%2fbsp%2fsap%2fhrrcf_start_ext%3frcfSpId%3d9002%26rcfContext%3dEXTRNL%27%29", "newcan", "scrollbars=yes,resizable=yes");
  }
}

function returncan() {
  sapCookie=readCookie('JSESSIONID');
  //alert(sapCookie + " sapCookie");
  if(sapCookie!=null){
    sapCookieValue = sapCookie.indexOf("wdsapp");
    }else{
    sapCookieValue = null;
  }
  //alert(sapCookieValue + " sapCookieValue");
  empCookie=readCookie('EMP_PORTALID');
    if (empCookie!=null && sapCookieValue!=null) {
        showPopup(true);
  }else{
    window.open ("https://careers.bnsf.com/sap/bc/webdynpro/sap/hrrcf_a_startpage_ext_cand?sap-language=EN&sap-wd-configId=ZBNSF_A_STARTPAGE_EXT_CAND", "returncan", "scrollbars=yes,resizable=yes");
  }
}


function readCookie(name) {
  //alert('in the function');
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    //alert(c.substring(nameEQ.length,c.length));
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie2(name) {
  //alert('in cookie');
  createCookie2(name,"",-1);
  var ca = document.cookie.split(';');
  //alert(ca);
}

function createCookie2(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

