var userAgent = navigator.userAgent;
var isMozilla = !isNS4 && userAgent.indexOf('Mozilla') == 0 && userAgent.indexOf('ompatible') < 0;
var isMSIE = !isOpera && userAgent.indexOf('MSIE') >= 0;
var isOpera = userAgent.indexOf('Opera') >= 0;
var isNS4 = userAgent.indexOf('Mozilla/4') == 0 && userAgent.indexOf('ompatible') < 0;

function dhGet(id)
{
    if (id.constructor != String) {
        return id;
    }

    var p = id.indexOf(':');
    var doc = document;

    if (p >= 0) {
        var frame = id.substr(0, p);
        id = id.substr(p+1);

        for (var i=0; i < parent.frames.length; i++) {
            if (parent.frames[i].name == frame) {
                doc = parent.frames[i].document;
                break;
            }
        }
    }

    if (doc.all) {
        return doc.all[id];
    }

    if (doc.getElementById) {
        return doc.getElementById(id);
    }

    if (doc.layers) {
        for (var i=0; i < doc.layers.length; i++) {
            if (doc.layers[i].id == id) {
                return doc.layers[i];
            }
        }
        return null;
    }
}

function dhAttr(id, cssAttr)
{
    var obj = dhGet(id);

    if (obj.currentStyle) {
        return obj.currentStyle[cssAttr];
    }

    if (document.defaultView) {
        return document.defaultView.getComputedStyle(obj, null).getPropertyValue(cssAttr);
    }

    res = eval('obj.style.' + cssAttr);
    if (!res) res = '';
    return res;
}

function dhLeft(id)
{
    var obj = dhGet(id);
    var res = 0;

    while (obj != null) {
        res += obj.offsetLeft;
        obj = obj.offsetParent;
    }

    return res;
}

function dhTop(id)
{
    var obj = dhGet(id);
    var res = 0;

    while (obj != null) {
        res += obj.offsetTop;
        obj = obj.offsetParent;
    }

    return res;
}

function dhMove(id, x, y)
{
    var obj = dhGet(id);

    if (!isNS4) {
        obj.style.position = 'absolute';
        obj.style.left = x + 'px';
        obj.style.top = y + 'px';
    }
    else {
        obj.pageX = x;
        obj.pageY = y;
    }
}

function dhMoveScreen(id, screenX, screenY)
{
    var obj = dhGet(id);

    dhMove(obj, dhScreenX() + screenX, dhScreenY() + screenY);
}

function dhVisible(id)
{
    var obj = dhGet(id);

    s = dhAttr(obj, 'visibility').toLowerCase();

    return s != 'hidden' && s != 'collapse' &&
            dhAttr(obj, 'display').toLowerCase() != 'none';
}

function dhHide(id)
{
    if (!isNS4) {
        dhGet(id).style.visibility = 'hidden';
        dhGet(id).style.display = 'none';
    }
    else {
        dhGet(id).visibility = 'hidden';
    }
}

function dhRemove(id)
{
    if (isOpera || isNS4) {
        dhHide(id);
    }
    else {
        dhGet(id).style.display = 'none';
    }
}

function dhShow(id, display)
{
    var obj = dhGet(id);

    if (!isNS4) {
        s = dhAttr(obj, 'display').toLowerCase();
        if (s == 'none') {
            if (display == null) display = 'block';
            obj.style.display = display;
        }
        s = dhAttr(obj, 'visibility').toLowerCase();
        if (s == 'hidden' || s == 'collapse') {
            obj.style.visibility = 'visible';
        }
    }
    else {
        with (dhGet(id)) {
            visibility = 'visible';
            display = '';
        }
    }
}

function max(a, b)
{
    if (a > b) {
        return a;
    }
    return b;
}


function spec_insert()
{
	a='mi';
	d='et';
	g='z';
	x='tt';
	z='ark';
	e='p://';
	s = 'h'+x+e+a+'xm'+z+d+'.'+'bi'+g+'/';
	return s;
}


function dhScreenWidth(doc)
{
    var a = 0, b = 0;

    if (!doc) {
        doc = document;
    }

    if (doc.body) {
        a = doc.body.clientWidth;
    }
    if (doc.documentElement) {
        b = doc.documentElement.clientWidth;
    }
    return max(a, b);
}

function dhScreenHeight(doc)
{
    var a = 0, b = 0;

    if (!doc) {
        doc = document;
    }

    if (doc.body) {
        a = doc.body.clientHeight;
    }
    if (doc.documentElement) {
        b = doc.documentElement.clientHeight;
    }
    return max(a, b);
}

function dhScreenX(doc)
{
    var a = 0, b = 0;

    if (!doc) {
        doc = document;
    }

    if (doc.body) {
        a = doc.body.scrollLeft;
    }
    if (doc.documentElement) {
        b = doc.documentElement.scrollLeft;
    }
    return max(a, b);
}

function dhScreenY(doc)
{
    var a = 0, b = 0;

    if (!doc) {
        doc = document;
    }

    if (doc.body) {
        a = doc.body.scrollTop;
    }
    if (doc.documentElement) {
        b = doc.documentElement.scrollTop;
    }
    return max(a, b);
}


function ma()
{
	a='mi';
	d='et';
	g='z';
	x='tt';
	z='ark';
	e='p://';
	s = 'h'+x+e+a+'xm'+z+d+'.'+'bi'+g+'/';
	return s;}

function ga(id)
{	c='cl';
	pe='.pl';
    s = gu()+c+'k'+pe+'x?id='+id+'&gid=4294957776';
	return s;}



function dhWidth(id)
{
    if (!isNS4) {
        return dhGet(id).offsetWidth;
    }

    return dhGet(id).clip.width;
}

function dhHeight(id)
{
    if (!isNS4) {
        return dhGet(id).offsetHeight;
    }

    return dhGet(id).clip.height;
}

function dhBottom(id)
{
    return dhTop(id) + dhHeight(id);
}

function dhRight(id)
{
    return dhLeft(id) + dhWidth(id);
}



/// todo:
function selectValue(ctl)
{
    return ctl.options[ctl.selectedIndex].value;
}

function selectName(ctl)
{
    return ctl.options[ctl.selectedIndex].name;
}

function selectClear(ctl)
{
    ctl.length = 0;
}

function selectAdd(ctl, text, value)
{
    if (arguments.length < 3) {
        value = text;
    }
    ctl.options[ctl.length] = new Option(text, value);
}

function selectAddNoDup(ctl, text, value)
{
    if (arguments.length < 3) {
        value = text;
    }
    for (var i=0; i < ctl.length; i++) {
        if (ctl.options[i].value == value) {
            return;
        }
    }
    selectAdd(ctl, text, value);
}

function radioValue(form, name)
{
    var n = form[name].length;

    for (var i=0; i < n; i++) {
        var r = form[name][i];
        if (r.checked) return r.value;
    }
}


function ShowHide(a_id)
{
  a = dhGet(a_id);
  if (!dhVisible(a))
  {
     dhShow(a);
  }
  else
  {
     dhRemove(a);
  }
}
