//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = 'images/false.png';
var imgTrue = 'images/true.png';

//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
    replaceChecks();
    // initMultiSelect();
    getBrowserSize();
    initLightbox();
    enableTooltips_1('mainArchive');
    enableTooltips_2('lightItems');
}

function replaceChecks() {

    //get all the input fields on the page
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for(var i=0; i < inputs.length; i++) {

        //check if the input is a checkbox
        if(inputs[i].getAttribute('type') == 'checkbox') {
            //create a new image
            var img = document.createElement('img');
            //check if the checkbox is checked
            if(inputs[i].checked) {
               imgTrue='buttons/'+inputs[i].value+'_true.jpg';
                img.src = imgTrue;
            } else {
                imgFalse='buttons/'+inputs[i].value+'_false.jpg';
                img.src = imgFalse;
            }

            //set image ID and onclick action
            img.id = 'checkImage'+i;

            img.width = 160;  // gmb-i 09/10/08 IE fix
            img.height = 16;  // gmb-i 09/10/08

            //set image
//            img.onclick = new Function('checkChange('+i+')' );
            img.onclick = new Function('checkChangeSubmit('+i+',"'+inputs[i].value+'")' );
            //place image in front of the checkbox
            inputs[i].parentNode.insertBefore(img, inputs[i]);

            //hide the checkbox
            inputs[i].style.display='none';
        }
    }
}

function checkall() {

    //get all the input fields on the page
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for(var i=0; i < inputs.length; i++) {

        //check if the input is a checkbox
        if((inputs[i].getAttribute('type') == 'checkbox') && (inputs[i].name.substring(0,3) == 'art')) {
            checkTrue(i,inputs[i].value);
        }
        if((inputs[i].getAttribute('type') == 'checkbox') && (inputs[i].name.substring(0,3) == 'cat')) {
            checkTrue(i,inputs[i].value);
        }
    }
    document.search1.submit();        
}

function checkall_artists() {

    //get all the input fields on the page
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for(var i=0; i < inputs.length; i++) {
        //check if the input is a checkbox
        if((inputs[i].getAttribute('type') == 'checkbox') && (inputs[i].name.substring(0,3) == 'art')) {
            checkTrue(i,inputs[i].value);
        }
    }
    document.search1.submit();    
}

function uncheckall() {

    //get all the input fields on the page
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for(var i=0; i < inputs.length; i++) {

        //check if the input is a checkbox
        if((inputs[i].getAttribute('type') == 'checkbox') && (inputs[i].name.substring(0,3) == 'art')) {
            uncheckChange(i,inputs[i].value);
        }
        //check if the input is a checkbox
        if((inputs[i].getAttribute('type') == 'checkbox') && (inputs[i].name.substring(0,3) == 'cat')) {
            uncheckChange(i,inputs[i].value);
        }
    }
}

//change the checkbox status and the replacement image
function checkChange(i, img_name) {
    if(inputs[i].checked) {
        inputs[i].checked = '';
        imgFalse='buttons/'+img_name+'_false.jpg';
        document.getElementById('checkImage'+i).src=imgFalse;      
    } else {
        inputs[i].checked = 'checked';
        imgTrue='buttons/'+img_name+'_true_sel.jpg';
        document.getElementById('checkImage'+i).src=imgTrue;        
    }
}

function checkTrue(i, img_name) {
    inputs[i].checked = 'checked';
    imgTrue='buttons/'+img_name+'_true_sel.jpg';
    document.getElementById('checkImage'+i).src=imgTrue;        
}

function checkChangeSubmit(i, img_name) {
    if (inputs[i].name.substring(0,3) == 'art') {
        uncheckall();   
        inputs[i].checked = 'checked';
        imgTrue='buttons/'+img_name+'_true_sel.jpg';
        document.getElementById('checkImage'+i).src=imgTrue;        
        document.search1.submit();           
    } else 
    if(inputs[i].checked) {
        inputs[i].checked = '';
        imgFalse='buttons/'+img_name+'_false.jpg';
        document.getElementById('checkImage'+i).src=imgFalse;
        document.search1.submit();        
    } else {
        inputs[i].checked = 'checked';
        imgTrue='buttons/'+img_name+'_true_sel.jpg';
        document.getElementById('checkImage'+i).src=imgTrue;        
        document.search1.submit();
    }
}

function uncheckChange(i, img_name) {

    inputs[i].checked = '';
    imgFalse='buttons/'+img_name+'_false.jpg';
    document.getElementById('checkImage'+i).src=imgFalse;

}

function toggleLayer(whichLayer)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        style2.display = style2.display? "":"block";
    }
    else if (document.all)
    {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = style2.display? "":"block";
    }
    else if (document.layers)
    {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = style2.display? "":"block";
    }
}

window.onload = init;