/**********************************************************************
*
* Jacek Smyda (C) 2001
*
***********************************************************************/

// Determine browser

var brName = navigator.appName;
var brVer  = parseInt(navigator.appVersion);

var isMinNS3 = (brName == "Netscape" && brVer >= 3) ? true : false;
var isMinNS4 = (document.layers) ? true : false;
var isMinNS6 = (isMinNS3 && document.getElementById) ? true : false;

var isMinIE4 = (document.all) ? true : false;
var isMinIE5 = (isMinIE4 && brVer >= 5) ? true : false;

var isDHTML  = (isMinNS4 || isMinNS6 || isMinIE4) ? true : false;

// Settings for DHTML

if (isDHTML) {
    dhtmlHidden  = (isMinNS4) ? 'hide' : 'hidden';
    dhtmlVisible = (isMinNS4) ? 'show' : 'visible';
}


// FUNCTIONS

function getLayerById(id) {
    if (isMinIE4) return document.all[id];
    if (isMinNS6) return document.getElementById(id);
}

function getLayer(id, base) {
    if (isMinIE4 || isMinNS6) return getLayerById(id);

    // Only for NS4
    if (!base) base = document;
    with (base) {
	if (layers[id]) return layers[id];
	// Sprawdzenie dla wszystkich potomnych
	for (nr = 0; nr < layers.length; nr++) {
	    temp = getLayer(id, layers[nr].document);
	    if (temp) return temp;
	}
    }
    return null;
}

function getLayerTag(id, content, z_idx, visible, left, top, width, height) {
    // Ustawienie wartości domyślnych
    if (width == 0) width = 1;
    if (!height) height = 0;
    if (!top) top = 0;
    if (!left) left = 0;
    if (!visible) visible = dhtmlHidden;
    if (!z_idx) z_idx = 10;
    
    if (isMinNS4) {
	return (
	    '<LAYER NAME="' + id + '" LEFT="' + left + '" TOP="' + top + '"' +
	    ((width) ? ' WIDTH="' + width + '"' : '') +
	    ((height) ? ' HEIGHT="' + height + '"' : '') +
	    ' VISIBILITY="' + visible + '" Z-INDEX="' + z_idx + '">' +
	    content + '</LAYER>'
	);
    } else {
	return (
	    '<DIV ID="' + id + '" STYLE="position: absolute; overflow: visible; left: ' + left + 'px; top: ' + top + 'px;' +
	    ((width) ? ' width: ' + width + 'px;' : '') +
	    ((height) ? ' height: ' + height + 'px;' : '') +
	    ' visibility: ' + visible + '; z-index: ' + z_idx + '">' +
	    content + '</DIV>'
	);
    }
}

function showLayer(id) {
    layer = getLayer(id);
    if (isMinNS4) layer.visibility = dhtmlVisible;
    if (isMinIE4) layer.style.visibility = dhtmlVisible;
}

function hideLayer(id) {
    layer = getLayer(id);
    if (isMinNS4) layer.visibility = dhtmlHidden;
    if (isMinIE4) layer.style.visibility = dhtmlHidden;
}

function writeToLayer(id, content) {
    layer = getLayer(id);
    if (isMinNS4) {
	layer.document.open();
	layer.document.write(content);
	layer.document.close();
    }
    if (isMinIE4) layer.innerHTML = content;
}

function moveToLayer(id, x, y) {
    layer = getLayer(id);
    if (isMinNS4) layer.moveTo(x, y);
    if (isMinIE4) {
	layer.style.left = x;
	layer.style.top  = y;
    }
}

function getWidthLayer(id) {
    layer = getLayer(id);
    if (isMinNS4) {
	if (layer.document.width)
	    return ( layer.document.width );
	else
	    return ( layer.clip.right - layer.clip.left );
    }
    if (isMinIE4) {
	if (layer.style.pixelWidth)
	    return ( layer.style.pixelWidth );
	else
	    return ( layer.clientWidth );
    }
    return -1;
}

function getHeightLayer(id) {
    layer = getLayer(id);
    if (isMinNS4) {
	if (layer.document.height)
	    return ( layer.document.height );
	else
	    return ( layer.clip.bottom - layer.clip.top );
    }
    if (isMinIE4) {
	if (layer.style.pixelHeight)
	    return ( layer.style.pixelHeight );
	else
	    return ( layer.clientHeight );
    }
    return -1;
}

function setBgColorLayer(id, color) {
    layer = getLayer(id);
    if (isMinNS4) layer.bgColor = color;
    if (isMinIE4) layer.style.backgroundColor = color;
}

function setBgImageLayer(id, src) {
    layer = getLayer(id);
    if (isMinNS4) layer.background.src = src;
    if (isMinIE4) layer.style.backgroundImage = "url(" + src + ")";
}

function createLayer(id, content, z_idx, visible, left, top, width, height) {
    this.writeln(getLayerTag(id, content, z_idx, visible, left, top, width, height));
}

// Umieszczenie w obiekcie document funkcji newLayer z wywołaniem: document.newLayer
if (isDHTML) {
    document.newLayer = createLayer;
}


// IMAGES

function getPageLeftImage(img) {
    var x, obj;
    if (isMinNS4) {
	if (img.container != null)
	    return ( img.container.pageX + img.x );
	else
	    return ( img.x );
    }
    if (isMinIE4) {
	x = 0;
	obj = img;
	while (obj.offsetParent != null) {
	    x += obj.offsetLeft;
	    obj = obj.offsetParent;
	}
	x += obj.offsetLeft;
	return x;
    }
    return -1;
}

function getPageTopImage(img) {
    var y, obj;
    if (isMinNS4) {
	if (img.container != null)
	    return ( img.container.pageY + img.y );
	else
	    return ( img.y );
    }
    if (isMinIE4) {
	y = 0;
	obj = img;
	while (obj.offsetParent != null) {
	    y += obj.offsetTop;
	    obj = obj.offsetParent;
	}
	y += obj.offsetTop;
	return y;
    }
    return -1;
}

// WINDOW

function getWidthWindow() {
    if (isMinNS4) return ( window.innerWidth );
    if (isMinIE4) return ( document.body.clientWidth );
    return -1;
}

function getHeightWindow() {
    if (isMinNS4) return ( window.innerHeight );
    if (isMinIE4) return ( document.body.clientHeight );
    return -1;
}


