//set before this script or not set
var gProduct;
var gAffiliateID;

var gProducts = new Array();
var gSWREGCodes = new Array();
var gREGNOWCodes = new Array();
var gCount = 0;

//note: spaces in item of gProducts should be replace with "-"
gProducts[gCount] = "FLV-Editor-Ultimate";
gSWREGCodes[gCount] = "100276-23";
gREGNOWCodes[gCount] = "13973-12&ss_short_order=true";
gCount++;

gProducts[gCount] = "FLV-Editor-Ultimate";
gSWREGCodes[gCount] = "82096-19";
gREGNOWCodes[gCount] = "13973-12&ss_short_order=true&currency=EUR";
gCount++;

gProducts[gCount] = "FLV-Editor-Ultimate";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-12,1234-32";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro";
gSWREGCodes[gCount] = "100276-2";
gREGNOWCodes[gCount] = "13973-27&ss_short_order=true";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-27,1234-32";
gCount++;

gProducts[gCount] = "Flash-Video-MX";
gSWREGCodes[gCount] = "100276-3";
gREGNOWCodes[gCount] = "13973-3&ss_short_order=true";
gCount++;

gProducts[gCount] = "Flash-Video-MX";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-3,1234-32";
gCount++;

gProducts[gCount] = "FLV-to-Video";
gSWREGCodes[gCount] = "100276-1";
gREGNOWCodes[gCount] = "13973-6&ss_short_order=true";
gCount++;

gProducts[gCount] = "FLV-to-Video";
gSWREGCodes[gCount] = "82096-10";
gREGNOWCodes[gCount] = "13973-6&currency=EUR&ss_short_order=true";
gCount++;

gProducts[gCount] = "FLV-to-Video";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-6,1234-32";
gCount++;

gProducts[gCount] = "FLV-to-Video-Lite";
gSWREGCodes[gCount] = "100276-4";
gREGNOWCodes[gCount] = "13973-16&ss_short_order=true";
gCount++;

gProducts[gCount] = "FLV-to-Video-Lite";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-16,1234-32";
gCount++;

gProducts[gCount] = "DVD-to-Flash";
gSWREGCodes[gCount] = "100276-5";
gREGNOWCodes[gCount] = "13973-26&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-Flash";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-26,1234-32";
gCount++;

gProducts[gCount] = "FlashVideoMXServer-Trial";
gSWREGCodes[gCount] = "100276-7";
gREGNOWCodes[gCount] = "13973-39&ss_short_order=true";
gCount++;

gProducts[gCount] = "FlashVideoMXServer-Trial";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-39,1234-32";
gCount++;

gProducts[gCount] = "FLV-Converter-SDK";
gSWREGCodes[gCount] = "100276-8";
gREGNOWCodes[gCount] = "13973-40&ss_short_order=true";
gCount++;

gProducts[gCount] = "FLV-Converter-SDK";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-40,1234-32&ss_short_order=true";
gCount++;

gProducts[gCount] = "FLV-Audio-Converter-SDK";
gSWREGCodes[gCount] = "100276-9";
gREGNOWCodes[gCount] = "13973-41&ss_short_order=true";
gCount++;

gProducts[gCount] = "FLV-Audio-Converter-SDK";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-41,1234-32";
gCount++;

gProducts[gCount] = "Moyea-FLV-Importer";
gSWREGCodes[gCount] = "100276-6";
gREGNOWCodes[gCount] = "13973-42&ss_short_order=true";
gCount++;

gProducts[gCount] = "Moyea-FLV-Importer";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-42,1234-32";
gCount++;

gProducts[gCount] = "Moyea-FLV-Importer-Pro";
gSWREGCodes[gCount] = "100276-10";
gREGNOWCodes[gCount] = "13973-43&ss_short_order=true";
gCount++;

gProducts[gCount] = "Moyea-FLV-Importer-Pro";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-43,1234-32";
gCount++;

gProducts[gCount] = "Flash-Video-MX";
gSWREGCodes[gCount] = "43908flash";
gREGNOWCodes[gCount] = "13973-3&ss_short_order=true";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro-5";
gSWREGCodes[gCount] = "100276-11";
gREGNOWCodes[gCount] = "13973-44&ss_short_order=true";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro-5";
gSWREGCodes[gCount] = "82096-4";
gREGNOWCodes[gCount] = "13973-44&currency=EUR&ss_short_order=true";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Std-5";
gSWREGCodes[gCount] = "100276-12";
gREGNOWCodes[gCount] = "13973-45&ss_short_order=true";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Std-5";
gSWREGCodes[gCount] = "82096-5";
gREGNOWCodes[gCount] = "13973-45&currency=EUR&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-Flash-5";
gSWREGCodes[gCount] = "100276-13";
gREGNOWCodes[gCount] = "13973-46&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-Flash-5";
gSWREGCodes[gCount] = "82096-6";
gREGNOWCodes[gCount] = "13973-46&currency=EUR&ss_short_order=true";
gCount++;

gProducts[gCount] = "FlashVideoMXServer-Trial";
gSWREGCodes[gCount] = "82096-7";
gREGNOWCodes[gCount] = "13973-39&currency=EUR&ss_short_order=true";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro-5";
gSWREGCodes[gCount] = "100276-14";
gREGNOWCodes[gCount] = "13973-6,13973-44";
gCount++;

gProducts[gCount] = "FLV-to-Video";
gSWREGCodes[gCount] = "100276-14";
gREGNOWCodes[gCount] = "13973-6,13973-44";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro-5";
gSWREGCodes[gCount] = "82096-8";
gREGNOWCodes[gCount] = "13973-6,13973-44&currency=EUR";
gCount++;

gProducts[gCount] = "FLV-to-Video";
gSWREGCodes[gCount] = "82096-8";
gREGNOWCodes[gCount] = "13973-6,13973-44&currency=EUR";
gCount++;

gProducts[gCount] = "FLV-to-Video";
gSWREGCodes[gCount] = "100276-16";
gREGNOWCodes[gCount] = "13973-6,13973-45";
gCount++;

gProducts[gCount] = "FLV-to-Video";
gSWREGCodes[gCount] = "82096-9";
gREGNOWCodes[gCount] = "13973-6,13973-45&currency=EUR";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Std-5";
gSWREGCodes[gCount] = "100276-16";
gREGNOWCodes[gCount] = "13973-6,13973-45";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Std-5";
gSWREGCodes[gCount] = "82096-9";
gREGNOWCodes[gCount] = "13973-6,13973-45&currency=EUR";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro-5";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-44,1234-32";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Std-5";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-45,1234-32";
gCount++;

gProducts[gCount] = "DVD-to-Flash-5";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-46,1234-32&ss_short_order=true";
gCount++;

gProducts[gCount] = "FlashVideoMXServer-Trial";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-39,1234-32";
gCount++;

gProducts[gCount] = "FLV-to-Video-Pro-3";
gSWREGCodes[gCount] = "100276-17";
gREGNOWCodes[gCount] = "13973-38&ss_short_order=true";
gCount++;

gProducts[gCount] = "FLV-to-Video-Pro-3";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-38,1234-32";
gCount++;

gProducts[gCount] = "FLV-to-Video-Pro-3";
gSWREGCodes[gCount] = "82096-11";
gREGNOWCodes[gCount] = "13973-38&ss_short_order=true&currency=EUR";
gCount++;

gProducts[gCount] = "FLV-to-Video-Pro-3";
gSWREGCodes[gCount] = "100276-18";
gREGNOWCodes[gCount] = "13973-38,13973-44";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro-5";
gSWREGCodes[gCount] = "100276-18";
gREGNOWCodes[gCount] = "13973-38,13973-44";
gCount++;

gProducts[gCount] = "FLV-to-Video-Pro-3";
gSWREGCodes[gCount] = "82096-12";
gREGNOWCodes[gCount] = "13973-38,13973-44&currency=EUR";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Pro-5";
gSWREGCodes[gCount] = "82096-12";
gREGNOWCodes[gCount] = "13973-38,13973-44&currency=EUR";
gCount++;

gProducts[gCount] = "FLV-to-Video-Pro-3";
gSWREGCodes[gCount] = "100276-19";
gREGNOWCodes[gCount] = "13973-38,13973-45";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Std-5";
gSWREGCodes[gCount] = "100276-19";
gREGNOWCodes[gCount] = "13973-38,13973-45";
gCount++;

gProducts[gCount] = "FLV-to-Video-Pro-3";
gSWREGCodes[gCount] = "82096-13";
gREGNOWCodes[gCount] = "13973-38,13973-45&currency=EUR";
gCount++;

gProducts[gCount] = "Flash-Video-MX-Std-5";
gSWREGCodes[gCount] = "82096-13";
gREGNOWCodes[gCount] = "13973-38,13973-45&currency=EUR";
gCount++;

gProducts[gCount] = "FLV-Converter-SDK";
gSWREGCodes[gCount] = "82096-1";
gREGNOWCodes[gCount] = "13973-40&ss_short_order=true&currency=EUR";
gCount++;

gProducts[gCount] = "FLV-Audio-Converter-SDK";
gSWREGCodes[gCount] = "82096-3";
gREGNOWCodes[gCount] = "13973-41&ss_short_order=true&currency=EUR";
gCount++;

gProducts[gCount] = "Moyea-FLV-Importer";
gSWREGCodes[gCount] = "82096-15";
gREGNOWCodes[gCount] = "13973-42&ss_short_order=true&currency=EUR";
gCount++;

gProducts[gCount] = "Moyea-FLV-Importer-Pro";
gSWREGCodes[gCount] = "82096-14";
gREGNOWCodes[gCount] = "13973-43&ss_short_order=true&currency=EUR";
gCount++;

gProducts[gCount] = "Flash-Video-Server";
gSWREGCodes[gCount] = "100276-20";
gREGNOWCodes[gCount] = "13973-11&ss_short_order=true";
gCount++;

gProducts[gCount] = "Flash-Video-Server";
gSWREGCodes[gCount] = "82096-16";
gREGNOWCodes[gCount] = "13973-11&ss_short_order=true&currency=EUR";
gCount++;

gProducts[gCount] = "Flash-Video-Server";
gSWREGCodes[gCount] = "1234-32";
gREGNOWCodes[gCount] = "13973-11,1234-32";
gCount++;



gProducts[gCount] = "Video-to-3GP-Converter";
gSWREGCodes[gCount] = "43908v23gp";
gREGNOWCodes[gCount] = "13973-7&ss_short_order=true";
gCount++;

gProducts[gCount] = "Video-to-iPod-Converter";
gSWREGCodes[gCount] = "43908v2ipod";
gREGNOWCodes[gCount] = "13973-2&ss_short_order=true";
gCount++;

gProducts[gCount] = "Video-to-iPhone-Converter";
gSWREGCodes[gCount] = "43908v2iphone";
gREGNOWCodes[gCount] = "13973-29&ss_short_order=true";
gCount++;

gProducts[gCount] = "Video-to-PSP-Converter";
gSWREGCodes[gCount] = "43908v2psp";
gREGNOWCodes[gCount] = "13973-8&ss_short_order=true";
gCount++;

gProducts[gCount] = "Video-to-Zune-Converter";
gSWREGCodes[gCount] = "43908v2zune";
gREGNOWCodes[gCount] = "13973-5&ss_short_order=true";
gCount++;

gProducts[gCount] = "Video-to-Apple-TV-Converter";
gSWREGCodes[gCount] = "43908v2appletv";
gREGNOWCodes[gCount] = "13973-30&ss_short_order=true";
gCount++;

gProducts[gCount] = "Video-Converter";
gSWREGCodes[gCount] = "43908videocvt";
gREGNOWCodes[gCount] = "13973-28&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-Ripper";
gSWREGCodes[gCount] = "43908dvdripper";
gREGNOWCodes[gCount] = "13973-18&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-iPod-Converter";
gSWREGCodes[gCount] = "43908dvd2ipod";
gREGNOWCodes[gCount] = "13973-19&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-iPhone-Converter";
gSWREGCodes[gCount] = "43908dvd2iphone";
gREGNOWCodes[gCount] = "13973-20&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-PSP-Converter";
gSWREGCodes[gCount] = "43908dvd2psp";
gREGNOWCodes[gCount] = "13973-21&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-Zune-Converter";
gSWREGCodes[gCount] = "43908dvd2zune";
gREGNOWCodes[gCount] = "13973-22&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-3GP-Converter";
gSWREGCodes[gCount] = "43908dvd23gp";
gREGNOWCodes[gCount] = "13973-23&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-Apple-TV-Converter";
gSWREGCodes[gCount] = "43908dvd2appletv";
gREGNOWCodes[gCount] = "13973-24&ss_short_order=true";
gCount++;

gProducts[gCount] = "DVD-to-Zune-Converter";
gSWREGCodes[gCount] = "43908dvd2zune";
gREGNOWCodes[gCount] = "13973-22&ss_short_order=true";
gCount++;

gProducts[gCount] = "YouTube-Converter";
gSWREGCodes[gCount] = "43908youtubecvt";
gREGNOWCodes[gCount] = "13973-31&ss_short_order=true";
gCount++;

gProducts[gCount] = "YouTube-to-iPod-Converter";
gSWREGCodes[gCount] = "43908youtube2ipod";
gREGNOWCodes[gCount] = "13973-32&ss_short_order=true";
gCount++;

gProducts[gCount] = "YouTube-to-iPhone-Converter";
gSWREGCodes[gCount] = "43908youtube2iphone";
gREGNOWCodes[gCount] = "13973-33&ss_short_order=true";
gCount++;

gProducts[gCount] = "YouTube-to-PSP-Converter";
gSWREGCodes[gCount] = "43908youtube2psp";
gREGNOWCodes[gCount] = "13973-34&ss_short_order=true";
gCount++;

gProducts[gCount] = "YouTube-to-Zune-Converter";
gSWREGCodes[gCount] = "43908youtube2zune";
gREGNOWCodes[gCount] = "13973-35&ss_short_order=true";
gCount++;

gProducts[gCount] = "YouTube-to-3GP-Converter";
gSWREGCodes[gCount] = "43908youtube23gp";
gREGNOWCodes[gCount] = "13973-36&ss_short_order=true";
gCount++;

gProducts[gCount] = "YouTube-to-Apple-TV-Converter";
gSWREGCodes[gCount] = "43908youtube2appletv";
gREGNOWCodes[gCount] = "13973-37&ss_short_order=true";
gCount++;

gProducts[gCount] = "iPod-Video-Converter-Suite";
gSWREGCodes[gCount] = "43908ipodcvtsuite";
gREGNOWCodes[gCount] = "13973-19,13973-2";
gCount++;

gProducts[gCount] = "iPhone-Video-Converter-Suite";
gSWREGCodes[gCount] = "43908iphonecvtsuite";
gREGNOWCodes[gCount] = "13973-20,13973-29";
gCount++;

gProducts[gCount] = "PSP-Video-Converter-Suite";
gSWREGCodes[gCount] = "43908pspcvtsuite";
gREGNOWCodes[gCount] = "13973-21,13973-8";
gCount++;

gProducts[gCount] = "Zune-Video-Converter-Suite";
gSWREGCodes[gCount] = "43908zunecvtsuite";
gREGNOWCodes[gCount] = "13973-22,13973-5";
gCount++;

gProducts[gCount] = "3GP-Video-Converter-Suite";
gSWREGCodes[gCount] = "439083gpcvtsuite";
gREGNOWCodes[gCount] = "13973-23,13973-7";
gCount++;

gProducts[gCount] = "Apple-TV-Video-Converter-Suite";
gSWREGCodes[gCount] = "43908appletvcvtsuite";
gREGNOWCodes[gCount] = "13973-24,13973-30";
gCount++;

gProducts[gCount] = "Video-DVD-Converter-Suite";
gSWREGCodes[gCount] = "43908vidvdcvtsuite";
gREGNOWCodes[gCount] = "13973-18,13973-28";
gCount++;

gProducts[gCount] = "Video-DVD-Converter-Suite";
gSWREGCodes[gCount] = "43908vidvdcvtsuite";
gREGNOWCodes[gCount] = "13973-18,13973-28";
gCount++;

gProducts[gCount] = "Video-YouTube-Converter-Suite";
gSWREGCodes[gCount] = "43908videoycvtsu";
gREGNOWCodes[gCount] = "13973-28,13973-31";
gCount++;

gProducts[gCount] = "iPod-YouTube-Converter-Suite";
gSWREGCodes[gCount] = "43908ipodycvtsu";
gREGNOWCodes[gCount] = "13973-2,13973-32";
gCount++;

gProducts[gCount] = "iPhone-YouTube-Converter-Suite";
gSWREGCodes[gCount] = "43908iphoneycvtsu";
gREGNOWCodes[gCount] = "13973-29,13973-33";
gCount++;

gProducts[gCount] = "PSP-YouTube-Converter-Suite";
gSWREGCodes[gCount] = "43908pspycvtsu";
gREGNOWCodes[gCount] = "13973-8,13973-34";
gCount++;

gProducts[gCount] = "Zune-YouTube-Converter-Suite";
gSWREGCodes[gCount] = "43908zuneycvtsu";
gREGNOWCodes[gCount] = "13973-5,13973-35";
gCount++;

gProducts[gCount] = "3GP-YouTube-Converter-Suite";
gSWREGCodes[gCount] = "439083gpycvtsu";
gREGNOWCodes[gCount] = "13973-7,13973-36";
gCount++;

gProducts[gCount] = "Apple-TV-YouTube-Converter-Suite";
gSWREGCodes[gCount] = "43908appletvycvtsu";
gREGNOWCodes[gCount] = "13973-30,13973-37";
gCount++;

gProducts[gCount] = "Moyea-Converter-Pack";
gSWREGCodes[gCount] = "43908mycvtpk";
gREGNOWCodes[gCount] = "13973-18,13973-28,13973-31";
gCount++;

gProducts[gCount] = "iPod-Converter-Pack";
gSWREGCodes[gCount] = "43908ipodcvtpk";
gREGNOWCodes[gCount] = "13973-19,13973-2,13973-32";
gCount++;

gProducts[gCount] = "iPhone-Converter-Pack";
gSWREGCodes[gCount] = "43908iphonecvtpk";
gREGNOWCodes[gCount] = "13973-20,13973-29,13973-33";
gCount++;

gProducts[gCount] = "PSP-Converter-Pack";
gSWREGCodes[gCount] = "43908pspcvtpk";
gREGNOWCodes[gCount] = "13973-21,13973-8,13973-34";
gCount++;

gProducts[gCount] = "Zune-Converter-Pack";
gSWREGCodes[gCount] = "43908zunecvtpk";
gREGNOWCodes[gCount] = "13973-22,13973-5,13973-35";
gCount++;

gProducts[gCount] = "3GP-Converter-Pack";
gSWREGCodes[gCount] = "439083gpcvtpk";
gREGNOWCodes[gCount] = "13973-23,13973-7,13973-36";
gCount++;

gProducts[gCount] = "Apple-TV-Converter-Pack";
gSWREGCodes[gCount] = "43908appletvcvtpk";
gREGNOWCodes[gCount] = "13973-24,13973-30,13973-37";
gCount++;
//add more product entries

function AffiliateItem(pid, affid)
{
  this.product = pid;
  this.affiliateid = affid;
}

function GetAffiliateItems()
{
var s = "" + document.cookie;
var ss = s.split("; ");
var i, j;
var product_affids = new Array();

product_affids.length = ss.length+1;

for(i=0,j=0; i<ss.length; ++i) {    
  if (ss[i].slice(0, 8) == "PRODUCT_") {
    product_affids[j] = new AffiliateItem(ss[i].split("_")[1], ss[i].split("=")[1]);
    ++j;
  }
}  

//new product overrides the old one
if (gProduct != undefined) {
  if (gProduct != "") {
  	for (i=0; i<j; ++i) {
     		if (product_affids[i].product == gProduct) {
	          product_affids[i].affiliateid = gAffiliateID;
        	  break;
		}
  	}
	if (i == j) {
	    product_affids[j] = new AffiliateItem(gProduct, gAffiliateID);
	    ++j;
  	}
   } 
} 


product_affids.length = j;
return product_affids;
}

function GetIsUsingRegnow()
{
  var s = ""+document.cookie;
  var ss = s.split("; ");
  var ss2;
  for(var i=0; i<ss.length; ++i) {
     ss2 = ss[i].split("=");
     if (ss2[0] == "USE_REGNOW_SYSTEM") {
        if (ss2[1] == "yes") {
           return true;
        }
     }
  } 
  return false;
}

var gAffiliateItems = GetAffiliateItems();
var gUsingRegnowSystem = GetIsUsingRegnow();

function Internal_GetAffiliateID(pc)
{
  for(var i=0; i<gAffiliateItems.length; ++i) {
     if (pc == gAffiliateItems[i].product) return gAffiliateItems[i].affiliateid;
  }
  return "";
}

function SWREG_GetAffiliateID(pc)
{
	for(var i=0; i<gCount; ++i) {
	  if (pc == gSWREGCodes[i]) {
		return Internal_GetAffiliateID(gProducts[i]);		
	  }
	}
	return "";
}

function REGNOW_GetAffiliateID(pc)
{
	for(var i=0; i<gCount; ++i) {
	  if (pc == gREGNOWCodes[i]) {
		return Internal_GetAffiliateID(gProducts[i]);		
	  }
	}
	return "";
}

function SWREG_TO_REGNOW(pc)
{
  for(var i=0; i<gCount; ++i) {
     if (gSWREGCodes[i] == pc) return gREGNOWCodes[i];
  }
  return "";
}

function SWREG_ParseProductID(href)
{
  var ss0 = href.split("?");
  var ss = ss0[1].split("&");
  var ss2;

  for(var i=0; i<ss.length; ++i) {
    ss2 = ss[i].split("=");
    if (ss2[0] == "p") {
      if (ss2[1].indexOf(":") != -1) return ""; //recursive orders ?
      else return ss2[1];
    }
  }
  return "";
}

function REGNOW_ParseProductID(href)
{
  var ss0 = href.split("?");
  var ss = ss0[1].split("&");
  var ss2;

  for(var i=0; i<ss.length; ++i) {
    ss2 = ss[i].split("=");
    if (ss2[0] == "item" || ss2[0] == "items") {
      return ss2[1];
    }
  }
  return "";
}

function REGNOW_BuildLink(pc, affid)
{
   if (affid != "") {
      return "https://www.regnow.com/softsell/nph-softsell.cgi?items=" + pc + "&affiliate=" + affid; 
   } else {
      return "https://www.regnow.com/softsell/nph-softsell.cgi?items=" + pc;
   }
}

function UpdatePurchaseLink()
{
  for(i=0; i<document.links.length; ++i) {     
     if (document.links[i].className == "purchase") {
        var href = document.links[i].href;
        if (href == "" || href == undefined) continue;
	var pc;
	var affid;
        if (href.indexOf(".swreg.org/cgi-bin/s.cgi?") != -1) { //swreg link           
	   pc = SWREG_ParseProductID(href);
	   if (pc != "") {
              affid = SWREG_GetAffiliateID(pc);
	      if (affid != "") {
		pc = SWREG_TO_REGNOW(pc);
                if (pc != "") {
		   document.links[i].href = REGNOW_BuildLink(pc, affid);
                }
	      } else if (gUsingRegnowSystem) {
                pc = SWREG_TO_REGNOW(pc);
                if (pc != "") {
		   document.links[i].href = REGNOW_BuildLink(pc, "");
                }
              }
	   }
        } else if (href.indexOf(".regnow.com/softsell/nph-softsell.cgi?") != -1) { //regnow link	   
	   pc = REGNOW_ParseProductID(href);
	   if (pc != "") {
             affid = REGNOW_GetAffiliateID(pc);
	     if (affid != "") {
		document.links[i].href = REGNOW_BuildLink(pc, affid);
	      }
	   }
        }
     }
  }
}

function SafeUpdate()
{ 
  try {
    UpdatePurchaseLink();
  } catch(e)
  { 
    ;
  }
}

SafeUpdate();