RFX_Base = 'http://toysrus.richfx.com/catalog_toysrus/diffabled_06_t/'
PassBack = escape('')
/* Function: GetUserId
* Description: returns the user id, if none
* creates one and sets it in a persistent cookie
*/
function GetUserId(CatalogID)
{
id = _rfxGetCookie(CatalogID)
if (!id)
{
id = GenerateNewId()
document.cookie=CatalogID + "=" + id + ";expires=Mon, 31 Dec 2010 23:59:59 UTC;";
}
return id
}
/* Function: GenerateNewId
* Description: Creates a random 64 character string used for unique ids.
*/
function GenerateNewId()
{
charList = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
//TODO: Add random number to shift the random iterator to.
uID = ""
for (i=0;i<64;i++)
uID+=charList.charAt(Math.random()*charList.length)
return uID;
}
/* Function: DeclareCatalogObject
* Description: returns html code to declare the flash object
*/
function DeclareCatalogObject(catSet,user)
{
var buff;
//this is needed for metrics purposes
HTMLVERSION = false;
flashParams = GetFlashParams(catSet,user)
//get the flash event handlers, and the metrics code.
buff = declareScriptTag('custom/flashevents.js') + declareScriptTag('script/log_manager.js');
//declare the iframe
buff += '
';
//declare the flash object
buff += '';
//if debug variable is set via the querystring show a textbox showing the debug info
if (catSet.debug)
buff += ''
//adding 'showobjectdec=true', shows the declaration of the object in plain text.
if (_rfxGetUrlParam("showobjectdec"))
return ""
else
return buff
}
/* Function: GetFlashParams
* Description: returns a string used for the flash object url parameters.
*/
function GetFlashParams(catSet,user)
{
var paramStr="";
var flashParams = new Array( "embedWidth","embedHeight","smallPictureHeight","smallPictureWidth","PRODX",
"PRODY","PRODWIDTH","PRODHEIGHT","HIGHRES","LOWBAND","MaxStickHeight",
"read_only", "base", "showProdPopupAnim","openingText","showSearchBorders" )
for (param in flashParams)
{
//if empty dont write
if (typeof(flashParams[param]) == "string" && eval("catSet." + flashParams[param]))
paramStr += flashParams[param] + "=" + eval("catSet." + flashParams[param]) + "&";
}
flashParams = new Array( "searches","mag_help","first_page","ViewID","iflags","arrow_help" )
for (param in flashParams)
{
//if empty dont write
if (typeof(flashParams[param]) == "string" && eval("user." + flashParams[param]))
paramStr += flashParams[param] + "=" + eval("user." + flashParams[param]) + "&";
}
return paramStr
}
/* Function: _rfxMain
* Description: entry point of the Catalog.
*/
function _rfxMain()
{
//populate template settings
PopulateMagicVariables(oSettings);
//start user specific code, only if cookies is supported.
if (isCookiesEnabled())
{
//get user vars
GetUserVars(oSettings,oUser)
}
//overrided user settings with url params
_rfxGetUrlParams(oSettings,oUser);
//Change Catalog Settings depending on user settings.
setResolution(oSettings,oUser.HighRes ? "high" : "low")
oSettings.SWFName = (oUser.HighRes) ? "loader_high.swf" : "loader_low.swf";
if (oUser.ViewID != oUser.UserID)
oSettings.read_only = true;
if (!oSettings.base) oSettings.base = location.href.substr(0,location.href.lastIndexOf('/'));
//add a slash to the end of base url if there isnt one already.
oSettings.base+=(oSettings.base.charAt(oSettings.base.length-1)!='/')?"/":"";
oSettings.productbase=oSettings.base;
//check if we should add caching.
checkBaseForCache()
oSettings.SWFName = oSettings.base + oSettings.SWFName;
//need to disable Product Popup for mac and non ie browsers.
oSettings.showProdPopupAnim = (document.all && navigator.userAgent.toLowerCase().indexOf("mac") <= 0 && navigator.userAgent.toLowerCase().indexOf("opera") <= 0) ? 1 : 0;
//override iflags if sent via url
checkOverrideIflag();
//check to see if html version is requested or required
if (html=Check4HtmlVersion())
return html;
//return flash object.
return DeclareCatalogObject(oSettings,oUser);
}
/* Function: checkBaseForCache
* Description: checks if we need to make the base come from earthcache, our cache provider.
* if so changes the base
*/
function checkBaseForCache()
{
if (_rfxGetUrlParam("dontcache") == "true")
return false;
//if location is a domain, and its not "testny" then use cache
if (oSettings.base.match(/\/\/([^\/]*)/))
{
hostname = RegExp.$1
if (hostname.match(/.*\.\D{2,4}$/) && hostname.indexOf("testny") < 0 && hostname.indexOf("edgesuite") < 0)
{
oSettings.base=oSettings.base.replace("richfx.com","richfx.com.edgesuite.net")
}
}
}
/* Function: declareScriptTag
* Description: returns script tag with the scriptFile supplied.
*/
function declareScriptTag(scriptFile)
{
return "\n";
}
/* Function: checkOverrideIflag
* Description: checks for iflags in the url or session cookie, if found displays those
* iFlags instead, and sets read_only to true.
*/
function checkOverrideIflag()
{
//check for the iflags in cookie
var temp
var tempIflags = _rfxGetCookie(oSettings.CatalogID + "_viewIflags");
//check for iflags in url, put in session cookie if found.
tempIflags = (temp=_rfxGetUrlParam("vif"))?temp:tempIflags;
if (temp)
{
oUser.iflags=tempIflags.replace(/a/g,",");
oSettings.read_only=1;
}
}
/*
* Function: showHTML()
* Description: returns true if we should show html version.
*/
function showHTML()
{
return oSettings.htmlEnabled && (_rfxGetUrlParam("ver") == "html" || !detectFlash() || !oSettings.flashEnabled || (navigator.userAgent.toLowerCase().indexOf('mac') >= 0 && oSettings.flash_version == 5))
}
/* Function: Check4HtmlVersion
* Description: Checks for html version in the query string or check if the user does not
* have flash 5.
*/
function Check4HtmlVersion()
{
//TODO: Support A/B test of html version.
if (showHTML())
{
return showHtmlVersion();
}
return false;
}
/* Function: showHtmlVersion
* Description: declares an iframe object with the html catalog version.
*/
function showHtmlVersion()
{
//30 is a constant difference in formatting the table.
var thumbNailViewHeight = (oSettings.thumbPictureHeight + 30) * (oUser.HighRes ? 4 : 3) + 50
if (_rfxGetUrlParam("zoom") == "true")
{
//create new embed sizes if in closeup view.
if (_rfxGetUrlParam("firstpage") < 2 || _rfxGetUrlParam("firstpage") == oSettings.totalPages)
oSettings.embedWidth = oSettings.largePictureWidth + 200;
else
oSettings.embedWidth = oSettings.largePictureWidth*2 + 200;
oSettings.embedHeight = oSettings.largePictureHeight + 75;
}
else
{
oSettings.embedHeight = Math.max(thumbNailViewHeight,oSettings.smallPictureHeight+50);
}
var debugStr=(_rfxGetUrlParam("debug"))?"&debug=true":"";
PassBack = (PassBack) ? PassBack : "nothing";
return ""
}
/* Function: _rfxGetUrlParams
* Description: checks for parameters in the url that should override any cookie values.
*/
function _rfxGetUrlParams(oSettings,oUser)
{
oSettings.base=(temp=_rfxGetUrlParam("RFX_Base"))?unescape(temp):oSettings.base;
oSettings.clientBase=(temp=_rfxGetUrlParam("URL_Base"))?temp:oSettings.clientBase;
oSettings.debug=(temp=_rfxGetUrlParam("debug"))?temp:oSettings.debug;
oSettings.showSearchBorders=(temp=_rfxGetUrlParam("ssb"))?temp:oSettings.showSearchBorders;
oUser.ViewID=(temp=_rfxGetUrlParam("catalog_id"))?temp:oUser.ViewID;
oUser.HighRes=(temp=_rfxGetUrlParam("res"))?temp=="high":oUser.HighRes;
oUser.first_page=(temp=_rfxGetUrlParam("firstpage"))?temp:oUser.first_page;
}
/* Function: _rfxGetUrlParam
* Description: returns value of url param if found
*/
function _rfxGetUrlParam(param)
{
queryStr = location.search
if (!queryStr) return; // if querystring is empty return
re = new RegExp(param + "=([^&=]*)(&|$)?","i")
if (queryStr.match(re))
return RegExp.$1
return null;
}
/* Function: setResSizes
* Description: populates a setting with the sizes of a certain resolution.
*/
function setResolution(settings,index)
{
var Arr = new Array()
for (attrib in settings.Resolutions)
{
eval("settings." + attrib + "=settings.Resolutions[attrib][index];")
}
return Arr;
}
/* Function: isCookiesEnabled
* Description: returns true if Cookies is enabled.
*/
function isCookiesEnabled()
{
document.cookie="enabled=true;"
return _rfxGetCookie("enabled") == "true"
}
/* Function: CatalogVars
* Description: contains all catalog settings
*/
function CatalogVars()
{
this.embedWidth;
this.embedHeight;
this.smallPictureWidth;
this.smallPictureHeight;
this.PRODX;this.PRODY;this.PRODWIDTH;this.PRODHEIGHT;
this.HIGHRES;
this.LOWBAND;
this.SWFName="loader.swf";
this.read_only=false;
this.base=(typeof(RFX_Base)=="string")?RFX_Base:"";
this.clientBase=location.href.replace(location.search,"") + "?"
this.showSearchBorders="false";
}
/* Function: UserSettings
* Description: contains variables that require cookies.
*/
function UserSettings()
{
this.HighRes;
this.UserID;
this.searches="";
this.mag_help=0;
this.arrow_help=0;
this.first_page=1;
this.ViewID
this.iflags="";
this.debug
}
/* Function: GetUserVars
* Description: populates the user specific information.
*
*/
function GetUserVars(settings,user)
{
user.UserID = user.ViewID = GetUserId(settings.CatalogID)
user.HighRes=_rfxGetCookie(settings.CatalogID + "_res")=="high"
if (settings.zoomMode == 1) //Magnify mode.
user.mag_help=(temp=_rfxGetCookie(settings.CatalogID + "_mag_help"))?temp:user.mag_help;
user.first_page=(temp=_rfxGetCookie(settings.CatalogID + "_current_page"))?temp:user.first_page;
if (settings.searchEnabled)
user.searches=(temp=_rfxGetCookie(settings.CatalogID + "_searches"))?temp:user.searches;
if (settings.iflagsEnabled)
user.iflags=(temp=_rfxGetCookie(settings.CatalogID + "_iflags"))?temp:user.iflags;
if (settings.zoomMode == 2) //Arrow zoom mode.
user.arrow_help=(temp=_rfxGetCookie(settings.CatalogID + "_arrow_help"))?temp:user.arrow_help;
}
/* Function: _rfxGetCookie
* Description: returns value of cookie specified in sName,
* null if not found.
*/
function _rfxGetCookie(sName)
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
// a cookie with the requested name does not exist
return null;
}
/* Function: geturl_FSCommand
* Description: Flash event handler for Mozilla based browsers
* For Mozilla based browsers we send the event via a getUrl javascript:geturl_FSCommand
* to facilitate the problem of talking to the browser in netscape&mac.
*/
function geturl_FSCommand(command, args) {
main_DoFSCommand(command, args)
}
/* Function: main_FSCommand
* Description: Flash event handler for IExplorer
*/
if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0) {
document.write(' \n');
document.write('on error resume next \n');
document.write('Sub main_FSCommand(ByVal command, ByVal args)\n');
document.write(' call main_DoFSCommand(command, args)\n');
document.write('end sub\n');
document.write(' \n');
}
/* Function: RCatSearch
* Description: Support for external search activation
*/
function RCatSearch(term) {
document.main.SetVariable("_level1/control/search/MyCombobox:SelectedText",term)
document.main.TCallLabel("_level1/control/search","click");
}
/* Function: RCatPrint
* Description: Support for external print activation
*/
function RCatPrint() {
document.main.TCallLabel("_level1/functions","print");
}
/* Function: detectFlash
* Description: returns true if flash 5 is detected.
*/
function detectFlash() {
var plugin;
var flash_version=0;
document.write("\nfunction jCreateObject(progID)\nOn Error Resume Next\nset jCreateObject=CreateObject(progID)\nend function\n");
for (i=5;i<=7;i++)
{
plugin = false
if (document.layers || navigator.userAgent.toLowerCase().indexOf("gecko") >= 0 || navigator.userAgent.toLowerCase().indexOf('mac') >= 0) { //netscape check
plugin = ((navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : false);
plugin = (plugin && plugin.description && parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) >= i) ? true : false;
} else {
plugin=typeof(jCreateObject("ShockwaveFlash.ShockwaveFlash." + i)) == "object";
}
if (plugin) flash_version = i;
}
oSettings.flash_version=flash_version;
return (flash_version > 0)
}
function rfxDebug(str)
{
if (oSettings.debug)
{
document.getElementById("fswindow").value+="\n"+str
document.getElementById('fswindow').scrollTop=document.getElementById('fswindow').scrollHeight;
}
}
/* Function: main_DoFSCommand
* Description: delegates events to the proper event handler.
*/
function main_DoFSCommand(command, args)
{
command += "";
args += "";
var func = (args) ? (command + "('" + args + "')") : (command +"()");
if (command == "debug")
{
rfxDebug(args)
return
}
if (oSettings.debug)
document.getElementById("fswindow").value+="\nFunction: " + func;
try
{
eval(func);
}
catch(e)
{
if (oSettings.debug)
if (document.all)
document.getElementById("fswindow").value+="\nCall Failed! -- " + e.description;
else
document.getElementById("fswindow").value+="\nCall Failed! -- " + e.message;
}
}
//objects holding settings
var oSettings = new CatalogVars();
var oUser = new UserSettings();
/* Function: MagicVarsLoaded
* Description: called after the magic vars are loaded.
*/
function MagicVarsLoaded()
{
document.write(_rfxMain());
}
//get magic variables function, call _rfxGetUrlParams to get base param
//magic.js then calls magic loaded, which eventually starts the catalog.
_rfxGetUrlParams(oSettings,oUser);
checkBaseForCache();
document.write(declareScriptTag('script/magic.js'));