<!--

// -- To remove leading and trailing spaces, and returns the shortened string --
function TrimString(szString)
{
      var i = 0;
      var j = 0;

      for (i=0; i<parseInt(szString.length); i++) {
            if(szString.charAt(i) != " ") {
                  for (j=parseInt(szString.length) - 1; j > i; j--) {
                        if (szString.charAt(j) != " ") {
                              break;
                        }
                  }
                  break;
            }
      }

      if (i > j)
            i = j;

      if (szString.length > 0 && szString.charAt(j) != " ")
            j++;

      return szString.substring(i, j);
}

// -- To set the shortened value as the input field new value--
function TrimField(szFieldName)
{
  var szNewStr="";
  if (szFieldName.value == "")
  	return;

  if (szFieldName.value.length > 0) {
	szNewStr = TrimString(szFieldName.value);
	szFieldName.value = szNewStr;
	}
}

// -- To set focus to the input box --
function SetFocusSelect(szFieldName)
{
      szFieldName.focus();
      szFieldName.select();
      return true;
}

// -- To set focus to the input box --
function SetFocus(szFieldName)
{
      szFieldName.focus();
      return true;
}

// -- To check that input box is not empty --
function IsEmpty(szFieldName)
{
   var i;
   var ch;

   if (szFieldName.value == "")	//Daniel 29/5
   		return true;

   TrimField(szFieldName);
   if (parseInt(szFieldName.value.length) == 0)
         return true;

      for (i=0; i<parseInt(szFieldName.value.length); i++) {
            ch = szFieldName.value.charAt(i);
            if (ch != ' ' && ch != '\t')
                  return false;
      }
      return true;
}


function IsValidEmail(szFieldName)
{
      var IsEmail;
      var ch;
      var checkAT;
      var checkPERIOD;

      checkAT = 0;
      checkPERIOD = 0;

      if (IsEmpty(szFieldName)) {
            alert("Please enter your email address.");
            SetFocusSelect(szFieldName);
            return false;
      }

      if (szFieldName.value.indexOf("@")==-1) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }


      if (szFieldName.value.indexOf("@")==0) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

      if (szFieldName.value.indexOf(":")>=0) {
     	    alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
     	    SetFocusSelect(szFieldName);
     	    return false;
      }

      if ((szFieldName.value.indexOf("."))-(szFieldName.value.indexOf("@"))==1){
     	    alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
     	    SetFocusSelect(szFieldName);
     	    return false;
      }

      if (szFieldName.value.indexOf("@")==(parseInt(szFieldName.value.length)-1)) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

      if (szFieldName.value.charAt(parseInt(szFieldName.value.length)-1)==".") {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

      if (szFieldName.value.indexOf(" ") != -1) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

      for(i=0; i<parseInt(szFieldName.value.length); i++) {
            ch= szFieldName.value.charAt(i)


			//Check for more than 1 '@' character
			if (ch == "@") {
				checkAT = checkAT + 1;
				if (checkAT >= 2) {
					IsEmail = false;
					break;
				}
			}

			//Check for more than 1 '.' character
			if (ch == ".") {
				checkPERIOD = checkPERIOD + 1;

			}

            if ((( ch >= "A") && (ch <= "Z")) || ((ch >= "a") && (ch <= "z")) || ((ch >= "0") && (ch <= "9")) ||
                  (ch == "$") || (ch == "-") || (ch == ".") || (ch == "&") || (ch == "+") || (ch == "!") ||
                  (ch == "*") || (ch == "`") || (ch == "(") || (ch == ")") || (ch == ",") || (ch == "@") ||
                  (ch == "_")) {
                  IsEmail= true;
            }
            else {
                  IsEmail= false;
                  break;
            }
      }

	  if (checkPERIOD == 0) {
	       	alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
		SetFocusSelect(szFieldName);
            	return false;
	  }

      if (!IsEmail) {
            alert("Sorry, your email address format is not acceptable or you may have entered invalid characters.");
            SetFocusSelect(szFieldName);
            return false;
      }

   return true;
}

function IsNumeric(szFieldName)
{
      var i;
      var IsNum;
      var ch;

      IsNum=true;
      TrimField(szFieldName);
      for(i=0; i<parseInt(szFieldName.value.length); i++) {
            ch=szFieldName.value.charAt(i);
            if ((ch >= "0") && (ch <= "9"))
               IsNum= true;
            else
                  return false;
      }
      return IsNum;
}

// -- To ensure that value is alphanumeric --
function IsValidPhone(szFieldName)
{
      var i;
      var IsValidPhone;
      var ch;

      IsValidPhone=true;
      TrimField(szFieldName);
      if (parseInt(szFieldName.value.length) == 0)
         IsValidPhone= true;

      for(i=0; i<parseInt(szFieldName.value.length); i++) {
            ch=szFieldName.value.charAt(i);
            if ( ((ch >= "0") && (ch <= "9")) || (ch == " ") || (ch == "-") || (ch == "+") )
                  IsValidPhone= true;
            else
                  return false;
      }
      return IsValidPhone;
}


function SubmitForm() {

	//Determine if there is a Name.
	if(IsEmpty(form1.Name))
	{
		//No name -Stop Submission
		alert("Sorry, you have not typed your name.");
		SetFocusSelect(form1.Name);
		return false;
	}

	//Determine if there is a phone.
	if(IsEmpty(form1.Tel))
	{
		//No name -Stop Submission
		alert("Sorry, you have not typed your telephone number.");
		SetFocusSelect(form1.Tel);
		return false;
	}

	//Determine if the phone no is valid.
	if(!IsEmpty(form1.Tel))
	{
			if(!IsValidPhone(form1.Tel))
			{
			//Invalid phone -Stop Submission
			alert("Sorry, you have not provide a valid telephone number");
			SetFocusSelect(form1.Tel);
			return false;
			}
	}


	//Determine if there is an email address.
	if(IsEmpty(form1.fEmail))
	{
		//No email -Stop Submission
		alert("Sorry, you have not typed your email address.");
		SetFocusSelect(form1.fEmail);
		return false;
	}

	//Determine if the email is valid.
	if(!IsValidEmail(form1.fEmail)) return false;;


	if(form1.Enquiry.options[0].selected == true || form1.Enquiry.options[1].selected == true)
	{
			alert("Sorry, you have not selected the type of the enquiries.");
			SetFocus(form1.Enquiry);
			return false;
	}


	if(IsEmpty(form1.Message))
	{
		//No Message - Question Submission
		//Determine if they care.
		var bolStop = confirm("Sorry, you have not typed a comments/enquiries? \n\nClick OK to continue submit without type in comments/enquiries. \nClick Cancel to type in comments/enquiries first.\n");

		if(bolStop==false)
		{
			//User clicked Cancel -Stop Submission
			SetFocusSelect(form1.Message);
			return false;
		}
	}


	return true;

}


//-->
