// ------------------------------------------------ //
//  CostSavingSystems, LLC                          //
//  WeatherGrid            | common.js              //
//  Author: Kevin Scholl   | kscholl@comcast.net    //
//  Created: 19 Feb 2005   | Updated: 29 Aug 2006   //
// ------------------------------------------------ //

// ------------------------------------------------//
// GLOBAL VARIABLE(S)
// ------------------------------------------------//

var POPWIN  = null;
var POPWIN2 = null;

// ------------------------------------------------//
// CLOSE EXISTING CHILD WINDOW
// ------------------------------------------------//

function closePopWin(theWin) {
  if ((theWin != null) && (theWin.closed != true))
  	theWin.close();
	}

// ------------------------------------------------//
// DISPLAY POPUP WINDOW
// ------------------------------------------------//

function popWindow(loc,x,y) {

  closePopWin(POPWIN);	// closes an existing popup window if user opens 
                				// new window before closing existing window
	
	if (!(x)) var winW = 562; 
		else var winW = x + 20;
	if (!(y)) var winH = 502; 
		else var winH = y + 20;
		
	var winPosX = (screen.width / 2) - (winW / 2);
	var winPosY = (screen.height / 2) - (winH / 2);

	var params  = "width=" + winW + ",height=" + winH + ",status=yes,toolbar=no,directories=no,scrollbars=yes,resizable=yes,menubar=no,location=no";

	POPWIN = window.open(loc,"WeatherGrid",params);
	POPWIN.moveTo(winPosX,winPosY);
	// POPWIN.focus;
	}

// ------------------------------------------------//
// DISPLAY POPUP WINDOW
// ------------------------------------------------//

function popWindow2(loc,x,y) {

  closePopWin(POPWIN2);	// closes an existing popup window if user opens 
                				// new window before closing existing window
	
	if (!(x)) var winW = 260; 
		else var winW = x + 20;
	if (!(y)) var winH = 600; 
		else var winH = y + 20;
		
	var winPosX = (screen.width / 2) - (winW / 2);
	var winPosY = (screen.height / 2) - (winH / 2);

	var params  = "width=" + winW + ",height=" + winH + ",status=yes,toolbar=no,directories=no,scrollbars=yes,resizable=yes,menubar=no,location=no";

	POPWIN2 = window.open(loc,"WeatherGrid2",params);
	POPWIN2.moveTo(winPosX,winPosY);
	POPWIN2.focus;
	}

// ------------------------------------------------//
// DISPLAY LARGE PHOTO
// ------------------------------------------------//

function popPhoto(whichPhoto) {

  closePopWin(); 	// closes an existing popup window if user opens 
        					// new window before closing existing window
	
	var winPosX = (screen.width / 2) - 281;
	var winPosY = (screen.height / 2) - 251;

var params  = "width=562,height=502,status=no,toolbar=no,directories=no,scrollbars=no,resizable=yes,menubar=no,location=no";

	POPWIN = window.open("","WeatherGrid",params);
	POPWIN.moveTo(winPosX,winPosY);

  POPWIN.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
  POPWIN.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml">');
	POPWIN.document.writeln('<head><title>WeatherGrid</title></head>');
  POPWIN.document.writeln('<body style="margin: 0; background-color: #EEE; padding: 0;">');
  POPWIN.document.writeln('  <div style="margin: 10px; border: 1px solid #CCC; padding: 10px; background-color: #FFF; text-align: center;">');
  POPWIN.document.writeln('    <a href="javascript:window.close();"><img src="' + whichPhoto + '" style="border: 0; width: 520px; height: 460px;" alt="Click to Close" title="Click to Close"></a>');
  POPWIN.document.writeln('  </div>');
  POPWIN.document.writeln('</body>');
  POPWIN.document.writeln('</html>');

	POPWIN.document.close();
  }

// ------------------------------------------------//
// SET UP GALLERY FOR EXPANDABLE IMAGES ON PAGE
// ------------------------------------------------//

function setupGallery() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
		if (links[i].className.match("popupImg")) {
			links[i].onclick = function() {
				popPhoto(this);
				return false;
				}
			}
		}
	}
	
window.onload = setupGallery;