/*
 * Javascript from RichFX
 */

function displayCatalog(catalog_name) {

  var client_name = 'reedsjewelers';	//Replace with the client name
  var passback = ''; //Replace with any parameter that need to be sent back with future calls to the client site
 
  var staging = 'testny';		//Replace with staging server name,file name or IP address

  regEx = /catalog_name=([^&=]*)(&|$)?/
  m=regEx.exec(location.search);
  if (m) {
    catalog_name = m[1];
  }

  if (location.port == '83')
  {
    // We are on the staging environment
	url = 'http://testny.richfx.com/catalog_' + client_name + '/' + catalog_name + '/asp/catalog_include.asp';
       url += "?URL_base=" + escape("http://" + location.hostname + ':83' + location.pathname + "&" + location.search.replace("\?","")) + "&rfx_catalog=1&passback=" + escape(passback);
  }
  else {	
  	// We are on live
	url = 'http://' + client_name + '.richfx.com/catalog_' + client_name + '/' +  catalog_name + '/asp/catalog_include.asp';	
        url += "?URL_base=" + escape("http://" + location.hostname + location.pathname + "&" + location.search.replace("\?","")) + "&rfx_catalog=1&passback=" + escape(passback);
  }

  document.write ('<scr' + 'ipt language=javascript src="' + url + '"></sc' + 'ript>');
  
}

function displayCatalog2(catalog_name) {
	//var catalog_name = 'holiday_special';	//Replace with the catalog name
	var client_name = 'reedsjewelers';			//Replace with the client name
	var versioningid = '';					//Replace with versioningid on versioning catalogs
	var passback = '';						//Replace with the variables you would like to get in the product page (example: var passback = 'param1=value1&param2=value2')

	if (location.search.match(/(rfx_catalogname|catalog_name)=([^&=]*)(&|$)?/)) catalog_name = RegExp.$2;
	if (location.search.match(/rfx_versioningid=([^&=]*)(&|$)?/)) versioningid=RegExp.$1;

	if (location.port == '83')
	{
		// We are on the staging environment
		var url = 'http://testny.richfx.com/catalog_' + client_name + '/' + catalog_name + '/asp/catalog_include.aspx';
	        url += "?URL_base=" + escape("http://" + location.hostname + ':83' + location.pathname + "&" + location.search.replace("\?","")) + "&rfx_catalog=1&rfx_passback=" + escape(passback); 
	}
	else {	
		var CDN = (location.search.match(/rfx_dontcache=true(&|$)?/) ? "" : ".edgesuite.net");
		// We are on live
		var url = 'http://' + client_name + '.richfx.com'+CDN+'/catalog_' + client_name + '/' +  catalog_name + '/asp/catalog_include.aspx';
	        url += "?URL_base=" + escape("http://" + location.hostname + location.pathname + "&" + location.search.replace("\?","")) + "&rfx_catalog=1&rfx_passback=" + escape(passback); 
	}

	if (versioningid.length>0) url+="&rfx_versioningid="+versioningid;

	document.write ('<scr' + 'ipt language=javascript src="' + url + '"></sc' + 'ript>');
}