function jumpTo(view, containerId) {
    var title = document.getElementById(containerId + ':titleInput').value;
    var section = document.getElementById(containerId + ':sectionInput').value;
    
    var substructure = "";
    
    var openparen = section.indexOf("(");
    if (openparen != -1) {
     substructure = section.substring(openparen);
     section = section.substring(0, openparen);
	 for(i=0; i<10; i++){ //up to 10 levels of depth
      substructure = substructure.replace(")(", "_");
	 }
     substructure = substructure.replace("(", "#substructure-location_");
     substructure = substructure.replace(")", "");
	 //alert("Trying to jump to: " + substructure);
    }
    
    
    
    
    var q = '';
    if (section == null || section.replace(/^\s\s*/, '').replace(/\s\s*$/, '') == '') {
        q = '(title:' + title + ' AND granuleclass:FRONTMATTER)&f=documentId';
    }
    else {
        q = '(title:' + title + ' section:' + section +' edition:prelim) OR (granuleid:USC-prelim-title' + title + '-section' + section + ')&f=treesort';
    }

    // Load window preferences from bean.
    var prefs = 'width=800,height=650,left=430,top=23,resizable=1';
    try  {
        // Load window's size/position preferences.
        var winTop = document.getElementById("winTop").value;
        var left = document.getElementById("left").value;
        var width = document.getElementById("width").value;
        var height = document.getElementById("height").value;
        if (!(winTop=="0" && left=="0" && width=="0" && height=="0")) {
            var prefs = "top=" + winTop +
                        ",left=" + left +
                        ",width=" + width +
                        ",height=" + height +
                        ",resizable=1";
        }
    } catch(e) {}
    resized = false;    // Flag to indicate when pop-up was already added.
    
    var link = view + '?req=' + q + '&edition=prelim&num=0&jumpTo=true';
    if(substructure != ""){
        link = link + substructure;
    }
    var popup = window.open(link,'',prefs);
    
    popup.focus();
    return popup;
}

var client=null;    // Keep the JSF client for the "Search for references to"'s form.

// Called when edition is modified in the dropdown.
function setVersion(obj) {
    // Set hidden element queryVersion
    obj.nextSibling.value = obj.options[obj.selectedIndex].value;
    // Set selected version in the standard reference's form.
    if (client && document.getElementById(client+ ":queryVersion2")) {
        document.getElementById(client+ ":queryVersion2").value = obj.nextSibling.value;
    }
}


//**************************** Multiple versions at Browse.xhtml.
// Called from cite_checker to set the menu as selected.
function set_selected_menuItem() {
    try {
        var a = document.getElementById("item_CITE_CHECKER");
        var img = a.children[0].children[0];
        // Replace background image and set the selected background.
        var src = img.src;
        var src2 = src.replace("u6.png", "u29.png");
        img.src = src2;
        var span = a.children[1].children[0].style.color="rgb(0, 0, 0)";
        // Display submenu.
        hide_subMenu("CITE_CHECKER");
    } catch (error) {
        hide_subMenu("CITE_CHECKER");
    }
}

// Get the selected query from top 10 queries's dropdown, and
// load the value into the simple search input text.
function setQuery(obj, input) {
    var inputId = obj.id.replace("versionsSel", "searchInput");
    var input = document.getElementById(inputId);
    input.value = obj.options[obj.selectedIndex].value;
    input.focus();
}

//Get the selected query from top 10 queries's dropdown, and
//load the value into the simple search input text.
function setAdvQuery(selectId, inputId, obj, input) {
    var inputId = obj.id.replace(selectId, inputId);
    var input = document.getElementById(inputId);
    input.value = obj.options[obj.selectedIndex].value;
    input.focus();
}

//Validate that searchInput/searchForInput are not empty, trim whitespaces.
function validateForm() {
    var inputs = document.getElementsByTagName("input");
    var invalidAdvSearch = null;
    var invalidSearchFor = null;
    for (var i=0; i<inputs.length; i++) {
        if (inputs[i].id.indexOf("advSearchInput")>0) {
            var value = inputs[i].value;
            if (value.length>0) {
                var newValue = value.replace(/(^\s*)/g, '');
                invalidAdvSearch = newValue.length==0;
                inputs[i].value = newValue;
            }
        } else if (inputs[i].id.indexOf("searchFor")>0) {
            var value = inputs[i].value;
            if (value.length>0) {
                var newValue = value.replace(/(^\s*)/g, '');
                invalidSearchFor = newValue.length==0;
                inputs[i].value = newValue;
            }
        }
    }
    if (invalidAdvSearch && (invalidSearchFor==null || invalidSearchFor))
        return false;
    return true;
}

// Set cells in blank in cite checker updates table if results not found.
function citeCheckerTableDefault() {
    try {
        var a = document.getElementsByTagName("table");
        if (a[0].id.indexOf("updatesTable")!=-1) {
           var table = a[0];
           var tbody = table.tBodies[0];
           if (tbody.rows[0].cells.length==1) {
              var y = document.createElement('td');
              y.innerHTML="&nbsp;";
              tbody.rows[0].appendChild(y);

              y = document.createElement('td');
              y.innerHTML="&nbsp;";
              tbody.rows[0].appendChild(y);

              y = document.createElement('td');
              y.innerHTML="&nbsp;";
              tbody.rows[0].appendChild(y);

              y = document.createElement('td');
              y.innerHTML="&nbsp;";
              tbody.rows[0].appendChild(y);

              y = document.createElement('td');
              y.innerHTML="&nbsp;";
              tbody.rows[0].appendChild(y);

              y = document.createElement('td');
              y.innerHTML="&nbsp;";
              tbody.rows[0].appendChild(y);

              y = document.createElement('td');
              y.innerHTML="&nbsp;";
              tbody.rows[0].appendChild(y);
           }
        }
    } catch (e) {}
}

// Based on searchString get the title/section and set input field's values.
function loadTextValues(searchString, title, section) {
    try {

        // Search the inputs for title and section.
        var titleId="";
        var sectionId="";
        var inputs = document.getElementsByTagName("input");
        for (var i=0; i<inputs.length; i++) {
            if (inputs[i].name.indexOf("title")!=-1) {
                titleId = inputs[i].name;
            } else if (inputs[i].name.indexOf("section")!=-1) {
                sectionId = inputs[i].name;
                break;
            }
        }

        // Exit if searchstring not defined.
        if (!searchString) {
            document.getElementById(titleId).focus();
            return;
        }

        // Set the text of the title and section.
        if (document.getElementById(titleId)) {
            document.getElementById(titleId).value = title.replace(" ","");
        }
        if (document.getElementById(sectionId)) {
            document.getElementById(sectionId).value = "";
            document.getElementById(sectionId).focus();
            // Set cursor after last value.
            document.getElementById(sectionId).value = document.getElementById(sectionId).value + section;
        }
    } catch(e) {}
}