/** VALIDATION **/

function CheckEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	var valid = true;

	if (str.indexOf(at)==-1){
		valid = false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		valid = false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		valid = false;
	}

	if (str.indexOf(at,(lat+1))!=-1){
		valid = false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		valid = false;
	}

	if (str.indexOf(dot,(lat+2))==-1){
		valid = false;
	}

	if (str.indexOf(" ")!=-1){
		valid = false;
	}

	return valid;					
}



function ValidateForm() {

	var email = document.contactForm.email;
	var errorMsg = "";	

	if ((email.value == null) || (email.value == "")) {
		errorMsg += "Please enter your email address.\n";
	} else if (CheckEmail(email.value) == false) {
		errorMsg += "The email address you entered is not valid.\n";
	}


	if (errorMsg.length > 0) {
		alert(errorMsg);
		return false;
	} else {
		return true;
	}
}


function ValidateApplicationForm() {

	var stageName = document.applicationForm.stageName;
	var legalName = document.applicationForm.legalName;
	var email = document.applicationForm.email;
	var phone = document.applicationForm.phone;
	var bio = document.applicationForm.bio;
	
	var errorMsg = "";	

	if ((stageName.value == null) || (stageName.value == "")) {
		errorMsg += "Please enter your stage name.\n";
	}	
	
	if ((legalName.value == null) || (legalName.value == "")) {
		errorMsg += "Please enter your legal name.\n";
	}		
	
	if ((email.value == null) || (email.value == "")) {
		errorMsg += "Please enter your email address.\n";
	} else if (CheckEmail(email.value) == false) {
		errorMsg += "The email address you entered is not valid.\n";
	}

	if ((phone.value == null) || (phone.value == "")) {
		errorMsg += "Please enter your phone number.\n";
	}	
	
	if ((bio.value == null) || (bio.value == "")) {
		errorMsg += "Please enter your bio.\n";
	}
	
	if (errorMsg.length > 0) {
		alert(errorMsg);
		return false;
	} else {
		return true;
	}
}


function ValidateSubmitForm() {

	var name = document.submitForm.email;
	var email = document.submitForm.email;

	var errorMsg = "";

	if ((email.value == null) || (email.value == "")) {
		errorMsg += "Please enter your email address.\n";
	} else if (CheckEmail(email.value) == false) {
		errorMsg += "The email address you entered is not valid.\n";
	}

	if ((name.value == null) || (name.value == "")) {
		errorMsg += "Please enter your name.\n";
	}

	if (errorMsg.length > 0) {
		alert(errorMsg);
		return false;
	} else {
		return true;
	}	
} 
 

function ValidateNewsletter() {

	var emailID = document.newsletterForm.email;

	if ((emailID.value == null) || (emailID.value == "")) {
		alert("Please enter your email address!");
		emailID.focus();
		return false;
	}

	if (CheckEmail(emailID.value) == false) {
		emailID.value="";
		emailID.focus();
		return false;
	}

	return true;
}


/** AUDIO PLAYER **/

AudioPlayer.setup("http://hushnightclub.ca/includes/player.swf", {
	width: 700,
	loader: 'C70000',
	righticonhover: 'C70000',
});


/** JQUERY **/

$(document).ready(function(){
	
	// Home page posters
	$('.imgcontainer').hover(
		function () {
			$(this).attr('style', 'border-color: #777777;');
			
		}, 
		function () {
			$(this).removeAttr('style');
		}
	);
	
	// Calendar
	$('td.datelink').hover(
		function () {
			$(this).attr('style', 'color: #666666; font-weight: bold; background-color: #EEEEEE; border: 1px solid #777777;');
			$('a', this).attr('style', 'color: #000000;');
		}, 
		function () {
			$(this).removeAttr('style');
			$('a', this).removeAttr('style');
		}
	);

});
