
// onDemandServer should be changed to point to the appropriate server
// For example, if you use sample.scene7.com for your requests, onDemandServer should be "sample.scene7.com"
var onDemandServer = "s.sears.com";


// Function: S7ConfigObject()
// Purpose: Constructor for the S7ConfigObject class
// Param: None
// Output: A new instantiated S7ConfigObject instance
// Notes: No need to use this function explicitly
function S7ConfigObject()
{

	this.isVersion		= "2.8";
	this.isViewerRoot	= "http://" + onDemandServer + "/is-viewers/";
	this.isRoot		= "http://" + onDemandServer + "/is/image/";

	this.codebase		= this.isViewerRoot + "/applets/" + this.isVersion + "/";
	this.archiveSuffix	= "";
	this.buttonPath		= this.isRoot + "/demo/buttons/";

	//used by js->flash communication.
	var ua        = navigator.userAgent.toLowerCase();
	this.isIeWin  = ua.indexOf('msie') != -1 && ua.indexOf('win') != -1 && ua.indexOf('opera') == -1 && ua.indexOf('webtv') == -1;
	this.isFsCommand = true;

}

// Function defaultInstanceName(string)
// Purpose:  generate an instance name for the image request
// Param:  img is the image request string to parse
// Output:  An instance name to use
// Notes:  No need to call this explicitly
S7ConfigObject.prototype.defaultInstanceName = function(img)
{
	var j = img.indexOf('?');
	var j1 = img.indexOf(',');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	j1 = img.indexOf(';');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	j1 = img.indexOf(':');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	j1 = img.indexOf('%3f');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	j1 = img.indexOf('%3F');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	if (j < 0) j = img.length;
	var i = img.lastIndexOf('/', j) + 1;
	return img.substring(i, j);
}

// Function: setFlashParam(int, string, int)
// Purpose: Set the Flash parameter for the DOM
// Param: inID ID number for the operation
// Param: inNAme is the name of the inner HTML object
// Param: inVale is the value of the inner HTML object
// Output: None
// Notes: No need to use this function explicitly
S7ConfigObject.prototype.setFlashParam = function(inId, inName, inVal) 
{
	if (this.isIeWin)
		document.getElementById(inId).SetVariable(inName, inVal);
	else 
	{
		var divcontainer = "flash_setvariables_" + inId;
		if (!document.getElementById(divcontainer))
		{
			var divholder = document.createElement("div");
			divholder.id = divcontainer;
			document.body.appendChild(divholder);
		}
		document.getElementById(divcontainer).innerHTML = "";
		var divinfo = "<embed src='../flash/gateway.swf' FlashVars='lc=" + inId + "&fq="+escape(inName + "=" + inVal)+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
		document.getElementById(divcontainer).innerHTML = divinfo;
	}
};

var flashOk = false;
// Function: checkFlash()
// Purpose : call this function and then test the flashOk variable
// Param: None
// Output: None, check flash is set
S7ConfigObject.prototype.checkFlash = function()
{
	if (S7Config.isIeWin)
	{
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flashOk = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7")) \n');
		document.write('if flashOk = false then \n');
		document.write('    flashOk = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")) \n');
		document.write('end if \n');
		document.write('</SCR' + 'IPT\> \n');
	}
	else if (navigator.plugins && navigator.plugins["Shockwave Flash"])
	{
		desc = navigator.plugins["Shockwave Flash"].description;
		flashOk = desc.indexOf(6.0) > 0 || desc.indexOf(7.0) > 0 || desc.indexOf(8.0) > 0;
	}
}

// Function: fsCommand(string)
// Purpose: Insert scripts into a document
// Param: instance is the instance name to use
// Output:  Inserts the appropriate formatting into the document
S7ConfigObject.prototype.fsCommand = function(instance)
{
	if (this.fsCommand)
	{
		document.write('<SCR'+'IPT LANGUAGE="VBScript"> Sub ' + instance + '_FSCommand(ByVal command, ByVal args)  call doFSCommand(command, args) end sub </SCR'+'IPT>');
		this.fsCommand = false;
	}
	return this.isIeWin ? 'fscommand:' : 'javascript:';
}

var S7Config		= new S7ConfigObject();

//backwards compatibility
var root			= S7Config.isViewerRoot;
var imageServer		= S7Config.isRoot;
var codebase		= S7Config.codebase;
var archiveSuffix	= S7Config.archiveSuffix;
var buttonPath		= S7Config.buttonPath;
function checkFlash() { S7Config.checkFlash(); }

// Function: getParam(string, string)
// Purpose:  Extract a parameter from the URL
// Param: p is the parameter name to search for in the URL
// Param: d is the default value to use if p is not found in the URL
// Output: The value p is set to in the URL, or d if none is specified
function getParam(p,d)
{
	var str = "" + unescape(document.location);
	var i = Math.max( str.indexOf('?'+p+'='), str.indexOf('&'+p+'=') );
	if ( i < 0 )
		return d;
	i+=2+p.length;
	var i2 = str.indexOf('&',i);
	var returnstr = str.substring(i,(i2<0?str.length:i2));
	return (returnstr.indexOf(',')>0?returnstr.split(','):returnstr);
};

function doFSCommand(inCommand, inArgs)
{
	eval(inArgs);
}


// Function: docWrite(string)
// Purpose: Embeds lines directly into the document to work around the IE activeX protocols
// Param: line is the string to embed in the document
// Output: None
function docWrite(line) {
    document.write(line);
}


// Function: isFlashCurrent(int, int, int)
// Purpose: To check the installed version of Flash against the supplied requirement
// Param: versionMajorReq is the integer value of the lowest allowed major version supported
// Param: versionMinorReq is the integer value of the lowest allowed minor version supported
// Param: versionRevisoinReq is the integer value of the lowest allowed revision version supported
// Output: True if the installed version of Flash meets the supplied requirements, false otherwise
// Notes: This will likely fail on versions before flash 6, but since we don't 
// support versions before 6.0r65 it is ok.
//
function isFlashCurrent(versionMajorReq, versionMinorReq, versionRevisionReq) {
    var versionMajor;
    var versionMinor;
    var versionRevision;

    // This If-else block captures the values of the Major, Minor and Revsion version numbers for the installed Flash plugin
    // First checks for Netscape, and Opera version 3 orlater
    if (navigator.plugins != null && navigator.plugins.length > 0) {
        if (navigator.plugins["Shockwave Flash"]) {
            // parse the description to get the version
            flashDescription = navigator.plugins["Shockwave Flash"].description;
            var descArray = flashDescription.split(" ");
            var tempArrayMajor = descArray[2].split(".");
            versionMajor = tempArrayMajor[0];
            versionMinor = tempArrayMajor[1];
            if (descArray[3] != "") {
                tempArrayMinor = descArray[3].split("r");
            } else {
                tempArrayMinor = descArray[4].split("r");
            }
            versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;

        }
    }
    // Next checks Internet Explorer
    else if (isIE && isWin && !isOpera) {
        try {
            var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + versionMajorReq);

            // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
            // so be careful.  Of course we don't run those versions.
            axo.AllowScriptAccess = "always";
            // required for v6.x?
            var version = axo.GetVariable("$version");
            // safe to call for 6.0r47 or greater
            flashDescription = version;

            // parse the version data
            tempArray = version.split(" ");
            // ["WIN", "2,0,0,11"]
            tempString = tempArray[1];
            // "2,0,0,11"
            versionArray = tempString.split(",");
            // ['2', '0', '0', '11']

            versionMajor = versionArray[0];
            versionMinor = versionArray[1];
            versionRevision = versionArray[2];
            // should be 3???
        } catch (e) {
        }
    }

    // test version
    if (versionMajor > versionMajorReq) {
	// alerts are just for demonstration and testing, disable when in production
    	//alert("Flash Version: " + versionMajor + "," + versionMinor + "," + versionRevision + " detected");
        return true;
    }
    if (versionMajor == versionMajorReq
            && versionMinor > versionMinorReq) {
	// alerts are just for demonstration and testing, disable when in production
        //alert("Flash Version: " + versionMajor + "," + versionMinor + "," + versionRevision + " detected");
       	return true;
    }
    if (versionMajor == versionMajorReq
            && versionMinor == versionMinorReq
            && versionRevision >= versionRevisionReq) {
	// alerts are just for demonstration and testing, disable when in production
	//alert("Flash Version: " + versionMajor + "," + versionMinor + "," + versionRevision + " detected");
        return true;
    }

    // alerts are just for demonstration and testing, disable when in production
    //alert("Flash Version: " + versionMajor + "," + versionMinor + "," + versionRevision + " detected");
    return false;
}

