function replaceCheckboxes ( orange, fms ) {
    var n;
    var img;
    var input;
    input = document.getElementsByTagName('input');
    for ( n = 0; n < input.length; ++n ) {
        if ( input[n].type !== 'checkbox' ) {
            continue;
        }
        img = document.createElement('img');
        img.input = input[n];
        img.input.img = img;
        img.src = '/images/design/transparentpixel.gif';
        img.style.width = '11px';
        img.style.height = '11px';
        img.updateImage = checkboxUpdateImage;
        img.onclick = checkboxImgOnClick;
        if ( img.input.onchange ) {
            img.input.onchange_def = img.input.onchange;
        }
        img.input.onchange = checkboxOnChange;
        img.input.onfocus = checkboxOnFocus;
        
        if ( fms ) {
            // fms
            img.style.backgroundImage = 'url(/images/design/fms/default/checkbox.gif)';
        } else {
            // horizon
            if ( orange ) {
                img.style.backgroundImage = 'url(/images/design/horizon/orange/checkbox.gif)';
            } else {
                img.style.backgroundImage = 'url(/images/design/horizon/default/checkbox.gif)';
            }
        }
        
        img.style.backgroundRepeat = 'no-repeat';
        img.updateImage();
        img.input.style.position = 'absolute';
        img.input.style.left = '-3000px';
        img.input.style.top  = '-3000px';
        img.input.parentNode.insertBefore(img, img.input);
    }
}


function checkboxUpdateImage () {
    this.style.backgroundPosition = this.input.checked ? 'left bottom' : 'left top';
}


function checkboxOnChange () {
    this.img.updateImage();
    if ( this.onchange_def ) {
        this.onchange_def();
    }
}


function checkboxOnFocus () {
    this.blur();
}


function checkboxImgOnClick () {
    if ( this.input.disabled === true ) {
        return false;
    }
    this.input.checked = !this.input.checked;
    this.updateImage();
    if ( this.input.onchange_def ) {
        this.input.onchange_def();
    }
}

