function find_object(id) {
    if (document.getElementById) { if (!(document.getElementById(id))) { return false; } return document.getElementById(id); } else return false;
}
function sto(path) {
    window.open(dynamicUrl+'/index/videoplayer?path='+path, 'stow', 'width=300,height=270,scrollbars=no,resizable=no,menubar=no');
}
function drotposta(user,host) {
    host = getMailHost(host);
    user = getMailUser(user);
    window.location='mailto:'+user+'\@'+host;
}
function drotpostaHTML (id, user, host) {
    host = getMailHost(host);
    user = getMailUser(user);
    if ((host != '') && (user !='') && (o = find_object(id))) {
        o.innerHTML = user+"@"+host;
    }
}
function getMailUser(user) {
    if (user == '')
        return user;
    else
        return decode64(user);
}
function getMailHost(host) {
    if (host==1) host='matton.se';
    else if (host==2) host='mattonbutiken.se';
    else if (host=='') host='';
    else host=decode64(host);
    return host;
}
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function decode64(input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
        }
    } while (i < input.length);

    return output;
}

function mk_add_div(idx) {
    div[div.length] = 0; 
}
var div = new Array;
function lc_swapit(id,on) {
    if (ob=find_handle(id)) { on?ob.visibility="visible":ob.visibility="hidden"; }
}
function find_handle(id) {
    if (document.getElementById) { if (!(document.getElementById(id))) { return false; } return document.getElementById(id).style; } else if (document.layers) return document.layers[id]; else if (document.all) return document.all[id].style; else return false;
}
function find_object(id) {
    if (document.getElementById) { if (!(document.getElementById(id))) { return false; } return document.getElementById(id); } else return false;
}
function mk_refresh(divtype) {
    if (divtype) {
        prefix="odiv_"; 
        hide_prefix="div_"; 
    } else {
        prefix="div_"; 
        hide_prefix="odiv_"; 
    }
    for (i=0;i<div.length;i++) {
        id =  prefix + i;
        hide_id = hide_prefix + i;
        if (div[i]) on=1; else on=0;
        lc_swapit(id,on);
        if (on && !divtype) {
            var o = find_object('td_'+i);
            var d = find_object(id);
            var m = find_object('main');
            if (o && d && m) {
                var r = o.parentNode.id && o.parentNode.id.match(/^tr_prdc/) ? true : false;
                if (r) {
                    d.style.left = findPosX(o) + o.offsetWidth + 'px';
                } else {
                    d.style.left = findPosX(o) - d.offsetWidth  +'px';
                }
                var op = o.offsetParent;
                if (op) {
                    var t = findPosY(o);
//                    if (t + d.offsetHeight > op.offsetTop + op.offsetHeight) t = op.offsetTop + op.offsetHeight - d.offsetHeight;
//                    if (t < op.offsetTop) t = op.offsetTop
                    d.style.top = t + 'px';
                }
            }
        }
        lc_swapit(hide_id,0);
    }
}
function mk_mouseover(idx, divtype) {
    if (divtype) prefix="oa_"; else prefix="a_"; 
    div[idx] = 1;
    setTimeout('mk_refresh('+divtype+')',200);
    if (o = find_object(prefix+idx)) {
        o.style.color='orange';
    }
}
function mk_mouseout(idx, divtype) {
    if (divtype) prefix="oa_"; else prefix="a_"; 
    div[idx] = 0;
    setTimeout('mk_refresh('+divtype+')',200);
    if (o = find_object(prefix+idx)) {
        o.style.color='';
    }
}
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
        curleft += obj.x;
    }
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent!=null) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) curtop += obj.y;
	return curtop;

}
