/* ------------------------------------------------------------
 * PROJECT        : Computer Recycling of Virginia, Inc.
 * FILENAME       : common.js
 * ------------------------------------------------------------
 * DATE CREATED   : 25 Sep 2006
 * LAST UPDATED   : 30 Oct 2007
 * ------------------------------------------------------------
 * AUTHOR(S)      : Kevin Scholl (http://www.ksscholl.com/)
 * ------------------------------------------------------------ */

/* ------------------------------------------------------------
 * GLOBAL VARIABLE(S)
 * ------------------------------------------------------------ */

var NUM_MSTHD_IMGS = 7; // change as necessary
var RAN_NUM        = 4; // default masthead image
var RAN_IMG        = null;

var POPWIN         = null;

/* ------------------------------------------------------------
 * POPUP WINDOW: CLOSE EXISTING POPUP WINDOW
 * ------------------------------------------------------------ */

function closePopWin(wndw) {
  if ((wndw != null) && (wndw.closed != true))
  	wndw.close();
	}

/* ------------------------------------------------------------
 * POPUP WINDOW: DISPLAY POPUP WINDOW
 * ------------------------------------------------------------ */

function popWindow(loc,w,h) {

  closePopWin(POPWIN);	// closes an existing popup window if user opens 
                				// new window before closing existing window
	
	if (!(w)) var winW = screen.width - 110; 
		else var winW = w;
	if (!(h)) var winH = screen.height - 160; 
		else var winH = h;
		
	var params  = "width=" + winW + ",height=" + winH + ",status=yes,toolbar=no,directories=no,scrollbars=yes,resizable=yes,menubar=no,location=no,top=50,left=50,screeny=50,screenx=50";

	POPWIN = window.open(loc,"CRVA",params);
	POPWIN.focus;
	}
	
/* ------------------------------------------------------------
 * DISPLAY LARGE PHOTO
 * ------------------------------------------------------------ */

function viewPhoto(whichPhoto,w,h) {

  closePopWin(POPWIN); 	// closes an existing popup window if user opens 
        					      // new window before closing existing window

	if (!(w)) var picW = 360; 
		else var picW = w;
	if (!(h)) var picH = 270; 
		else var picH = h;

	var params  = "width=" + picW + ",height=" + picH + ",status=no,toolbar=no,directories=no,scrollbars=no,resizable=yes,menubar=no,location=no,top=50,left=50,screeny=50,screenx=50"

	POPWIN = window.open("","CRVA",params);

  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>CRVA</title></head>');
  POPWIN.document.writeln('<body style="margin: 0; background-color: #FFF; padding: 0;">');
  POPWIN.document.writeln('  <div style="margin: 0; border: 0; padding: 0; background: transparent;">');
  POPWIN.document.writeln('    <a href="javascript:window.close();"><img src="' + whichPhoto + '" style="border: 0; width: ' + picW + 'px; height: ' + picH + 'px;" 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() {
				viewPhoto(this);
				return false;
				}
			}
		}
	}
	
window.onload = setupGallery;

/* ------------------------------------------------------------
 * SEARCH, POWERED BY GOOGLE
 * ------------------------------------------------------------ */

function submitSearch() {
	var theForm = document.forms['srchCRVA'];
	var srchRng = theForm.srchRange.options[theForm.srchRange.selectedIndex].value;
  var kywrd   = theForm.srchTerms.value;
	var srchLnk = "http://www.google.com/";
	
	switch (srchRng) {
		case "CRVA":
		  // srchLnk = srchLnk + "custom?sitesearch=www.recycle4va.com&q=" + kywrd;
		  srchLnk = srchLnk + "custom?sitesearch=www.recycle4va.org&q=" + kywrd;
			top.location = srchLnk;
			break;
		case "AUC":
		  srchLnk = srchLnk + "custom?sitesearch=stores.ebay.com/Recycle4va&q=" + kywrd;
			top.location = srchLnk;
			break;
		case "WWW":
		  srchLnk = srchLnk + "search?q=" + kywrd;
			top.location = srchLnk;
			break;
		default:
		  alert("Please select where you'd like to search...");
			return false;
		}
	}