function openpopup(url, menubar, width, height) {
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var _newWindow = null;
    //    alert("width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1");
    if (menubar) {
        _newWindow = window.open(url, "_blank", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1");
    } else {
        _newWindow = window.open(url, "_blank", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0");
    }
    //    center(_newWindow);
    _newWindow.focus();

}

function center(_window) {
    _window.moveBy(((screen.width - _window.width) / 2,(screen.height - _window.height) / 2));
}

function maximize() {
    window.moveTo(0, 0);
    window.resizeTo(screen.width, screen.height);
}


function hideShow(divid, hide, show, showmaindiv) {
    var divhide = document.getElementById(divid + hide);
    var divshow = document.getElementById(divid + show);

    divhide.style.display = 'none';
    divshow.style.display = 'none';

    if (showmaindiv) {
        divshow.style.display = '';
        divhide.style.display = 'none';
    } else {
        divshow.style.display = '';
        divhide.style.display = 'none';
    }
}


function updateMicroficheNumber(url, archiveId, microficheId, frameId, infoId, infocmicid) {
    var archive = document.getElementById(archiveId);
    var mic = document.getElementById(microficheId);
    var frame = document.getElementById(frameId);
    var spaninfo = document.getElementById(infoId);
    spaninfo.innerHTML = '';
    var spanmicinfo = document.getElementById(infocmicid);
    spanmicinfo.innerHTML = '';
    if (mic.value != '' && frame.value != '') {

    } else {
        mic.value = "";
        frame.value = "";
    }
    var query = 'archive=' + escape(archive.value);
    xmlhttpPost(url, infoId, query);
}

function updateFrame(url, archiveId, microficheId, frameId, infoId) {
    var archive = document.getElementById(archiveId);
    var mic = document.getElementById(microficheId);
    var frame = document.getElementById(frameId);
    if (frame.value != '' && mic.value != '') {

    } else {
        frame.value = "";
        if (mic.value == '') return;
    }
    var query = 'archive=' + escape(archive.value) + '&' + 'microfiche=' + escape(mic.value);
    xmlhttpPost(url, infoId, query);
}


var mid;
var xmlHttpReq = false;
function xmlhttpPost(strURL, id, query) {

    this.mid = id;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    strURL = strURL + '?' + query;
    xmlHttpReq.open('GET', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = updateInfo;
    self.xmlHttpReq.send(null);
}

function updateInfo() {
    if (xmlHttpReq.readyState == 4) {
        var input = document.getElementById(mid);
        input.innerHTML = xmlHttpReq.responseText;
    }
}

function reloadParent() {
    opener.location.reload();
}

function reloadPage() {
    setTimeout('window.location.reload()', 3000);
}

function refreshParent() {
    if (window.opener.document.location)
        window.opener.document.location.refresh();
}

function deactivateCheckboxes(sourceCheckbox) {
    var markCheckboxes = getElementsByClass("markCheckbox");
    if (markCheckboxes != null && (markCheckboxes.length > 0)) {
        var i;
        for (i = 0; i < markCheckboxes.length; i++) {
            if (markCheckboxes[i] != sourceCheckbox && markCheckboxes[i].checked == false) {
                markCheckboxes[i].disabled = true;
            }
        }
    }
}

function bookmarkPage(url, title) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) {
        window.external.AddFavorite(url, title);
    } else if (window.opera && window.print) {
        // Nothing to do here
    }
    var t = setTimeout("window.close();", 10000);
    return true;
}

