var ieFlag = false;
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) ieFlag = true;
var editor;

function errorHandler(message)
{
	$('disabledZone').style.visibility = 'hidden';
    if (typeof message == "object" && message.name == "Error" && message.description)
    {
        alert("Error: " + message.description);
    }
    else
    {
        alert(message);
    }
}

function pageHeight() {
	var myHeight;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		myHeight = document.body.scrollHeight;
	}
	else // Explorer Mac;
	     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		myHeight = document.body.offsetHeight;
	}
	return myHeight;
}

function toggle(theID) {
foo = document.getElementById(theID);
if (foo.style.display == 'none') foo.style.display = 'inline';
else foo.style.display = 'none';
return;
}

// this function puts the dark screen over the entire page
function dark()
{
   var myHeight = pageHeight();	
   var page_screen = document.getElementById('page_screen');
   page_screen.style.height = myHeight + 'px';
   page_screen.style.display = 'block';
}

// this function removes the dark screen and the page is light again
function light()
{
   var page_screen = document.getElementById('page_screen');
   page_screen.style.display = 'none';
}

function stripNonAlphaNumeric(str) {
  var r = str.replace(/[^a-zA-Z0-9]+/g,'');
  return r;
}

function showBox (Content) {
	var foo = document.getElementById('editWindow');
	var bar = document.getElementById('editContent');
	    w = 500;
	    h = 300;
		usingThisWidth = ( document.documentElement.clientWidth ? document.documentElement.clientWidth : window.innerWidth )
		usingThisHeight = ( document.documentElement.clientHeight ? document.documentElement.clientHeight : window.innerHeight )
	    xc = Math.round((usingThisWidth/2)-(w/2))
	    yc = Math.round((usingThisHeight/2)-(h/2))
	    
		foo.style.width='500px';
		foo.style.height='300px';
		
	    foo.style.left = xc + "px";
	    foo.style.top  = yc + "px";
	    foo.style.display = 'block';
		bar.innerHTML = Content;
	
		dark();
}

function imageZoom (image,caption) {
	var foo = document.getElementById('imgWindow');
	var bar = document.getElementById('zoomImg');
	var cap = document.getElementById('zoomCaption');
	var newImg = new Image();
	newImg.src = "/userfiles/gallery/" + image;
	
	
	newImg.onload = function(){
		bar.src = newImg.src;
		if (caption) cap.innerHTML = caption;
		
		w = newImg.width;
		h = newImg.height;
		xc = Math.round((document.body.clientWidth / 2) - (w / 2));
		yc = 10;
		
		foo.style.width = w + 40 + 'px';
		foo.style.height = h + 80 + 'px';
		
		foo.style.left = xc + "px";
		foo.style.top = yc + "px";
		foo.style.display = 'block';
		
		dark();
	}
}

function hideImg() {
	var foo = document.getElementById('imgWindow');
	var bar = document.getElementById('zoomImg');
	bar.src = "img/dot.html";
	
	foo.style.display='none';
	
	light();
}

function confirmContact(emailAddress) {
	DWREngine._execute(_cfscriptLocation,null,'makeConfirmContent',emailAddress,showBox);
	return false;
}

function sendContactMessage () {
	hideEdit();
	return true;
}

function validateContactForm () {
if(""==document.emailForm.name.value)
{
alert("Please enter your name.");
return false;
}

if(""==document.emailForm.email.value)
{
alert("Please enter your email address.");
return false;
}
document.emailForm.submit();
return true;	
}

