Storytellers = {
	verifyContact: function(form) {
		var errors = new Array();
		
		// Require that they have chosen a preference for how to get back to them
		if( $('contact_preferred_contact').selectedIndex < 1 )
			errors[errors.length] = 'Please specify a contact preference.'
			
		// Require that they have provided a phone number OR email address depending on their contact preference
		if( errors.length < 1 ) {
			var preferred_contact = $('contact_preferred_contact').options[$('contact_preferred_contact').selectedIndex].text;
			
			if( preferred_contact == 'Phone' && !$('contact_phone').value )
				errors[errors.length] = 'Please specify a phone number for us to contact you at.';
			else if ( preferred_contact == 'Email' && !$('contact_email').value )
				errors[errors.length] = 'Please specify an email address for us to contact you at.';
			
		} else {
			if ( !$('contact_email').value && !$('contact_phone').value )
				errors[errors.length] = 'Please specify a phone number or email address for us to contact you at.';
		}
		
		// Make sure they they have an enquiry
		if( !$('contact_enquiry').value )
			errors[errors.length] = 'Please specify a message to deliver.';
	
			
		// If there are any errors, alert them and return false.  Otherwise let it go through.
		if( errors.length > 0 ) {
			var message = "Please correct the following issues before proceeding:\n\n";
			for(var i = 0; i < errors.length; i++)
				message += " - " + errors[i] + "\n";
			alert(message);
			return false
		}
		
		return true; // Yay!
	}
}

Storytellers.Photos = {
	goAlbum: function(box) {
		// Make sure we have a valid option
		if(!box || box.selectedIndex < 1) return;
		var option = box.options[ box.selectedIndex ];
		if(!option.text) return;
		
		window.location = '/gallery?album=' + option.text;
	}
}



Utils = {
	confirmDelete: function(link, text) {
		if( confirm('Are you sure you wish to permanently and irreversibly delete this ' + text + ' and all related information?') ) {			
			return true; // They said yes
		}
		
		return false;  // They said no
	},
	
	selectNavigation: function(box, url_string) {
		// No box?  No options?  No selection?
		if(!box || !box.options || box.selectedIndex == -1) return;
		
		// Get the ID of the selected item
		var id = box.options[box.selectedIndex].value;
		if(id == '' || id == 0) return;
		
		// Apend it to the url string
		url_string = url_string + id;
		
		// Change the window location
		window.location = url_string;		
		
	}
}


