﻿var action = 'kw';
function getQueryStringKeyValue(key) {
    if (window.location.search) {
        qs = window.location.search.substring(1);
        keys = qs.split("&");
        for (i = 0; i < keys.length; i++) {
            keyValue = keys[i].split("=");
            if (keyValue[0] == key) {
                return keyValue[1];
            }
        }
    }
    return "";
}



indent = 0;
btn = 0;
y1 = 0; x1 = 0;
function mouseDown(e) {
    e = e || event;
    btn = 0;
    if (e.which) { btn = e.which; }
    else if (e.button) { btn = e.button; }
    if (btn == 1) {
        x1 = e.offsetX;
        y1 = e.offsetY;
    }
}

function mouseUp(e) {
    btn = 0;
}

function mouseMove(e) {
    e = e || event;
    var x2, y2, x, y;
    if (e.x) {
        x2 = e.x;
        y2 = e.y;
    } else {
        x2 = e.clientX;
        y2 = e.clientY;
    }

    if (btn == 1) {
        $get('authorityTitle').focus();
        $get('authorityDiv').style.posLeft = x2 - x1 - 5;
        $get('authorityDiv').style.posTop = y2 - y1 - 10;
    }
}


function onResixeWindows() {
    setHeight(); 
}

function setHeight() {
    var h = getBrowserHeight();
    if (h > 0) {
        $get('mainTd').style.height = h + 'px';
        try {
            $get('Navigation').style.height = (h - $get('topData').offsetHeight - $get('tabsDiv').offsetHeight + 5) + 'px';
            $get('leftPanel').style.height = (parseInt($get('Navigation').style.height) - $get('tabsDiv').offsetHeight - 20) + 'px';
            $get('dataDiv').style.height = (h - $get('tableID').offsetHeight - $get('tableID').offsetTop - 30) + 'px';
        } catch (Error) {
        }
    }
}

function showCredits() {
    var h = document.documentElement.clientHeight;
    var w = parseInt($get('sideTD').clientWidth) + parseInt($get('leftPanel').clientWidth + $get('dataDiv').clientWidth + 15) - 200;
    $get('CreditsDisplay').style.width =  '200px';
    $get('CreditsDisplay').style.top = (h - 80) + 'px';
    $get('CreditsDisplay').style.left = (w)  + 'px';
   // $get('CreditsDisplay').innerHTML = 'h=' + h + ' w=' + w;
    $get('CreditsDisplay').style.display = 'block';
}


function getBrowserHeight() {
    var winH;
    if (self.innerWidth) {
        winH = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientWidth) {
        winH = document.documentElement.clientHeight;
    } else if (document.body) {
        winH = document.body.clientHeight;
    }
    return winH;
}

function getBrowserWidth() {
    var winW;
    if (self.innerWidth) {
        winW = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth) {
        winW = document.documentElement.clientWidth;
    } else if (document.body) {
        winW = document.body.clientWidth;
    }

    return winW;
}

GetWidth = function(elem) {
    function _Convert(val) {
        if (!val) { return; }
        val = val.replace("px", "");
        if (isNaN(val)) { return 0; }
        return parseInt(val);
    }
    var currentStyle;
    if (elem.currentStyle) { currentStyle = elem.currentStyle; }
    else if (window.getComputedStyle) { currentStyle = document.defaultView.getComputedStyle(elem, null); }
    else { currentStyle = elem.style; }
    return (elem.offsetWidth -
		_Convert(currentStyle.marginLeft) -
		_Convert(currentStyle.marginRight) -
		_Convert(currentStyle.borderLeftWidth) -
		_Convert(currentStyle.borderRightWidth));
}


GetHeight = function(elem) {
    function _Convert(val) {
        if (!val) { return; }
        val = val.replace("px", "");
        if (isNaN(val)) { return 0; }
        return parseInt(val);
    }
    var currentStyle;
    if (elem.currentStyle) { currentStyle = elem.currentStyle; }
    else if (window.getComputedStyle) { currentStyle = document.defaultView.getComputedStyle(elem, null); }
    else { currentStyle = elem.style; }
    return (elem.offsetHeight -
		_Convert(currentStyle.marginTop) -
		_Convert(currentStyle.marginBottom) -
		_Convert(currentStyle.borderTopWidth) -
		_Convert(currentStyle.borderBottomWidth));
}


function reloadPage(langid) {
    window.location.href = "http://" + location.host + location.pathname + changeQueryStringValue("langID", langid);
}

function loadPage(id) {
    window.location.href = "http://" + location.host + location.pathname + "?langID=" + getQueryStringKeyValue("langID");
}

function onFail(result) {
    alert(result._message);
}

function changeQueryStringValue(key, value) {
    findIt = false;
    newqs = "?";
    if (window.location.search) {
        qs = window.location.search.substring(1);
        keys = qs.split("&");
        for (i = 0; i < keys.length; i++) {
            keyValue = keys[i].split("=");
            if (keyValue[0] == key) {
                keyValue[1] = value;
                findIt = true;
            }
            if (i > 0) { newqs += "&"; }
            newqs += (keyValue[0] + "=" + keyValue[1]);
        }
        if (!findIt) { newqs += ("&" + key + "=" + value); }
    } else { newqs += (key + "=" + value); }
    return newqs;
}

function getQweryString() {
    var qs;
    qs = "?langID=" + $get('langID').value +
                    "&OrderID=" + $get('changeOrder').value +
                    "&NbReturnObjects=" + $get('nbResultByPage').value +
                    "&NewResult=" + $get('newResult').value +
                    "&quickSearchValue=" + getSearchKeywordOption() + "!$!" +
                    $get('searchBox').value;
    return qs;
}


function showLeftPanel(tab, panelName) {
    var tabsDiv = $get('tabsDiv');
    var leftDiv = $get('leftPanel');
    for (i = 0; i < tabsDiv.childNodes.length; i++) {
        if (tabsDiv.childNodes[i].nodeType == 1) {
            tabsDiv.childNodes[i].style.borderBottomColor = 'Black';
            tabsDiv.childNodes[i].style.color = '#9f9e9e';
        }
    }
    for (i = 0; i < leftDiv.childNodes.length; i++) {
        if (leftDiv.childNodes[i].className == 'leftPanelOn') {
            leftDiv.childNodes[i].className = 'leftPanelOff';
        }
    }

    c = '#eeeeee';
    tab.style.color = '#eeeeee';
    tab.style.borderBottomColor = '#363636';
    $get(panelName).className = 'leftPanelOn';

    if (tab.id == 'archiveTab') {
        if ($get('DataTable').rows.length == 0) {
            setWhiteToolBar($get('trArchive'), $get('trPaging'));
            GetArchivesSynopsisWs();
        }
    }
}


function SuggestionClick(e) {
    if (e.id == 'suggestion') {
        $get('hitBoxrightT').style.left = ($get('sideTD').offsetWidth + $get('leftTD').offsetWidth + $get('TextBoxQuickSearch').offsetLeft) + 'px';
        $get('hitBoxrightT').style.top = ($get('topData').offsetHeight + $get('searchTr').offsetHeight) + 'px';
        $get('hitBoxrightT').style.display = 'block';
    } else {
    $get('hitBoxrightT').style.display = 'none';
    }
}


function DisplayHint(event) {
    if (event.keyCode != 13) {
        if ($get('suggestion').checked) {
            action = 'auth'
            isAuthority = true;
            SuggestionClick($get('suggestion'));
            Gel.CollectionObject.GetKeyWordsHint($get('TextBoxQuickSearch').value, SetHintBox, onFail);
        }
    } else {

        var values = $get('TextBoxQuickSearch').value.split("=");
        if (values.length > 1) {
            switch (values[0]) {
                case "pkg": action = 'pkg';
                    page = $get('page').value;
                    Sys.Application.addHistoryPoint(
                    { s: values[1], p: $get('page').value, a: action, nr: 1 }, values[1]);
                    break;
            }
        } else {
            action = 'kw'
            isAuthority = false;
            getCcaObjects($get('TextBoxQuickSearch').value, true);
        }
    }
        
}

function SetHintBox(KeyWordsHints) {
    innerHtmlConstituents = "";
    innerHtmlSujets = "";
    innerHtmlPublications = "";
    innerHtmlExhibitions = "";
    if (KeyWordsHints.length > 0) {
        for (i = 0; i < KeyWordsHints.length; i++) {
            switch (KeyWordsHints[i].authorityType) {
                case 2: innerHtmlSujets += getDisplayGetAuthorityObjectSpan(KeyWordsHints[i].ID, 3, KeyWordsHints[i].authorityType, KeyWordsHints[i].Hint, KeyWordsHints[i].DisplayHint, true);
                    break;
                case 3: innerHtmlConstituents += getDisplayGetAuthorityObjectSpan(KeyWordsHints[i].ID, 3, KeyWordsHints[i].authorityType, KeyWordsHints[i].Hint, KeyWordsHints[i].DisplayHint, true);
                    break;
                case 10: innerHtmlPublications += getDisplayGetAuthorityObjectSpan(KeyWordsHints[i].ID, 3, KeyWordsHints[i].authorityType, KeyWordsHints[i].Hint, KeyWordsHints[i].DisplayHint, true);
                    break;
                case 11: innerHtmlExhibitions += getDisplayGetAuthorityObjectSpan(KeyWordsHints[i].ID, 3, KeyWordsHints[i].authorityType, KeyWordsHints[i].Hint, KeyWordsHints[i].DisplayHint, true);
                    break;
            }
        }
    }
    $get('hitConstituents').innerHTML = innerHtmlConstituents;
    $get('hitSubjects').innerHTML = innerHtmlSujets;
   // $get('hitPublications').innerHTML = innerHtmlPublications;
   // $get('hitExhibitions').innerHTML = innerHtmlExhibitions;
}

function getDisplayGetAuthorityObjectSpan(id, langID, typeID, displayInFunction, displayValue, AddValueToHistory) {
    innerHtml = "<span class='constituentLink2'";
    innerHtml += " onmouseover='c=this.style.color;this.style.color=";
    innerHtml += ' "#2be62b"';
    innerHtml += "'";
    innerHtml += " onmouseout='this.style.color=c'";
    innerHtml += " onclick='GetAuthorityObjects(" + id + "," + typeID + ",\"" + displayInFunction.replace("'", "&#39").replace("\"", "&#34;") + "\"," + AddValueToHistory + ")'>";
    innerHtml += displayValue + "</span><br/>";
    return innerHtml;
}

function deleteAllTableRow(tableName) {
    for (var i = tableName.rows.length - 1; i >= 0; i--) {
        tableName.deleteRow(i);
    }
}

function getImageOnlyValue() {
    if ($get('imageOnly').checked) {
        return 1;
    }
    return 0;
}

function hideLoadingGif(hide) {
    if (hide) {
        $get('loadingGif').style.display = 'none';
    } else {
        $get('loadingGif').style.display = 'block';
    }
}

function getSortOrder() {
    var sortRadio = document.getElementsByName("sortr");
    for (i = 0; i < sortRadio.length; i++) {
        if (sortRadio[i].checked) {
            return sortRadio[i].value;
        }
    }
}


var nbShowPage = 8;
function setPaging(page, pageSize, nbResults) {
    var nbPages = Math.ceil(nbResults / pageSize);
    var fdp, fp, lp = 0, ldp = 0;

    if (nbPages < nbShowPage) {
        fdp = '';
        fp = 1;
        lp = nbPages;
        ldp = '';
    } else if (page >= (nbPages - (nbShowPage / 2))) {
        lp = nbPages;
        lpd = '';
        fpd = 1;
        fp = nbPages - nbShowPage;
    } else if (page <= (nbShowPage / 2)) {
        lpd = nbPages;
        fdp = '';
        lp = nbShowPage;
        fp = 1;
    } else {
        lpd = nbPages;
        fpd = 1;
        lp = parseInt(page) + (nbShowPage / 2);
        fp = lp - nbShowPage;
    }

    if (page == 1) {
        $get('leftPaging').style.visibility = "hidden";
    } else {
        $get('leftPaging').style.visibility = "visible";
    }

    if (page == nbPages) {
        $get('rightPaging').style.visibility = "hidden";
    } else {
        $get('rightPaging').style.visibility = "visible";
    }
    

    var strPages = "";
    for (i = fp; i <= lp; i++) {
        if (i == page) {
            strPages += '<span class="pagingPageHit"';
        } else {
            strPages += '<span class="pagingPage"';
        }
        strPages += ' onmouseover="c=this.style.color;this.style.color=' + "'#2be62b';" + '" onmouseout="this.style.color=c;" ';
        strPages += ' onclick="changePages(' + i + ')">' + i + '</span>';
    }
    $get('paging').innerHTML = strPages;
}


function getResult() {
    var value = $get('TextBoxQuickSearch').value;
    var values = value.split("=");
    if (values.length > 1) {
        switch (values[0]) {
            case "pkg": action = 'pkg';
                page = $get('page').value;
                Sys.Application.addHistoryPoint(
                    { s: values[1], p: $get('page').value, a: action, nr: 1 }, values[1]);
                break; 
        }
    } else {
        action = 'kw'
        isAuthority = false;
        getCcaObjects($get('TextBoxQuickSearch').value, true);
    }
}

function getCcaObjectsWS(value) {
    setWhiteToolBar($get('trPaging'), $get('trArchive'));
    $get('hitBoxrightT').style.display = 'none';
    deleteAllTableRow($get('DataTable'));
    hideLoadingGif(false);
    showLeftPanel($get('historicalTab'), 'historiqueDiv')

    Gel.CollectionObject.GetJSONCcaObjects(value,
            $get('session').value, getSortOrder(),
            $get('nbResultsByPage').value,
            $get('page').value, 
            parseInt($get('NewQuery').value),
            $get('NewResult').value,
            $get('searchArchiveOnly').value,
            getImageOnlyValue(),
            displayResultObjects, onFail);
}


function getCcaPackageObjectsWS(value) {
    setWhiteToolBar($get('trPaging'), $get('trArchive'));
    $get('hitBoxrightT').style.display = 'none';
    deleteAllTableRow($get('DataTable'));
    hideLoadingGif(false);
    showLeftPanel($get('historicalTab'), 'historiqueDiv')

    Gel.CollectionObject.GetJSONCcaPackageObjects(value,
            $get('session').value, getSortOrder(),
            20,
            $get('page').value, 
            parseInt($get('NewQuery').value),
            displayResultObjects, onFail);
}



function getCcaObjects(value, addValueToHistorique, fromHistPoint) {
    $get('hitBoxrightT').style.display = 'none';
    if (addValueToHistorique &(getQueryStringKeyValue('page').length  == 0)) {
        $get('page').value = "1";
        $get('NewResult').value = "1";
        $get('NewQuery').value = "1";
    }
    page = $get('page').value;
    var nres = $get('NewResult').value;
    var nque = $get('NewQuery').value;
    Sys.Application.addHistoryPoint(
         { s: value + '', p: page, a: action, nr: nres, nq: nque },value);
    if (addValueToHistorique) {
        addHistorique(value, 1, 0);
    }
}



function objectMouseOver(table) {
    table.className = 'objectHeaderTBodyHover';
}
function objectMouseOut(table) {
    table.className = 'objectHeaderTBody';
}

function getNewParagraph(t, classN) {
    var p = document.createElement('p'); ;
    p.className = classN;
    p.innerHTML = t;
    return p;
}

function setEntryPage() {
    if (getQueryStringKeyValue('query').length > 0) {

        $get('TextBoxQuickSearch').value = getQueryStringKeyValue('query');

        if (getQueryStringKeyValue('page').length > 0) {
            $get('page').value = getQueryStringKeyValue('page');
        }
        var limit = getQueryStringKeyValue('limit');
        action = 'kw';
        page = $get('page').value;
        if (limit.length > 0) {
            if (limit == "5") {
                var np = Math.ceil((parseInt(page) * parseInt(limit)) / 20);
                page = np;
                $get('page').value = page;
                limit = 20;
                
            }

            $get('nbResultsByPage').value = limit;
        }

       
        Sys.Application.addHistoryPoint(
         { s: $get('TextBoxQuickSearch').value, p: $get('page').value, a: action, nr: 1, nq: 1 }, $get('TextBoxQuickSearch').value);


       // getCcaObjectsWS(getQueryStringKeyValue('query'), true);
    } else if (getQueryStringKeyValue('pkg').length > 0) {
        $get('TextBoxQuickSearch').value = 'pkg=' + getQueryStringKeyValue('pkg');
        if (getQueryStringKeyValue('page').length > 0) {
            $get('page').value = getQueryStringKeyValue('page');
        }
        action = 'pkg';
        page = $get('page').value;
        Sys.Application.addHistoryPoint(
         { s: getQueryStringKeyValue('pkg'), p: $get('page').value, a: action }, getQueryStringKeyValue('pkg'));
        getCcaPackageObjectsWS(getQueryStringKeyValue('pkg'), true);
    } else if (location.hash.length > 0) {
        var historyPoint;
        var a_, s_, p_ = 1, nr_ = 1, nq_ = 1;

        historyPoints = location.hash.replace(/#/g, '');
        historyPoints = historyPoints.split('&');
        for (var n in historyPoints) {
            var point = historyPoints[n].split('=');
            switch (point[0]) {
                case 'a': a_ = point[1]; break;
                case 'nr': nr_ = point[1]; break;
                case 'p': p_ = point[1]; break;
                case 'nq': nq_ = point[1]; break;
                case 's': s_ = point[1]; break;
            }
        }
        Sys.Application.addHistoryPoint({ a: a_, nr: nr_, p: p_, nq: nq_, s: s_ },s_);
    }
}

function getNewLinkLine(element,onClique,label,className,id){
    var e = document.createElement(element);
    innerHtml = '<' + element + ' class="' + className + '" onclick="' + onClique + '"';
    if (id) {
        innerHtml += ' id=' + id;
    }
    innerHtml += ' onmouseover = "this.style.color=' + "'#2be62b';" + '"';
    innerHtml += ' onmouseout = "this.style.color=' + "'#363636';";
    innerHtml += '">' + label + '</' + element + '>';
    e.innerHTML = innerHtml
    return e;
}

function changePages(page) {
    $get('page').value = page;
    $get('NewQuery').value = 2;
    $get('NewResult').value = 0;

    switch (action) {
        case 'auth':
            GetAuthorityObjects(AutorityID, AuthorityTypeID,AuthorityDisplay, false, false);
            break;
        case 'kw':
            getCcaObjects($get('TextBoxQuickSearch').value, false);
            break;
        case 'pkg':
            getCcaPackageObjectsWS($get('TextBoxQuickSearch').value.split("=")[1]);
            break;
    }
}


function changeImageOnly() {
    $get('page').value = "1";
    $get('NewQuery').value = 1;
    $get('NewResult').value = 1;
    switch (action) {
        case 'auth':
            GetAuthorityObjects(AutorityID, AuthorityTypeID, AuthorityDisplay, false, false);
            break;
        case 'kw':
            getCcaObjects($get('TextBoxQuickSearch').value, false);
            break;
    }
}

function sortResults() {
    $get('page').value = "1";
    $get('NewQuery').value = 2;
    $get('NewResult').value = 1;
    switch (action) {
        case 'auth':
            GetAuthorityObjects(AutorityID, AuthorityTypeID, AuthorityDisplay, false, false);
            break;
        case 'kw':
            getCcaObjects($get('TextBoxQuickSearch').value, false);
            break;
    }
}

function nextPage(np) {
    $get('page').value = (parseInt($get('page').value) + np);
    $get('NewQuery').value = 2;
    $get('NewResult').value = 1;
    switch (action) {
        case 'auth':
            GetAuthorityObjects(AutorityID, AuthorityTypeID, AuthorityDisplay, false, false);
            break;
        case 'kw':
            getCcaObjects($get('TextBoxQuickSearch').value, false);
            break;
    }
}



function copyDataToPrintTable()
{

    var temp = $get('printDiv');
    temp.innerHTML = '<table id="printTable">' + $get('DataTable').innerHTML + '</table>';

}


function displayResultObjects(ccaObjects) {
    hideLoadingGif(true);
    if (ccaObjects.length > 0) {
        $get('nbresults').innerHTML = ccaObjects[0].NbResults;

        setPaging($get('page').value, $get('nbResultsByPage').value, ccaObjects[0].NbResults);
        for (k = 0; k < ccaObjects.length; k++) {
            addCCAobject(ccaObjects[k], ccaObjects[k].ObjectID, k);
        }
    }
    else {
        $get('nbresults').innerHTML = "0";
    }

    if (expandDetail) {
        expandDetail = false;
       GetObjectDetail(ccaObjects[0].ObjectID, 'objectDetailTBody' + ccaObjects[0].ObjectID, '1');
   }

   copyDataToPrintTable();

  // var data = $get('dataDiv');
   //var ifr = $get('printIframe');
  

}


function addCCAobject(ccaObject, ID, line) {
    var parentContainer = $get('DataTable').insertRow(-1).insertCell(-1);
    var containers = new ObjectsTable(ccaObject.ObjectID);
    containers.Parent = parentContainer;
    containers.IsFromArchive = false;
    containers.FillWithObject(ccaObject);
    containers = null; 
}



function AddToSelection(objectID, objectTitle, imagePath, objectNumber, tableName) {
    showLeftPanel($get('selectionTab'), 'selectionDiv');
    var selectionTable = $get(tableName);
    var tr = selectionTable.insertRow(-1);
    tr.className = 'SelectionobjectHeaderTBody';
    tr.id = '_S_' + objectID;
    cTtitle = tr.insertCell(-1);
    if (imagePath != 'null') {
        var thumbnail = document.createElement('img');
        thumbnail.className = 'SelectionthumbNailImg';
        thumbnail.src = imagePath;
        cTtitle.appendChild(thumbnail);
        thumbnail.onclick = function() {
        window.open("http://svrdam.cca.qc.ca/ZooMI/Default.aspx?obj=" + objectNumber, "ZoomImage", "scrollbars=no,menubar=no,toolbar=0,width=1000,height=620");
        };
        thumbnail.alt = objectNumber;
    }
    cTtitle.className = 'selectionTitleCell';
    var par = getNewParagraph(objectTitle, 'SelectionP');
    par.onclick = function() { 
        getCcaObjectByIDWS(objectID); 
    }
    
    cTtitle.appendChild(par);
}




function GetAuthorityObjectsWs(id, authorityTypeID) {
    setWhiteToolBar($get('trPaging'), $get('trArchive'));
    showLeftPanel($get('historicalTab'), 'historiqueDiv');
    setWhiteToolBar($get('trPaging'), $get('trArchive'));
    deleteAllTableRow($get('DataTable'));
    hideLoadingGif(false);
    isAuthority = true;
    AutorityID = id;
    AuthorityTypeID = authorityTypeID;

    Gel.CollectionObject.GetAuthorityObjects2(
        id,
        authorityTypeID,
        $get('session').value,
        getSortOrder(),
            20,
            $get('page').value,
            parseInt($get('NewQuery').value),
            $get('NewResult').value,
            $get('searchArchiveOnly').value,
            getImageOnlyValue(), displayResultObjects, onFail);

}

isAuthority = false;
AutorityID =0;
AuthorityTypeID = 0;
AuthorityDisplay = '';
function GetAuthorityObjects(id, authorityTypeID, display, addHistory, fromHistPoint) {
    action = 'auth'
    isAuthority = true;
    AutorityID = id;
    AuthorityTypeID = authorityTypeID;
    AuthorityDisplay = display;
    $get('hitBoxrightT').style.display = 'none';

    if (addHistory) {
        $get('NewQuery').value = 1;
        $get('page').value = 1;
    }
    page = $get('page').value;
    var nres = $get('NewResult').value;
    var nque = $get('NewQuery').value;
    if (!fromHistPoint) {
        Sys.Application.addHistoryPoint(
         { s: id, p: page, a: action , d: display, at: authorityTypeID, nr: nres, nq: nque },display);
    }
     if (addHistory) {
      addHistorique(display, authorityTypeID + 20, id);
    }
}



function GetObjectDetail(objectId, objectTBody, querystring) {
    var detailTBody = $get(objectTBody);
    if (detailTBody.rows.length == 0) {
        var row = detailTBody.insertRow(-1);
        var dataCell = row.insertCell(-1);
        dataCell.className = "dataCellDetail";
        dataCell.id = 'dataCell' + objectId;
        dataCell.colSpan = 2;
        Gel.CollectionObject.GetObjectDetail(objectId, $get('langID').value,$get('TextBoxQuickSearch').value, GetObjectsDetails, onFail);
    }
    var actionSpan = $get('actionSpan' + objectId);
    var arrow = $get('arrow_' + objectId);
    if (detailTBody.className == 'objectDetail') {
        detailTBody.className = 'objectDetailOpen';
        actionSpan.innerHTML = labels.__lblLess;
        arrow.src = "./Images/readLess_arrow_grey.png";
    } else {
        detailTBody.className = 'objectDetail';
        actionSpan.innerHTML = labels.__lblMore;
        arrow.src = "./Images/readMore_arrow_grey.png";
    }
}


var childArchive = null;
function GetArchivesParents(child) {
    
    showLeftPanel($get('archiveTab'), 'archiveDiv')
    setWhiteToolBar($get('trArchive'), $get('trPaging'));
    childArchive = child;
    child_id = child.ObjectID;
    Gel.CollectionObject.GetArchivesParents(child.ObjectID, SyncArchiveTree, onFail);
}

var child_id = 0;
function GetArchivesParents2(childID) {
    showLeftPanel($get('archiveTab'), 'archiveDiv')
    setWhiteToolBar($get('trArchive'), $get('trPaging'));
    child_id = childID;
    Gel.CollectionObject.GetArchivesParents(childID, SyncArchiveTree2, onFail);
}


function SyncArchiveTree2(archiveParents) {
    var p;
    isLoading = true;
    var child = ob_getFirstChildOfNode(ob_getFirstNodeOfTree(), true);
    if (child) {
        ob_t2_Remove(child.id);
    }
    aparents = archiveParents;
    addArchiveObjectTreeNode3(archiveParents[0], child_id);
    var first = ob_getFirstChildOfNode(ob_getFirstNodeOfTree(), true);
    ob_SelectedId(first.id);
}


function SyncArchiveTree3(parentArchiveID, parentArchiveNumber,archiveParentTitle, ArchiveID) {
    var p;
    isLoading = true;
    var child = ob_getFirstChildOfNode(ob_getFirstNodeOfTree(), true);
    if (child) {
        ob_t2_Remove(child.id);
    }
    addArchiveObjectTreeNode4(parentArchiveID,parentArchiveNumber,archiveParentTitle,ArchiveID)
    var first = ob_getFirstChildOfNode(ob_getFirstNodeOfTree(), true);
    ob_SelectedId(ArchiveID);
   // ob_SelectedId(childArchive.id);
   // window.scrollTo(0, $get(childArchive.id).offsetHeight - 100); 

   // var first = ob_getFirstChildOfNode(ob_getFirstNodeOfTree(), true);
   // ob_SelectedId(first.id);
}


var z = 1;
var aparents = null;
function SyncArchiveTree(archiveParents) {
    var p;
    isLoading = true;
    var child = ob_getFirstChildOfNode(ob_getFirstNodeOfTree(), true);
    if (child) {
        ob_t2_Remove(child.id);
    }
    aparents = archiveParents;
    addArchiveObjectTreeNode2(archiveParents[0], childArchive);
    var first = ob_getFirstChildOfNode(ob_getFirstNodeOfTree(), true);
    ob_SelectedId(first.id);
    ob_SelectedId(childArchive.id);
    window.scrollTo(0, $get(childArchive.id).offsetHeight - 100); 
    
}

function CheckIfIsArchive(classificationID) {
    var isArchive = false;
    for (i = 0; i < classif.length; i++) {
        if (classificationID == classif[i]) {
            isArchive = true;
            break;
        }
    }
    return isArchive;
}

var lastCell = null;
// topLevelArchiveClassification = new Array(6
var classif = new Array(5, 6, 7, 10, 12, 21, 34, 35, 37, 38, 39);
function GetObjectsDetails(ccaObject, eventArgs) {
    var dataCellName = 'dataCell' + ccaObject.ObjectID;
    var isArchive = false;

    isArchive = CheckIfIsArchive(ccaObject.ClassificationID);
    if (isArchive) {
        lastCell = $get(dataCellName);
        Gel.CollectionObject.GetObject(ccaObject.ObjectID, $get('langID').value, displayArchiveObjectDetail, onFail);
    } else {
        $get(dataCellName).appendChild(getNewParagraph(labels.__lblName, 'labelTitle'));
        InsertConstituents('constituentLink', ccaObject.Constituents, $get('langID').value, dataCellName);
        
        $get(dataCellName).appendChild(getNewParagraph(labels.__lblTitle, 'labelTitle'));
        for (var n in ccaObject.Titles) {
            if (n == 0) {
                $get(dataCellName).appendChild(getNewParagraph(ccaObject.Titles[n].Title, 'objectTitle'));
            } else {
                $get(dataCellName).appendChild(getNewParagraph(ccaObject.Titles[n].Title, 'objectTitle2'));
            }
        }
        if ((ccaObject.Dates.length > 0) | (ccaObject.DisplayDate.length > 0)) {
            $get(dataCellName).appendChild(getNewParagraph('DATE(S)', 'labelTitle'));
            if (ccaObject.Dates.length > 0) {
                for (var n in ccaObject.Dates) {
                    $get(dataCellName).appendChild(getNewParagraph(ccaObject.Dates[n].Event + ' ' + ccaObject.Dates[n].DateText, 'detailP'));
                }
            } else {
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.DisplayDate, 'detailP'));
            }
        }
       //

        $get(dataCellName).appendChild(getNewParagraph(labels.__lblPhyDesc, 'labelTitle'));
        $get(dataCellName).appendChild(getNewParagraph(ccaObject.ObjectCount + ' ' + ccaObject.ObjectName, 'detailP'));
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.Medium, 'detailP'));
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.Dimensions, 'detailP'));
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.Inscribed, 'detailP'));

        if (ccaObject.Signed.length > 0) {
            $get(dataCellName).appendChild(getNewParagraph('INSCRIPTIONS', 'labelTitle'));
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.Signed, 'detailP'));
        }
        if (ccaObject.RelatedConstituents.length > 0) {
            $get(dataCellName).appendChild(getNewParagraph(labels.__lblRela, 'labelTitle'));
            InsertConstituents('constituentLink', ccaObject.RelatedConstituents, $get('langID').value, dataCellName);
        }
        if (ccaObject.Historique.length + ccaObject.Description.length > 0) {
            $get(dataCellName).appendChild(getNewParagraph('NOTES', 'labelTitle'));
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.Description, 'detailP'));
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.Historique, 'detailP'));
        }
        if (ccaObject.Historique.length + ccaObject.Recherche.length > 0) {
            $get(dataCellName).appendChild(getNewParagraph('SOURCES', 'labelTitle'));
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.Recherche, 'detailP'));
        }
        if (ccaObject.Sites.length > 0) {
            $get(dataCellName).appendChild(getNewParagraph(labels.__lblSub, 'labelTitle'));
            InsertSites('detail', ccaObject.Sites, $get('langID').value, dataCellName);
        }
        
        if (ccaObject.KeyWords.length > 0) {
            $get(dataCellName).appendChild(getNewParagraph(labels.__lblKeyW, 'labelTitle'));
            InsertKeywords('detail', ccaObject.KeyWords, $get('langID').value, dataCellName);
        }

/* A voir avec ALENK juillet 2009
        if (ccaObject.RelatedObjects.length > 0) {
            $get(dataCellName).appendChild(getNewParagraph(labels.__lblRelaObj, 'labelTitle'));
            InsertRelatedObjects(ccaObject.RelatedObjects, $get('langID').value, dataCellName);
        }
  */
        if (ccaObject.Sites.length > 0) {
            $get(dataCellName).appendChild(getNewParagraph(labels.__lblGeo, 'labelTitle'));
            InsertGeo('detail', ccaObject.Sites, $get('langID').value, dataCellName);
        }
        $get(dataCellName).appendChild(getNewParagraph('&nbsp;', 'CreditLine'));
        $get(dataCellName).appendChild(getNewParagraph(ccaObject.ObjectNumber, 'CreditLine'));
        //bug sf
        if (ccaObject.HasAnImage==true) {
            $get(dataCellName).appendChild(getNewParagraph(ccaObject.CopyRight, 'CreditLine'));
        }
        $get(dataCellName).appendChild(getNewParagraph(ccaObject.CreditLine, 'CreditLine'));
    }

    copyDataToPrintTable();
}



function InsertRelatedObjects(ListOfRelatedObjects, langID, dataCellName) {
    var t2 = document.createElement('table');
    t2.cellPading = 0;
    t2.cellSpacing = 0;
    t2.className = 'relatedTable';
    s = '';
    for (var i = 0; i < ListOfRelatedObjects.length; i++) {
        if (ListOfRelatedObjects[i].Relation != "Contient") {
            if (s != ListOfRelatedObjects[i].Relation) {
                c = t2.insertRow(-1).insertCell(-1);
                c.colSpan = 2;
                c.appendChild(getNewParagraph(ListOfRelatedObjects[i].Relation, 'labelTitle2'));
                s = ListOfRelatedObjects[i].Relation;
            }
            var p = document.createElement('p');
            p.className = 'detailP';
            p.innerHTML = getObjectSpan(ListOfRelatedObjects[i], ListOfRelatedObjects[i].ObjectNumber + ' - ' + ListOfRelatedObjects[i].Title);

            if (ListOfRelatedObjects[i].ImagePath.length > 0) {
                var r = t2.insertRow(-1);
                var c1 = r.insertCell(-1);
                var thumbnail = document.createElement('img');
                thumbnail.className = 'thumbNailImg';
                c1.className = "objectCell";
                var thumbNailDiv = document.createElement('div');
                thumbNailDiv.className = 'objectThumbnailCell';

                thumbNailDiv.appendChild(thumbnail);
                thumbnail.onclick = function() {
                    window.open("http://svrdam.cca.qc.ca/ZooMI/Default.aspx?obj=" + ccaObject.RelatedObjects[i].ObjectNumber, "ZoomImage", "scrollbars=no,menubar=no,toolbar=0,width=1000,height=620");
                };
                thumbnail.alt = ListOfRelatedObjects[i].ObjectNumber;
                thumbnail.src = ListOfRelatedObjects[i].ImagePath;
                c1.appendChild(thumbNailDiv);
                var c2 = r.insertCell(-1);
                c2.className = "dataCell2";
                c2.appendChild(p);
            } else {
                var c3 = t2.insertRow(-1).insertCell(-1);
                c3.colSpan = 2;
                c3.className = "dataCell2";
                c3.appendChild(p);
            }
        }
    }

    $get(dataCellName).appendChild(t2);
}

var caObj = null;
function getObjectSpan(ccaObject, displayValue) {
    caObj = ccaObject;
    innerHtml = '<span class="keywordLink" ';
    isArchive = false;
    for (var j = 0; j < classif.length; j++) {
        if (ccaObject.ClassificationID == classif[j]) {
            isArchive = true;
            break;
        }
    }
    if (isArchive) {
        innerHtml += "onclick='GetArchivesParents2(" + ccaObject.ObjectID + ")'";
    } else {
    innerHtml += "onclick='getCcaObjectByIDWS(" + ccaObject.ObjectID + ") '";
    }
    innerHtml += ">" + displayValue + "</span>";
    return innerHtml;
}

var expandDetail = false;
function getCcaObjectByIDWS(objectID) {
    setWhiteToolBar($get('trPaging'), $get('trArchive'));
    $get('hitBoxrightT').style.display = 'none';
    deleteAllTableRow($get('DataTable'));
    hideLoadingGif(false);
    showLeftPanel($get('historicalTab'), 'historiqueDiv')
    $get('NewResult').value = "1";
    $get('NewQuery').value = "1";
    Gel.CollectionObject.GetJSONCcaObjectByID(objectID, displayResultObjects, onFail);
   // expandDetail = true;
}



function InsertConstituents(className, listOfConstituents, langID, dataCellName) {
    dataCell = $get(dataCellName);
    for (var i = 0; i < listOfConstituents.length; i++) {
        if (listOfConstituents[i].DisplayName.length > 0) {
            p = document.createElement('p');
            p.className = 'detailP';
            p.innerHTML = '<span>' + listOfConstituents[i].Prefix + ' ';
            if (listOfConstituents[i].WebDisplay == null || listOfConstituents[i].WebDisplay.length == 0) {
                listOfConstituents[i].WebDisplay = listOfConstituents[i].DisplayName.replace(/\'/, " ").replace(/\"/, ' ');
            }
            p.innerHTML += getShowAuthoritySpan(listOfConstituents[i].ConstituentID, $get('langID').value, 3, listOfConstituents[i].DisplayName.replace(/\'/, " ").replace(/\"/, ' '), listOfConstituents[i].WebDisplay, true, className);
            if (className == 'ReleatedConstituent') {
                if (listOfConstituents[i].Role.length > 0) {
                    p.innerHTML += '<span class="ReleatedConstituentLabel">' + listOfConstituents[i].Role + '</span></span>';
                } else {
                    p.innerHTML += '<span class="ReleatedConstituentLabel">' + listOfConstituents[i].Relation + '</span></span>';
                }
            } else {
                p.innerHTML += ' ' + listOfConstituents[i].Role + '</span>';
            }
        }
        dataCell.appendChild(p);            
    }
}

function InsertSites(className,listOfSites, langID, dataCellName) {
    dataCell = $get(dataCellName);
    for (var i = 0; i < listOfSites.length; i++) {
        p = document.createElement('p');
        p.className = 'detailP';
        p.innerHTML = '<span>';
        if (listOfSites[i].WebDisplay == null) {
            listOfSites[i].WebDisplay = listOfSites[i].SiteName;
        }
        p.innerHTML += getShowAuthoritySpan(listOfSites[i].SiteID, $get('langID').value, 2, listOfSites[i].WebDisplay.replace(/\'/, "\\\'").replace(/\"/, '\\\"'), listOfSites[i].SiteName, true, 'constituentLink');
        p.innerHTML += ' </span>';
        dataCell.appendChild(p);            
    }
}

function InsertGeo(className, listOfSites, langID, dataCellName) {
    dataCell = $get(dataCellName);
    for (var i = 0; i < listOfSites.length; i++) {
        p = document.createElement('p');
        p.className = 'detailP';
       // p.innerHTML = '<span>' + listOfSites[i].SiteGeography + '</span>';
        dataCell.appendChild(p);
    }
}


function InsertKeywords(className,listOfKeyWords, langID, dataCellName) {
    dataCell = $get(dataCellName);
    p = document.createElement('p');
    p.className = 'detailP';
    for (var i = 0; i < listOfKeyWords.length; i++) {
        p.innerHTML += getKeyWordySpan(listOfKeyWords[i].TermID, listOfKeyWords[i].Term, listOfKeyWords[i].WebDisplay);
    }
   dataCell.appendChild(p);            
}



function getShowAuthoritySpan(id, langID, typeID, conName, displayValue, AddValueToHistory, className) {
    innerHtml = '<span class="' + className + '" ';
    innerHtml += "onclick='showAuthorityDiv(" + id + "," + langID + "," + typeID + ',"';
    innerHtml += conName.replace(/'/gi, '`') + '",' + AddValueToHistory + ")'";
    innerHtml += ' onmouseover = "c=this.style.color;this.style.color=' + "'#2be62b';" + '"';
    innerHtml += ' onmouseout = "this.style.color=c;"';
    innerHtml += " >" + displayValue + "</span>";
    return innerHtml;
}
 
function getKeyWordySpan(id,term, displayValue) {
    innerHtml = '<span class="keywordLink" ';
    innerHtml += "onclick='GetAuthorityObjects(" + id + ',100,"' + term + '"' + ",true)'";
    innerHtml += ' onmouseover = "c=this.style.color;this.style.color=' + "'#2be62b';" + '"';
    innerHtml += ' onmouseout = "this.style.color=c;"';
    innerHtml += ">" + displayValue + "</span>";
    return innerHtml;
}

function closeAuthorityDiv() {
    $get('authorityDiv').style.display = 'none';
}

function insertAuthListNoLink(list,classN, dataCell){
    for (var i = 0; i < list.length; i++) {
        if (list[i].length > 0) {
            p = document.createElement('p');
            p.className = classN;
            p.appendChild(document.createTextNode(list[i]));
            dataCell.appendChild(p);
        } 
    }
}


function insertSimpleAuthListNoLink(list, classN, dataCell) {
    for (var i = 0; i < list.length; i++) {
            p = document.createElement('p');
            p.className = classN;
            p.appendChild(document.createTextNode(list[i]));
            dataCell.appendChild(p);
    }
}

function fillSite(site){
    var tableName = $get('authorityTable');
    deleteAllTableRow(tableName);
    var dataCell = tableName.insertRow(-1).insertCell(-1);
    dataCell.id = "authorityDataCell";
    $get('seeAllAuth').innerHTML = site.SiteName;
    $get('btnSeeAll').onclick = function() { 
        //isAuthority = true;
    GetAuthorityObjects(site.SiteID, 2, site.SiteName, true); 
        closeAuthorityDiv();
        $get('TextBoxQuickSearch').value = site.SiteName;
    };
 
    
    if (site.VarantsNames.length > 0) {
        dataCell.appendChild(getNewParagraph(site.LabelSiteVariantNames, 'authoritySmallTitle'));
         dataCell.appendChild(getNewParagraph(site.VarantsNames, 'detailA', dataCell));
    }
    if (site.SiteGeography != null ) {
        dataCell.appendChild(getNewParagraph("geo", 'authoritySmallTitle'));
        dataCell.appendChild(getNewParagraph(site.SiteGeography, 'detailA'));
    }

    if (site.RelatedConstituents != null) {
        dataCell.appendChild(getNewParagraph(site.LabelRelatedConstituent, 'authoritySmallTitle'));
        InsertConstituents('ReleatedConstituent', site.RelatedConstituents, $get('langID').value, 'authorityDataCell');
    }

    if (site.Dates.length > 0) {
        dataCell.appendChild(getNewParagraph(site.LabelDates, 'authoritySmallTitle'));
        for (var n in site.Dates) {
            dataCell.appendChild(getNewParagraph(site.Dates[n].Event + ' ' + site.Dates[n].DateText, 'detailP'));
        }
    }

    if (site.HistoricalNotes != null) {
        dataCell.appendChild(getNewParagraph(site.LabelHistoricalNote, 'authoritySmallTitle'));
        dataCell.appendChild(getNewParagraph(site.HistoricalNotes, 'detailA'));
    }

    if (site.Comments != null) {
        //dataCell.appendChild(getNewParagraph(site.LabelSourceName, 'authoritySmallTitle'));
        dataCell.appendChild(getNewParagraph(site.Comments, 'detailA'));
    }

    if (site.Sources != null) {
        dataCell.appendChild(getNewParagraph(site.LabelSourceName, 'authoritySmallTitle'));
        dataCell.appendChild(getNewParagraph(site.Sources, 'detailA'));
    } 
}



function fillAuthority(constituent) {
    var tableName = $get('authorityTable');
    deleteAllTableRow(tableName);
    var dataCell = tableName.insertRow(-1).insertCell(-1);
    dataCell.id = "authorityDataCell";
    $get('seeAllAuth').innerHTML = constituent.Constituent.DisplayName;
    $get('btnSeeAll').onclick = function() {
        //isAuthority = true;
        GetAuthorityObjects(constituent.Constituent.ConstituentID, 3, constituent.Constituent.DisplayName, true); 
        closeAuthorityDiv();
        $get('TextBoxQuickSearch').value = constituent.Constituent.DisplayName;
    };
    if (constituent.Constituent.Variants.length > 0) {
        dataCell.appendChild(getNewParagraph(constituent.LabelVariantNames, 'authoritySmallTitle'));
        insertAuthListNoLink(constituent.Constituent.Variants, 'detailA', dataCell);
    }
    if (constituent.Constituent.BirthLabel.length > 0) {
        dataCell.appendChild(getNewParagraph(constituent.LabelBrithPlace, 'authoritySmallTitle'));
        dataCell.appendChild(getNewParagraph(constituent.Constituent.BirthLabel, 'detailA'));
    }
    if (constituent.Constituent.DeathLabel.length > 0) {
        dataCell.appendChild(getNewParagraph(constituent.LabelDeathPlace, 'authoritySmallTitle'));
        dataCell.appendChild(getNewParagraph(constituent.Constituent.DeathLabel, 'detailA'));
    }
    if (constituent.Constituent.Occupations.length > 0) {
        dataCell.appendChild(getNewParagraph('Occupations','authoritySmallTitle'));
        insertAuthListNoLink(constituent.Constituent.Occupations, 'detailA', dataCell);
    }
    if (constituent.Constituent.Biography.length > 0) {
        dataCell.appendChild(getNewParagraph('notes', 'authoritySmallTitle'));
        dataCell.appendChild(getNewParagraph(constituent.Constituent.Biography, 'detailA'));
    }
    if (constituent.Constituent.RelativesConstituents.length > 0) {
        dataCell.appendChild(getNewParagraph(constituent.LabelRelatedConstituents, 'authoritySmallTitle'));
        InsertConstituents('ReleatedConstituent', constituent.Constituent.RelativesConstituents, $get('langID').value, 'authorityDataCell');
    }

    if (constituent.Constituent.Biography.length > 0) {
        dataCell.appendChild(getNewParagraph(constituent.LabelRelaedSites, 'authoritySmallTitle'));
        InsertSites('detailA', constituent.Constituent.RelatedSites, $get('langID').value, 'authorityDataCell');
    }


   /*
    if (constituent.Constituent.RelativesConstituents) {
        InsertConstituentRelation(constituent.LabelRelatedConstituents, constituent.Constituent.RelativesConstituents, $get('langID').value, tableName);
    }
    InsertRelatedSites(constituent.LabelRelaedSites, constituent.Constituent.RelatedSites, constituent.langID, tableName);
   
    addAuthoritySimpleList('Biographical Source', constituent.Constituent.BiographicalSources, tableName);
    InsertRelatedPublications(constituent.LabelPublications, constituent.Constituent.Publications, constituent.langID, tableName);
    InsertRelatedExhibitions(constituent.LabelExhibtions, constituent.Constituent.Exhibitions, constituent.langID, tableName);
    */
}



function showAuthorityDiv(ID, langID, authorityType, displayValue, addHistory) {
    $get('authorityDiv').style.display = 'block';
    switch (authorityType) {
        case 2:
            Gel.CollectionObject.GetSite(ID, langID, fillSite, onFail);
            break;
        case 3: Gel.CollectionObject.GetConstituent(ID, langID, fillAuthority, onFail);
            break;
        case 10:
            fillExhibition(ID, displayValue);
            break;
        case 11:
            fillPublication(ID, displayValue);
            break;
            
    }
}


var c;
function grennMouseover(e) {
    c = this.style.color;
    this.style.color='#2be62b';
}


function grennMouseOut(e) {
    this.style.color=c;
}



function addHistorique(histValue, type, id) {
    var e = document.createElement('div');
    e.className = 'historique';
    e.innerHTML = histValue;
    e.onmouseover = grennMouseover;
    e.onmouseout = grennMouseOut;
    
    switch (type) {
        case -1:
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'arch'; loadTreeWs(id, 3, 1, histValue); }
            break;
        case 1:
            e.onclick = function() {
                $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'kw'; getCcaObjectsWS(histValue, false); $get('TextBoxQuickSearch').value = histValue; 
                };
            break;
        case 2 :
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'auth'; showAuthorityDiv(id, $get('LangID').value, type, histValue, false); };
            break;
        case 3:
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'auth'; showAuthorityDiv(id, 3, type, histValue, false); };
            break;
        case 10:
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'auth'; showAuthorityDiv(id, 10, type, histValue, false); };
            break; 
        case 11:
            e.onclick = function() { action = 'auth'; showAuthorityDiv(id, $get('LangID').value, type, histValue, false); };
            break;
        case 22 :
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'auth'; GetAuthorityObjectsWs(id, type - 20, histValue, false); $get('TextBoxQuickSearch').value = histValue; }
            break;
        case 23:
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'auth'; GetAuthorityObjectsWs(id, type - 20, histValue, false); $get('TextBoxQuickSearch').value = histValue; }
            break;
        case 30:
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'auth'; GetAuthorityObjectsWs(id, type - 20, histValue, false); $get('TextBoxQuickSearch').value = histValue; }
            break;
        case 31:
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'auth'; GetAuthorityObjectsWs(id, type - 20, histValue, false); $get('TextBoxQuickSearch').value = histValue; }
            break;
        case 120:
            e.onclick = function() { $get('NewQuery').value = 1; $get('NewResult').value = 1; action = 'auth'; GetAuthorityObjectsWs(id, type - 20, histValue, false); $get('TextBoxQuickSearch').value = histValue; }
            break;
    }
    e.style.paddingLeft = indent + 'px';
    var cel = $get('hisoriqueTable').insertRow(0).insertCell(-1);
    cel.appendChild(e);
}

function setWhiteToolBar(tOn, tOff) {
    tOn.className = 'whiteToolBar';
    tOff.className = 'whiteToolBarOff';
}

function GetArchivesSynopsisWs() {
    setWhiteToolBar($get('trArchive'), $get('trPaging'));
    $get('TextBoxQuickSearch').value = '';
    deleteAllTableRow($get('DataTable'));
    hideLoadingGif(false);
    Gel.CollectionObject.GetArchivesSynopsis(DisplayArchivesSynopsis, onFail);
}

function GetArchivesSynopsis(langID) {
    action = 'synop';
    Sys.Application.addHistoryPoint(
         { a: action },'Synopsis');
}

function DisplayArchivesSynopsis(ArchivesSynopsis) {
    var tableName = $get('DataTable');
    hideLoadingGif(true);
    for (i = 0; i < ArchivesSynopsis.length; i++) {
        innerHtml = "<div class='archTitle' ";
        innerHtml += ' onmouseover = "c=this.style.color;this.style.color=' + "'#2be62b';" + '"' + ' onmouseout = "this.style.color=c;"';
        innerHtml += ' onclick="loadTree(' + ArchivesSynopsis[i].ObjectID + ',' + 3 + "," + 2 + ",'" + ArchivesSynopsis[i].ObjectNumber + "')" +  '" >' + ArchivesSynopsis[i].Title + ", " + ArchivesSynopsis[i].Dated + ", " + ArchivesSynopsis[i].ObjectNumber + "</div>";
        innerHtml += "<div class='archive'>" + ArchivesSynopsis[i].EncodedSysnopsis + "</div>";
        var c = tableName.insertRow(-1).insertCell(-1);
        c.innerHTML = innerHtml;
        c.className = 'synopsCell';
    }

    copyDataToPrintTable();
   
}

function loadTree3(parentID, archiveobjectID, langID, displayValue) {
    loadTree(archiveobjectID, langID, 1,  displayValue.replace("'", " ").replace("\"", " "));
    ob_t26('a' + parentID);
    ob_SelectedId('a' + archiveobjectID);
}


function loadTreeWs(archiveobjectID, displayValue) {
    showLeftPanel($get('archiveTab'), 'archiveDiv');
    setWhiteToolBar($get('trArchive'), $get('trPaging'));
    deleteAllTableRow($get('DataTable'));
    hideLoadingGif(false);
    $get('TextBoxQuickSearch').value = '';
    Gel.CollectionObject.GetObject(archiveobjectID, $get('langID').value, displayArchiveObject, onFail);
}

var isLoading = false;
var firstNode;
function loadTree(archiveobjectID, idLang, type, displayValue) {
    if (idLang) {
        if (type == 2) {
            var child = ob_getFirstChildOfNode(ob_getFirstNodeOfTree(), true);
            if (child) {
                ob_t2_Remove(child.id);
            }
            tree_selected_id = null;
            $get('ArchiveDisplay').innerHTML = displayValue;
        }
        if (!isLoading) {
            setWhiteToolBar($get('trArchive'), $get('trPaging'));
            firstNode = 1;
            action = 'arch';
             Sys.Application.addHistoryPoint(
                { s: archiveobjectID, a: action, d: displayValue.replace(/^\s\s*/, '').replace(/\s\s*$/, '') }, displayValue.replace(/^\s\s*/, '').replace(/\s\s*$/, ''));
            addHistorique(displayValue, -1, archiveobjectID);
        }
        
    }
}

function addArchiveObjectTreeNode(archiveObject) {
    ob_t2_Add("root_" + ob_tree_id, 'a' + archiveObject.ObjectID, '<span  onclick="loadTree(' +
                archiveObject.ObjectID + "," + $get('langID').value + ",1,'" + archiveObject.ObjectNumber + "')\" class='archiveLevelTreeNode'>" +
                archiveObject.ArchiveObjectLevelTitle.replace("'", " ").replace("\"", " ") +
                "</span>", null, null, "FilltreeNode.aspx?objectID=" + archiveObject.ObjectID + "&langID=" + $get('langID').value);
}

function addArchiveObjectTreeNode2(archiveObject,child) {
    ob_t2_Add("root_" + ob_tree_id, 'a' + archiveObject.ObjectID, "<span  onclick='loadTree(" +
                archiveObject.ObjectID + "," + $get('langID').value + ",1,\"" + archiveObject.ObjectNumber + "\")' class='archiveLevelTreeNode'>" +
                archiveObject.ArchiveObjectLevelTitle.replace("'", " ").replace("\"", " ") +
                "</span>", true, null, "FillFulltreeNode.aspx?objectID=" + child.ObjectID + "&langID=" + $get('langID').value);
}

function addArchiveObjectTreeNode3(archiveObject, childID) {
    ob_t2_Add("root_" + ob_tree_id, 'a' + archiveObject.ObjectID, "<span  onclick='loadTree(" +
                archiveObject.ObjectID + "," + $get('langID').value + ",1,\"" + archiveObject.ObjectNumber + "\")' class='archiveLevelTreeNode'>" +
                archiveObject.ArchiveObjectLevelTitle.replace("'", " ").replace("\"", " ") +
                "</span>", true, null, "FillFulltreeNode.aspx?objectID=" + childID + "&langID=" + $get('langID').value);
}

function addArchiveObjectTreeNode4(parentArchiveID, parentAtrchiveNumber, parentArchiveTitle, childID) {
    ob_t2_Add("root_" + ob_tree_id, 'a' + parentArchiveID, "<span  onclick='loadTree(" +
                parentArchiveID + "," + $get('langID').value + ",1,\"" + parentAtrchiveNumber + "\")' class='archiveLevelTreeNode'>" +
                parentArchiveTitle.replace("'", " ").replace("\"", " ") +
                "</span>", true, null, "FillFulltreeNode.aspx?objectID=" + childID + "&langID=" + $get('langID').value);
}


function selectTreeNode(nodeID) {
    ob_t26(nodeID);
}


function InsertListOfNotes(className, listOfText, table) {
    for (i = 0; i < listOfText.length; i++) {
        InsertTextCell(className, listOfText[i].WebTextEntry, table);
    }
}


function InsertTextCell(className, celValue, table) {
    var cell = table.insertRow(-1).insertCell(-1).innerHTML = '<div class=' + className + ' >' + celValue + '</div>';
}

function insertDescriptiveNote(title, notes, table) {
    if (notes.length > 0) {
        InsertTextCell("Asubtitle", title, table);
        InsertListOfNotes("Atext", notes, table);
    }
}

function InsertInventoryObject(piece, tableName) {
    InsertTextCell("AsmallInventoryTitle", piece.ObjectCount + " " + piece.ObjectName, tableName);
    InsertTextCell("AtextInventory", piece.ObjectNumber, tableName);
    InsertTextCell("AtextInventory", piece.Date, tableName);
    InsertTextCell("AtextInventory", piece.Description, tableName);
    InsertTextCell("AtextInventory", piece.Medium, tableName);
    InsertTextCell("AtextInventory", piece.Dimensions, tableName);
    InsertTextCell("AtextInventory", piece.CurContainer, tableName);
}


function displayArchive(archive, table) {
    var cell = table.insertRow(-1).insertCell(-1);
   // cell.innerHTML = 'toto';

    InsertTextCell("AobjectNumber", archive.ObjectNumber, table);
   
    InsertTextCell("Atitle", archive.ArchiveObjectLevelTitle, table);
    InsertTextCell("", archive.HeaderDate, table);
   
    var c1 = table.insertRow(-1).insertCell(-1);
    c1.id = 'c1';
    InsertConstituents('constituentLink', archive.ArchiveCreatorsConstituents, archive.langID, c1.id);
    var c2 = table.insertRow(-1).insertCell(-1);
    c2.id = 'c2';
    InsertConstituents("ReleatedConstituent", archive.ArchiveRelatedConstituents, archive.langID, c2.id);
    var c3 = table.insertRow(-1).insertCell(-1);
    c3.id = 'c3';
    InsertSites("", archive.Sites, archive.langID, c3.id);
    InsertListOfNotes("Acollation", archive.Collation, table);
    InsertTextCell("Asubtitle2", archive.NoticeDecriptiveTitle, table);
    insertDescriptiveNote(archive.BiographicalSketchTitle, archive.BiographicalSketch, table);
    insertDescriptiveNote(archive.AdministrativeHistoryTitle, archive.AdministrativeHistory, table);
    insertDescriptiveNote(archive.ScopeAndContentTitle, archive.ScopeAndContent, table);
    insertDescriptiveNote(archive.CustodialHistoryTitle, archive.CustodialHistory, table);
    
    if (archive.RddaNotes.length > 0) {
        var rddaTitle = '';
        InsertTextCell("Asubtitle", archive.RddaNotesTitle, table);
        for (i = 0; i < archive.RddaNotes.length; i++) {
            if (rddaTitle != archive.RddaNotes[i][0]) {
                InsertTextCell("AsmallTitle", archive.RddaNotes[i][0], table);
                rddaTitle = archive.RddaNotes[i][0];
            }
            if (archive.RddaNotes[i][2].length == 0) {
                InsertTextCell("Atext", archive.RddaNotes[i][1], table);
            } else {
                var link = "<a href='" + archive.RddaNotes[i][2] + "' target='_blank' >" + archive.RddaNotes[i][1] + "</a>";
                InsertTextCell("Atext", link, table);
            }
        }
    }


    for (i = 0; i < 4; i++) {
        if (archive.Childs[i].length > 0) {
            InsertTextCell("Asubtitle2", archive.Childs[i][0].DefaultFieldLabel.toUpperCase(), table);
            for (var j = 0; j < archive.Childs[i].length; j++) {
                innerHtml = "<div class='spacer'>&nbsp;</div><span  class='constituentLink' onclick='loadTree3(" + archive.ObjectID + "," + archive.Childs[i][j].ObjectID + "," + archive.langID;
                innerHtml += ',"' + archive.ObjectNumber + '")' + "' ";
                innerHtml += ' onmouseover = "c=this.style.color;this.style.color=' + "'#2be62b';" + '"' + ' onmouseout = "this.style.color=c;">';
                innerHtml += archive.Childs[i][j].Title.replace("'", " ").replace("\"", " ") + "</span>";
                InsertTextCell("Atext2", innerHtml, table);
                InsertTextCell("Atext2", archive.Childs[i][j].DisplayName, table);
                InsertTextCell("Atext2", archive.Childs[i][j].ObjectNumber, table);
                InsertTextCell("Atext2", archive.Childs[i][j].Date, table);
                if (archive.Childs[i][j].MainSite) {
                    innerHtml = "<span class='ReleatedConstituent2' onclick='showAuthorityDiv(";
                    innerHtml += archive.Childs[i][j].MainSite.SiteID + "," + archive.langID + ',2,"';
                    innerHtml += archive.Childs[i][j].MainSite.SiteName + '")' + "'";
                    innerHtml += ' onmouseover = "c=this.style.color;this.style.color=' + "'#2be62b';" + '"' + ' onmouseout = "this.style.color=c;"';
                    innerHtml += ">" + archive.Childs[i][j].MainSite.SiteName + "</span>";
                    InsertTextCell("ReleatedConstituent2", innerHtml, table);
                }
            }
        }
    }


    if (archive.Classements.length > 0) {
        InsertTextCell("Asubtitle2", archive.InventoryTitle, table);
        for (i = 0, objList = archive.Classements; i < objList.length; i++) {
            InsertTextCell("AInventoryTitle", objList[i], table);
            for (j = 0, piecesList = archive.ListOfObjectByClassement[objList[i]]; j < piecesList.length; j++) {
                var piece = piecesList[j];
                    var parentContainer = table.insertRow(-1).insertCell(-1);
                    var containers = new ObjectsTable(piece.ObjectID);
                    containers.Parent = parentContainer;
                    containers.IsFromArchive = true;
                    containers.FillWithObject(piece);
            }
        }
    }
/*
    var printiframe = window.frames[0];
    var printDiv = printiframe.document.getElementsByTagName("div");
    printDiv[0].appendChild(table); 
*/
}

function displayArchiveObjectDetail(archiveObject) {
    var table = document.createElement("table");
    lastCell.appendChild(table);
   /*
    var c1 = table.insertRow(-1).insertCell(-1);
    c1.innerHTML = "sync archive tree";
    c1.className = "sync";
    c1.onmouseover = grennMouseover;
    c1.onmouseout = grennMouseOut;

    c1.onclick = function() {
     GetArchivesParents(archiveObject); 
    };
    */
    displayArchive(archiveObject, table);
}

function displayArchiveObject(archiveObject) {
    if (!tree_selected_id) {
        addArchiveObjectTreeNode(archiveObject);
    }

    selectTreeNode('a' + archiveObject.ObjectID);
    hideLoadingGif(true);
    var table = $get('DataTable');
    displayArchive(archiveObject, table);
    copyDataToPrintTable();

}


/*
function addCCAobject2(ccaObject, ID, line) {
var objectCell = $get('DataTable').insertRow(-1).insertCell(-1);
var objectTable = document.createElement('table');
objectTable.cellPading = 0;
objectTable.cellSpacing = 0;
objectTable.id = 'objectTable' + ccaObject.ObjectID;
var objectHeaderTBody = document.createElement('tbody');
objectTable.appendChild(objectHeaderTBody);
objectTable.className = 'objectHeaderTBody';
var objectDetailTBody = document.createElement('tbody');
objectDetailTBody.id = 'objectDetailTBody' + ccaObject.ObjectID;
objectDetailTBody.className = 'objectDetail';
objectTable.appendChild(objectDetailTBody);

var groupTBody = document.createElement('tbody');
groupTBody.id = 'groupTBody' + ccaObject.ObjectID;
groupTBody.className = 'objectDetail';
objectTable.appendChild(groupTBody);

    
var objectHeaderRow = objectHeaderTBody.insertRow(-1);
var dataCell;

if (ccaObject.MainImagePath) {
var imageCell = objectHeaderRow.insertCell(-1);
imageCell.className = "objectCell";
var thumbnail = document.createElement('img');
thumbnail.className = 'thumbNailImg';
var thumbNailDiv = document.createElement('div');
thumbNailDiv.className = 'objectThumbnailCell';
thumbNailDiv.appendChild(thumbnail);
thumbnail.onclick = function() {
window.open("http://svrdam.cca.qc.ca/ZooMI/Default.aspx?obj=" + ccaObject.ObjectNumber, "ZoomImage", "scrollbars=no,menubar=no,toolbar=0,width=1000,height=620");
};
thumbnail.alt = ccaObject.ObjectNumber;
thumbnail.src = ccaObject.MainImagePath;
imageCell.appendChild(thumbNailDiv);
dataCell = objectHeaderRow.insertCell(-1);
} else {
dataCell = objectHeaderRow.insertCell(-1);
dataCell.colSpan = 2;
}
dataCell.className = "dataCell";
   
    
objectCell.appendChild(objectTable);
dataCell.appendChild(getNewParagraph(ccaObject.ObjectCount + ' ' + ccaObject.ObjectName, 'detailP')); 
    
    
if (ccaObject.DisplayName.length > 0) {
dataCell.appendChild(getNewParagraph(ccaObject.DisplayName, 'DisplayName'));
}
if (ccaObject.Title.length > 0) {
dataCell.appendChild(getNewParagraph(ccaObject.Title, 'detailP'));
}
//bug ....
if (ccaObject.DisplayDate) {
if (ccaObject.DisplayDate.length > 0) {
dataCell.appendChild(getNewParagraph(ccaObject.DisplayDate, 'detailP'));
}
} else {
dataCell.appendChild(getNewParagraph(ccaObject.Date, 'detailP'));
}


if (ccaObject.ObjectNumber.length > 0) {
dataCell.appendChild(getNewParagraph(ccaObject.ObjectNumber, 'detailP'));
}
if (ccaObject.Description.length > 0) {
dataCell.appendChild(getNewParagraph(ccaObject.Description, 'detailP'));
}

if (ccaObject.IsAnArchive) {
if (ccaObject.Inscribed.length > 0) {
dataCell.appendChild(getNewParagraph(ccaObject.Inscribed, 'detailP'));
}
}

if (ccaObject.ColNumber) {
if (ccaObject.ColNumber.length > 0) {
dataCell.appendChild(getNewParagraph(ccaObject.ColNumber, 'detailP'));
}
}
    
     
addToSelectection = "AddToSelection(" + ccaObject.ObjectID + ",'" + ccaObject.Title.replace("'", "&#39;") + "','" + ccaObject.MainImagePath + "','" + ccaObject.ObjectNumber + "','selectionTable')";
    
var actionDiv = document.createElement('div');
actionDiv.className = 'objectDetailAction';
actionDiv.id = 'actionDiv' + ccaObject.ObjectID;

var actionCell = objectHeaderTBody.insertRow(-1).insertCell(-1);
actionCell.colSpan = 2;
if ((ccaObject.Classification == "volume") | (ccaObject.Classification == "groupe") | (ccaObject.Classification == "groupe logique")) {
// var group =  new TmsGroupDisplay(ccaObject.ObjectID);
// group.Create(objectTable);
onGroupExpand = "GetTmsGroupChilds(" + ccaObject.ObjectID + ")";
actionDiv.appendChild(getNewLinkLine('span', onGroupExpand, 'Contient', 'objectDetailLink', 'actionSpan' + ccaObject.ObjectID));
var arrow = document.createElement('img');
arrow.id = 'arrow2_' + ccaObject.ObjectID;
arrow.src = "./Images/readMore_arrow_grey.png";
arrow.className = 'objectDetailImg';
actionDiv.appendChild(arrow);
actionDiv.appendChild(getNewLinkLine('span', '', '|', 'objectDetailSep'));
}

onClique = "GetObjectDetail('" + ccaObject.ObjectID + "','" + objectDetailTBody.id + "'," + 1 + ')';
if (ccaObject.CanExpand == true) {
actionDiv.appendChild(getNewLinkLine('span', onClique, labels.__lblMore, 'objectDetailLink', 'actionSpan' + ccaObject.ObjectID));
var arrow = document.createElement('img');
arrow.id = 'arrow_' + ccaObject.ObjectID;
arrow.src = "./Images/readMore_arrow_grey.png";
arrow.className = 'objectDetailImg';
actionDiv.appendChild(arrow);
actionDiv.appendChild(getNewLinkLine('span', '', '|', 'objectDetailSep'));
}
    
actionDiv.appendChild(getNewLinkLine('span', addToSelectection, labels.__lblAddToList + ' +', 'objectDetailAddHist'));
    
if (ccaObject.ArchiveName) {
var archivesPaths = ccaObject.ArchivePath.split("/");
if (archivesPaths) {
var firstPath = ''
           
var j = archivesPaths.length - 1;
while ((firstPath.length < 2) & (j >= 0)){
firstPath = archivesPaths[j].split('$');
j -= 1;
}
var firstPathNumber = firstPath[0];
var firstObjectID = firstPath[2];
var sArchive = 'GetArchivesParents2(' + firstObjectID + ')';
actionDiv.appendChild(getNewLinkLine('span', '', '|', 'objectDetailSep'));
actionDiv.appendChild(getNewLinkLine('span', sArchive, ccaObject.ArchiveName, 'objectDetailAddHist'));
}
}

actionCell.appendChild(actionDiv);
}
*/

