var contextPath = "/solution";

function MM_goToURL() { //v3.0
    var i, args = MM_goToURL.arguments;
    document.MM_returnValue = false;
    for (i = 0; i < (args.length - 1); i += 2) {
        eval(args[i] + ".location='" + args[i + 1] + "'");
    }
}
function setCheckedContainName(form, chkName, val) {
    dml = document.forms[form];
    len = dml.elements.length;
    for (i = 0; i < len; i++) {
        if (dml.elements[i].id != null && dml.elements[i].id != "" && dml.elements[i].id.indexOf(chkName) == 0) {
            dml.elements[i].checked = val;
        }
    }
}
function setChecked(form, chkName, val) {
    dml = document.forms[form];
    len = dml.elements.length;
    for (i = 0; i < len; i++) {
        if (dml.elements[i].id != null && dml.elements[i].id != "" && dml.elements[i].id == chkName) {
            dml.elements[i].checked = val;
        }
    }
}
function openListManagerWindow(winName, factoryName, ids, foreignForm, foreignAttributeCallBack) {
    var url = contextPath + "/list-manager.do?fct=" + factoryName + "&ids=" + ids;
    win = window.open(url, winName, "width=370, height=340");
    win.foreignForm = foreignForm;
    win.foreignAttributeCallBack = foreignAttributeCallBack;
    win.focus();
}
function openListFormManagerWindow(winName, factoryName, elements, foreignForm, foreignAttributeCallBack) {
    var url = contextPath + "/list-form-manager.do?lff=" + factoryName + "&elements=" + elements;
    win = window.open(url, winName, "width=370, height=340");
    win.foreignForm = foreignForm;
    win.foreignAttributeCallBack = foreignAttributeCallBack;
    win.focus();
}
function openTermsOfUseWindow(url) {
    win = window.open(url, "popup_terms", "toolbar=no,menubar=no,scrollbars=no,resizable=no,width=520,height=532");
    win.focus();
}
function openPrintDetailPreviewWindow(winName, url) {
    win = window.open(url, winName, "toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes");
    win.focus();
}
function openShowImageWindow(winName, url) {
    win = window.open(url, winName, "toolbar=no,menubar=no,scrollbars=no,resizable=no,width=520,height=577");
    win.focus();
}
function openMediaPlayerWindow(winName, url) {
    win = window.open(url, winName);
    win.focus();
}
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) {
        x.src = x.oSrc;
    }
}
function MM_preloadImages() { //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) {
            d.MM_p = new Array();
        }
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++) {
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
        }
    }
}
function MM_findObj(n, d) { //v4.01
    var p, i, x;
    if (!d) {
        d = document;
    }
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) {
        x = d.all[n];
    }
    for (i = 0; !x && i < d.forms.length; i++) {
        x = d.forms[i][n];
    }
    for (i = 0; !x && d.layers && i < d.layers.length; i++) {
        x = MM_findObj(n, d.layers[i].document);
    }
    if (!x && d.getElementById) {
        x = d.getElementById(n);
    }
    return x;
}
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3) {
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) {
                x.oSrc = x.src;
            }
            x.src = a[i + 2];
        }
    }
}
function changeVideoTrailerState(videoTrailerId, videoTrailerState) {
    changeFormProperty("searchResultForm", "videoTrailerId", videoTrailerId);
    changeFormProperty("searchResultForm", "videoTrailerState", videoTrailerState);
    doPostBack("searchResultForm", "changeVideoTrailerStateAction");
}
function changeCatalogListingState(catalogListingId, catalogListingState) {
    changeFormProperty("searchResultForm", "catalogListingId", catalogListingId);
    changeFormProperty("searchResultForm", "catalogListingState", catalogListingState);
    doPostBack("searchResultForm", "changeCatalogListingStateAction");
}
function preloadImages() {
    MM_preloadImages("http://www.ipexview.com/images/bt_buy_on.gif", "http://www.ipexview.com/images/bt_addnew_on.gif", "http://www.ipexview.com/images/bt_account_on.gif", "http://www.ipexview.com/images/bt_myipextv_on.gif", "http://www.ipexview.com/images/bt_listings_on.gif", "http://www.ipexview.com/images/bt_login_on.gif", "http://www.ipexview.com/images/bt_join_on.gif", "http://www.ipexview.com/images/bt_contact_on.gif", "http://www.ipexview.com/images/bt_help_on.gif", "http://www.ipexview.com/images/bt_go_on.gif", "http://www.ipexview.com/images/bt_searchtips_on.gif", "http://www.ipexview.com/images/bt_advanced_on.gif", "http://www.ipexview.com/images/bt_signout_on.gif", "http://www.ipexview.com/images/bt_admin_on.gif", "http://www.ipexview.com/images/bt_requests_new_on.gif", "http://www.ipexview.com/images/bt_requests_on.gif", "http://www.ipexview.com/images/arrow_next_on.gif", "http://www.ipexview.com/images/arrow_nextend_on.gif", "http://www.ipexview.com/images/arrow_previous_on.gif", "http://www.ipexview.com/images/arrow_previousstart_on.gif", "http://www.ipexview.com/images/bt_blog_on.gif");
}
function openShowVideoTrailerClipWindow(winName, vt) {
    var url = contextPath + "/show-video-trailer-clip.do?vt=" + vt;
    win = window.open(url, winName, "width=490, height=400, resizable=yes");
    win.focus();
}
function $() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == "string") {
            element = document.getElementById(element);
        }
        if (arguments.length == 1) {
            return element;
        }
        elements.push(element);
    }
    return elements.length != 0 ? elements : null;
}
function filterByPortfolio(selectedPortfolioId) {
    changeFormProperty("searchResultForm", "portfolioId", selectedPortfolioId);
    doPostBack("searchResultForm", "filterByPortfolioAction");
}
function processCarriageReturn(textareaId) {
    replaceWith = "<br>";
    textarea = document.getElementById(textareaId);
    textarea.value = escape(textarea.value);
    for (i = 0; i < textarea.value.length; i++) {
        if (textarea.value.indexOf("%0D%0A") > -1) {
            textarea.value = textarea.value.replace("%0D%0A", replaceWith);
        } else {
            if (textarea.value.indexOf("%0A") > -1) {
                textarea.value = textarea.value.replace("%0A", replaceWith);
            } else {
                if (textarea.value.indexOf("%0D") > -1) {
                    textarea.value = textarea.value.replace("%0D", replaceWith);
                }
            }
        }
    }
    textarea.value = unescape(textarea.value);
}
function escapeTextArea(textareaId) {
    textarea = document.getElementById(textareaId);
    textarea.value = escape(textarea.value);
}
function unescapeTextArea(textareaId) {
    textarea = document.getElementById(textareaId);
    textarea.value = unescape(textarea.value);
}
function openFeaturedProductionOrderManagerWindow(winName, foreignForm, foreignAttributeCallBack) {
    var url = contextPath + "/featured-productions-order-manager.do";
    win = window.open(url, winName, "width=370, height=340");
    win.foreignForm = foreignForm;
    win.foreignAttributeCallBack = foreignAttributeCallBack;
    win.focus();
}
function changeOrganizationState(catalogListingId, catalogListingState) {
    changeFormProperty("organizationList", "catalogListingId", catalogListingId);
    changeFormProperty("organizationList", "catalogListingState", catalogListingState);
    doPostBack("organizationList", "changeOrganizationStateAction");
}
function orderBy(form, field) {
    var orderFieldValue = retrieveFormProperty(form, "orderby");
    var ascFieldValue = retrieveFormProperty(form, "asc");
    
    if (orderFieldValue == field) {
        if (ascFieldValue == 'true') {
            changeFormProperty(form, "asc", 'false');
        }
        else {
            changeFormProperty(form, "asc", 'true');
        }
    }
    else {
        changeFormProperty(form, "asc", 'true');
    }
    changeFormProperty(form, "orderby", field);
    
    doPost(form);
}
//Insert listing
function openUploadResourceWindow(winName, url, callBack) {
    win = window.open(url, winName, "toolbar=no,menubar=no,resizable=no,width=520,height=400");
    win.callBack = callBack;
    win.focus();
}
function openListingEditorHelpWindow(anchor) {
    url = contextPath + "/dynamic-content.do?url=help_text/listings_manager_help.html#" + anchor;
    win = window.open(url, "listing_editor_help", "toolbar=no,menubar=no,scrollbars=yes,resizable=no,width=536,height=532");
    win.focus();
}
function openListingEditorResourceHelpWindow(url, params) {
    url = contextPath + "/dynamic-content.do?url=" + url;
    win = window.open(url, "listing_editor_help", params);
    win.focus();
}
function openCheckTrailerSpace(winName, url, callBack) {
    win = window.open(url, winName, "toolbar=no,menubar=no,scrollbars=no,resizable=no,width=520,height=260");
    win.callBack = callBack;
    win.focus();
}

function openABook(winName, url) {
    win = window.open(url, winName, "toolbar=no,menubar=no,scrollbars=yes,resizable=no,width=470,height=430");
    win.focus();
}
