// JavaScript Document



window.onload = Initiate;

// Initiate function called by the onload attribute of the body tag in each Village Arts web page 

function Initiate() {



doQuote();


// this routine finds the local current date and inserts
// the data into the element identified by the id tag
var d = new Date();
document.getElementById("DateBox").innerHTML=d.toLocaleDateString();


// this secion of code creates the menu items and depending on the title of the page, inserts the current class for specific css

// set the inital variables
var docTitle = document.title;
var menuline = "";

// Define a menu item constructor object 
function Menu(ur, tit, head, include) {
		this.urlref = ur;
		this.title = tit;
		this.heading = head;
		this.include = include;
}

// define the menu array
var m = new Array();
m[0] = new Menu("index.html", "Village Arts, Kohukohu, Hokianga, New Zealand", "home", "true");
m[1] = new Menu("current.html", "4 Years On, Village Arts, Kohukohu, New Zealand", "exhibition", "true");
m[3] = new Menu("artists.html", "Artists, Village Arts, Kohukohu", "artists", "true");
m[2] = new Menu("ukulele.html", "Ukulele, Village Arts, Kohukohu, New Zealand", "ukulele", "true");
m[4] = new Menu("showcase.html", "Showcase, Village Arts, Kohukohu", "showcase", "false");
m[5] = new Menu("small.html", "Great Little Room, Village Arts, Kohukohu", "great little room", "false");
m[6] = new Menu("HistoricKohukohu.html", "Historic Photographs and Kohukohu Book, Village Arts, Kohukohu", "historic", "true");
m[7] = new Menu("jemail.html", "Contact Form, Village Arts, Kohukohu", "contact", "true");

// loop through array and build menu code
for (var z = 0; z < m.length; z++) {
	if (m[z].include == "true") {
		menuline = menuline + "<a href=" + m[z].urlref;
		if (m[z].title == docTitle) 
			menuline = menuline + " class='current'>";
		else {
			menuline = menuline + ">";
		}
	
	menuline = menuline + m[z].heading + "</a>";	
	}
}

// apply html code to the element containing the menu items
document.getElementById("menuitems").innerHTML=menuline;



// add an event listener for the email validation textbox on the contact form on the contact page jemail.html
// add an event listener for the quotation, when clicked it selects another quote


if (document.addEventListener) { 
	document.getElementById("emailcheck").addEventListener("blur", validateEmail, true);
	document.getElementById("quotationcontainer").addEventListener("click", doQuote, true);
}
	
else if (document.attachEvent) { 
	document.getElementById("emailcheck").attachEvent("onchange", validateEmail);
	document.getElementById("quotationcontainer").attachEvent("onclick", doQuote);
}

// end of initiate function
}


//functions:

// doQuote
//this function randomly selects a quotation from the array and inserts it into the quotation text	

function doQuote() {	


// First, define a constructor for each quotation
function Quotation(q, a, s) {
		this.quote = q;
		this.author = a;
		this.source = s;
}

// The next sequence of code creates the array and the randomised quote generator 
// first define the array
var a = new Array();

// add new Quotation object functions containing the quotes
a[0] = new Quotation("Art is not made for anybody and is, at the same time, for everybody.", "Piet Mondrian","");
a[1] = new Quotation("My garden is my most beautiful masterpiece.", "Claude Monet","");
a[2] = new Quotation("If I were a better artist, I'd be a painter, and if I were a better writer, I'd write books... but I'm not, so I draw cartoons!", "Charles Shultz","");
a[3] = new Quotation("Sometimes I've believed as many as six impossible things before breakfast.", "Lewis Carroll","");
a[4] = new Quotation("When I paint, the sea roars. The others splash about in the bath.", "Salvador Dali","");
a[5] = new Quotation("I constantly have to negotiate with my doubts.", "Peter Doig","");
a[6] = new Quotation("At moments of great enthusiasm it seems to me that no one in the world has ever made something this beautiful and important.", "M.C. Escher","");
a[7] = new Quotation("Every man's work, whether it be literature or music or pictures or architecture or anything else, is always a portrait of himself.", "Samuel Butler","");
a[8] = new Quotation("The job of the artist is always to deepen the mystery.", "Francis Bacon","");
a[9] = new Quotation("Great art is as irrational as great music. It is mad with its own loveliness.", "George Jean Nathan","");
a[10] = new Quotation("Painting is easy when you don't know how, but very difficult when you do.", "Edgar Degas","");
a[11] = new Quotation("If the population of a region is weighted too far toward small villages, modern civilisation can never emerge; but if the population is weighted too far toward big cities, the earth will go to ruin because the population isn't where it needs to be, to take care of it.", "Christopher Alexander, Sara Ishikawa, Murray Silverstein", "A Pattern Language");
a[12] = new Quotation("Above all, it is a matter of loving art, not understanding it.", "Fernand Leger","");
a[13] = new Quotation("How a community supports the arts provides insight into how the community views itself.", "James E. Rogers","Cinergy Corp");
a[14] = new Quotation("You don't take a photograph, you make it.", "Ansel Adams","");
a[15] = new Quotation("A photograph is a secret about a secret. <br/>The more it tells you the less you know.", "Diane Arbus","");
a[16] = new Quotation("A photograph is neither taken nor seized by force. It offers itself up. It is the photo that takes you. One must not take photos.", "Henri Cartier-Bresson","");
a[17] = new Quotation("Black and white are the colors of photography. To me they symbolise the alternatives of hope and despair to which mankind is forever subjected.", "Robert Frank","");
a[18] = new Quotation("The best zoom lens is your legs.", "Ernst Haas","");
a[19] = new Quotation("There is no substitute for feeling the stone, the metal, the plaster, or the wood in the hand; to feel its weight; to feel its texture; to struggle with it in the world rather than in the mind alone.", "William M. Dupree","");
a[20] = new Quotation("When you slow down enough to sculpt, you discover all kinds of things you never noticed before.", "Karen Jobe","");
a[21] = new Quotation("Sculpture is the stuff you trip over when you are backing up trying to look at a painting.", "Jules Olitski","");
a[22] = new Quotation("When inspiration doesn't come, I go halfway to meet it.", "Sigmund Freud","");
a[23] = new Quotation("All art is autobiographical; the pearl is the oyster's autobiography.", "Federico Fellini","");
a[24] = new Quotation("Art is the great democrat, calling forth creative genius from every sector of society, disregarding race or religion or wealth or color.", "John F. Kennedy","");
a[25] = new Quotation("As an artist, all I need is my paints and brushes - and someone to drag me away when the canvas is done.", "Pablo Picasso","");
a[26] = new Quotation("If you could say it in words, there'd be no reason to paint.", "Edward Hopper","");
a[27] = new Quotation("I shut my eyes in order to see.", "Paul Gauguin","");
a[28] = new Quotation("The job of the artist is always to deepen the mystery.", "Francis Bacon","");
a[29] = new Quotation("As a child I drew like Raphael but it has taken me a lifetime to draw like a child.", "Pablo Picasso","");
a[30] = new Quotation("O great creator of being grant us one more hour to perform our art and perfect our lives.", "Jim Morrison","");
a[31] = new Quotation("Whakapapa comes warts and all, making east very different to west.", "Tony Watkins and Graeme North","Kohukohu Historic Precinct");
a[32] = new Quotation("Heritage Precincts should never be finished just as no building should ever be finished.", "Tony Watkins and Graeme North","Kohukohu Historic Precinct");
a[33] = new Quotation("Imperfection leaves the path open to discovery.", "Tony Watkins and Graeme North","Kohukohu Historic Precinct");
a[34] = new Quotation("Heritage Precincts should celebrate imperfection. For the Japanese, Wabi-sabi is the art of seeing perfection through imperfection.", "Tony Watkins and Graeme North","Kohukohu Historic Precinct");
a[35] = new Quotation("Economic strategies which marginalise some people in society have no place in a Heritage Precinct.", "Tony Watkins and Graeme North","Kohukohu Historic Precinct");
a[36] = new Quotation("Strengthening communities so that they will be able to protect their own inheritance is far more important than protecting buildings in the hope that this will build community.", "Tony Watkins and Graeme North","Kohukohu Historic Precinct");
a[37] = new Quotation("An essential ingredient of true wisdom is a dash of folly.", "Amin Maalouf", "");
a[38] = new Quotation("Every person has a pattern language in his mind. This is as true of any great creative artist, as of the humblest builder.", "Christopher Alexander", "The Timeless Way of Building");
a[39] = new Quotation("Outside of a dog, a book is man's best friend. <br/>Inside of a dog, it's too dark to read.", "Groucho Marx", "");
a[40] = new Quotation("Time flys like an arrow, fruit flies like a banana", "Anon", "");
a[41] = new Quotation("To become truly immortal, a work of art must escape all human limits: logic and common sense will only interfere. But once these barriers are broken, it will enter the realms of childhood visions and dreams.", "Giorgio de Chirico", "");
a[42] = new Quotation("Art is creativity, creativity is passion, passion is love.", "Andrew Brynjulson", "");
a[43] = new Quotation("I dream a lot. I do more painting when I'm not painting. It's in the subconscious.", "Andrew Wyeth", "");
a[44] = new Quotation("There's no retirement for an artist, it's your way of living so there's no end to it.", "Henry Moore", "");
a[45] = new Quotation("Beginning with audacity is a very great part of the art of painting.", "Winston Churchill", "");
a[46] = new Quotation("A great architect is not made by way of a brain nearly so much as he is made by way of a cultivated, enriched heart.", "Frank Lloyd Wright", "");
a[47] = new Quotation("The architect must not only understand drawing, but music.", "Vitruvius Pollio ", "");
a[48] = new Quotation("Design is the search for a magical balance between business and art; art and craft; intuition and reason; concept and detail; playfulness and formality; client and designer; designer and printer; and printer and public.", "Valerie Pettis", "");
a[49] = new Quotation("Bad design is smoke, while good design is a mirror.", "Juan-Carlos Fernandez", "");
a[50] = new Quotation("blank", "", ""); // the last object is never selected by the random integer generator next

 
// create randomised integer based on the size of the array

var randomNo = Math.floor(Math.random()*(a.length-1));

// this sequence checks to see if the randomNo is the same as the last number which is stored in the cookie
// if it is then it selects another number

var lqc = document.cookie;
if (lqc) {
	var lastquote = lqc.substring(6, lqc.length);
	while (randomNo == lastquote) {
		randomNo = Math.floor(Math.random()*(a.length-1));
	}
}

// first find the source - the source parameter of the quotation constructor object which is now part of the a[] array
var theSource = a[randomNo].source;
var sourceResponse = "";

// we now need to give the source the italic tag and correct ending html
if (theSource != "") {
	sourceResponse = ", " + "<i>" + theSource + "</i>";
}

// insert the quote into the tage with the quotationcontainer id 
document.getElementById("quotationcontainer").innerHTML="<span class='thequote'><a href=''>&quot;" + a[randomNo].quote + "&quot;</a></span><br /><span class='theauthor'>" + a[randomNo].author + sourceResponse + "</span>";

var g = new Date(document.lastModified);
document.getElementById("lastupdate").innerHTML="Updated: " + g.toLocaleDateString() + " |";

// Code to create the html content of footer

var footerline = "Village Arts, PO Box 18, Kohukohu 0453, Hokianga, Northland, New Zealand  | Tel: +64 09 405-5827 | <a href='jemail.html' class='footerlink'>Contact us</a>  <br/> Last updated: " + g.toLocaleDateString() + " | &copy;Village Arts 2008. All rights reserved. | Quote (" + randomNo + ")";

// insert the footer html code into the footer element
document.getElementById("footer").innerHTML=footerline;

//set cookie to record last quote number used - to ensure next quote is different
document.cookie = "quote=" + randomNo;


//end of doQuote function
}


// the next functions are used on the contact page to validate the form

// the first called by the event listener for the email validation text box and checks to see that it is the same as the first email text box

function validateEmail() { //this function runs when the emailcheck element has lost focus
var ec = document.getElementById("emailcheck");
var ef = document.getElementById("emailfield");
if (ec.value !== ef.value) {
	alert("the email addresses are not the same !");
	ec.value ="";
	ec.focus();
	}
}


// this function checks the form before submission of the form to ensure that the form is correctly filled out
// note that the server-side php routine checks for incorrect characters and may also cancel the submission.

function checkForm() {

var ec = document.getElementById("emailcheck");
var ef = document.getElementById("emailfield");
var nm = document.getElementById("emailname");
var sj = document.getElementById("subject");
var cm = document.getElementById("comments");


if (ef.value == "") {
	alert("please enter an email address");
	ef.focus();
	return false;
}

else if (ec.value !== ef.value) {
	alert("the email addresses do not the match !");
	ec.value ="";
	ef.value ="";
	ef.focus();
	return false;
}

else if (nm.value == "") {
	alert("please enter your name");
	nm.focus();
	return false;
}

else if (cm.value == "") {
	alert("please enter a message");
	cm.focus();
	return false;
}
	
else {
	return true;
}

// end of checkForm function
}




