function collapseAll(id) {
    // Collapse up to 50 elements
    for (var x = 1; x <= 50; x++) {
        // with id exp + x
        var exp = 'exp' + x // var name
        // except id
        if (id != exp) {
            var content = document.getElementById(exp);
            if (content) content.style.display = 'none';
        }
    }
}

// Expand/collapse divs
function expander(id) {

    // Start by colapsing everything except our id
    collapseAll(id);

    var content = document.getElementById(id);
    if (content.style.display == 'none') {
        // Expand
        content.style.display = '';
    }
    else {
        // Colapse
        content.style.display = 'none';
    }

    // adjust containers
    matchHeight('container', 'container2');

}

// Expand divs
function expanderNoClose(id) {

    // Start by colapsing everything except our id
    collapseAll(id);

    // Expand
    var content = document.getElementById(id);
    content.style.display = '';

    // adjust containers
    matchHeight('container', 'container2');

}

// Adjust the height of div continers to match each other
function matchHeight(max, adjust) {

    if (document.getElementById(max) && document.getElementById(adjust)) {

        var d = document.getElementById(max);
        var e = document.getElementById(adjust);

        if(d.offsetHeight) {
            e.style.height = d.offsetHeight;
        }
        else if(d.style.pixelHeight) {
            e.style.height = d.style.pixelHeight;
        }


    }
}

// Open window
function openWindow(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',noresizable'

    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// Flash fix for IE
function ieupdate() {
    if (document.getElementsByTagName) {
        // Get all the tags of type object in the page.
        var objs = document.getElementsByTagName("object");
        for (i=0; i<objs.length; i++) {
            // Get the HTML content of each object tag
            // and replace it with itself.
            objs[i].outerHTML = objs[i].outerHTML;
        }
    }
}


// When the page loads:
window.onload = function() {
    // Adjust containers
    var i = document.getElementById('container').offsetHeight;
    var j = document.getElementById('container2').offsetHeight;
    if (i > j) matchHeight('container', 'container2');
    else if (i < j) matchHeight('container2', 'container');

}

// When the page unloads:
window.onunload = function() {
    // Flash fix for IE
    if (document.getElementsByTagName) {
        //Get all the tags of type object in the page.
        var objs = document.getElementsByTagName("object");
        for (i=0; i<objs.length; i++) {
            // Clear out the HTML content of each object tag
            // to prevent an IE memory leak issue.
            objs[i].outerHTML = "";
        }
    }
}

// Popup images
var pic = null
var popImg = null  // use this when referring to pop-up image
var picTitle = null
var imgCount = 0
var imgWinName = "popImg"

function openPopImg(picName, windowTitle, windowWidth, windowHeight){
  closePopImg()
  picTitle = windowTitle
  imgWinName = "popImg" + imgCount++ //unique name for each pop-up window
  popImg = window.open(picName, imgWinName,
           "toolbar=no,scrollbars=no,resizable=no,width=" 
           + (parseInt(windowWidth)+20)  + ",height=" 
           + (parseInt(windowHeight)+15)) 
  }
function closePopImg(){    // close pop-up window if it is open 
  if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popImg != null) if(!popImg.closed) popImg.close() 
  }
function setStatus(msg){
  status = msg
  return true
  }

var priorPic = new Array()
var noPic = 0
var foundit = false

function openPopImg(picName,  windowTitle, windowWidth, windowHeight){
  var i = 0
  if(pic == picName && winOpen()){
    popImg.focus()
    }
  else{
    foundit = false
    for(i=0; i<=noPic; i++){
      if (priorPic[i] == picName)
        foundit = true 
      }
    pic = picName
    closePopImg()
    picTitle = windowTitle
    imgWinName = "popImg" + imgCount++ //unique name for each pop-up window
    if(!foundit){
      priorPic[noPic++] = pic
      }
    popImg = openPopImgWin(imgWinName, windowWidth, windowHeight)
    }
  }
function openPopImgWin(imgWinName, windowWidth, windowHeight){
  var winFeatures = "toolbar=no,scrollbars=no,resizable=no,width=" 
    + windowWidth + ",height=" + windowHeight
  return window.open("../photos/popup_photos.htm", imgWinName, winFeatures)
  }
function winOpen(){
  if(popImg != null){ 
    if(popImg.closed != true) return true; else return false
    }  
  else
    return false
  }
  
// Use this function to control placement of pop-up window
// in Netscape 4+ and Internet Explorer 4+
function openPopImgWin(imgWinName, windowWidth, windowHeight){
  var leftX = 20  // distance of window's left side from left of screen
  var topY = 20   // distance of window's top side from top of screen
  var winFeatures = "toolbar=no,scrollbars=no,resizable=no,width=" 
    + windowWidth + ",height=" + windowHeight
  if (leftX>0){
    winFeatures += ",screenX=" + leftX + ",left=" + leftX	
                + ",screenY=" + topY + ",top=" + topY
    }
  return window.open("../photos/popup_photos.htm", imgWinName, winFeatures)
  }
  
 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 = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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;
}
