/* 
  ------------------------------------------------
  TabBar Magic menu scripts
  Copyright (c) 2005-2006 Project Seven Development
  www.projectseven.com
  Version: 1.0.5 
  ------------------------------------------------
*/

var p7tbma=new Array();
var p7tbmt=new Array();

function P7_initTBM(){ //v1.0.2 by PVII-www.projectseven.com
 //define over and down image suffix
 var Iv = "_f2";
 var Id = "_f3";
 var i,j,x,k,d,nV,tB,tbs,iM,im,ts,tA,sA,nA=new Array();
 document.p7tbmsw=new Array();p7tbma=arguments;
 if(!document.getElementById||document.p7tbmf){return;}
 tb=document.getElementById('p7TBM');if(!tb){return;}tb.onmouseout=P7_TBMclose;
 tB=document.getElementById('p7TBM');nV=document.getElementById('p7TBMroot');
 if(!nV||!tB){return;}tA=nV.getElementsByTagName('A');j=0;for(i=0;i<tA.length;i++){
 p7tbmt[j]=tA[i].id;j++;d='p7TBMsub'+tA[i].id.replace('p7TBMt','');
 tbs=document.getElementById(d);if(tbs){tbs.onmouseover=function(){P7_TBMsub(this);};}
 p7tbmt[j]=(tbs)?tbs.id:false;tA[i].hasSub=p7tbmt[j];j++;tA[i].isRoot=true;
 tA[i].onclick=function(){return P7_TBMtrig(this);};
 tA[i].onmouseover=function(){P7_TBMovr(this);};tA[i].p7state=0;tA[i].hasIm=false;
 iM=tA[i].getElementsByTagName('IMG');if(iM&&iM[0]){im=iM[0];ts=im.getAttribute("src");
 x=ts.lastIndexOf(".");nA[0]=ts.substring(0,x);nA[1]='.'+ts.substring(x+1);
 im.p7mimg=new Array();im.p7mimg[0]=ts;if(p7tbma[1]>1){ts=nA[0]+Iv+nA[1];
 P7_TBMpl(ts);}im.p7mimg[1]=ts;if(p7tbma[1]==3){im.p7mimg[2]=ts;}
 if(p7tbma[1]==1||p7tbma[1]==2){ts=nA[0]+Id+nA[1];P7_TBMpl(ts);if(p7tbma[1]==1){
 im.p7mimg[1]=ts;}}im.p7mimg[2]=ts;im.p7state=0;tA[i].hasIm=true;}}
 document.p7tbmf=true;P7_TBMopen();
}

function P7_TBMpl(ims){ //v1.0.2 by PVII-www.projectseven.com
 var x=document.p7tbmsw.length;document.p7tbmsw[x]=new Image();document.p7tbmsw[x].src=ims;
}

function P7_TBMovr(a){ //v1.0.2 by PVII-www.projectseven.com
 if(!document.p7tbmf){return;}if(document.p7TBMtm){clearTimeout(document.p7TBMtm);}P7_TBMswp(a);
 if(p7tbma[0]==1){document.p7TBMtm=setTimeout("P7_TBMshow('"+a.id+"')",p7tbma[4]);
 }else{P7_TBMshow(a.id);}
}

function P7_TBMswp(d){ //v1.0.2 by PVII-www.projectseven.com
 var i,cl,a;for(i=0;i<p7tbmt.length;i+=2){a=document.getElementById(p7tbmt[i]);
 cl=a.className;if(p7tbmt[i]!=d.id){if(a.p7state<2){if(cl.indexOf("p7TBMon")>-1){
 a.className=cl.replace("p7TBMon",'');}if(a.hasIm){im=a.getElementsByTagName('IMG')[0];
 if(im.p7state<2){im.src=im.p7mimg[0];}}}}else{if(a.p7state!=2){if(cl.indexOf("p7TBMon")==-1){
 a.className=(cl&&cl.length>0)?cl+" p7TBMon":"p7TBMon";}if(a.hasIm){
 im=a.getElementsByTagName('IMG')[0];if(im.p7state<2){im.src=im.p7mimg[1];}}}}}
}

function P7_TBMshow(d){ //v1.0.5 by PVII-www.projectseven.com
 var a,i,im,cl;a=document.getElementById(d);if(a.hasIm){im=a.getElementsByTagName('IMG')[0];
 if(im.p7state==0){im.src=im.p7mimg[1];im.p7state=1;}}if(a.hasSub){if(a.p7state!=2){
 a.p7state=1;cl=a.className;if(cl.indexOf("p7TBMon")==-1){
 a.className=(cl&&cl.length>0)?cl+" p7TBMon":"p7TBMon";}}
 document.getElementById(a.hasSub).style.visibility="visible";}P7_TBMtg(a);
}

function P7_TBMtg(d){ //v1.0.2 by PVII-www.projectseven.com
 var i,im,s,cl;for(i=0;i<p7tbmt.length;i+=2){if(!d||p7tbmt[i]!=d.id){
 a=document.getElementById(p7tbmt[i]);if(a.hasIm){im=a.getElementsByTagName('IMG')[0];
 if(im.p7state<2){im.src=im.p7mimg[0];im.p7state=0;}}if(a.p7state!=2){a.p7state=0;
 cl=a.className;if(cl.indexOf("p7TBMon")>-1){a.className=cl.replace("p7TBMon",'');}}
 s=document.getElementById(p7tbmt[i+1]);if(s){s.style.visibility="hidden";}}}
}

function P7_TBMtrig(a){ //v1.0.2 by PVII-www.projectseven.com
 var h,hh,ret=false;P7_TBMdown(a);h=a.href;hh='javascript:; javascript:void(0)';
 if(p7tbma[3]==1){if(h.charAt(h.length-1)=='#'||document.location.href==h){
 ret=false;}else{ret=(hh.indexOf(h)>-1)?false:true;}}else{ret=false;}return ret;
}

function P7_TBMdown(a){ //v1.0.2 by PVII-www.projectseven.com
 var i,aa,im,cl;for(i=0;i<p7tbmt.length;i+=2){aa=document.getElementById(p7tbmt[i]);
 aa.p7state=0;aa.className=P7_trim(aa.className.replace("p7TBMdown",''));if(aa.hasIm){
 im=aa.getElementsByTagName('IMG')[0];im.p7state=0;}}a.p7state=2;if(a.hasIm){
 im=a.getElementsByTagName('IMG')[0];im.p7state=2;im.src=im.p7mimg[2];}else{cl=a.className;
 a.className=(cl&&cl.length>0)?cl+" p7TBMdown":"p7TBMdown";}P7_TBMshow(a.id);
}
function P7_trim(t){ //v1.0.2 by PVII-www.projectseven.com
 t=t.replace(/^\s/,'');t=t.replace(/\s$/,'');return t;
}

function P7_TBMclose(evt){ //v1.0.2 by PVII-www.projectseven.com
 var i,pp,tS,d,p,f,m=true;evt=(evt)?evt:((event)?event:null);if(evt){
 tS=(evt.relatedTarget)?evt.relatedTarget:evt.toElement;if(tS){pp=tS;
 while(pp){if(pp.id){d=pp.id;if(pp.id.indexOf("p7TBM")>-1){m=false;break;}}
 pp=pp.parentNode;}if(m){f='P7_TBMtg()';if(p7tbma[2]==1){for(i=0;i<p7tbmt.length;i+=2){
 p=document.getElementById(p7tbmt[i]);if(p.p7state==2){f="P7_TBMshow('"+p.id+"')";}}}
 if(p7tbma[0]==1){eval('document.p7TBMtm=setTimeout("'+f+'",'+parseInt(p7tbma[4]+50)+')');
 }else{eval(f);}}}}
}

function P7_TBMsub(s){ //v1.0.2 by PVII-www.projectseven.com
 if(document.p7TBMtm){clearTimeout(document.p7TBMtm);}
 var d=s.id.replace("p7TBMsub","p7TBMt"),a=document.getElementById(d);
 P7_TBMswp(a);
}

function P7_TBMmark(){document.p7TBMop=arguments;}

function P7_TBMopen(){ //v1.0.2 by PVII-www.projectseven.com
var x,i,j,k,kk,wH,tM,tA,pp,cl,a,nd,op,r1,aU;wH=window.location.href;wHost=window.location.hostname;
/*if (wH.substring(wH.indexOf("_guide/"))) {
	wH=wH.replace('ctd_guide/','');
	wH=wH.replace('general_guide/','');
	wH=wH.replace('water_sample_guide/','');
}*/

if (wH.indexOf("/geotraces/cruises/section_maps/")>0) {
	wH= 'http://' + wHost + '/geotraces/cruises/section_maps/';
} else if (wH.indexOf("/geotraces/data/inventories/")>0) {
	wH= 'http://' + wHost + '/geotraces/data/inventories/';
} else if (wH.indexOf("/geotraces/cruises/documentation/")>0) {
	wH= 'http://' + wHost + '/geotraces/cruises/documentation/';
} else if (wH.indexOf("/geotraces/data/submission/")>0) {
	wH= 'http://' + wHost + '/geotraces/data/submission/';
}



var mt = new Array(1,'','');if(document.p7TBMop){mt=document.p7TBMop;}op=mt[0];
if(op<1){return;}r1=/index\.[\S]*/i;k=-1,kk=-1;tM=document.getElementById('p7TBM');
tA=tM.getElementsByTagName("A");for(j=0;j<tA.length;j++){aU=tA[j].href.replace(r1,'');
if(op>0){if(tA[j].href==wH||aU==wH){k=j;kk=-1;break;}}if(op==2){if(tA[j].firstChild){
if(tA[j].firstChild.nodeValue==mt[1]){kk=j;}}}if(op==3 && tA[j].href.indexOf(mt[1])>-1){
kk=j;}if(op==4){for(x=1;x<mt.length;x+=2){if(wH.indexOf(mt[x])>-1){
if(tA[j].firstChild&&tA[j].firstChild.nodeValue){if(tA[j].firstChild.nodeValue==mt[x+1]){
kk=j;}}}}}}k=(kk>k)?kk:k;if(k>-1){a=false;if(!tA[k].hasIm&&!tA[k].isRoot){cl=tA[k].className;
tA[k].className=(cl&&cl.length>0)?cl+" p7TBMmark":"p7TBMmark";}pp=tA[k].parentNode;
while(pp){if(pp.id&&pp.id=='p7TBMroot'){a=tA[k];break;}if(pp.id&&pp.id.indexOf('p7TBMsub')>-1){
 nd='p7TBMt'+pp.id.replace('p7TBMsub','');a=document.getElementById(nd);break;}
pp=pp.parentNode;}if(a){P7_TBMdown(a);}}
}


addEvent(window, "load", alternate_init);

function alternate_init() {
	// Find all tables with class sortable and make them sortable
	if (!document.getElementsByTagName) return;
	tbls = document.getElementsByTagName("table");
	for (ti=0;ti<tbls.length;ti++) {
		thisTbl = tbls[ti];
		if (((' '+thisTbl.className+' ').indexOf("table1") != -1) && (thisTbl.id)) {
			alternate(thisTbl);
		}
	}
}

function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,	NS6 and Mozilla
// By Scott Andrew
{
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("Handler could not be removed");
	}
} 

function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}

function alternate(table) {
	// Take object table and get all it's tbodies.
	var tableBodies = table.getElementsByTagName("tbody");
	// Loop through these tbodies
	for (var i = 0; i < tableBodies.length; i++) {
		// Take the tbody, and get all it's rows
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		// Loop through these rows
		for (var j = 0; j < tableRows.length; j++) {
			// Check if j is even, and apply classes for both possible results
			if ( (j % 2) == 0  ) {
				if (tableRows[j].className == 'odd' || !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					tableRows[j].className += " even";
				}
			} else {
				if (tableRows[j].className == 'even' || !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				}
				tableRows[j].className += " odd";
			} 
		}
	}
}

function Div_show(pass) { 
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
   if(divs[i].id.match(pass)){ 
      if (document.getElementById) {
         divs[i].style.display="block";
		 if (document.getElementById("bookmark")) {
            document.getElementById("bookmark").style.color = '#FFFF00';
		 }
      } else {
         if (document.layers) { // Netscape 4 
            document.layers[divs[i]].display="block"; 
         } else { // IE 4
            document.all.hideShow.divs[i].display="block";
         } 
      }
   }
} 
}
function Div_hide(pass) { 
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
   if(divs[i].id.match(pass)){ 
      if (document.getElementById) {
         divs[i].style.display="none";
		 if (document.getElementById("bookmark")) {
            document.getElementById("bookmark").style.color = '#FFFFFF';
		 }
      } else {
         if (document.layers) { // Netscape 4 
            document.layers[divs[i]].display="none"; 
         } else { // IE 4
            document.all.hideShow.divs[i].display="none";
         } 
      }
   }
} 
}

function dd_StatusBarMsg(msgStr) { //v1.0 www.dazdezines.com/mme
  if(!msgStr) {msgStr = "";}
  window.status=msgStr;
  document.MM_returnValue = true;
}

function dd_StatusBarMsgClear(msgStr) {
  if(!msgStr) {msgStr = "";}
  window.status=msgStr;
  document.MM_returnValue = true;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function setCookie (name, value, lifespan, access_path) {   
  var cookietext = name + "=" + escape(value)  
    if (lifespan != null) {  
      var today=new Date()     
      var expiredate = new Date()      
      expiredate.setTime(today.getTime() + 1000*60*60*24*lifespan)
      cookietext += "; expires=" + expiredate.toGMTString()
    }
    if (access_path != null) { 
      cookietext += "; path=" + access_path + "; domain=.bodc.ac.uk;"  
    }
   document.cookie = cookietext 
   return null  
}

function sort(sortby) {
		setCookie("sort", sortby, 365, "/geotraces/");
		return true;
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	if (!readCookie(name)) {
		document.cookie = name+"="+value+expires+"; path=/; domain=.bodc.ac.uk;";
	}
}

function createnewCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/; domain=.bodc.ac.uk;";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
    rnd.seed = (rnd.seed*9301+49297) % 233280;
    return rnd.seed/(233280.0);
};

function rand(number) {
    return Math.ceil(rnd()*number);
};

function PopupPic(sPicURL) {
     window.open( "image.html?"+sPicURL, "", "resizable=0,height=335,width=800");
}


var refer=document.referrer;
createnewCookie('referer',refer,0);
doc=document.location;
createnewCookie('document',doc,0);
tid = new Date();
timeid = tid.getTime();
if (!readCookie('sessionid')) {
   createCookie('sessionid',timeid,0);
}
if (readCookie('userid')) {
   var myuserid = readCookie('userid');
   if (myuserid.length < 14) {
      eraseCookie('userid');
   }
}
if (readCookie('__utmv')) {
   var myutmv = readCookie('__utmv');
   if (myutmv.length < 24) {
      eraseCookie('__utmv');
   }
}
if (!readCookie('__utmv') && readCookie('userid')) {
	var myuserid = readCookie('userid');
	document.cookie = "__utmv=174674225."+myuserid+"; expires=Sun, 18 Jan 2038 00:00:00 GMT; path=/; domain=.bodc.ac.uk;";
}

