///////////////////////////////////////////////////////////////
////////////////BEGIN SHOW / HIDE GALLERY IMAGE////////////////
///////////////////////////////////////////////////////////////
function ToggleDisplay(id)
{
	// Current position clicked on
	var full		= document.getElementById("full_"+id);
	var thumb		= document.getElementById("thumb_"+id);
	var fullHide	= "";
	var thumbHide	= "";
	var imageCount = getElementsByClassName(document,'img','galleryThumb').length;
	
	// If the element clicked on was already open, don't force the close
	if (full.style.display != 'block')
	{
		// Run through all available links
		for (i=1; i<=imageCount; i++)
		{
			// Find opened full image
			fullHide		= document.getElementById("full_"+i);
			thumbHide		= document.getElementById("thumb_"+i); 
			// If visable, hide it and remove highlight around thumbnail
			if (fullHide.style.display == 'block')
			{
				fullHide.style.display		= 'none';
	        	fullHide.style.visibility	= 'hidden';
				thumbHide.style.opacity		= '.5';
				thumbHide.style.filter		= 'alpha(opacity=50)';
				// Break out of loop since there can only be one
				break;
			}
	    }
		// Then display new full photo and highlight new thumbnail
		full.style.display		= 'block';
        full.style.visibility	= 'visible';
		thumb.style.opacity		= '0';
		thumb.style.filter	= 'alpha(opacity=0)';
	}
}

function getElementsByClassName(oElm, strTagName, strClassName)
{
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++)
	{
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className))
		{
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
//////////////////////////////////////////////////////////////////
// Function to delete default content in field when clicked on. //
//////////////////////////////////////////////////////////////////
function delDef(val)
{
	if (val.value=="Street, City, State, Zip Code")
	{
		val.value="";
	}
}
//////////////////////////////////////////////////////////////
// Function to grab address and pass it over to Google Maps //
//////////////////////////////////////////////////////////////
function mapit(theForm)
{
	var sAddress = (theForm.address.value!="Street, City, State, Zip Code")?theForm.address.value:"";
	var eAddress = "304 A North Main Street, Spring Valley, NY 10977";
	sAddress = URLEncode(sAddress);
	eAddress = URLEncode(eAddress);
	window.open("http://maps.google.com/maps?f=d&hl=en&saddr="+sAddress+"&daddr="+eAddress+"&ie=UTF8&iwloc=addr")
}

function URLEncode(str)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = str;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
}