var Btype = 0;
var browserName=navigator.appName; 
if (browserName=="Netscape")
{ 
  Btype=0;
}
else 
{ 
 if (browserName=="Microsoft Internet Explorer")
 {
   Btype=1;
 }
 else
  {
     Btype=0;
   }
}


function xColor(e,s)
{
  if(!(e=xGetElementById(e))) return '';
  var c='';
  if(e.style && xDef(e.style.color)) {
    if(xStr(s)) e.style.color=s;
    c=e.style.color;
  }
  return c;
}



function xScrollTop(e, bWin)
{
var offset=0;
if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
	var w = window;
	if (bWin && e) w = e;
	if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
	else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
}
else {
	e = xGetElementById(e);
	if (e && xNum(e.scrollTop)) offset = e.scrollTop;
}
return offset;
}


function WinLoad(shref) {
var load = window.open('help.html#' + shref,'WIMBY_GIGL_Help','scrollbars=yes,menubar=no,height=400,width=600,resizable=no,toolbar=no,location=no,status=no');
}

function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}

function resizeBan(){
	
		var iClient = xClientHeight();

		if (xGetElementById('UsePseudoHeight').value == "TRUE")
		{
			iClient =  Math.min(iClient,parseInt(xGetElementById('PseudoHeight').value)); 
		}
		
		var iTabLinks = xHeight("Tablinks");
		var iBanner = Math.max(xHeight("frmBanner"), xHeight("Banner")) + 2;
		

		
		var iTitle1 = xHeight("SubTitleBar");
		var iTitle2 = xHeight("TitleBar");
		var Trial = xHeight('Trail'); 
		xHeight("TitleBar");
		var iSpaceAvail = iClient - iBanner - Trial ;
		var iSpaceUsed = iTitle1 + iTitle2 + iTabLinks + Trial;
		var iSpaceLeft = iSpaceAvail - iSpaceUsed;

		var iheight = parseInt('' + (iSpaceLeft / 2)) - 5;
		if (Btype==0) iheight-=25;


		var iClientWidth = xClientWidth();
		var iMenuWidth = Math.max(xWidth("Fmenu"),xWidth("Dmenu")) + 3;
		var iWidth = (iClientWidth - iMenuWidth) -10 ;
		if (Btype==0) iWidth-=25;

		//alert(iClient + ' , ' + iTabLinks + ' , ' + iBanner + ' , ' + iTitle1 + ' , ' + iTitle2 + ' , ' + iheight);

		var iTopmenuHeight = xHeight('Fmenu');

		xTop('Trail',iBanner);
		xTop('frmMain',iBanner + Trial + 4);
		xTop('Fmenu',iBanner);
		xTop('Dmenu',iBanner + iTopmenuHeight + 10);



		if (xGetElementById('ExpandForMap').value == "TRUE")
		{
				xHeight('Map',parseInt(xGetElementById('MapHeight').value) + 35); 
		}
		else
		{
				xHeight('Map',iheight); 
		}


		xHeight('ARKive',iheight); 
		xHeight('RecordDetails',iheight); 
		xHeight('Organisation',iheight); 
		xHeight('SpeciesList',iheight); 
		
		xWidth('ARKive',iWidth); 
		xWidth('RecordDetails',iWidth); 
		xWidth('Map',iWidth); 
		xWidth('Organisation',iWidth); 
		xWidth('SpeciesList',iWidth); 
		xWidth("Tablinks",iWidth);
		xWidth("SubTitleBar",iWidth);
		xWidth("TabDiv",iWidth);
		xWidth("TitleBar",iWidth);
		xWidth("frmMain",iWidth)

		if (Btype==1) iWidth-=15;
		xWidth('Trail',iWidth ); 

		xLeft('Trail',iMenuWidth + 5);
		xLeft('frmMain',iMenuWidth + 5);	
		
		xHeight("Dmenu", iClient - xHeight("Fmenu")  - iBanner - 15);
		xHeight("contentsDynamic", xHeight("Dmenu"));

return ;

}

function resizeBan2()

{
		

		var iClient = xClientHeight();
		
		if (xGetElementById('UsePseudoHeight').value == "TRUE")
		{
				iClient =  Math.min(iClient,parseInt(xGetElementById('PseudoHeight').value)); 
		}




		var iClientWidth = xClientWidth();

		var iMenuWidth = Math.max(xWidth("Fmenu"),xWidth("Dmenu")) + 3;

		var iBannerHeight = Math.max(xHeight("frmBanner"), xHeight("Banner")) + 2;

		var iTopmenuHeight = xHeight('Fmenu');

		var Trial = xHeight('Trail'); 

		var iheight = iClient - iBannerHeight - Trial - 14 ;

		var iWidth = (iClientWidth - iMenuWidth) -15 ;

		if (Btype==0) iheight-=20;

		xTop('Trail',iBannerHeight);
		xTop('frmMain',iBannerHeight + Trial + 4);
		xTop('Fmenu',iBannerHeight);
		xTop('Dmenu',iBannerHeight + iTopmenuHeight + 10);


		xHeight('frmMain',iheight ); 
		xWidth("frmMain",iWidth);

		xHeight('SPlashIfr',iheight - 170); 

		if (Btype==1) iWidth+=15; // required for the iframe in ff

		xWidth('SPlashIfr',iWidth -18 ); 

		if (Btype==1) iWidth-=15;
		xWidth('Trail',iWidth ); 
		
		xLeft('Trail',iMenuWidth + 5);
		xLeft('frmMain',iMenuWidth + 5);

		xHeight("Dmenu", iClient - xHeight("Fmenu")  - iBannerHeight - 15);
		xHeight("contentsDynamic", xHeight("Dmenu"));

		xHeight("SearchControls", xHeight("frmMain") - xHeight("Splash") - 8);
		xHeight("ResultsPnl2",xHeight("frmMain") - 8);
		xHeight("ResultsPnl1",xHeight("frmMain") - 8);
		
return ;

}

function setBookmark(url,str)
{
	if(str=='')str=url;
	if (document.all)window.external.AddFavorite(url,str);
	else alert('First close this window and then\nPress CTRL and D to add a bookmark to:\n"'+url+'".');
} 

function xLeft(e, iX)
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if (css && xStr(e.style.left)) {
    if(xNum(iX)) e.style.left=iX+'px';
    else {
      iX=parseInt(e.style.left);
      if(isNaN(iX)) iX=xGetComputedStyle(e,'left',1);
      if(isNaN(iX)) iX=0;
    }
  }
  else if(css && xDef(e.style.pixelLeft)) {
    if(xNum(iX)) e.style.pixelLeft=iX;
    else iX=e.style.pixelLeft;
  }
  return iX;
}


function xTop(e, iY)
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xStr(e.style.top)) {
    if(xNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(xNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  return iY;
}


function xHeight(e,h)
{
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(h)) {
    if (h<0) h = 0;
    else h=Math.round(h);
  }
  else h=-1;
  var css=xDef(e.style);
  if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    h = xClientHeight();
  }
  else if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
    if(h>=0) {
      var pt=0,pb=0,bt=0,bb=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pt=gcs(e,'padding-top',1);
        if (pt !== null) {
          pb=gcs(e,'padding-bottom',1);
          bt=gcs(e,'border-top-width',1);
          bb=gcs(e,'border-bottom-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetHeight,e.style.height)){
          e.style.height=h+'px';
          pt=e.offsetHeight-h;
        }
      }
      h-=(pt+pb+bt+bb);
      if(isNaN(h)||h<0) return;
      else e.style.height=h+'px';
    }
    h=e.offsetHeight;
  }
  else if(css && xDef(e.style.pixelHeight)) {
    if(h>=0) e.style.pixelHeight=h;
    h=e.style.pixelHeight;
  }
  return h;
}


function xClientWidth()
{
  var w=0;
  if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) w-=16;
  }
  return w;
}



function xWidth(e,w)
{
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(w)) {
    if (w<0) w = 0;
    else w=Math.round(w);
  }
  else w=-1;
  var css=xDef(e.style);
  if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    w = xClientWidth();
  }
  else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
    if(w>=0) {
      var pl=0,pr=0,bl=0,br=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pl=gcs(e,'padding-left',1);
        if (pl !== null) {
          pr=gcs(e,'padding-right',1);
          bl=gcs(e,'border-left-width',1);
          br=gcs(e,'border-right-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetWidth,e.style.width)){
          e.style.width=w+'px';
          pl=e.offsetWidth-w;
        }
      }
      w-=(pl+pr+bl+br);
      if(isNaN(w)||w<0) return;
      else e.style.width=w+'px';
    }
    w=e.offsetWidth;
  }
  else if(css && xDef(e.style.pixelWidth)) {
    if(w>=0) e.style.pixelWidth=w;
    w=e.style.pixelWidth;
  }
  return w;
}


function xClientHeight()
{
  var h=0;
 if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  }
  return h;
}

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xNum()
{
  for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
  return true;
}

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}


