
function updateClock ( )
{
  var currentTime = new Date ( );

  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}



  function checkForm() {
name = document.getElementById("name").value;
  email = document.getElementById("email").value;
subject= document.getElementById("subject").value;
  comment = document.getElementById("comment").value;
  human = document.getElementById("human").value;
  
  
  if (name == "") {
  hideAllErrors();
document.getElementById("nameError").style.display = "inline";
document.getElementById("name").select();
document.getElementById("name").focus();
  return false;
  } else if (email == "") {
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
document.getElementById("email").focus();
  return false;
  } else if (subject == "") {
hideAllErrors();
document.getElementById("subjectError").style.display = "inline";
document.getElementById("subject").select();
document.getElementById("subject").focus();
  return false;
  }else if (comment == "") {
hideAllErrors();
document.getElementById("commentError").style.display = "inline";
document.getElementById("comment").select();
document.getElementById("comment").focus();
  return false;
  }
 else if (human == "") {
hideAllErrors();
document.getElementById("humanError").style.display = "inline";
document.getElementById("human").select();
document.getElementById("human").focus();
  return false;
  }else if (human != "5") {
hideAllErrors();
document.getElementById("humanWrong").style.display = "inline";
document.getElementById("human").select();
document.getElementById("human").focus();
  return false;
  }
hideAllErrors();
  return emailCheck(email);
  }
 
  function hideAllErrors() {
document.getElementById("nameError").style.display = "none"
document.getElementById("emailError").style.display = "none"
document.getElementById("commentError").style.display = "none"
document.getElementById("subjectError").style.display = "none"
document.getElementById("humanError").style.display = "none"
document.getElementById("humanWrong").style.display = "none"
  }
  
    function checkOrderJsp() {
	  hideAllOrderError();
	  hideAllHumanErrors();
  email = document.getElementById("email").value;
  human = document.getElementById("human").value;
  var toreturn=true;
  alert ("else Toreturn Email Check:" + toreturn);
  if (email == "") {
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
document.getElementById("email").focus();
  toreturn= false;
  } if (human != "5") {
document.getElementById("humanWrong").style.display = "inline";
document.getElementById("human").select();
document.getElementById("human").focus();
  toreturn= false;
  }

  if (toreturn==true){
	  toreturn=emailCheck(email);
	  alert ("Toreturn Email Check:" + toreturn);
	  return toreturn;
  }else{
  	alert ("else Toreturn Email Check:" + toreturn);
	  return false;
  }
  alert ("last return Email Check:" + toreturn);
  return toreturn;
}

 
  function hideAllHumanErrors() {
document.getElementById("humanError").style.display = "none"
document.getElementById("humanWrong").style.display = "none"
  }
  
  
    function hideAllOrderError() {
document.getElementById("emailError").style.display = "none"
document.getElementById("humanError").style.display = "none"
document.getElementById("humanWrong").style.display = "none"
  }
  


function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

if (user.match(userPat)==null) {
alert("The username doesn't seem to be valid.");
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}


if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}


if (len<2) {
alert("This address is missing a hostname!");
return false;
}

return true;
}





