// JavaScript Document

//names of files at top level: in desired order of display, left to right
var files = ["index.html","resume.html","projects.html","misc.html"];//,"contact.php"];
//text to display for each link
var display = ["Home","Resume","Projects","Other"];//,"Contact"];

function createPrimaryNav(path, current){
	//@param path - file path to reach the top level of the site from the current page
	//							ex: ".." or "../.." or "../", etc.; error if path is omitted
	//@param current - matches display index to set class='current' for link
	if (path != null){
		if (path.substr(path.length-1) != "/"){
			//normalize the submitted path name for compatability
			path = path + "/";
		}
	}
	else path = "";

	document.write("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
	document.write("<tr><td id=\"tabspace\">&nbsp;</td>");
	for (var i = 0; i < files.length; i++){
		document.write("<td class=\"tab\"><a ");
		if (i == current) document.write(" class=\"current\" ");
		document.write("href=\"" + path + files[i] + "\">" + display[i] + "</a>");
	}
	document.write("<td id=\"extender\">&nbsp;</td></tr></table>");
}

function createTertiaryNav(path){
	//@param path - file path to reach the top level of the site from the current page
	//							ex: ".." or "../.." or "../", etc.; error if path is omitted
	if (path != null){
		if (path.substr(path.length-1) != "/"){
			//normalize the submitted path name for compatability
			path = path + "/";
		}
	}
	else path = "";

	for (i = 0; i < files.length; i++){
		if (i > 0) document.write(" | ");
		document.write("<a href=\"" + path + files[i] + "\">" + display[i] + "</a>");
	}
	document.write("<p>&copy; 2008 Wayne Weibel, All rights reseverd.<br />");
	document.write("last modified: " + document.lastModified + "</p>");
}

function displayQuotes(num){
	for (var i = 0; i < num; i++){
		var randomnumber=Math.floor(Math.random()*quotes.length);
		document.write(quotes[randomnumber]);
		quotes.splice(randomnumber,1);
	}
}

function validEmail(){
	var validAddress = /^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$/g;
	var allSpaces = /^\s*$/g;
	var address = document.getElementById("email_address").value;
	var subject = document.getElementById("email_subject").value;
	var message = document.getElementById("email_message").value;
	
	
	if (subject.match(allSpaces)) {
		document.getElementById("email_subject").value = "No Subject";
	}

	if (message.match(allSpaces)) {
		alert("No Message To Send");
		return false;
	}
/*
	if (!(address.match(validAddress))) {
		alert("Invalid Email Entered");
		return false;
	}
*/	
	return true;	
}

var quotes = [
							"<p class=\"quote\">There are two modes of acquiring knowledge, namely by reasoning and experience.<br /><span>- Roger Bacon</span></p>",
							"<p class=\"quote\">To wish to be better than the world is to be already on the threshold of immortality.<br /><span>- F.H. Bradley</span></p>",
							"<p class=\"quote\">If chance is defined as an event produced by random motion without any causal nexus, I would say there is no such thing as chance.<br /><span>- Boethius</span></p>",
							"<p class=\"quote\">You can see a lot by just looking.<br /><span>- Yogi Berra</span></p>",
							"<p class=\"quote\">The moment a little boy is concerned with which is a jay and which is a sparrow, he can no longer see the birds or hear them sing.<br /><span>- Eric Berne</span></p>",
							"<p class=\"quote\">Do not seek to follow in the footsteps of the wise.  Seek what they sought.<br /><span>- Matsuo Basho</span></p>",
							"<p class=\"quote\">Truth only reveals itself when one gives up all preconceived ideas.<br /><span>- Shoseki</span></p>",
							"<p class=\"quote\">Every man is a damn fool for at least five minutes every day; wisdom consists in not exceeding the limit.<br /><span>- Elbert Hubbard</span></p>",
							"<p class=\"quote\">A child can ask questions that a wise man cannot answer.<br /><span>- Unknown</span></p>",
							"<p class=\"quote\">We are made wise not by the recollection of our past, but by the responsibility for our future.<br /><span>- George Bernard Shaw</span></p>",
							"<p class=\"quote\">Love all, trust a few, do wrong to none.<br /><span>- Shakespeare</span></p>",
							"<p class=\"quote\">My goal in life is to be as good of a person my dog already thinks I am.<br /><span>- Unknown</span></p>",
							"<p class=\"quote\">If your work speaks for itself, don't interrupt.<br /><span>- Henry J. Kaiser</span></p>",
							"<p class=\"quote\">Life's a journey, not a destination.<br /><span>- Aerosmith</span></p>",
							"<p class=\"quote\">When a true genius appears in the world, you may know him by this sign, that the dunces are all in confederacy against him.<br /><span>- Jonathan Swift</span></p>",
							"<p class=\"quote\">Conformity is that jailer of freedom and the enemy of growth.<br /><span>- John F. Kennedy</span></p>",
							"<p class=\"quote\">If everyone is thinking alike then somebody isn't thinking.<br /><span>- George S. Patton</span></p>",
							"<p class=\"quote\">None are more hopelessly enslaved than those who falsely believe they are free.<br /><span>- Johann Wolfgang von Goethe</span></p>",
							"<p class=\"quote\">Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.<br /><span>- Dr. Seuss</span></p>",
							"<p class=\"quote\">Never be bullied into silence.  Never allow yourself to be made a victim.  Accept no one's definition of your life; define yourself.<br /><span>- Harvey Fierstein</span></p>",
							"<p class=\"quote\">It's a great thing when you realize you still have the ability to surprise yourself.  Makes you wonder what else you can do that you've forgotten about.<br /><span>- Alan Ball, <i>American Beauty</i> 1999</span></p>",
							"<p class=\"quote\">Your work is to discover your world and then with all your heart give yourself to it.<br /><span>- Buddha</span></p>",
							"<p class=\"quote\">I may not have gone where I intended to go, but I think I have ended up where I intended to be.<br /><span>- Douglas Adams</span></p>",
							"<p class=\"quote\">And remember, no matter where you go, there you are.<br /><span>- Confucius</span></p>",
							"<p class=\"quote\">Our major obligation is not to mistake slogans for solutions.<br /><span>- Edward R. Murrow</span></p>",
							"<p class=\"quote\">We have too many high sounding words and too few actions that correspond with them.<br /><span>- Abigail Adams</span></p>",
							"<p class=\"quote\">A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.<br /><span>- John F. Kennedy</span></p>",
							"<p class=\"quote\">I am the inferior of any man whose rights I trample underfoot.<br /><span>- Horace Greeley</span></p>",
							"<p class=\"quote\">Give to every human being every right that you claim for yourself.<br /><span>- Robert Ingersoll</span></p>",
							"<p class=\"quote\">Those who deny freedom to others deserve it not for themselves.<br /><span>- Abraham Lincoln</span></p>",
							"<p class=\"quote\">They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.<br /><span>- Benjamin Franklin</span></p>",
							"<p class=\"quote\">I am always doing that which I cannot do, in order that I may learn how to do it.<br /><span>- Pablo Picasso</span></p>",
							"<p class=\"quote\">If we don't believe in freedom of expression for people we despise, we don't believe in it at all.<br /><span>- Noam Chomsky</span></p>"
							];

//-----TESTING DATA AND FUNCTION------------------------------------------------------------------------------------------------------------
var valid_addresses = ["l3tt3rsAndNumb3rs@domain.com","has-dash@domain.com","hasApostrophe.o'leary@domain.org",
											 "uncommonTLD@domain.museum","uncommonTLD@domain.travel","uncommonTLD@domain.mobi",
											 "countryCodeTLD@domain.uk","lettersInDomain@911.com","underscore_inLocal@domain.net",
											 "IPInsteadOfDomain@[127.0.0.1]","IPAndPort@[127.0.0.1:25]","subdomain@sub.domain.com",
											 "local@dash-inDomain.com","dot.inLocal@foo.com","a@singleLetterLocal.org",
											 "singleLetterDomain@x.org","&*=?^+{}'~@validCharsInLocal.net"];

var invalid_addresses = [""," ","missingDomain@.com","@missingLocal.org","missingatSign.net","missingDot@com","noBracketsOnIP@127.0.0.1",
												 "two@@signs.com","colonButNoPort@127.0.0.1:","someone-else@127.0.0.1.26",".localStartsWithDot@domain.com",
												 "localEndsWithDot.@domain.com","two..consecutiveDots@domain.com","domainStartsWithDash@-domain.com",
												 "domainEndsWithDash@domain-.com","TLDDoesntExist@domain.moc","numbersInTLD@domain.c0m",
												 "missingTLD@domain.","! \"#$%(),/;<>[]`|@invalidCharsInLocal.org","invalidCharsInDomain@! \"#$%(),/;<>_[]`|.org",
												 "local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org","noBracketsOnIPWithPort@127.0.0.1:25"];

function testAddresses(){
	var validAddress = /^[A-z0-9\-_]+(\.[A-z0-9\-_]+)*@(([A-z0-9]+\-?[A-z0-9]+)+\.)+[A-z]{2,6}$/;
	document.write("<h2>VALID ADDRESSES</h2>");
	for(i = 0; i < valid_addresses.length; i++){
		address = valid_addresses[i];
		if (address.match(validAddress)) {
			document.write("<p>" + address + "&nbsp;&nbsp;&nbsp;&nbsp; VALID</p>");
		}
		else document.write("<p style='color:red'>" + address + "&nbsp;&nbsp;&nbsp;&nbsp; INVALID</p>");
	}
	document.write("<h2>INVALID ADDRESSESS</h2>");
	for(i = 0; i < invalid_addresses.length; i++){
		address = invalid_addresses[i];
		if (address.match(validAddress)) {
			document.write("<p>" + address + "&nbsp;&nbsp;&nbsp;&nbsp; VALID</p>");
		}
		else document.write("<p style='color:red'>" + address + "&nbsp;&nbsp;&nbsp;&nbsp; INVALID</p>");
	}

}
//EOF
