$(document).ready(function() {
	//Make each banner fade in
	$("div#header").fadeIn(2000);
	
	//Contact popup
	$("a[rel='contactPopup']").click(function() {
		//Create a variable to hold window features
		var winFeatures = "height=450,width=375,resizable=0,scrollBars=0,location=0";
		//Variable that refers to the actual window
		newWin = window.open(this.href, 'Contact', winFeatures);
		//Make sure this doesn't fire automatically
		return false;
	});
	
	//Music Chart popup
	$("a[rel='musicChart']").click(function() {
		//Variable that contains window's features
		var winFeatures = "height=550,width=900, resizable=0,scrollBars=0,location=0";
		//Variable that references the actual window...
		newWin = window.open(this.href, 'Charts', winFeatures);
		//Make sure window doesn't open automatically
		return false;
	});

});

function validateForm(form) {
	//Determine if this is a valid email address
	//form names: who_txt, where_txt, comments_txt
	if(validateEmailAddress(form.email_field) == false) {
		//Post an alert box telling the user to put a valid email address in
		alert("Please enter a valid email address!");
		//Focus the form element
		form.email_field.focus();
		//return a false value to the function
		return false;
	}
	
	//Determine if this input field has any text in it
	if(fieldContainsText(form.name_field) == false) {
		//Post an alert box telling the user to put a name in
		alert("Please put your name in there!");
		//Focus the form element
		form.name_field.focus();
		//return a false value to the function
		return false;
	}
	
	//Determine if this input field has any text in it
	if(fieldContainsText(form.comment_field) == false) {
		//Post an alert box telling the user to put a name in
		alert("Please put your comments in there!");
		//Focus the form element
		form.comment_field.focus();
		//return a false value to the function
		return false;
	}
	
	return true;
}

function validateEmailAddress(element) {
	//Determine if the input contains the characters @ and a period
	if(element.value.indexOf("@") != "-1" && element.value.indexOf(".") != "-1") {
		//It does, all is ok
		return true;
	} else {
		//Not a valid email address
		return false;
	}
}

function fieldContainsText(element) {
	//Determine if the input has any text in it
	if(element.value == "" || element.value == null) {
		//No text in the input
		return false;
	} else {
		//There's text in the input
		return true;
	}
}

function resetForm() {
	//Define new Array to hold all form fields to clear text from
	var formFields = new Array("form.name_field", "form.email_field", "form.comment_field");
	//Loop through each element in the Array
	for(var i=0; i < formFields.length; i++) {
		//Strip all text from the fields in the Array
		formFields[i].value = "";
	}
	//Let the user know that the form has been cleared...
	alert("Form has been cleared.");
}
