dom = (document.getElementById)? true : false;
nn4 = (document.layers)? true : false;
ie = (document.all)? true : false;
ie4 = (!dom && ie)? true : false;
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;
var activeElem = null;

function preloadImages()
{
    var 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 DoSubmit(aName)
{
  var frm = findObject(aName);
  if( frm ) {
    frm.submit();
  };

  return false;
}

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 toggleElement( elemId, toggleActive )
{
    var elem = getElement( "sm_"+elemId );
    if( elem == null )
        return true;
    if( toggleElement.arguments.length == 1 )
        toggleActive = true;

    if( activeElem && toggleActive && (activeElem != elemId) )
        {
        turnElementOff( activeElem );
        // alert( activeElem );
        low( "m", activeElem, true );
        }

    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";
        }
    activeElem = elemId;
    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 hi( img, l )
{
    if( activeElem == img )
        return;
    var obj = findObject( img );
    if( obj )
        obj.src = "/img/"+l+"a_" + img + ".gif";
}

function low( img, l )
{
    if( activeElem == img && low.arguments.length < 3 )
        return;
    var obj = findObject( img );
    if( obj )
        obj.src = "/img/"+l+"_" + img + ".gif";
}

// This function writes HTML code into a layer
function WriteLayer(layer,code,doc)
{
    if( doc == null )
        doc = "document";   
    if (nn4)
        {
        layer.document.open();
        layer.document.write( code );
        layer.document.close();
        }
    else
    {
        if (ie4)
        {
        layer.innerHTML = code;
        }
        else
            if (dom)
            {
            layer.innerHTML = code;
            }
    }
}

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 GetWindowWidth()
{
  return ns6 ? window.innerWidth-20 : document.body.clientWidth;
}

function GetWindowHeight()
{
  return ns6 ? window.innerHeight-20 : document.body.clientHeight;
}

function showLargerImage(Title, ImageLink, Width, Height)
{
  var w, h, l, t, s; s = '';
  if (!Width)  Width=530;
  if (!Height) Height=380;

  Width = Width+Width*0.1
  Height = Height+Height*0.1;

  if(Width<screen.width-20)
    w = Width;
  else
  {
    s = ',scrollbars=yes';
    w = screen.width-20;
  }
  l = Math.round((screen.width-w)/2)-5;
  if(Height<screen.height-40)
    h = Height;
  else
  {
    s = ',scrollbars=yes';
    h = screen.height-40;
  }
  t = Math.round((screen.height-h)/2)-15;
  w=window.open('/popup.asp?ImageLink=' + ImageLink + '&Title=' + Title,'LargerImage','width='+w+',height='+h+',left='+l+',top='+t+',status=0,toolbar=0,menubar=0,location=0,directories=0'+s);
  w.focus();
  return false;
}

function GetRadioValue(RadioButton)
{
  for(var i = 0; i < RadioButton.length; i++)
    if(RadioButton[i].checked)
      return RadioButton[i].value;
}

function SetRadioValue(RadioButton, Value)
{
  for(var i = 0; i < RadioButton.length; i++)
    if(RadioButton[i].value == Value)
    {
      RadioButton[i].checked = true;
      break;
    }
  return false;
}
        