function signUpCorpOption(rsid,srid,cid,redirectURL,freeTrialDays)
{
  var url='/shared/async/corpFunnel.jsp';
  var opts='';
  if (rsid != null)
    opts += (opts.length > 0 ? '&' : '') + 'rsid=' + rsid;
  if (srid != null){
    srid = srid.replace(/\x2b/g, '%2B');
    opts += (opts.length > 0 ? '&' : '') + 'srid=' + srid;
  }
  if (cid != null)
    opts += (opts.length > 0 ? '&' : '') + 'cid=' + cid;
  if (redirectURL != null)
    opts += (opts.length > 0 ? '&' : '') + 'redirectURL=' + redirectURL;
  if(freeTrialDays != null)
    opts += (opts.length > 0 ? '&' : '') + 'ftDays=' + freeTrialDays;
  if (opts.length > 0)
    url += '?' + opts
  return showPopupOverlay('corpFunnel', 617, 360, url);
}

function signUpEarnBuyAsync(rsid,srid,cid,redirectURL)
{
  var url='/shared/async/earnBuyAsync.jsp';
  var opts='';
  if (rsid != null)
    opts += (opts.length > 0 ? '&' : '') + 'rsid=' + rsid;
  if (srid != null){
    srid = srid.replace(/\x2b/g, '%2B');
    opts += (opts.length > 0 ? '&' : '') + 'srid=' + srid;
  }
  if (cid != null)
    opts += (opts.length > 0 ? '&' : '') + 'cid=' + cid;
  if (redirectURL != null)
    opts += (opts.length > 0 ? '&' : '') + 'redirectURL=' + redirectURL;
  if (opts.length > 0)
    url += '?' + opts
  return showPopupOverlay('thirtyDayFTAsync', 670, 360, url);
}

function signUpEarnBuyPage(rsid,srid,cid,redirectURL)
{
  var url='/thirtyDayFT.jsp';
  var opts='';
  if (rsid != null)
    opts += (opts.length > 0 ? '&' : '') + 'rsid=' + rsid;
  if (srid != null){
    srid = srid.replace(/\x2b/g, '%2B');
    opts += (opts.length > 0 ? '&' : '') + 'srid=' + srid;
  }
  if (cid != null)
    opts += (opts.length > 0 ? '&' : '') + 'cid=' + cid;
  if (redirectURL != null)
    opts += (opts.length > 0 ? '&' : '') + 'redirectURL=' + redirectURL;
  if (opts.length > 0)
    url += '?' + opts
    
  window.location = url;
}



//TODO

function replaceLinksHrefByRegex( hrefRegexMatchArray, hrefReplacement )
{
  for(var i=0;i<document.links.length;i++){
    var link = document.links[i].href;
    for(j=0;j<hrefRegexMatchArray.length;j++)
    {
      if (link.match(hrefRegexMatchArray[j]))
      {
        document.links[i].href=hrefReplacement;
        break;
      }
    }
  }
}

function corpFunnelReplaceLinks( hrefReplacement )
{
  var signupsRegex =
	[
	  /\/register.jsp(\?|$)/,
	  /\/subscribePremiumServices.jsp(\?|$)/
	];
  replaceLinksHrefByRegex( signupsRegex, hrefReplacement );
}