function pageLoad() {
  if ($get("ISN") !== null) {
    $get("ISN").focus();
  }
}

function detectKey(myfield,e,dec) {
  var key;
  var keychar;
  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);
  // control keys
  if (key==13) {
    if (myfield.id == "ISN") {
      getISN();
    } else {
      getISNISL();
    }
  }
}

function getISN() {
 PageMethods.GetISN($get("ISN").value, OnSucceeded, OnFailed);
}

function getISNISL() {
  PageMethods.GetAEwithISL($get("ISL").value,$get("ISN").value , OnSucceeded, OnFailed);
}

function OnSucceeded(result, userContext, methodName) {
  if (result.startsWith("ISL")) { //Multiple ISLs show ISL input field
    $get("divISL").style.display = 'block';
    $get("ISL").focus(); 
  }else if (result.startsWith("We cannot verify")) { //ISN not found
    alert(result); 
  } else { //ISN found
    window.location.href = result;
  } 
}

function OnFailed(error, userContext, methodName) {
  onUpdated();
  if(error !== null)  {
    alert("An error occurred: "+ error.get_message());
  }
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
