﻿   
function GetDay(intDay){
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
                         "Thursday", "Friday", "Saturday")
    return DayArray[intDay]
    }

  function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December") 
    return MonthArray[intMonth] 	  	 
    }
  function getDateStrWithDOW(){
    var today = new Date()
    var year = today.getYear()
    if(year<1000) year+=1900
    var todayStr = GetDay(today.getDay()) + ", "
    todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
    todayStr += ", " + year
    return todayStr
    }
   
    
    
    
    
    
    function formValidator() {
        // Make quick references to our fields

        var valid = true;
        var name = document.getElementById('name');
        var tel = document.getElementById('tel');
        var company = document.getElementById('company');
        var emailadd = document.getElementById('emailadd');
        var comments = document.getElementById('comments');

        // Check each input in the order that it appears in the form!
        if (isAlphabet(name, "Please enter only letters for your name")) {
            if (isNumeric(tel, "Please enter a valid contact telephone number with no spaces")) {
                if (lengthRestriction(tel, "Please check your telephone number, 11 characters allowed")) {
                    if (emailValidator(emailadd, "Please enter a valid email address")) {
                        if (commentsValidator(comments, "Please note, no links or script code should be input here!")) {
                            return true;
                        }
                    }
                }
            }
        }


        // valid = false;

        function notEmpty(elem, helperMsg) {
            if (elem.value.length == 0) {
                alert(helperMsg);
                elem.focus(); // set the focus to this input
                valid = false;
            }
            return true;
        }

        function isNumeric(elem, helperMsg) {
            var numericExpression = /^[0-9]+$/;
            if (elem.value.match(numericExpression)) {
                return true;
            } else {
                alert(helperMsg);
                elem.focus();
                valid = false;
            }
        }

        function isAlphabet(elem, helperMsg) {
            var alphaExp = /^[a-z A-Z]+$/;
            if (elem.value.match(alphaExp)) {
                return true;
            } else {
                alert(helperMsg);
                elem.focus();
                valid = false;
            }
        }


        function lengthRestriction(elem, helperMsg) {
            var uInput = elem.value;
            if ((uInput.length < 12 && uInput.length > 10)) {
                return true;
            } else {
                alert(helperMsg);
                elem.focus();
                valid = false;
            }
        }


        function emailValidator(elem, helperMsg) {
            var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
            if (elem.value.match(emailExp)) {
                return true;
            } else {
                alert(helperMsg);
                elem.focus();
                valid = false;
            }
        }

        function commentsValidator(elem, helperMsg) {
            var commentsExp = /HTTP/i;
            if (elem.value.match(commentsExp)) {
                alert(helperMsg);
                elem.focus();
                valid = false;

            } else {

                var commentsExp = /URL/i;
                if (elem.value.match(commentsExp)) {
                    alert(helperMsg);
                    elem.focus();
                    valid = false;

                } else {

                    var commentsExp = /SCRIPT/i;
                    if (elem.value.match(commentsExp)) {
                        alert(helperMsg);
                        elem.focus();
                        valid = false;

                    }

                }
            }
        }


        if (valid === true) {
            document.callbackform.submit();
        }

    }  

 
