function setPrefix(elmName) {
	if (document.getElementById != null) {
		return document.getElementById(elmName);
	}
	if (document.all != null) {
		return document.all[elmName];
	}
}

function createGallery(galleryid) {
	var tbody = document.getElementsByTagName("body")[0];
	
	var divGalleryBG = setPrefix('divGalleryBG');
	
	if (!divGalleryBG) {
		divGalleryBG = document.createElement('div');
		divGalleryBG.style.position = 'absolute';
		divGalleryBG.style.overflow = 'hidden';
		divGalleryBG.style.display = 'none';
		divGalleryBG.style.top = '0px';
		divGalleryBG.style.left = '0px';
		if (detectMacXFF2()) {
			divGalleryBG.style.backgroundImage = 'url(../images/000000_80.png)';
		}
		else {
			divGalleryBG.style.backgroundColor = '#000000';
			divGalleryBG.style.opacity= .80;                      
			divGalleryBG.style.MozOpacity= .80;                   
			divGalleryBG.style.filter='alpha(opacity=80)';
		}
		divGalleryBG.style.zIndex = 998;
		divGalleryBG.id = 'divGalleryBG';
		tbody.appendChild(divGalleryBG);
		divGalleryBG = setPrefix('divGalleryBG');
	}
	
	// Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = (document.body.scrollWidth)+'px';
        var pageHeight = (document.body.scrollHeight)+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = (document.body.offsetWidth)+'px';
      var pageHeight = (document.body.offsetHeight)+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
	
	divGalleryBG.style.width = pageWidth;
	divGalleryBG.style.height = pageHeight;
	
	divGalleryBG.style.display = 'block';
	
	
	
		
	
	var pageHeight = window.innerHeight || document.documentElement.clientHeight;
	var pageScroll = window.pageYOffset || document.documentElement.scrollTop;
	var flashHeight = 610;
	var flashWidth = 900;
	//if (pageHeight < flashHeight) {
	//	flashWidth = flashWidth * (pageHeight / flashHeight);
	//	flashHeight = pageHeight;
	//}
	//alert(pageHeight);
	//alert(pageScroll);
	var posy = (pageHeight)/2 + (pageScroll) - flashHeight/2;
	if (posy < 0) {
		posy = 0;
	}
	//if ((posy + 700) > (pageHeight - pageScroll)) {
	//	posy = 0;
	//}
	var posx = (window.innerWidth || document.body.clientWidth)/2 - flashWidth/2;
	if (posx < 0) posx = 0;
	
	var divGallery = setPrefix('divGallery');
	
	if (!divGallery) {
		var divGallery = document.createElement('div');
		divGallery.style.position = 'absolute';
		divGallery.style.display = 'none';
		divGallery.style.zIndex = 999;
		divGallery.style.width = flashWidth + 'px';
		divGallery.style.height = flashHeight + 'px';
		divGallery.id = 'divGallery';
		tbody.appendChild(divGallery);
		divGallery = setPrefix('divGallery');
	}
	
	divGallery.style.top = posy + 'px';
	divGallery.style.left = posx + 'px';
	divGallery.innerHTML = 	'' + 
							'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+flashWidth+'" height="'+flashHeight+'" id="gallery" align="middle">' +
							'<param name="allowScriptAccess" value="sameDomain" />' + 
							'<param name="allowFullScreen" value="false" />' +
							'<param name="WMODE" value="Transparent" />' +
							'<param name="movie" value="../swf/photogallery.swf?galleryid=' + galleryid + '" />' +
							'<param name="play" value="false" />' +
							'<param name="loop" value="false" />' +
							'<param name="quality" value="high" />' +
							'<param name="bgcolor" value="#000000" />' +
							'<embed src="../swf/photogallery.swf?galleryid=' + galleryid + '" play="false" loop="false" quality="high" bgcolor="#000000" width="'+flashWidth+'" height="'+flashHeight+'" name="gallery" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" />' +
							'</object>';

	
	
	divGallery.style.display = 'block';
	
	
}
	function closeGallery() {
		var divGalleryBG = setPrefix('divGalleryBG');
		var divGallery = setPrefix('divGallery');
	
	
	if (divGalleryBG) {
		divGalleryBG.style.display = 'none';
	}
	if (divGallery) {
		divGallery.style.display = 'none';
	}
	}
	
	function findPos(obj) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
		
	}
	
	return [curleft, curtop];
}

function detectMacXFF2() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}

function queryFormElements(formName){

	var theForm = setPrefix(formName);
	var queryString = "";
	for(i=0; i<theForm.childNodes.length; i++){
		//queryString += theForm.childNodes[i].name + "=" + theForm.childNodes[i].value + "\n";
		if (theForm.childNodes[i].name != "undefined") {
			if(theForm.childNodes[i].type == "text" || theForm.childNodes[i].type == "textarea"){
				queryString += theForm.childNodes[i].name + "=" + theForm.childNodes[i].value + "&";
			}
			else if(theForm.childNodes[i].type == "hidden") {
				queryString += theForm.childNodes[i].name + "=" + theForm.childNodes[i].value + "&";
			}
			else if(theForm.childNodes[i].type == "radio") {
				if(theForm.childNodes[i].checked == true ) {
					queryString += theForm.childNodes[i].name + "=" + theForm.childNodes[i].value + "&";
				}
			}
			else if(theForm.childNodes[i].type == "checkbox") {
				queryString += theForm.childNodes[i].name + "=" + theForm.childNodes[i].checked + "&";
			}
			else if(theForm.childNodes[i].type == "select-one") {
				queryString += theForm.childNodes[i].name + "=" + theForm.childNodes[i].options[theForm.childNodes[i].selectedIndex].text + "&";
			}
			
		}
	}
	queryString = queryString.substr(0,queryString.length-1);
	return queryString;

}

function validateForm(formName) {
	var theForm = setPrefix(formName);
	for(i=0; i<theForm.childNodes.length; i++){
		if (theForm.childNodes[i].name != "undefined") {
			if (theForm.childNodes[i].name == "EmailFrom" && theForm.childNodes[i].value == "") {
				alert('Please enter a valid email address.');
				theForm.childNodes[i].focus();
				return false;
			}
			if (theForm.childNodes[i].name == "EmailFrom" && theForm.childNodes[i].value.indexOf(".") < 2 && theForm.childNodes[i].value.indexOf("@") < 0) {
				alert('Please enter a valid email address.');
				theForm.childNodes[i].focus();
				return false;
			}
		}
	}
	
	return true;
}

function UpdateClock() {
	tDate = new Date();
	tHours = tDate.getHours();
	tMinutes = tDate.getMinutes();
	tMeridian = "AM";
	
	if (tHours > 12) {
		tHours = tHours - 12;
		tMeridian = "PM";
	}
	
	if (tMinutes < 10) {
		tMinutes = "0" + tMinutes;
	}
	//if (blinker == true) {
		setPrefix("Clock").innerHTML = tHours + ":" + tMinutes + " " + tMeridian;
	//	blinker = false;
	//}
	//else {
	//	setPrefix("TB_Clock").innerHTML = tHours + "<span style='visibility:hidden'>:</span>" + tMinutes + " " + tMeridian;
	//	blinker = true;
	//}
}

window.onload = function() {
	clock = setInterval("UpdateClock()", 1000);
}
