function findObject(id){
	if(document.images) return document.images(id);
	return document[id];
}

function switchImage(name){
	reset();
	findObject(name).src = "images/" + name + "On.jpg";
}

function reset(){
	findObject('Home').src = "images/Home.jpg";
	findObject('Menu').src = "images/Menu.jpg";
	findObject('Order').src = "images/Order.jpg";
	findObject('Awards').src = "images/Awards.jpg";
	findObject('Directions').src = "images/Directions.jpg";
}

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

function closeup(image){
	var url= 'closeup.php?img='+image;
	window.open(url, 'Meeting Street Cafe', 'width=500, height=400, scrollbars=no');
}

/* Check format of email - Heavily borrowed from Sandeep, at javascript.internet.com */
function isValidEmail(emailStr) {
  // An address is of the form username@domain 
  var emailPat=/^(.+)@(.+)$/
  // Special Chars: ( ) < > @ , ; : \ " . [ ]    */
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
  // Valid Chars = anything that's not specialChars
  var validChars="\[^\\s" + specialChars + "\]"
  // Allow for quoted username
  var quotedUser="(\"[^\"]*\")"
  // Atom: basically a series of non-special characters
  var atom=validChars + '+'
  // A word is either an atom or quoted string.
  var word="(" + atom + "|" + quotedUser + ")"
  // A user is a bunch.of.words or "a quoted string"
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
  // user@domain, like tech.apple.com
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
  // user@IP, like 192.168.1.1
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

  // split into user and domain
  var matchArray=emailStr.match(emailPat)
  if (matchArray==null) {
   // CHECK: too many @'s or too few 
 	alert("Please use a valid email address, containing one '@'.")
 	return false
  }
  var user=matchArray[1]
  var domain=matchArray[2]
 
  // CHECK: valid username 
  if (user.match(userPat)==null) {
      // user is not valid
      alert("The username in your email address is invalid.")
      return false
  }
 
  // CHECK: valid IP domain
  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("Destination IP address is invalid!")
  		return false
  	    }
      }
      return true
  }
  
  // CHECK: valid symbolic domain
  var domainArray=domain.match(domainPat)
  if (domainArray==null) {
  	alert("The domain name doesn't seem to be valid.")
      return false
  }
  
  // CHECK: symbolic domain ends in country code or TLD
  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>4) {
     // the address must end in a two, three or three letter word.
     alert("The address must end in a three-letter domain, or two letter country.") 
     return false
  }
  
  // CHECK: presence of hostname before domain
  if (len<2) {
     alert("This address is missing a hostname!")
     return false
  }
  
  // WHEW! We're cool.
  return true;
}