﻿function gId(id) { return document.getElementById(id); }

//function hideView(isVisible, idToHideView) {
//    if ($get(idToHideView))
//        $get(idToHideView).style.display = test ? 'block' : 'none';
//}


function hideView(idToHideView, idHandle) {
    if (document.getElementById(idToHideView)) {
        document.getElementById(idToHideView).style.display = document.getElementById(idToHideView).style.display == 'none' ? '' : 'none';
        if (document.getElementById(idHandle))
            document.getElementById(idHandle).className = 'selected';
    }
}

function viewIndex(startName, indexToView, countMax, hidRef) {
    document.getElementById(hidRef).value = indexToView;
    for (var p = 1; p <= countMax; p++) {
        if (document.getElementById(startName + p))
            document.getElementById(startName + p).style.display = 'none';
    }
    document.getElementById(startName + indexToView).style.display = 'block';
}

function hvIndex(startName, indexToView, oSource) {
    //alert(document.body.getAttribute(startName+'IndexSov'));
    if (document.body.getAttribute(startName + 'IndexSov'))
        document.getElementById(startName + document.body.getAttribute(startName + 'IndexSov')).style.display = 'none';
    document.getElementById(startName + indexToView).style.display = 'block';
    document.body.setAttribute(startName + 'IndexSov', indexToView);
    if (oSource) {
        if (document.body.getAttribute(startName + 'HandleNameSov')) {
            document.getElementById(document.body.getAttribute(startName + 'HandleNameSov')).className =
				document.body.getAttribute(startName + 'HandleNameClassNameSov');
        }
        document.body.setAttribute(startName + 'HandleNameSov', oSource.id);
        document.body.setAttribute(startName + 'HandleNameClassNameSov', oSource.className);
        oSource.className = 'selected';
    }
}

//Objet Onglet
function tabObject(aHandleStartName, aContentStartName, hIdStoreObject) {

    this.classNameOver = 'selected';
    this.classNameSelected = 'selected';
    this.handleStartName = aHandleStartName;
    this.contentStartName = aContentStartName;

    this.getSelectedIndex = function() {
        if (document.getElementById(hIdStoreObject))
            return document.getElementById(hIdStoreObject).value;
        else
            return undefined;
    }
    this.setSelectedIndex = function(val) {
        if (document.getElementById(hIdStoreObject))
            document.getElementById(hIdStoreObject).value = val;
        return val;
    }

    //this.selectedIndex = undefined;
    this.overTab = function(indexTab) {
        //Cache la selection
        if (this.getSelectedIndex() != undefined) {
            this.hideTab(this.getSelectedIndex());
        }
        this.viewTab(indexTab)
    }

    this.outTab = function(indexTab) {
        this.hideTab(indexTab)
        //View la selection
        if (this.getSelectedIndex() != undefined)
            this.viewTab(this.getSelectedIndex());
    }

    this.viewTab = function(indexTab) {
        if (document.getElementById(aHandleStartName + indexTab)) {
            if (!document.getElementById(aHandleStartName + indexTab).classNameSov && !document.getElementById(aHandleStartName + indexTab).classNameSov == '') {
                document.getElementById(aHandleStartName + indexTab).classNameSov = document.getElementById(aHandleStartName + indexTab).className;
            }
            document.getElementById(aHandleStartName + indexTab).className = this.classNameOver;
            document.getElementById(aContentStartName + indexTab).style.display = 'block';
        }
    }

    this.hideTab = function(indexTab) {
        if (document.getElementById(aHandleStartName + indexTab)) {
            if (document.getElementById(aHandleStartName + indexTab).classNameSov)
                document.getElementById(aHandleStartName + indexTab).className = document.getElementById(aHandleStartName + indexTab).classNameSov;
            else
                document.getElementById(aHandleStartName + indexTab).className = '';

            if (document.getElementById(aContentStartName + indexTab))
                document.getElementById(aContentStartName + indexTab).style.display = 'none';
        }
    }

    this.selectTab = function(indexTab) {
        if (this.getSelectedIndex() != undefined)
            this.hideTab(this.getSelectedIndex());
        this.setSelectedIndex(indexTab);
        this.viewTab(indexTab);
    }


    //Init
    if (this.getSelectedIndex() != '')
        this.selectTab(this.getSelectedIndex());
    else
        this.selectTab(0);
}


//Objet Onglet
function accordionObject(aHandleStartName, aContentStartName, hIdStoreObject, aAllowViewHide) {

    this.classNameOver = 'selected';
    this.classNameSelected = 'selected';
    this.handleStartName = aHandleStartName;
    this.contentStartName = aContentStartName;

    //Option
    this.allowViewHide = aAllowViewHide;

    this.getSelectedIndex = function() {
        if (document.getElementById(hIdStoreObject))
            return document.getElementById(hIdStoreObject).value;
        else
            return undefined;
    }
    this.setSelectedIndex = function(val) {
        if (document.getElementById(hIdStoreObject))
            document.getElementById(hIdStoreObject).value = val;
        return val;
    }

    //this.selectedIndex = undefined;
    this.overTab = function(indexTab) {
        //Cache la selection
        if (this.getSelectedIndex() != undefined) {
            this.hideTab(this.getSelectedIndex());
        }
        this.viewTab(indexTab)
    }

    this.outTab = function(indexTab) {
        this.hideTab(indexTab)
        //View la selection
        if (this.getSelectedIndex() != undefined)
            this.viewTab(this.getSelectedIndex());
    }

    this.viewTab = function(indexTab) {
        if (document.getElementById(aHandleStartName + indexTab)) {
            if (!document.getElementById(aHandleStartName + indexTab).classNameSov && !document.getElementById(aHandleStartName + indexTab).classNameSov == '') {
                document.getElementById(aHandleStartName + indexTab).classNameSov = document.getElementById(aHandleStartName + indexTab).className;
            }
            document.getElementById(aHandleStartName + indexTab).className = this.classNameOver;
            document.getElementById(aContentStartName + indexTab).style.display = 'block';
        }
    }

    this.hideTab = function(indexTab) {
        if (document.getElementById(aHandleStartName + indexTab)) {
            if (document.getElementById(aHandleStartName + indexTab).classNameSov)
                document.getElementById(aHandleStartName + indexTab).className = document.getElementById(aHandleStartName + indexTab).classNameSov;
            else
                document.getElementById(aHandleStartName + indexTab).className = '';

            if (document.getElementById(aContentStartName + indexTab))
                document.getElementById(aContentStartName + indexTab).style.display = 'none';
        }
    }

    this.selectTab = function(indexTab) {
        if (this.getSelectedIndex() != undefined && this.getSelectedIndex() != indexTab)
            this.hideTab(this.getSelectedIndex());

        this.setSelectedIndex(indexTab);
        //Affiche ou Cache
        if (gId(aContentStartName + indexTab) && this.allowViewHide) {
            //if (document.getElementById(aContentStartName + indexTab).style.display == 'none') {
            this.viewTab(indexTab);
            //} else {
            //   this.hideTab(indexTab);
            //}
        }
        else
            this.viewTab(indexTab);
    }


    //Init
    if (this.getSelectedIndex() != '')
        this.selectTab(this.getSelectedIndex());
    else
        this.selectTab(0);
}

/****** View on Checked ******/
//Objet Onglet
function viewOnCheckedObject(aCheckBoxId, aContentId) {

    this.checkBoxId = aCheckBoxId;
    this.contentId = aContentId;

    this.checkbox = document.getElementById(checkBoxId);
    this.content = document.getElementById(contentId);

    if (checkbox && content) {

        checkbox.onchange = function() {
            content.style.display = checkbox.checked ? '' : 'none';
        }
    }
}

/****** *************** ******/



