var ua = navigator.userAgent.toLowerCase();
var isSafari = (ua.indexOf('safari') > -1);


function tooltip(event, tooltip_contents) {

        var t, td, tc, x, y;

        if(!event) {
            event = window.event;
        }

        t = window.document.getElementById("tooltip");
        td = window.document.getElementById("tooltip_div");
        tc = window.document.getElementById("tooltip_contents");

        x = event.clientX;
        y = event.clientY + 10;
        
        var tmp;

        tmp = getWindowWidth();
        if(tmp != null) {
            if(x + t.offsetWidth > tmp) {
                x = tmp - t.offsetWidth;
            }
        }

        tmp = getWindowHeight();
        if(tmp != null) {
            if(y + t.offsetHeight > tmp) {
                y = event.clientY - t.offsetHeight;
            }
        }

        t.style.left = x + "px";
        if(isSafari){
            t.style.top = (y + document.body.scrollTop) + "px";
        }
        else {
            t.style.top = (y + document.body.parentNode.scrollTop) + "px";
        }

        t.style.left = x + "px";
        if(isSafari){
            t.style.top = (y + document.body.scrollTop) + "px";
        }
        else {
            t.style.top = (y + document.body.parentNode.scrollTop) + "px";
        }

        td.className = "tooltip";
        tc.innerHTML = tooltip_contents;

        tooltipShow();

}

function tooltip1(event, tooltip_contents) {

        var t, td, tc, x, y;

        if(!event) {
            event = window.event;
        }

        t = window.document.getElementById("tooltip");
        td = window.document.getElementById("tooltip_div");
        tc = window.document.getElementById("tooltip_contents");

        x = event.clientX;
        y = event.clientY + 10;
        
        var tmp;

        tmp = getWindowWidth();
        if(tmp != null) {
            if(x + t.offsetWidth > tmp) {
                x = tmp - t.offsetWidth;
            }
        }

        tmp = getWindowHeight();
        if(tmp != null) {
            if(y + t.offsetHeight > tmp) {
                y = event.clientY - t.offsetHeight;
            }
        }

        t.style.left = x + "px";
        if(isSafari){
            t.style.top = (y + document.body.scrollTop) + "px";
        }
        else {
            t.style.top = (y + document.body.parentNode.scrollTop) + "px";
        }

        t.style.left = x + "px";
        if(isSafari){
            t.style.top = (y + document.body.scrollTop) + "px";
        }
        else {
            t.style.top = (y + document.body.parentNode.scrollTop) + "px";
        }

        td.className = "tooltip";
        tc.innerHTML = tooltip_contents;

        tooltipShow();

}

function tooltipimg(event, tooltip_contents) {

        var t, td, tc, x, y;

        if(!event) {
            event = window.event;
        }

        t = window.document.getElementById("tooltip1");
        td = window.document.getElementById("tooltip_div1");
        tc = window.document.getElementById("tooltip_contents1");

        x = event.clientX;
        y = event.clientY + 10;
        
        var tmp;

        tmp = getWindowWidth();
        if(tmp != null) {
            if(x + t.offsetWidth > tmp) {
                x = tmp - t.offsetWidth;
            }
        }

        tmp = getWindowHeight();
        if(tmp != null) {
            if(y + t.offsetHeight > tmp) {
                y = event.clientY - t.offsetHeight;
            }
        }

        t.style.left = x + "px";
        if(isSafari){
            t.style.top = (y + document.body.scrollTop) + "px";
        }
        else {
            t.style.top = (y + document.body.parentNode.scrollTop) + "px";
        }

        t.style.left = x + "px";
        if(isSafari){
            t.style.top = (y + document.body.scrollTop) + "px";
        }
        else {
            t.style.top = (y + document.body.parentNode.scrollTop) + "px";
        }
        

        td.className = "tooltip1";
        tc.innerHTML = tooltip_contents;

        tooltipimgShow();

}

function tooltipimgShow() {
    window.document.getElementById("tooltip1").style.display = "block";
}

function tooltipimgHide() {
    window.document.getElementById("tooltip1").style.display = "none";
}


function tooltipShow() {
    window.document.getElementById("tooltip").style.display = "block";
}

function tooltipHide() {
    window.document.getElementById("tooltip").style.display = "none";
}

function replaceImage(img_id,file){
    document.getElementById(img_id).src = file;
}

function showElements(objname){
    var elements = document.getElementsByTagName(objname);
    for(var i = 0; i < elements.length; i++){
        elements[i].style.visibility = 'visible';    
    }
}

function getWindowHeight() {
    var height;

    if(window.innerHeight != null) {
        height = window.innerHeight;
    } else if(document.documentElement && document.documentElement.clientHeight) {
        height = document.documentElement.clientHeight;
    } else if(document.body != null) {
        height = document.body.clientHeight;
    } else {
        height = null;
    }

    return height;
}

function getWindowWidth() {
    var width;
    
    if(window.innerWidth != null) {
        width = window.innerWidth;
    } else if(document.documentElement && document.documentElement.clientWidth) {
        width = document.documentElement.clientWidth;
    } else if(document.body != null) {
        width = document.body.clientWidth;
    } else {
        width = null;
    }
    
    return width;
}
