function validateForm(form)
{
	if(form.address.value == '' && form.postal.value == '' && form.city.value == '' && form.province.value == '' && form.country.value == '')
	{
		alert('You must enter in something to search for in the form');
	}
	else
	{
		geoCodeAddress(document.addrForm);
	}
}

function checkKey(form,e)
{
	var keycode;
	
	if(window.event)
	{
		keycode = window.event.keyCode;
	}
	else
	{
		if(e)
		{
			keycode = e.which;
		}
		else
		{
			return true;
		}
	}
	//Key code 13 is enter/return
	if(keycode == 13)
	{
		validateForm(form);
	}
	else
	{
		return true;
	}
}

//Sets up the links in the hidden div and shows it
function readyLinks()
{
	$('urlLink').value = "http://www.whatsmygps.com/index.php?lat="+$('latitude').value+"&lng="+$('longitude').value;
	$('htmlLink').value = "<a href='http://www.whatsmygps.com/index.php?lat="+$('latitude').value+"&lng="+$('longitude').value
		+ "'>http://www.whatsmygps.com/index.php?lat="+$('latitude').value+"&lng="+$('longitude').value+"</a>";
	$('bbLink').value = "[url]http://www.whatsmygps.com/index.php?lat="+$('latitude').value+"&lng="+$('longitude').value+"[/url]";
	
	showBox('linkBox','links');
}

//Function that creates the new popup window for the email form
function emailForm()
{
	var lat;
	var lng;
	var zoom;
	lat = $("latitude").value;
	lng = $("longitude").value;
	zoom = getCurrentZoom();
	
	window.open('_email.php?lat='+lat+'&lng='+lng+'&zoom='+zoom,'_blank','resizable=no,toolbar=no,height=400,width=500');
}

//Function to make the box appear on the screen
//box = string id for a 'box' div
function showBox(box,target)
{
	$(box).setStyle('display','block');
	placeBox($(box),target);
}

//Function to make the box disappear from the screen
//box = string id for a 'box' div
function hideBox(box)
{
	$(box).setStyle('display','none');
}

//Function that places the 'box' next to the 'target' (to its right)
function placeBox(box, target)
{
	//Gets the top offset of the element
	var tTop = $(target).getPosition().y;
	//Gets the right side of the element via x position + width + a spacer
	var tSide = $(target).getPosition().x + $(target).getSize().x + 5;
	
	//Set CSS styles
	box.setStyle('position','absolute');
	box.setStyle('z-index',99);
	box.setStyle('top',tTop);
	box.setStyle('left',tSide);
}

//Function that handles when the address textboxes are focused on
function focusAddress(text, obj)
{
	if($(obj).value == text)
	{
		$(obj).value = "";
		$(obj).setStyle("color","black");
	}
}

//Function that handles when the user leaves the address textboxes
function blurAddress(text, obj)
{
	if($(obj).value == "" || $(obj).value == text)
	{
		$(obj).value = text;
		$(obj).setStyle("color","gray");
	}
}

function loadPage()
{
	blurAddress('Address','address');
	blurAddress('Town/City','city');
	blurAddress('Province/State','province');
	blurAddress('Postal Code/Zip','postal');
	blurAddress('Country','country');
}
