function lastModDate() 
{
   // Modified code snippet borrowed from
   // http://home.clara.net/shotover/datetest.htm
   // Used for the formatting of the lastModified Document property
  
   var lmDate = new Date(document.lastModified);	// Create a new Date Object and set to lastmodifed date
   var lmDay = lmDate.getDate(); 	         		// Extract Day
   var lmMonth = lmDate.getMonth() + 1; 	 		// Extract Month
   var lmYear = lmDate.getFullYear(); 	         	// Extract Year
   var lmSeconds = lmDate.getSeconds();				// Extract Seconds
   var lmMinutes = lmDate.getMinutes();				// Extract Minutes
   var lmHours = lmDate.getHours();					// Extract Hours

   // Create new string objects
   nlmDay = new String(lmDay);
   nlmMonth = new String(lmMonth);
   nlmHours = new String(lmHours);
   nlmMinutes = new String(lmMinutes);
   nlmSeconds = new String(lmSeconds);

   // Test for single digit numbers and pad them with "0's" if required 	 
   if( nlmDay.length == 1 )
   { 
      nlmDay = "0" + nlmDay;
   }
 
   if( nlmMonth.length == 1 )
   {
      nlmMonth = "0" + nlmMonth;
   }

   if( nlmHours.length == 1 )
   {
      nlmHours = "0" + nlmHours;
   }

   if( nlmMinutes.length == 1 )
   {
      nlmMinutes = "0" + nlmMinutes;
   }

   if( nlmSeconds.length == 1 )
   {
      nlmSeconds = "0" + nlmSeconds;
   }
	 
   // Output the formatted last modified date and display the result
   // document.write ("Last Updated: " + nlmDay + "/" + nlmMonth + "/" + lmYear + " - " + nlmHours + ":" + nlmMinutes + ":" + nlmSeconds); 
   document.write ("Last Updated: 15/07/2011 - 08:50:00"); 
}

function currentDateTime()
{
   // Modified code snippet borrowed from
   // http://home.clara.net/shotover/datetest.htm
   // Used for the formatting of the current time property     

   var currentTime = new Date();				// Create a new Date Object and set to the current date
   var cDay = currentTime.getDate();			// Extract Day
   var cMonth = currentTime.getMonth() + 1;		// Extract Month
   var cYear = currentTime.getFullYear();		// Extract Year
   var cSeconds = currentTime.getSeconds();		// Extract Seconds
   var cMinutes = currentTime.getMinutes();		// Extract Minutes
   var cHours = currentTime.getHours();			// Extract Hours

   // Create new string objects
   ncDay = new String(cDay);
   ncMonth = new String(cMonth);
   ncHours = new String(cHours);
   ncMinutes = new String(cMinutes);
   ncSeconds = new String(cSeconds);

   // Test for single digit numbers and pad them with "0's" if required 	 
   if( ncDay.length == 1 )
   { 
      ncDay = "0" + ncDay;
   }
 
   if( ncMonth.length == 1 )
   {
      ncMonth = "0" + ncMonth;
   }

   if( ncHours.length == 1 )
   {
      ncHours = "0" + ncHours;
   }

   if( ncMinutes.length == 1 )
   {
      ncMinutes = "0" + ncMinutes;
   }

   if( ncSeconds.length == 1 )
   {
      ncSeconds = "0" + ncSeconds;
   }

   document.write (" -||- Current Date and Time is: " + ncDay + "/" + ncMonth + "/" + 
      cYear + " - " + ncHours + ":" + ncMinutes + ":" + ncSeconds); 	// Display the result
}

function validateRegFields()
{
   // Adapted code snippet borrowed from
   // course text 'The complete reference HTML & XHTML'
   // by Thomas A Powell Chapter 14.
        
   custEmail = new String(document.getElementById("email").value);
   firstName = new String(document.getElementById("fname").value);
   lastName = new String(document.getElementById("surname").value);
   address = new String(document.getElementById("addr").value);
   city = new String(document.getElementById("city").value);
   custAge = new String(document.getElementById("age").value);
   
   
   if ((custEmail == null) || (custEmail.length == 0))
   {
      alert("Please enter your email address, this field is required !");
      document.getElementById("email").focus();
      return false; 
   }
  
   var positionOfAt = custEmail.indexOf('@',1);
  
   if (( positionOfAt == -1) || (positionOfAt == (custEmail.length-1))) 
   {
      alert("Please enter a valid e-mail address in the following format: yourname@yourdomain.com");
      document.getElementById("email").focus();
      return false;
   }

   var positionOfDot = custEmail.indexOf('.',positionOfAt + 2);

   if (( positionOfDot == -1) || (positionOfDot == (custEmail.length-1)))
   {
      alert("Please enter a valid e-mail address in the following format: yourname@yourdomain.com");
      document.getElementById("email").focus();
      return false;
   }
   
   if ((firstName == null) || (firstName.length == 0))
   {
      alert("Please enter your first name, this field is required !");
      document.getElementById("fname").focus();
      return false; 
   }
  
   if ((lastName == null) || (lastName.length == 0))
   {
      alert("Please enter your last name, this field is required !");
      document.getElementById("surname").focus();
      return false; 
   }
   
   if ((address == null) || (address.length == 0))
   {
      alert("Please enter your address, this field is required !");
      document.getElementById("addr").focus();
      return false; 
   }
   
   if ((city == null) || (city.length == 0))
   {
      alert("Please enter your City, this field is required !");
      document.getElementById("city").focus();
      return false; 
   }
  
   if ((custAge == null) || (custAge.length == 0))
   {
      alert("Please enter your age, this field is required !");
      document.getElementById("age").focus();
      return false; 
   }
   
   
   if (isNaN(custAge))
   {
	   alert("Field must contain only digits");
	   document.getElementById("age").focus();
	   return false;
   }

  
   if ((parseInt(custAge) < 16) || (parseInt(custAge) > 90))
   {
      alert("Invalid age! Please re-enter your age.");
      document.getElementById("age").focus();
      return false; 
   }

   
   return true;  
}

function validateCartQty()
{
   qtyValue = new String(document.getElementById("qty").value);
	
   if (isNaN(qtyValue))
   {
      document.getElementById("qty").focus();
      document.getElementById("qty").value = 1;
      return true;
   }

   if ((qtyValue == null) || (qtyValue.length == 0))
   {
      document.getElementById("qty").focus();
      document.getElementById("qty").value = 1;
      return true; 
   }
	
}

