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(product_url) {
    loadProductPW(product_url);
}

function loadProductPW(product_url) {
    product_url = fixURL(product_url);
    var theParent = parent.window.opener;
    try {
        if ((theParent != null)
                && (theParent.location != null)
                && !theParent.closed) {
            theParent.location = product_url;
            theParent.focus();
            return;
        }
    } catch (errorInfo) {}

    fixUrl = false;
    loadProductNW(product_url,false);
    fixUrl = true;
}

function loadProductCW(product_url) {
    product_url = fixURL(product_url);
    document.location = product_url;
}

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(currentFrame) {
    alert("feedback for frame " + currentFrame);
}

function reload(enlargeState, currentFrame) {
    document.location = document.location.pathname + "?" + reloadParams + "&el=" + enlargeState;
}

function onProductIconClick() {
    loadProductPW(productIconURL);
}

function onLogoClick() {
    if(logoClickURL != '')
        loadProductPW(logoClickURL);
}

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 = "";
            document.frmState.submit();
        }
    }
}

function openPrivacy() {
    var html = privacyCopy;
    newWin = window.open("","privacy","width=" + privacyWindowWidth + ",height=" + privacyWindowHeight);
    newWin.document.write(html);
    newWin.document.close();
}

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 (v)
        {
            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(name) {
    if (document.getElementById && document.getElementById(name))
        return document.getElementById(name).style;
    if (document.all && document.all[name])
        return document.all[name].style;
    if (document.layers)
        return document[name];
}


function goToPage(page) {
    setFlashParam(instance, "currentFrame", page);
}


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://s7d2.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 docWrite(line) {
    document.write(line);
}

function  ParentOpener(url,parentname) {
    if(self.opener && !self.opener.closed)
        self.opener.location=url;
    else
        window.open(url,parentname);
}