// JavaScript Document

function FindObject(n, d)
{
	//v4.01
	var p, i, x;
	if(!d)
		d=document;
		
	if ((p=n.indexOf("?"))>0&&parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	
	if (!(x=d[n])&&d.all)
		x=d.all[n];
	
	for (i=0; !x&&i < d.forms.length; i++)
		x=d.forms[i][n];
	
	for (i=0; !x&&d.layers && i < d.layers.length; i++)
		x=FindObject(n,d.layers[i].document);
	
	if(!x && d.getElementById)
		x=d.getElementById(n);
	
	return x;
}

function UpdateImage()
{
	//v3.0
	var i, j=0, x, a=UpdateImage.arguments;
	
	document.MM_sr=new Array;
	for(i=0; i < (a.length-2); i += 3)
		if ((x=FindObject(a[i])) != null)
		{
			document.MM_sr[j++]=x;
			if(!x.oSrc)
				x.oSrc=x.src;
			
			x.src=a[i+2];
		}
}

function Init()
{
	i = 1;
	images = [
				'images/rotate/main1.jpg',
				'images/rotate/main2.jpg',
				'images/rotate/main3.jpg',
				'images/rotate/main4.jpg',
				'images/rotate/main5.jpg'
			];

	setTimeout("SwapImage('rotate', 'images/rotate/main2.jpg', '1', 'Volunteer Cabin Rentals');",4000);
}

function SetTimer()
{
	setTimeout("SwapImage('rotate', 'images/rotate/main3.jpg', '0', 'Volunteer Cabin Rentals');",4000);
}

function SwapImage()
{
	UpdateImage('rotate', '', images[i], 1);
	i++;
	if (i == images.length)
		i=0;
	setTimeout("SwapImage();",4000);
	
}


function checkrequired(which)
{
	var pass=true;
	if (isValidEmail(which.email))
	{
		if (document.images)
		{
			for (i=0;i<which.length;i++)
			{
				var tempobj=which.elements[i];
				if (tempobj.name.substring(0,8)=="required")
				{					
					if (((tempobj.type=="text"||tempobj.type=="textarea")&&
					tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
					tempobj.selectedIndex==0))
					{
						pass=false;
						break;
					}
				}
			}
		}
		if (!pass)
		{
			shortFieldName=tempobj.name.substring(9,30).toUpperCase();
			alert("Please enter your "+shortFieldName+".");
			tempobj.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		which.email.focus();
		return false;
	}
}

function isValidEmail(the_email)
{
	var passed=true;
	if (the_email.value.length < 4)
	{
		passed=false;
	}
	else
	{
		if (! allValidChars(the_email))
		{  // check to make sure all characters are valid
			passed=false;
		}
		else
		{
			if (the_email.value.indexOf("@") < 1)
			{ //  must contain @, and it must not be the first character
				passed=false;
			}
			else
			{
				if (the_email.value.lastIndexOf(".") <= the_email.value.indexOf("@"))
				{  // last dot must be after the @
					passed=false;
				}
				else
				{
					if (the_email.value.indexOf("@") == the_email.value.length)
					{  // @ must not be the last character
						passed=false;
					}
				}
			}
		}
	}
	if (!passed)
	{
		alert("Please enter a valid email address");
		//the_email.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function allValidChars(an_email)
{
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < an_email.value.length; i++)
  {
	var letter = an_email.value.charAt(i).toLowerCase();
	if (validchars.indexOf(letter) != -1)
	  continue;
	parsed = false;
	break;
  }
  return parsed;
}
