    
function openlink(menuitem){
  var menu = { name: menuitem };
  $.ajax({
    type: "PUT",
    url: window.name,
    contentType: "application/json",
    data: JSON.stringify(menu),
    success: function (data) {
    }
  });
}

//https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
function validURL(str) {
  var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
    '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
    '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
    '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
    '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
    '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
  return !!pattern.test(str);
}

function convertLinks(){
  $("#form a").each(function() {
    if(!validURL($(this).attr('href'))){
      $(this).attr('href', "javascript:openlink('" + $(this).attr('href') + "');")
    }
  })
}


$(document).ready(function(){
  
  convertLinks();
});

