// Function: fixURL(string)
// Purpose:  Formats URL strings correctly for use in our eCatalog functions
// Param: product_url is the string that will be adjusted
// Output: The adjusted string
// Notes:  No need to call this function explicitly

    var fixUrl = true;
    function fixURL(product_url) {
      if(product_url.indexOf("http://") == -1 && product_url.indexOf("https://") == -1)
        product_url = "http://" + callBack + product_url;
        if(urlPassBack != "") {
            if(product_url.indexOf("?") == -1) {
                product_url += "?";
            } else {
                product_url += "&";
            }	
            product_url += urlPassBack;
        }
        return product_url;
    }

// Function: loadProduct(string)
// Purpose:  To load a product URL for our Image Maps
// Param: product_url is the string that will be opened
// Output: None, the window is opened
// Notes:  The default function called in the eCatalog Image Map HREF template

    function loadProduct(product_url) {
                    loadProductPW(product_url);
    }

// Function: loadProductPW(string)
// Purpose:  To load a product URL for our Image Maps in the Parent Window
// Param: product_url is the string that will be opened
// Output: None, the window is opened
// Notes:  Can be substituted in the HREF template for Image Maps, usually best just to use loadProduct()

    function loadProductPW(product_url) {
            product_url = fixURL(product_url);
            var theParent = parent.window.opener;
            if ((theParent != null) && (theParent.location != null) && !theParent.closed) {
                theParent.location = product_url;
                theParent.focus();
            } else {
                fixUrl = false;
                loadProductNW(product_url,false);
                fixUrl = true;
            }
    }


// Function: loadProductCW(string)
// Purpose:  To load a product URL for our Image Maps in the Current Window
// Param: product_url is the string that will be opened
// Output: None, the page is loaded
// Notes:  Can be substituted in the HREF template for Image Maps, usually best just to use loadProduct()

    function loadProductCW(product_url) {
            product_url = fixURL(product_url);
            document.location = product_url;
    }


// Function: loadProductNW(string)
// Purpose:  To load a product URL for our Image Maps in a New Window
// Param: product_url is the string that will be opened
// Output: None, the window is opened
// Notes:  Can be substituted in the HREF template for Image Maps, usually best just to use loadProduct()

    function loadProductNW(product_url) {
    if(fixUrl) {
        product_url = fixURL(product_url);
    }
    var new_window = window.open( product_url, windowName, windowFeatures);
    new_window.focus();
    }


// Function: launchFeedback(int)
// Purpose:  Debugging alert for eCatalog frames
// Param:  currentFrame is the frame number of the current page of the eCatalog
// Output: None, the alert is created
// Notes: No need to call this function explicitly
        
    function launchFeedback(currentFrame) {
        alert("feedback for frame " + currentFrame);
    }


// Function: reload(boolean, int)
// Purpose:  Reloads the window with the state information for changing the size of the eCat
// Param: currentFrame is the frame number of the current page of the eCatalog so that it can be loaded
// Param: enlargestate is the value of this parameter
// Output: None, the alert is created
// Notes: No need to call this function explicitly

    function reload(enlargeState, currentFrame) {
        document.location = document.location.pathname + "?" + reloadParams + "&el=" + enlargeState;
    }

// Function: onProductionIconClick()
// Purpose:  event Handler for clicking on a product icon
// Param: None
// Output: None, the window is loaded
// Notes: No need to call this function explicitly
        
    function onProductIconClick() {
            loadProductPW(productIconURL);
    }

// Function: onLogoClick()
// Purpose:  event Handler for clicking on the logo
// Param: None
// Output: None, the window is loaded
// Notes: No need to call this function explicitly

    function onLogoClick() {		
            if(logoClickURL != '')
                    loadProductPW(logoClickURL);
    }	

// Function: saveState(int, string, boolean)
// Purpose:  saves the state information for the eCatalog
// Param: type is an integer representing the type of state information operation this is being used by
// Param: stateinfo is a string representing the stateinformation for the current state of the eCat
// Param: finalBlock is a boolean flag to determine when that last piece of information has been reached
// Output: None
// Notes: No need to call this function explicitly

    var xmlStateInfo = "";
    function saveState(type,stateInfo,finalBlock) {
        var tmpSI = "";
        xmlStateInfo += stateInfo;
        if(arguments.length < 3)
            finalBlock = true;
        if(finalBlock) {
            if(type==1) {  //email to a friend
                tmpSI = xmlStateInfo;
                xmlStateInfo = "";
                window.open("","emailfriend","width=" + emailWindowWidth + ",height=" + emailWindowHeight + ",location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
                document.frmState.currentState.value=tmpSI;
                xmlStateInfo = "";
	//alert(tmpSI);
                document.frmState.submit();
            }
        }
    }

// Function: openPrivacy()
// Purpose:  event Handler for opening the privacy window
// Param: None
// Output: None, the window is loaded
// Notes: No need to call this function explicitly
        	
    function openPrivacy() {
        var html = privacyCopy;
        newWin = window.open("","privacy","width=" + privacyWindowWidth + ",height=" + privacyWindowHeight);
        newWin.document.write(html);
        newWin.document.close();
    }

// Function: resizeStage(int, int)
// Purpose: Function to allow the eCatalog to automaticly resize itself
// Param: w is the integer value of the width in pixels
// Param: h is the integer value of the height in pixels
// Output: None, the window is resized
// Notes: No need to call this function explicitly

    function resizeStage(w, h) {
            var elementId = 'ZoomMX';		//match the id attribute of the OBJECT element
            var isSafari = ((navigator.appName=='Safari') || (navigator.userAgent.toLowerCase().indexOf('safari')>-1));
            var elm = null;
            if (!isSafari) {
                    elm = document.embeds[elementId];
            }
            var checkElm = false;
            if (elm) {
                    checkElm = true;
            } else {
                    checkElm = false;
            }
            if (!isSafari && checkElm) {
                    elm.width = w;
                    elm.height= h;
            } else {
                    v = getElement(elementId);
                    if (document.getElementById)
                    {
                            v.width = w;
                            v.height = h;
                    }
                    else if (v.all)
                    {
                            v.posWidth = w;
                            v.posHeight = h;
                    }
                    else if (v.clip)
                    {
                            v.clip.width = w;
                            v.clip.height = h;
                    }
            }	
    }

// Function: getElement(string)
// Purpose: Function to perform browser sniffing and grab DOM elements
// Param: name is the name of the object to grab
// Output: The DOM object
// Notes: No need to call this function explicitly

    function getElement(name) {
            if (document.getElementById) 
                    return document.getElementById(name).style;
            if (document.all) 
                    return document.all[name].style;
            if (document.layers) 
                    return document[name];
    }


// Function: goToPage(int)
// Purpose: Function to change pages
// Param: page is the page number of the eCatalog to go to
// Output: None, the page is loaded
// Notes: No need to call this function explicitly

function goToPage(page) {
        setFlashParam(instance,"currentFrame",page);
}


// Function: setFlashParam(string, string, int)
// Purpose: Function to change enbedded Flash parameters
// Param: inId is the variable to set
// Param: inName is the name of the inner DOM object to alter
// Param: inVal is the new value of the variable to set
// Output: None, the variable is set
// Notes: No need to call this function explicitly

function setFlashParam(inId, inName, inVal)
{
     
                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='http://s7d1.scene7.com/is-viewers/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;
};

// Function: ParentOpener(string, string)
// Purpose: Function to determine which DOM opener to use, and use it
// Param: url is the URL to load
// Param: parentname is the name of the current object's parent
// Output: None, the window is opened
// Notes: No need to call this function explicitly

function  ParentOpener(url,parentname) {
    if(self.opener && !self.opener.closed)
        self.opener.location=url;
    else
        window.open(url,parentname);
}