// JavaScript Document
//validate the log in form
function validate_LogInForm ()
{
    valid = true;

    if ( document.login.email.value == "" )
    {
        alert ( "Please fill in the 'Email' box." );
        valid = false;
    } 
    return valid;

	if ( document.login.password.value == "" )
    {
        alert ( "Please fill in the 'Password' box." );
        valid = false;
    } 
	
}
//validdate the administration logon page
function validateAdminLogOn() {
	valid = true;
	
  if (document.adminLogIn.adminName.value == "" ) {
	   alert("Please enter the administrator username")
	   document.adminLogIn.adminName.focus()
	   valid = false;
	   } 
		else if ( document.adminLogIn.adminPassword.value == "" ) {
		alert("Please enter the administrator password")
		document.adminLogIn.adminPassword.focus()
		valid = false;
	   }
		return valid;
}


//Check to ensure a valid username/email and that the password field has been filled in
//otherwise an error message will be displayed.
function validateTheLogIn() { 

	var em = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/ 
	var pa = /^([a-zA-Z0-9]{1,50})$/
	
	if (!em.test(login.email.value)) { 
	alert("Please enter a valid email address e.g \"yourname@hotmail.com\"") 
	document.login.email.focus()
	} 
	else if (!pa.test(login.password.value)) { 
	alert("Please enter a valid password")
	document.login.password.focus() 
	}
	else document.login.submit()
}

//validation for the feedback form

function validateFeedback () {
	var eml	= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/ 
	var nam = /^([a-zA-Z0-9\s]{1,255})$/ 
	var fdbk = /^([a-zA-Z0-9\s]{1,255})$/
	valid = true;
	
	if (!eml.test(feedbackfrm.email.value)) { 
	alert("Please enter a valid email address e.g \"yourname@hotmail.com\"") 
	document.feedbackfrm.email.focus()
	valid = false;
	} 
	else if (!nam.test(feedbackfrm.username.value)) {
		alert("Please enter your name")
		document.feedbackfrm.name.focus()
		valid = false;
	}
		else if (!fdbk.test(feedbackfrm.fdbk.value)) {
		alert("Please enter your feedback or comment")
		document.feedbackfrm.fdbk.focus()
		valid = false;
	}
	return valid;
}

//validate the review form

function validateReview () {
	var com = /^([a-zA-Z0-9\s.,]{1,255})$/ 
	valid = true;
	
	if (!com.test(review.review.value)) { 
	alert("Please enter your feedback or review") 
	document.review.review.focus()
	valid = false;
	} 
}

//Validation for the Sign Up form
function validateSignUp () {
	
	var em = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/ 
	var pa = /^([a-zA-Z0-9]{1,50})$/
	var nam = /^([a-zA-Z0-9\s]{1,255})$/ 
	var art = /^([a-zA-Z0-9\s]{1,255})$/ 
	var twn = /^([a-zA-Z0-9\s]{1,255})$/ 
	var cty = /^([a-zA-Z0-9\s]{1,255})$/ 
	
	valid = true;
	
	if (!em.test(goldsignup.email.value)) { 
	alert("Please enter a valid email address e.g \"yourname@hotmail.com\"") 
	document.goldsignup.email.focus()
	valid = false;
	} 
	else if (!pa.test(goldsignup.password.value)) { 
	alert("Please enter a valid password")
	document.goldsignup.password.focus() 
	valid = false;
	}
	else if (!nam.test(goldsignup.username.value)) {
		alert("Please enter your name")
		document.goldsignup.username.focus()
		valid = false;
	}
	else if (!art.test(goldsignup.bandname.value)) {
		alert("Please enter your artist/band name")
		document.goldsignup.bandname.focus()
		valid = false;
	}
	else if (!twn.test(goldsignup.residence.value)) {
		alert("Please enter your town")
		document.goldsignup.residence.focus()
		valid = false;
	}
	else if (!cty.test(goldsignup.country.value)) {
		alert("Please enter your country")
		document.goldsignup.country.focus()
		valid = false;
	}
//	else document.login.submit()
	return valid;
}
//Validation for the upload page/EditMusic
function validateUploadTrack () {
	
	valid = true;
	
	var fileName = /^([a-zA-Z0-9\s\\.:]{1,255})$/ 
	var theTitle = /^([a-zA-Z0-9\s]{1,255})$/ 
	
 	if (!fileName.test(uploadSong.userfile.value)) {
// 	if (document.uploadSong.userfile.value == "") {
	 	alert("Please select an audio track to upload")
	 	document.uploadSong.userfile.focus()
	 	valid = false;
 	} 
	if (!theTitle.test(uploadSong.item_code.value)) {
		alert("Please enter a title to your audio track")
		document.uploadSong.item_code.focus()
		valid = false;
	}
	return valid;

}
//Validation for profile page for no changes
function validateProfile () {
	
	valid = true;
	
  if (( document.updateProfile.password.value == "" ) &&
     ( document.updateProfile.email.value == "" ) &&
     ( document.updateProfile.userfile.value == "" ) &&
     ( document.updateProfile.website.value == "" ) &&
     ( document.updateProfile.profile.value == "" )) {
		alert("No changes made - profile unchanged")
		valid = false;
	}
	
	return valid;
}