//FUNCTIONS TO MANAGE POP-UPS

//Opens a pop-up window
function popwin(url,win,attribs) {
  if (typeof winpop == "undefined") {
    winpop=window.open(url,win,attribs);
  }else{
    if (winpop.closed) {
      winpop=window.open(url,win,attribs)
    }else{
      winpop.close(); winpop=window.open(url,win,attribs);
    }
  }
}

//closes the popups when the parent page is closed.
function closepops() { 
winpop.close();
} 

//Opens a second pop-up window from an existing pop-up
function newwin(url,win,attribs) {
  if (typeof winmore == "undefined") {
    winmore=window.open(url,win,attribs);
  }else{
    if (winmore.closed) {
      winmore=window.open(url,win,attribs)
    }else{
      winmore.close(); winmore=window.open(url,win,attribs);
    }
  }
}

//closes the popups when the parent page is closed.
function closemore() { 
winmore.close();
} 


//FUNCTIONS TO MANAGE THE GLOSSARY POP-UPS (Needed because pop-up pages may contain glossary entries)

//Opens a glossary pop-up 
function newglos(url,win,attribs) {
  if (typeof gloswin == "undefined") {
    gloswin=window.open(url,win,attribs);
  }else{
    if (gloswin.closed) {
      gloswin=window.open(url,win,attribs)
    }else{
      gloswin.close(); gloswin=window.open(url,win,attribs);
    }
  }
}

//opens a window for more information from the glossary pop-up
function glosmore(url,win,attribs) {
  if (typeof winglos == "undefined") {
    winglos=window.open(url,win,attribs);
  }else{
    if (winglos.closed) {
      winglos=window.open(url,win,attribs)
    }else{
      winglos.close(); winglos=window.open(url,win,attribs);
    }
  }
}

//closes the popups when the parent glossary definition is closed.
function closeglosmore() { 
winglos.close();
} 



//IMAGE MANAGEMENT

//Function to change images contained in layers
function changeimg(layername,imgname,imgsrc) {
	if (document.getElementById) {
		document.getElementById(imgname).src=imgsrc;
	} else if (document.layers)	{
	    document.layers[layername].document[imgname].src=imgsrc;
   	}else{
      document[imgname].src=imgsrc;
   	}
}

//Function to change images NOT contained in layers
function chimg(imgname,imgsrc) {
	if (document.getElementById) {
		document.getElementById(imgname).src=imgsrc;
	}else{
		document[imgname].src=imgsrc;
	}
}


//LAYER MANAGEMENT

/* Function to make sure layer functions work in both IE and Netscape.  Loaded with command in BODY tag*/
function init()
{
    if (document.getElementById) 
    {
		layerRef="document.getElementById";
            b1='("'; b2='")';
		styleSwitch=".style";
	} else 
	{
		if (navigator.appName == "Netscape")
		{
         	if (document.layers) 
         	{
				layerRef="document.layers";
            	b1='["'; b2='"]';
				styleSwitch="";
         	} else {
				layerRef="document.all";
           		b1='["'; b2='"]';
				styleSwitch=".style";
			}
		}
	} 
}

/* Two functions to hide and show layers */

var timerset=0

function showLayer(layerName){
	eval(layerRef+b1+layerName+b2+styleSwitch+'.visibility="visible"');
}
        
function hideLayer(layerName){
      timerset=0
	eval(layerRef+b1+layerName+b2+styleSwitch+'.visibility="hidden"');
}  

// Hides several numbered layers, shows one
function showHide(ltype,lcount,ltoshow){
	count=lcount+1;
	for (var i=1; i<count; i++) {	
  		lname=ltype+i;	
        hideLayer(lname);
	}
	showLayer(ltoshow);
}



/* Function to write HTML formatted text into a named layer.  
  GIF Animations that only run once need to be loaded using this functions before they are revealed or they will not animate in IE */

function writelayer(layerName,layerText) {
   if (document.getElementById) {
      document.getElementById(layerName).innerHTML = layerText;
   }else{
      if (document.layers)	{
         with (document.layers[layerName].document){
            open(); write(layerText); close();
         }
      }
      if (document.all) {
      	 document.all[layerName].innerHTML = layerText;
      }
   }
}

// MOVING LAYERS
function movefigure(mfig) {	
	mfig=mfig;
	if (document.all) figtomove=mfig[0];
	if (document.getElementById) figtomove = document.getElementById(mfig[0]);  	x = mfig[1] + "px"; 	y = mfig[2] + "px";  	figtomove.style.left = x;  	figtomove.style.top = y;
}

//Expanding layers - see FAQ.
function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}else {
		el.style.display = '';
	}
}

function removeAll(count) {
  count=count+1;  // Count is the number of questions on the page +1
  for (var i=1; i<count; i++) {	
  	obj="a"+i;	
	var el = document.getElementById(obj);  	 
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
  }
}

function startPage(count) {
  count=count+1;  // Count is the number of questions on the page +1
  for (var i=1; i<count; i++) {	
  	obj="a"+i;	
	var el = document.getElementById(obj);  
	el.style.visibility = 'visible';	 
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
  }
}

//Expanding layers - see FAQ.
function showMenu(count,mapno) {
	count=count+1;
	for (var i=1; i<count; i++) {	
  		obj="a"+i;	
		var el = document.getElementById(obj);  	 
		if ( el.style.display != 'none' ) {
			el.style.display = 'none';
		}
  	}
  	obj="a"+ mapno;
  	var el = document.getElementById(obj);
	el.style.display = '';
}

// Hides several numbered layers, shows one
function displayHide(ltype,lcount,ltoshow){
	count=lcount+1;
	for (var i=1; i<count; i++) {	
  		obj=ltype+i;	
		var el = document.getElementById(obj); 
		el.style.visibility = 'visible';	 
		el.style.display = 'none';

	}
 	var el = document.getElementById(ltoshow);
	el.style.display = '';
}

