function setActive(tag)
{
	var element = document.getElementById(tag);
	element.className = 'active';
	//element.style.className = 'active';
	//element.style.class = 'active';
}

function load()
{
	if (GBrowserIsCompatible())
	{
		// Create basic map
		var map = new GMap2(document.getElementById("map"));
		
		// Set map controls and center point
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(29.628384, -98.651733), 13);
				
		// Add map marker to map
		var point = new GLatLng(29.628384, -98.651733);
		map.addOverlay(new GMarker(point));
	}
}

function showSidebar(thePage)
{
	var gmapBox = document.getElementById('gmap');
	var gmapDiv = document.getElementById('gmapDiv');
	var centerBox = document.getElementById('center');
	var centerDiv = document.getElementById('centerDiv');
	var tourBox = document.getElementById('tour');
	var tourDiv = document.getElementById('tourDiv');
	var infoBox = document.getElementById('info');
	var infoDiv = document.getElementById('infoDiv');
	var tipsBox = document.getElementById('tips');
	var tipsDiv = document.getElementById('tipsDiv');
	
	var bldrBKG = document.getElementById('builders_nav');
	var barclay = document.getElementById('barclay');
	var diamante = document.getElementById('diamante');
	var cariola = document.getElementById('cariola');
	
	if (thePage == 'home')
	{
		tourBox.style.display = 'block';
		tourDiv.style.display = 'block';
		infoBox.style.display = 'block';
		infoDiv.style.display = 'block';
		tipsBox.style.display = 'block';
	}else if(thePage == 'contact')
	{
		gmapBox.style.display = 'block';
		//gmapDiv.style.display = 'block';
		centerBox.style.display = 'block';
		centerDiv.style.display = 'block';
	}else if(thePage == 'barclay')
	{
		barclay.style.display = "block";
		bldrBKG.className = 'barclayBKG';
	}else if(thePage == 'diamante')
	{
		diamante.style.display = "block";
		bldrBKG.className = 'diamanteBKG';
	}else if(thePage == 'cariola')
	{
		cariola.style.display = "block";
		bldrBKG.className = 'cariolaBKG';
	}else
	{
		tourBox.style.display = 'block';
		tourDiv.style.display = 'block';
		infoBox.style.display = 'block';
	}
}

function swapImage(tag)
{
	document.getElementById('img1').style.display = "none";
	document.getElementById('img2').style.display = "none";
	document.getElementById('img3').style.display = "none";
	
	var image = document.getElementById(tag);
	image.style.display = "block";
}

var pos = 1;
var t;

function community(tag)
{
	var arr = new Array('sunrise', 'hill', 'park', 'sunset', 'skyline', 'pool', 'pavilion', 'courts', 'trails', 'entrance');
	
	for(i = 0; i < 10; i++)
	{
		var tag1 = arr[i];
		var tag2 = arr[i] + '_img';
		document.getElementById(tag1).className = "";
		document.getElementById(tag2).style.display = "none";
		if (tag1 == tag) { pos = i; }
	}
	
	if (tag)
	{
		var link = document.getElementById(tag);
		var img = tag + '_img';
		var image = document.getElementById(img);
		clearTimeout(t);
		if (pos == 10) { pos = 0; }else{ pos++; }
	}else
	{
		var link = document.getElementById(arr[pos]);
		var img = arr[pos] + '_img';
		var image = document.getElementById(img);
		//alert(pos);
		if (pos == 10) { pos = 0; }else{ pos++; }
		//alert(pos);
	}
	
	link.className = "active";
	image.style.display = "block";
	
	//t = setTimeout("community('');", 4000);
}

function community_auto()
{
	t = setTimeout("community('');", 4000);
}

function check_control(box, tag)
{
	var divBox = document.getElementById(tag);
	
	if (box.checked == true)
	{
		divBox.style.display = 'block';
	}else{
		divBox.style.display = 'none';
	}
}

function validateForm(formName)
{
	var theForm = document.getElementById(formName);
	var invalid = false;
	
	if (theForm.name == 'contactForm')
	{
		if (theForm.firstName.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.firstName);
		}
		
		if (theForm.lastName.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.lastName);
		}
		
		if (theForm.email.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.email);
		}
		
		if (theForm.address.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.address);
		}
		
		if (theForm.city.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.city);
		}
		
		if (theForm.state.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.state);
		}
		
		if (theForm.zip.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.zip);
		}
		
		if (theForm.daytime.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.daytime);
		}
		
		if (invalid == true)
		{
			alert('This form is invalid. Please check the highlighted fields for accuracy.');
			return;
		}
		
		theForm.action = 'thank-you.shtml'
		theForm.submit();
	}else if (theForm.name == 'landbuyingForm')
	{
		if (theForm.firstName.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.firstName);
		}
		
		if (theForm.lastName.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.lastName);
		}
		
		if (theForm.email.value == '')
		{
			invalid = true;
			highlightInvalid(theForm.email);
		}
		
		if (invalid == true)
		{
			alert('This form is invalid. Please check the highlighted fields for accuracy.');
			return;
		}
		
		theForm.action = 'thank-you.shtml'
		theForm.submit();
	}
}

function highlightInvalid(theField)
{
	theField.parentNode.id = 'invalid';
}