﻿function getScrollXY() {
    var x = 0, y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    return [x, y];
}
function testScroll() {
    // Initialize scrollbar cache if necessary
    if (window._pageXOffset==null) {
        window._pageXOffset = window.pageXOffset
        window._pageYOffset = window.pageYOffset
    }
    // Expose Internet Explorer compatible object model
    document.body.scrollTop = window.pageYOffset
    document.body.scrollLeft = window.pageXOffset
    window.document.body.scrollHeight = document.height
    window.document.body.scrollWidth = document.width    
    // If cache!=current values, call the onscroll event
    if (((window.pageXOffset!=window._pageXOffset) || 
    (window.pageYOffset!=window._pageYOffset)) && (window.onscroll)) 
        window.onscroll()
    // Cache new values
    window._pageXOffset = window.pageXOffset
    window._pageYOffset = window.pageYOffset
}
// Create compatibility layer for Netscape
if (document.layers) {
    document.body = new Object
    setInterval("testScroll()",50)
}

function savePosition() {
    // remember pos
    var pos = getScrollXY();
    var intX = pos[0];
    var intY = pos[1];
    document.cookie = "scrollPos=!~" + intX + "#" + intY+ "~!";
}

function setPos(){
    var strCook = document.cookie;
    if(strCook.indexOf("!~")!=0){
        var intS = strCook.indexOf("scrollPos=!~");
        var intE = strCook.indexOf("~!", intS);
        var strPos = strCook.substring(intS+2,intE);
        var pos = strPos.split("#");
        window.scrollTo(pos[0], pos[1]);
    }
}
window.onload = setPos;
window.onscroll = savePosition;

// object hide or show
function ShowHide(name)
{
	var Obj = (document.getElementById) ? document.getElementById(name) : document.all[name];
	if(Obj != null) Obj.style.display = (Obj.style.display == 'none') ? '' : 'none';
}
// mail - anty spam
function MailTo(intUser, intDomain, intDescription, intClass)
{
	var mail = '';
	if(!intClass) intClass = 'mailto';
	mail += '<a href=' + '"mailto:' + intUser + '\x40' + intDomain + '" class="' + intClass + '">';
	mail += (intDescription) ? intDescription : (intUser + '\x40' + intDomain);
	mail += '</a>';
	document.write(mail);
}
function NewWindow(url, name, width, height, scroll)
{
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	win = window.open(url, name, "height=" + height + ", width=" + width + ", top=" + TopPosition + ", left=" + LeftPosition + ", scrollbars=" + scroll + ", resizable=yes, menubar=no, toolbar=no, location=no, directories=no, status=no");
	if(win.window.focus) win.window.focus();
}
