/* Selected works */
function displayWorks()
{
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="450" height="535" title="slideshow" align="middle">');
document.write('<param name="movie" value="slideshow/slideshow.swf">');
document.write('<param name="quality" value="high"><param name="bgcolor" value="#383634"><param name="base" value=".">');
document.write('<embed base="." src="slideshow/slideshow.swf" quality="high" bgcolor="#383634" name="slideshow" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="450" height="535" ></embed>');
document.write('</object>');
}

/* Copyright information, all pages */
now = new Date
thisYear=now.getYear();
if (thisYear < 1900) {
thisYear = thisYear + 1900;
}
function displayCopy()
{
//	document.write('<table height="50px" cellpadding="0" cellspacing="0"><tr><td id="copyright" valign="bottom">');
//	document.write('Copyright &copy; ' + thisYear + ' by Leona Wood Projects. &nbsp;All rights reserved.</td></tr></table>');
	document.write('<p id="copyright">');
	document.write('Copyright &copy; 2011&mdash;' + thisYear + ' by Leona Wood Projects. &nbsp;All rights reserved.</p>');
}

/* Home page, sepia photo */
function displayPortrait()
{
	document.write('<img alt="Leona Wood at Home" src="images/LWPortrait.gif" width="349px" height="445px" hspace="25">');
}

/* Book page */
function displayTitle()
{
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="224" height="40" id="bookpagetitle" align="middle">');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="movie" value="images/bookpagetitle.swf" />');
document.write('<param name="quality" value="high" /><param name="bgcolor" value="#383634" />');
document.write('<embed src="images/bookpagetitle.swf" quality="high" bgcolor="#383634" width="224" height="40" name="bookpagetitle" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
}

/* Contact page */
function forInfo(subj)
{
var part1 = "mailto";
var part2 = "info";
var part3 = "leona";
var part4 = "wood";
var part5 = "com";
var part6 = "email";
var part = part2 + "@" + part3 + part4 + "." + part5;

document.write('<a href="' + part1 + ':' + part + '?SUBJECT=' + subj + '">' + part6 + '</a>');
}

/* emails to webmaster */
function forWM(subj)
{
var part1 = "mailto";
var part2 = "webmaster";
var part3 = "leona";
var part4 = "wood";
var part5 = "com";
var part6 = "webmaster";
var part = part2 + "@" + part3 + part4 + "." + part5;

document.write('<a href="' + part1 + ':' + part + '?SUBJECT=' + subj + '">' + part6 + '</a>');
}

/* orderform.php validation is in the page */

/* Validate email address on order form */
function emailCheck (emailStr) {
/* Does email address match 
   the user@domain format; separates 
   the user name from the domain. */
var emailPat=/^(.+)@(.+)$/
/* Pattern for matching all special characters, 
   not allowed in the address,
   including ( ) < > @ , ; : \ " . [ ];  */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* Characters allowed in a user name or domain name  
   by stating which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* Pattern applies if user name is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* For domains that are IP addresses, rather than symbolic names,
   e.g., joe@[123.124.233.4] is a legal email address. 
   NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   A word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// Pattern that describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* Pattern that describes the structure of a standard symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

/* Determine whether the email address is valid. */

/* Pattern breaks up user@domain into
   pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* This address doesn't fit the standard format */
	alert("Email address does not match standard format (check @ and .'s).")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if user is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("Invalid email user name.")
    return false
}

/* Validate IP address if the email address is at an IP address */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Invalid IP address.")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Invalid domain name.")
    return false
}

/* domain name seems valid; make sure that it ends in a
   three-letter word (com, edu, gov, etc.) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Break up the domain to get a count of 
   how many atoms it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two-letter or three-letter word.
   alert("The email address must end in a three-letter domain, or two-letter country code.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This email address is missing a host name."
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid
return true;
}
// end of email checking routine

// error checking for form
function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = new Array;
	var fieldDescription = new Array;
		var fieldRequired = Array("Name", "Email");
		// field descriptions to appear in alert box
		var fieldDescription = Array("Name", "Email address");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += "   " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += "   " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += "   " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += "   " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);

		return false;
	}
}


function formCheck(formobj){
	var fieldRequired = new Array;
	var fieldDescription = new Array;
	// Enter name of mandatory fields
	var fieldRequired = Array("firstname", "lastname", "address", "city", "state", "postalcode", "country", "email", "quantity");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("First Name", "Last Name", "Address", "City", "State", "Zip/postal code", "Country", "Email address", "Quantity");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];

		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += "   " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += "   " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += "   " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += "   " + fieldDescription[i] + "\n";
				}
			}
		}
		if ( (obj.name == "quantity") && (obj.value >= 15) ) {
			alert("Quantity may not be over 14.");
			return false;
		}
	}
	

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

