Edit in JSFiddle

//% Substitute for %FormName Meta-HTML;
var cskGetFormName = function()
{
  var URI = location.href;  

  //% Get the base url and site name
  var baseUri = URI.replace("/psp/", "/psc/");
  var serverUri = baseUri.split("/psc/")[0];
  baseUri = serverUri + baseUri.match(/\/ps(c|p)\/([^\/]*)?\/?([^\/]*)?\/?([^\/]*)?\//)[0];
  var psSiteName = (URI.split("/"))[4];

  var cskFormCounter = "0";

  if(psSiteName.indexOf("_") != -1) 
  {
    var lIndex = psSiteName.lastIndexOf("_");
    var lastStr = psSiteName.substr(lIndex+1);
    
   if(typeof(lastStr) != 'undefined' && lastStr != "" && !isNaN(lastStr))
   {
      cskFormCounter = psSiteName.substr(lIndex+1, lIndex+1);
   }
  }
  return "win" + cskFormCounter;
};