dom = (document.getElementById)? true : false;
nn4 = (document.layers)? true : false;
ie = (document.all)? true : false;
ie4 = (!dom && ie)? true : false;

var doc;

function preloadImages()
{
    doc = document;
    if( doc.images )
        {
        if( !doc.preloadImgs )
            doc.preloadImgs = new Array();
        var i, j = doc.preloadImgs.length;
        var a = preloadImages.arguments;
        for(i=0; i<a.length; i++)
            {
            doc.preloadImgs[j] = new Image;
            doc.preloadImgs[j++].src = a[i];
            }
        }
}

function findObject( id, doc )
{
    var i;

    if( doc == null )
        doc = document;

    if( dom )
        return doc.getElementById( id );
    else
        {
        if( ie4 )
        return doc.all[ id ];
        }

    for( i=0; i<doc.forms.length; i++ )
        for( j=0; j<doc.forms[i].elements.length; j++ )
        if( id == doc.forms[i].elements[j].name )
            return doc.forms[i].elements[j];

    for( i=0; i<doc.images.length; i++ )
        if( id == doc.images[i].name )
        return doc.images[i];

    if( doc.layers == null )
        return null;

    for( i=0; i<doc.layers.length; i++ )
        {
        if( id == doc.layers[i].name )
            return doc.layers[i];
        var x = findObject( id, doc.layers[i].document );
        if( x != null )
            return x;
        } 
    return null;
}

function showElem(elemId)
{
    if (dom)
        document.getElementById(elemId).style.visibility = "visible";
    else
        if (ie4)
        document.all[elemId].style.visibility = "visible";
        else
        if (nn4)
            document.layers[elemId].visibility = "show";
}

function hideElem(elemId)
{
    if (dom)
         document.getElementById(elemId).style.visibility = "hidden";
    else
        if (ie4)
        document.all[elemId].style.visibility = "hidden";
        else
        if (nn4) document.layers[elemId].visibility = "hide";
}

function turnElementOff( elemId )
{
    var elem = getElement( "sm_"+elemId );
    if( elem == null )
        return true;
    if( dom || ie4 )
        elem.style.display = "none";
    else
        {
        if( nn4 )
            elem.display = "none";
        }
}

function toggleElem( elemId )
{
    var elem = findObject( elemId );

    if( dom || ie4 )
        (elem.style.display == "none")?elem.style.display="":elem.style.display="none";
    else
        {
        if( nn4 )
            (elem.display == "none")?elem.display="":elem.display="none";
        }
    return false;
}

function getElement( elemId )
{
    if (dom)
        return document.getElementById(elemId);
    else
        if (ie4)
            return document.all[elemId];
        else
            if (nn4)
                return document.layers[elemId];
    return null;
}

function anchorPosX(anchorPtr)
{
    if (document.layers)
        return anchorPtr.x;
    else if (document.getElementById || document.all)
        {
        var pos = anchorPtr.offsetLeft;
        while (anchorPtr.offsetParent != null)
            {
            anchorPtr = anchorPtr.offsetParent;
            pos += anchorPtr.offsetLeft;
            }
        return pos;
        }
}

function anchorPosY(anchorPtr)
{
    if (document.layers)
        return anchorPtr.y;
    else if (document.getElementById || document.all)
        {
        var pos = anchorPtr.offsetTop;
        while (anchorPtr.offsetParent != null)
            {
            anchorPtr = anchorPtr.offsetParent;
            pos += anchorPtr.offsetTop;
            }
        return pos;
        }
}

function show_params( obj ) { s = ''; k = 0; for( i in obj ) { s = s + i +'=' + eval( 'obj.' + i )+'\n'; k++; if( k>20 ) { alert( s ); s = ''; k = 0; } } if( k ) alert( s ); } 

function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}

function getOpacityProperty()
{
	var p;
	if (typeof document.body.style.opacity == 'string') p = 'opacity';
	else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
	
	return (getOpacityProperty = new Function("return '"+p+"';"))();
}

function fadeOpacity(sElemId, sRuleName, bBackward, callBack)
{
	var elem = document.getElementById(sElemId);
	if (!elem || !getOpacityProperty() || !fadeOpacity.aRules[sRuleName]) return;
	
	var rule = fadeOpacity.aRules[sRuleName];
	var nOpacity = rule.nStartOpacity;
	
	if (fadeOpacity.aProc[sElemId]) {clearInterval(fadeOpacity.aProc[sElemId].tId); nOpacity = fadeOpacity.aProc[sElemId].nOpacity;}
	if ((nOpacity==rule.nStartOpacity && bBackward) || (nOpacity==rule.nFinishOpacity && !bBackward)) return;

	fadeOpacity.aProc[sElemId] = {'nOpacity':nOpacity, 'tId':setInterval('fadeOpacity.run("'+sElemId+'")', fadeOpacity.aRules[sRuleName].nDalay), 'sRuleName':sRuleName, 'bBackward':Boolean(bBackward), 'callBack':callBack};
}

fadeOpacity.addRule = function(sRuleName, nStartOpacity, nFinishOpacity, nDalay){fadeOpacity.aRules[sRuleName]={'nStartOpacity':nStartOpacity, 'nFinishOpacity':nFinishOpacity, 'nDalay':(nDalay || 30),'nDSign':(nFinishOpacity-nStartOpacity > 0?1:-1)};};

fadeOpacity.back = function(sElemId,callBack){fadeOpacity(sElemId,fadeOpacity.aProc[sElemId].sRuleName,true,callBack);};

fadeOpacity.run = function(sElemId)
{
	var proc = fadeOpacity.aProc[sElemId];
	var rule = fadeOpacity.aRules[proc.sRuleName];
	
	proc.nOpacity = Math.round(( proc.nOpacity + .1*rule.nDSign*(proc.bBackward?-1:1) )*10)/10;
	setElementOpacity(document.getElementById(sElemId), proc.nOpacity);
	
	if (proc.nOpacity==rule.nStartOpacity || proc.nOpacity==rule.nFinishOpacity) 
		{
		clearInterval(fadeOpacity.aProc[sElemId].tId);
		if( fadeOpacity.aProc[sElemId].callBack != '' )
			eval( fadeOpacity.aProc[sElemId].callBack );
		}
}
fadeOpacity.aProc = {};
fadeOpacity.aRules = {};