
function validateForm()
{
var flagError="0" ;

if (document.getElementById("txtFName").value == "")
  {
   document.getElementById("error1").style.display = "block";
   flagError = "1";

  }
   else if (document.getElementById("txtFName").value != "")
  {
   var validation_return = checkForSpecialCharactersRegistration(document.getElementById("txtFName"));
   if (validation_return == true)
   {
   document.getElementById("illerror1").style.display = "block";
   flagError = "1";
   }
  }
 if (document.getElementById("txtLName").value == "")
  {
   document.getElementById("error2").style.display = "block";
   flagError = "1";
  }
 else if (document.getElementById("txtLName").value != "")
  {
   var validation_return = checkForSpecialCharactersRegistration(document.getElementById("txtLName"));
   if (validation_return == true)
   {
   document.getElementById("illerror2").style.display = "block";
   flagError = "1";
   }
  }
  if (document.getElementById("txtEmail").value == "")
  {
   document.getElementById("error3").style.display = "block";
   flagError = "1";
  }
 else if (validateEmailAddress (document.getElementById("txtEmail")) == false) {
   document.getElementById("illerror3").style.display = "block";
   flagError = "1";
}
if (document.getElementById("txtQuery").value == "")
  {
   document.getElementById("error4").style.display = "block";
   flagError = "1";

  }
   else if (document.getElementById("txtQuery").value != "")
  {
   var validation_return = checkForSpecialCharactersCompanyAddress(document.getElementById("txtQuery"));
   if (validation_return == true)
   {
   document.getElementById("illerror4").style.display = "block";
   flagError = "1";
   }
  }
  
if (flagError == "1")
  {
flagError = "0";
return false;
  }
 else
  {
   return true;
  }
  
  }
  
  
 function allGood(id,number)
{
 if(id)
  {
   document.getElementById("error"+number).style.display = "none";
   document.getElementById("illerror"+number).style.display = "none";

  }
}

             function checkForSpecialCharactersRegistration (field) {

                var entry = field.value;

                for (var i = 0; i < entry.length; i++) {

                    var j = entry.charCodeAt(i);

                  if (j < 32) { // allowing . SPACE

                        return true;
                    }

                   if (j >32 && j < 65) { // allowing . SPACE

                        return true;
                    }

                   if (j > 90 && j < 97) {

                            return true;

                    }

                    if (j > 122) {
                        return true;
                    }
                }

                return false;
            }


           function checkForSpecialCharactersZip (field) {

                var entry = field.value;

                for (var i = 0; i < entry.length; i++) {

                    var j = entry.charCodeAt(i);

                    if (j < 48) { // allowing . SPACE

                        return true;
                    }

                    if (j > 57 && j < 65) {

                        return true;

                    }

                   if (j > 90 && j < 97) {

                            return true;

                    }

                    if (j > 122) {
                        return true;
                    }
                }
                return false;
            }


            function checkForSpecialCharactersPhone (field) {

                var entry = field.value;

                for (var i = 0; i < entry.length; i++) {

                    var j = entry.charCodeAt(i);

                    if (j < 45) { // allowing . SPACE

                        return true;
                    }
                    if (j > 46 && j < 48) {
                        return true;
                    }
                    if (j > 57) {
                        return true;
                    }
                }
                return false;
            }

            function checkForSpecialCharactersUserName (field) {

                var entry = field.value;

                for (var i = 0; i < entry.length; i++) {

                    var j = entry.charCodeAt(i);

                    if (j < 45) { // allowing . SPACE

                        return true;
                    }
                    if (j > 46 && j < 48) { // allowing . SPACE

                        return true;
                    }
                    if (j > 57 && j < 65) { // allowing . SPACE

                        return true;
                    }
                    if (j > 90 && j < 95) { // allowing . SPACE

                        return true;
                    }
                    if (j > 95 && j < 97) { // allowing . SPACE

                        return true;
                    }
                    if (j > 122) { // allowing . SPACE

                        return true;
                    }
                }
                return false;
            }

            function checkForSpecialCharactersCompanyAddress (field) {

                var entry = field.value;

                for (var i = 0; i < entry.length; i++) {

                    var j = entry.charCodeAt(i);

                    if (j < 32) { // allowing . SPACE

                        return true;
                    }
                    if (j>32 && j < 35) { // allowing . SPACE

                        return true;
                    }
                    if (j>57 && j < 65) { // allowing . SPACE

                        return true;
                    }
                     if (j>125) { // allowing . SPACE

                        return true;
                    }
                }
                return false;
            }

            function validateEmailAddress (field) {


                if (spacesInEntry(field)) {

                   // alert ('Invalid Email Address! No spaces are allowed');
                    field.select();
                    field.focus();
                    return false;
                }


                var emailAddress = field.value.split("@");
                if (emailAddress.length != 2) {

                   // alert ('Invalid Email Address!');
                    field.select();
                    field.focus();
                    return false;
                } else {

                    if (emailAddress[0] == '') {

                        //alert ('Invalid Email Address!');
                        field.select();
                        field.focus();
                        return false;
                    }

                    emailAddress[0] = emailAddress[0].replace ( / /g, ""); // replace spaces globablly

                    if (emailAddress[0].length == 0) {

                       // alert ('Invalid Email Address!');
                        field.select();
                        field.focus();
                        return false;
                    }

                    if (checkEmailUserName(emailAddress[0]) == false) {
                        //alert ('Invalid username for the email address!');
                        field.select();
                        field.focus();
                        return false;
                    }
                }
                var domainAddress = emailAddress[emailAddress.length - 1].split(".");

                if (domainAddress.length < 2) {
                   // alert ('Invalid Email Address!');
                    field.select();
                    field.focus();
                    return false;
                } else {

                    for (var j = 0; j < domainAddress.length; j++) {

                        if (domainAddress[j] == '') {

                           // alert ('Invalid Email Address!');
                            field.select();
                            field.focus();
                            return false;
                        }
                    }
                }
                return true;
            }

            function spacesInEntry (field) {
                var entry = field.value;
                var originalLength = entry.length;

                var temp = entry.replace (/ /g, "");
                var tempLength = temp.length;

                if (originalLength != tempLength) {


                    return true;
                }
                return false;
            }

            function isNumber (str) {
//var checkFlag = true;
                if (str.length == 0) {
                    return false;
                }
                for (var i = 0; i < str.length; i++) {

                    var j = str.charCodeAt(i);

                    //if (j < 48 || j > 57) {

                    if (isCharacterNumerical(j) == true) {

                       return  true;

                    }


                }
                return false;
            }

            function isCharacterNumerical (charCode) {

                if (charCode < 48 || charCode > 57) {
                        return false;
                }
                return true;
            }

            function isCharacterAlpha (charCode) {

                var upperCase = false, lowerCase = false;

                    // A - Z : 65 - 90, a -z : 97 - 122

                    if (charCode >= 65 && charCode <= 90) {
                        upperCase = true;
                    }

                    if (charCode >= 97 && charCode <= 122) {
                        lowerCase = true;
                    }

                return lowerCase || upperCase;
            }

            function checkEmailUserName (emailId) {


            //letters(a-z),numbers(0-9),underscore(_),dot(.) and hyphen(-)


                for (var i = 0; i < emailId.length; i++) {

                    var j = emailId.charCodeAt(i);
                    if (j == 45 || j == 46 || j == 95) { // . - _ allowed
                        continue;
                    }
                    if (isCharacterAlpha(j) == false && isCharacterNumerical(j) == false) {
                        return false;

                    }

                }
                return true;
            }