// JavaScript Document

//use the following var to remember an image's original src value
//the imageRoll function will constantly update this value, allowing the imageOut function to use its current value
var imageSourceValue = '';
function imageRoll(imageObject)
{
	//store the current src value
	imageSourceValue = imageObject.src;
	//grab the directory from the src attribute
	var folderIndex = imageObject.src.lastIndexOf("/");
	var theDirectory = imageObject.src.substring(0,folderIndex+1);//returns the DIR in the form http://domain.com/folder
	//test for image file type, jpg v. gif
	var theFileType = imageObject.src.substring(imageObject.src.length-3);//grab the last 3 characters, they represent the file type

	imageObject.src=theDirectory+imageObject.name+'-on.'+theFileType;
}
function imageOut(imageObject)
{
	//retrieve the original image src attribute
	imageObject.src = imageSourceValue;
}

var googleWindow = 0;
var popWin = 0;
function popGoogle()
{
	var left = 100;
	var top = 50;
	var width = 650;
	var height = 600;

  if(googleWindow)
  {
    if(!googleWindow.closed) googleWindow.close();
  }

  googleWindow = open('http://northernforestcanoetrail.org/googleMapChooseLocation.htm', 'googleWindow', 'toolbar=1,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}

function popEnews(email)
{
	var left = 100;
	var top = 50;
	var width = 550;
	var height = 400;
	
	popWin = open('http://northernforestcanoetrail.org/enews.cfm?emailAddress='+email, 'popWin', 'toolbar=1,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	
}

function checkForm()
{
	var d = document.submitform;
	var badPhoto = false;
	var re = new RegExp("^[A-Za-z0-9_-]+[A-Za-z0-9_\.\-]*[A-Za-z0-9_-]+@[A-Za-z0-9_-]+[A-Za-z0-9\.-]*\\.[a-zA-Z]{2,4}$","i");
		
	var theEXT = d.photo1.value.substring(d.photo1.value.length-3).toLowerCase();;//grab the last 3 characters, they represent the file type
	
	if(d.photo1.value == '')
	{
		alert('Please choose your photo.');
	}
	else if(theEXT != 'jpg' && theEXT != 'peg')
	{
		badPhoto = true;
		alert('Photo 1 must be saved in the .JPG or .JPEG file format.');
	}
	
	else if(d.sectionID.selectedIndex == 0)
	{
		alert('Please choose a section.');
	}
	
	else if(d.title.value == '')
	{
		alert('Please enter a title for your photo.');
	}
	else if(d.name.value == '')
	{
		alert('Please enter your name.');
	}
	else if(!re.test(d.email.value))
	{
		alert('Your email address does not seem to be correct!');
	}
	else if(d.latitude.value == '')
	{
		alert('Please choose the photo\'s location.');
	}
	else if(d.description.length > 2000)
	{
		alert('Please limit your description to 2000 characters.');
	}
	else if(document.getElementById("agree").checked == false){alert('Please check that you have read the Terms & Conditions!');}
	else if(!badPhoto)
	{
		d.submit();
		document.getElementById("uploadingText").style.visibility = "visible";
	}
}

function popUpWindow(thefile)
{
	var left = 100;
	var top = 50;
	var width = 650;
	var height = 600;

  if(popWin)
  {
    if(!popWin.closed) popWin.close();
  }

  popWin = open(thefile, 'popWin', 'toolbar=1,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}

function videoSubmit(){

	var d = document.videoForm;
	var re = new RegExp("^[A-Za-z0-9_-]+[A-Za-z0-9_\.\-]*[A-Za-z0-9_-]+@[A-Za-z0-9_-]+[A-Za-z0-9\.-]*\\.[a-zA-Z]{2,4}$","i");
	if(!re.test(d.subject.value)){alert("Your email address does not seem to be correct!");}
	else if(d.name.value==''){alert("You must enter your name!");}
	else if(d.title.value==''){alert("You must enter the title of your video!");}
	else if(d.description.length > 2000)
	{
		alert('Please limit your description to 2000 characters.');
	}
	else if(d.sectionID.selectedIndex == 0)
	{
		alert('Please choose a section.');
	}
	else if(d.videoURL.value==''){alert("You must enter the URL of your video from YOUTUBE.COM!");}
	else if(d.embedScript.value==''){alert("You must enter the embed script of your video from YOUTUBE.COM!");}
	else
	{
		d.submit();
	}
}


var popUpWin=0;
function outsideWindow(URLStr)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600,left=10, top=10,screenX=10,screenY=10');
}