function get_index_file(){
	 return document.location.pathname.replace(/^.*[\/\\]/g, '');
}
var childOpen = false
//if (opener != null)
//  {
//  opener.childOpen = true
//  opener.window_obj = self
//  }
var window_obj = null;
var _now
var _weekday
var _monthname
var _daynumber
var _monthnumber
var _year
var _hour
var _hour12
var _ap
var _min
var _sec
var _micro

function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
function add_leading_zero(value){
  if (value < 10) {
  	return "0" + value;
  }
  else {
  	return "" + value;
  }
}
function set_date_vars(date_){
	_now=new Date();
	if (date_) {
		_weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		_monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		_daynumber = add_leading_zero(_now.getDate());
		_monthnumber = add_leading_zero(_now.getMonth() + 1);
		_year = "" + _now.getFullYear();
	}
	else { // time
		_hour12 = _now.getHours();
		_hour = add_leading_zero(_hour12);
		if (_hour12 > 12) {
			 _hour12 = _hour12 - 12;
			 _ap = 'PM';
			}
		else {
			 _ap = 'AM';
			}
		_hour12 = add_leading_zero(_hour12);
		_min = add_leading_zero(_now.getMinutes());
		_sec = add_leading_zero(_now.getSeconds());
		_micro = add_leading_zero(_now.getTime());
	}
}
//-----------------------------------------------------------------//
// Popup a new page in a window                                    //
//-----------------------------------------------------------------//

function popupWindow (winurl, winname, winfeatures, waitingMessage)
{
	// This launches a new window in the centre of the screen, and then
	// focuses it if window.focus() is supported.
    var now = new Date();
    var rand = now.getTime();
    winname += rand; // Make name unique
    childOpen = true
	var amountdown  = 0;
	var amountright = 0;
	var t_H, t_W, w_Y, w_X;
	var a_T = "top=", a_L = "left=";
    window_obj = null; // This is necessary to avoid error: The callee (server [not server application]) is not available and disappeared       
    if (winurl == null)  return;
	if (winfeatures == null) {
	  winfeatures = "height=480, width=510, resizable=2,scrollbars, screenY=" + amountdown + ",screenX=" + amountright;
	  t_W = 510;
	  t_H = 480;
	} else {
	  winfeatures = winfeatures.toLowerCase();
	  if( winfeatures.indexOf("width=") > -1 ) {
		  t_P = winfeatures.indexOf("width=")+6;
		  if( (winfeatures.indexOf(",",t_P)-t_P) > 0 ) {
			t_W = parseInt(winfeatures.substr(t_P, (winfeatures.indexOf(",",t_P)-t_P))); }
		  else {
			t_W = parseInt(winfeatures.substr(t_P)); }
	  } else {
		  winfeatures = "width=510, " + winfeatures;
		  		  t_W = 510 }

	  if( winfeatures.indexOf("height=") > -1 ) {
		  t_P = winfeatures.indexOf("height=")+7;
		  if( (winfeatures.indexOf(",",t_P)-t_P) > 0 ) {
			t_H = parseInt(winfeatures.substr(t_P, (winfeatures.indexOf(",",t_P)-t_P))); }
		  else {
			t_H = parseInt(winfeatures.substr(t_P)); }
	  } else {
		  winfeatures = "height=480, " + winfeatures
		  t_H = 480 }
		  
	}
        // Calculate top position of window
        if( winfeatures.indexOf("toolbar") > -1 )
          { w_Y = ((screen.height-80-t_H)/2); }
        else
          { w_Y = ((screen.height-40-t_H)/2); }

	w_X = ((screen.width-t_W)/2);

        // If top= is not supplied, plug in calculated value 
	if( winfeatures.indexOf(a_T) == -1 ) { winfeatures = winfeatures + "," + a_T + w_Y; }

        // If left= is not supplied, plug in calculated value
	if( winfeatures.indexOf(a_L) == -1 ) { winfeatures = winfeatures + "," + a_L + w_X; }
    //
    // If a waiting message was passed in, pop up this window first
    if (arguments.length > 3)
      {
       window_obj = window.open("",winname,winfeatures);
       window_obj.document.write("<HTML><BODY BGCOLOR='Linen'><TABLE HEIGHT='100%' WIDTH='100%'><TR><TD VALIGN='MIDDLE' ALIGN='CENTER'><H1>" + waitingMessage + "<H1></TD></TR></TABLE></BODY></HTML>");
       window_obj.location = winurl;
      }	
    else {        
	  window_obj = window.open(winurl,winname,winfeatures);
      }
	//CenterWindow(window_obj, t_W, t_H);

	// Popups may fail if blocked by browser
  try {
   if (window_obj.opener == null){
       window_obj.opener = window; 
     }
     window_obj.opener.name = "myparent";	
     window_obj.focus();
  	 return; 
      }
  catch (got_error) {
  	 alert ("Error encountered popping up detail window, popup windows may be blocked by your browser. Try changing your browser settings to allow popups.");
  	 return; // Element does not exist
      }
}
function window_handling()
{
}

function popup(url,width,height,page)
{
width = reduce_width_to_max(width);
height = reduce_height_to_max(height);
popupWindow(url+'&layout=nomenu', page,
               'height='+height+',width='+width+',resizable=2,scrollbars');
}

function popupImage(imageid,width,height,size)
{
// Width and Height reflect the image size, adjust for extra stuff
width = reduce_width_to_max(width + 50);
height = reduce_height_to_max(height + 70); // Allow for description
popupWindow(get_index_file()+'?page=image_viewer&imageid='+imageid+'&imagesize='+size+'&layout=nomenu', imageid,
               'height='+height+',width='+width+',resizable=2,scrollbars');
}

function reduce_width_to_max(width)
{
var maxwidth = (screen.width > 0) ? (screen.width - 20) : 800;
if (width > 0 && width < maxwidth)
  return width;
else
  return maxwidth;
}

function reduce_height_to_max(height)
{
var maxheight = (screen.height > 0) ? (screen.height - 60) : 600;

if (height > 0 && height < maxheight)
  return height;
else
  return maxheight;
}
function handleError() {
	return true;
}

function updateLayer(lyr, html, only_if_exists)
{ 
//	alert(lyr+"="+html);
  if (arguments.length == 3) {
     if (only_if_exists){
     	if (!divExists(lyr)){
     		return;
     	}
     }
  }
  if (document.all || document.getElementById)
  {
    var p = lyr.indexOf('.');
    var id = p != -1 ? lyr.substring(lyr.lastIndexOf('.') + 1) : lyr;
    if (document.all)
    {
      document.all[id].innerHTML = html;
    }
    else
    {
      var l = document.getElementById(id);
      var r = document.createRange();
      r.selectNodeContents(l);
      r.deleteContents();

      var docFrag = r.createContextualFragment(html);
      l.appendChild(docFrag);
    }
  } else {
	//Netscape 4 stuff....
	document.layers[lyr].document.write(html);
	document.layers[lyr].document.close();
  }
}
function toggleDiv(switchTextDiv,showHideDiv,showDiv,hideDiv) {
	var ele = document.getElementById(showHideDiv);
	var text = document.getElementById(switchTextDiv);
	if (typeof showDiv === "undefined") {
		showDiv = 'showtext';
	}
	if (typeof hideDiv === "undefined") {
		hideDiv = 'hidetext';
	}
	var show = document.getElementById(showDiv);
	var hide = document.getElementById(hideDiv);
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		text.innerHTML = show.innerHTML;
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = hide.innerHTML;
	}
}
function divExists(lyr)
{ 
    var p = lyr.indexOf('.');
    var id = p != -1 ? lyr.substring(lyr.lastIndexOf('.') + 1) : lyr;
    if (document.all){
      return ((typeof document.all[id] == 'undefined') ? false : true);
    }
    else {
      // Under netscape, we need try and catch to detect missing div
       try {
         var test = document.getElementById(id).style.visibility;
         return true; // Exists
         }
       catch (got_error) {
       	 return false; // Element does not exist
         }
      }      	 
}
function correctPNGs() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.length > 9) {
	  	if (imgName.substring(imgName.length-9, imgName.length) == "TRANS.PNG")
	     {
	     correctPNG(img);
	     i = i-1;
	     }
      }
   }
}
function correctPNG(img) 
   {
	 var imgID = (img.id) ? "id='" + img.id + "' " : ""
	 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	 var imgStyle = "display:inline-block;" + img.style.cssText 
	 if (img.align == "left") imgStyle = "float:left;" + imgStyle
	 if (img.align == "right") imgStyle = "float:right;" + imgStyle
	 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
	 var strNewHTML = "<span " + imgID + imgClass + imgTitle
	 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
	 img.outerHTML = strNewHTML;
   }
if (navigator.appName == "Microsoft Internet Explorer") 
{
 window.attachEvent("onload", correctPNGs);
}
