// JavaScript Document

//Used to send the user home when the logo is clicked
function goHome()
{
	//alert("going to move");
	document.location = "http://www.backyardgrill.com"
}

//Used to control the sound on the home page
function toggleSound ()
{
	
	var icon = document.getElementById("soundIcon").src;

	if (icon.indexOf("soundsOn") != -1)
	{
		document.all.tags("bgSound")[0].volume = -10000;
		document.getElementById("soundIcon").src = "imgs/soundsOff.jpg";
	}
	else
	{
		document.all.tags("bgSound")[0].volume = 0;
		document.getElementById("soundIcon").src = "imgs/soundsOn.jpg";
	}
	
}

//Contact form validatio
function validateContact()
{
	var thisField = document.frmContact.txtComment.value;
	var thisEmail = document.frmContact.Email.value;
	var error = "N/A";
	var errField;
	var emailFilter=/^.+@.+\..+$/;
	
	
	if (!(emailFilter.test(thisEmail))) 
	{ 
		   error = "Please enter a valid email address.\n";
		   errField = thisEmail;
	}
	else if (!(thisEmail.length > 0))
	{
		   error = "Please enter a valid email address.\n";
		   errField = thisEmail;
	}
	else if (!(thisField.length > 0))
	{
		error = "Please verify you have entered a comment or question.";
		errField = thisField;
	}
	
	if (error != "N/A")
	{
		alert(error);
		errField.focus();
	}
	else
	{
		document.frmContact.submit();
	}
}


//Contact form validatio
function validateClubContact()
{
	var thisField = document.frmClubContact.txtName.value;
	var thisEmail = document.frmClubContact.txtEmail.value;
	var error = "N/A";
	var errField;
	var emailFilter=/^.+@.+\..+$/;
	
	
	if (!(emailFilter.test(thisEmail))) 
	{ 
		   error = "Please enter a valid email address.\n";
		   errField = thisEmail;
	}
	else if (!(thisEmail.length > 0))
	{
		   error = "Please enter a valid email address.\n";
		   errField = thisEmail;
	}
	else if (!(thisField.length > 0))
	{
		error = "Please verify you have entered your name.";
		errField = thisField;
	}
	
	if (error != "N/A")
	{
		alert(error);
		errField.focus();
	}
	else
	{
		document.frmClubContact.submit();
	}
}


//Ajax Stuff Here
function mapCaller(str)
{
	//Update the map with the desired location
	new Ajax.Updater('backyardDirections', 'includes/map.php', { method: 'get',parameters: {id: str}  });	
}

function verifyUsedCode(id)
{
	isUsed = confirm('Are you sure you want to mark the code: ' + id + ' as used?');
	
	if (isUsed)
	{
		//newLocation = 'http://www.backyardgrill.com/validCodes.php?action=' & id;
		//var newLocation = id;
		//alert('Going to mark as used -> ' + newLocation);
		//alert('Going to mark as used ->' + id);
		document.location = "http://www.backyardgrill.com/validCodes.php?action=" + id;
	}
	else
		alert(id + ' Was not used yet');
}