// Global variable defaultEmptyOK defines default return value 
// for many functions when they are passed the empty string. 
// By default, they will return defaultEmptyOK.
//
// defaultEmptyOK is false, which means that by default, 
// these functions will do "strict" validation.  Function
// isInteger, for example, will only return true if it is
// passed a string containing an integer; if it is passed
// the empty string, it will return false.
//
// You can change this default behavior globally (for all 
// functions which use defaultEmptyOK) by changing the value
// of defaultEmptyOK.
//
// Most of these functions have an optional argument emptyOK
// which allows you to override the default behavior for 
// the duration of a function call.
//
// This functionality is useful because it is possible to
// say "if the user puts anything in this field, it must
// be an integer (or a phone number, or a string, etc.), 
// but it's OK to leave the field empty too."
// This is the case for fields which are optional but which
// must have a certain kind of content if filled in.

var defaultemptyok = false

// decimal point character differs by language and culture
var decimalPointDelimiter = "."

function validatesendgeneralenquiry() {
/***************************************************************************/
/* Special Req's :- None                                                   */
/* Related Files :- None                                                   */
/* Purpose       :- Check data has been entered before submitting form     */
/* Version       :- 1.00                                                   */
/* Author        :- Dennis McDermott                                       */
/* Date          :- 21/04/2009                                             */
/***************************************************************************/
/* Desc of Mod   :-                                                        */
/* Modified By   :-                                                        */
/* Date          :-                                                        */
/***************************************************************************/

if (trim(document.frmsendgeneralenquiry.yourname.value) == "") {
  alert("Please enter your name");
	document.frmsendgeneralenquiry.yourname.focus();
	return;
}

if (trim(document.frmsendgeneralenquiry.subject.value) == "") {
  alert("Please enter a Subject");
	document.frmsendgeneralenquiry.subject.focus();
	return;
}

if (trim(document.frmsendgeneralenquiry.youremail.value) != "") {
	if (! isemail(trim(document.frmsendgeneralenquiry.youremail.value))) {
	  alert("It does not look like you have entered a valid e-mail address")
	  document.frmsendgeneralenquiry.youremail.focus();
	  return;
	}
}

if (trim(document.frmsendgeneralenquiry.yourmessage.value) == "") {
  alert("Please enter your message");
	document.frmsendgeneralenquiry.yourmessage.focus();
	return;
}
      
if (trim(document.frmsendgeneralenquiry.yourphone.value) == "" && 
    trim(document.frmsendgeneralenquiry.youremail.value) == ""
	) {
  alert("Please enter some contact details, either:\n\nTelephone Number\nor\nE-mail");
	document.frmsendgeneralenquiry.youremail.focus();
}  
else {
/* clean the entered data */
document.frmsendgeneralenquiry.yourname.value = replacebannedchars(document.frmsendgeneralenquiry.yourname.value)
document.frmsendgeneralenquiry.subject.value = replacebannedchars(document.frmsendgeneralenquiry.subject.value)
document.frmsendgeneralenquiry.yourphone.value = replacebannedchars(document.frmsendgeneralenquiry.yourphone.value)
document.frmsendgeneralenquiry.youremail.value = replacebannedchars(document.frmsendgeneralenquiry.youremail.value)
document.frmsendgeneralenquiry.yourmessage.value = replacebannedchars(document.frmsendgeneralenquiry.yourmessage.value)

/* submit the form */
/* hide the submit, reset and show brochure links to stop users clicking twice */
for (var i=0; i < document.links.length; i++) {
	if (document.links[i].name == "submitlink" || document.links[i].name == "resetlink" || document.links[i].name == "showbrochurelink") {
	  document.links[i].style.visibility='hidden' 
  }
}
document.frmsendgeneralenquiry.submit()
}
}
/***************************************************************************/
/*               End of function validatesendgeneralenquiry()              */
/***************************************************************************/

function replacebannedchars(strinputtext) 
/***************************************************************************/
/* Special Req's :- None                                                   */
/* Related Files :- None                                                   */
/* Purpose       :- Replaces all " or '  characters with the ` character   */
/*               :- in the input string and passes the result back         */
/* Version       :- 1.00                                                   */
/* Author        :- Dennis McDermott                                       */
/* Date          :- 05/04/2004                                             */
/***************************************************************************/
/* Desc of Mod   :-                                                        */
/* Modified By   :-                                                        */
/* Date          :-                                                        */
/***************************************************************************/
{
  strwithbannedcharsreplaced = strinputtext.replace(/"|'/g,"`")
  return strwithbannedcharsreplaced
}
/***************************************************************************/
/*                   End of function replacebannedchars()                  */
/***************************************************************************/



/*
==================================================================
ltrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function ltrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to ltrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
rtrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function rtrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to rtrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return rtrim(ltrim(str));
}

function isemail(string) {
/***************************************************************************/
/* Special Req's :- None                                                   */
/* Related Files :- None                                                   */
/* Purpose       :- Check to see if string represents a valid email address*/
/* Version       :- 1.00                                                   */
/* Author        :- Dennis McDermott                                       */
/* Date          :- 03/05/2003                                             */
/***************************************************************************/
/* Desc of Mod   :-                                                        */
/* Modified By   :-                                                        */
/* Date          :-                                                        */
/***************************************************************************/

if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
  return true;
else
  return false;
}
/***************************************************************************/
/*                        End of function isemail()                        */
/***************************************************************************/


