function checkForm (target)
{
        var name = document.getElementById("name");
        var tel = document.getElementById("tel");
        var fax = document.getElementById("fax");
        var email = document.getElementById("email");
        var price = document.getElementById("price");
        var address = document.getElementById("delivery_address");
        var comments = document.getElementById("comments");
        var material1 = document.getElementById("material1");
        var material2 = document.getElementById("material2");
        var material3 = document.getElementById("material3");
        var material4 = document.getElementById("material4");
        var quantity1 = document.getElementById("quantity1");
        var quantity2 = document.getElementById("quantity2");
        var quantity3 = document.getElementById("quantity3");
        var quantity4 = document.getElementById("quantity4");
        var form = document.getElementById("form");

        if (name.value.toString() == "" || tel.value.toString() == "" || email.value.toString() == "" || price.value.toString() == "" || address.value.toString() == "")
        {
                alert("Please enter all your details in their respective fields before submitting the form. Thank you.");
                if (name.value.toString() == "") { name.focus(); }
                else if (tel.value.toString() == "") { tel.focus(); }
                else if (email.value.toString() == "") { email.focus(); }
                else if (price.value.toString() == "") { price.focus(); }
                else if (address.value.toString() == "") { address.focus(); }
        }
        else
        {
                var invalid1 = "<";
                var invalid2 = ">";
                var name1 = false;
                var name2 = false;
                var tel1 = false;
                var tel2 = false;
                var fax1 = false;
                var fax2 = false;
                var email1 = false;
                var email2 = false;
                var price1 = false;
                var price2 = false;
                var address1 = false;
                var address2 = false
                var comments1 = false;
                var comments2 = false;
                var material11 = false;
                var material12 = false;
                var material21 = false;
                var material22 = false;
                var material31 = false;
                var material32 = false;
                var material41 = false;
                var material42 = false;
                var quantity11 = false;
                var quantity12 = false;
                var quantity21 = false;
                var quantity22 = false;
                var quantity31 = false;
                var quantity32 = false;
                var quantity41 = false;
                var quantity42 = false;

                var i = 0;
                for (i = 0; i < name.value.length; i++)
                      {
                              if (name.value.toString().charAt(i) == "<")
                         {
                                 name1 = true;
                         }
                        else if (name.value.toString().charAt(i) == ">")
                        {
                                name2 = true;
                        }
                      }
                for (i = 0; i < tel.value.length; i++)
                      {
                              if (tel.value.toString().charAt(i) == "<")
                         {
                                 tel1 = true;
                         }
                        else if (tel.value.toString().charAt(i) == ">")
                        {
                                tel2 = true;
                        }
                      }
                for (i = 0; i < fax.value.length; i++)
                      {
                              if (fax.value.toString().charAt(i) == "<")
                         {
                                 fax1 = true;
                         }
                        else if (fax.value.toString().charAt(i) == ">")
                        {
                                fax2 = true;
                        }
                      }
                for (i = 0; i < email.value.length; i++)
                      {
                              if (email.value.toString().charAt(i) == "<")
                         {
                                 email1 = true;
                         }
                        else if (email.value.toString().charAt(i) == ">")
                        {
                                email2 = true;
                        }
                      }
                for (i = 0; i < price.value.length; i++)
                      {
                              if (price.value.toString().charAt(i) == "<")
                         {
                                 price1 = true;
                         }
                        else if (price.value.toString().charAt(i) == ">")
                        {
                                price2 = true;
                        }
                      }
                for (i = 0; i < address.value.length; i++)
                      {
                              if (address.value.toString().charAt(i) == "<")
                         {
                                 address1 = true;
                         }
                        else if (address.value.toString().charAt(i) == ">")
                        {
                                address2 = true;
                        }
                      }
                for (i = 0; i < comments.value.length; i++)
                      {
                              if (comments.value.toString().charAt(i) == "<")
                         {
                                 comments1 = true;
                         }
                        else if (comments.value.toString().charAt(i) == ">")
                        {
                                comments2 = true;
                        }
                      }
                for (i = 0; i < material1.value.length; i++)
                      {
                              if (material1.value.toString().charAt(i) == "<")
                         {
                                 material11 = true;
                         }
                        else if (material1.value.toString().charAt(i) == ">")
                        {
                                material12 = true;
                        }
                      }
                for (i = 0; i < material2.value.length; i++)
                      {
                              if (material2.value.toString().charAt(i) == "<")
                         {
                                 material21 = true;
                         }
                        else if (material2.value.toString().charAt(i) == ">")
                        {
                                material22 = true;
                        }
                      }
                for (i = 0; i < material3.value.length; i++)
                      {
                              if (material3.value.toString().charAt(i) == "<")
                         {
                                 material31 = true;
                         }
                        else if (material3.value.toString().charAt(i) == ">")
                        {
                                material32 = true;
                        }
                      }
                for (i = 0; i < material4.value.length; i++)
                      {
                              if (material4.value.toString().charAt(i) == "<")
                         {
                                 material41 = true;
                         }
                        else if (material4.value.toString().charAt(i) == ">")
                        {
                                material42 = true;
                        }
                      }
                for (i = 0; i < quantity1.value.length; i++)
                      {
                              if (quantity1.value.toString().charAt(i) == "<")
                         {
                                 quantity11 = true;
                         }
                        else if (quantity1.value.toString().charAt(i) == ">")
                        {
                                quantity12 = true;
                        }
                      }
                for (i = 0; i < quantity2.value.length; i++)
                      {
                              if (quantity2.value.toString().charAt(i) == "<")
                         {
                                 quantity21 = true;
                         }
                        else if (quantity2.value.toString().charAt(i) == ">")
                        {
                                quantity22 = true;
                        }
                      }
                for (i = 0; i < quantity3.value.length; i++)
                      {
                              if (quantity3.value.toString().charAt(i) == "<")
                         {
                                 quantity31 = true;
                         }
                        else if (quantity3.value.toString().charAt(i) == ">")
                        {
                                quantity32 = true;
                        }
                      }
                for (i = 0; i < quantity4.value.length; i++)
                      {
                              if (quantity4.value.toString().charAt(i) == "<")
                         {
                                 quantity41 = true;
                         }
                        else if (quantity4.value.toString().charAt(i) == ">")
                        {
                                quantity42 = true;
                        }
                      }

                if ((name1 == true && name2 == true) ||
                (email1 == true && email2 == true) ||
                (tel1 == true && tel2 == true) ||
                (fax1 == true && fax2 == true) ||
                (address1 == true && address2 == true) ||
                (price1 == true && price2 == true) ||
                (comments1 == true && comments2 == true) ||
                (material11 == true && material12 == true) ||
                (material21 == true && material22 == true) ||
                (material31 == true && material32 == true) ||
                (material41 == true && material42 == true) ||
                (quantity11 == true && quantity12 == true) ||
                (quantity21 == true && quantity22 == true) ||
                (quantity31 == true && quantity32 == true) ||
                (quantity41 == true && quantity42 == true))

                {
                        alert("Please note that html code is not allowed in this form! Please remove it and resubmit.");
                }
                else
                {
                        if ((name.value.toString().search("http") != -1 || tel.value.toString().search("http") != -1 || fax.value.toString().search("http") != -1 || email.value.toString().search("http") != -1 || address.value.toString().search("http") != -1 || comments.value.toString().search("http") != -1) ||
                        (name.value.toString().search("href") != -1 || tel.value.toString().search("href") != -1 || fax.value.toString().search("href") != -1 || email.value.toString().search("href") != -1 || address.value.toString().search("href") != -1 || comments.value.toString().search("href") != -1) ||
                        (name.value.toString().search("://") != -1 || tel.value.toString().search("://") != -1 || fax.value.toString().search("://") != -1 || email.value.toString().search("://") != -1 || address.value.toString().search("://") != -1 || comments.value.toString().search("://") != -1))
                        {
                                alert("No html links are allowed in this form! Please remove them and resubmit.");
                        }
                        else
                        {
                                if (IsText(name) == false || IsNumeric(tel) == false || IsNumeric(fax) == false || IsAlphaNumeric(address) == false || IsNumeric(price) == false || IsNumeric(quantity1) == false || IsNumeric(quantity2) == false || IsNumeric(quantity3) == false || IsNumeric(quantity4) == false || IsAlphaNumeric(material1) == false || IsAlphaNumeric(material2) == false || IsAlphaNumeric(material3) == false || IsAlphaNumeric(material4) == false)
                                {
                                        alert("Either your name or delivery address is not all text OR your tel, fax, price or quantities are not all numerics. Please only enter valid characters and resubmit.");
                                }
                                else
                                {
                                        form.submit();
                                }
                        }
                }
        }
}

function IsText(txt)

{
   var ValidChars = "abcdefghijklmnopqrstuvwxyz-'ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
   var isText = true;
   var sText = txt.value;
   if (sText == "") { return isText; }
   var Char;


   for (i = 0; i < sText.length && isText == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
                 isText = false;
         }
      }
   return isText;
}

function IsNumeric(txt)

{
   var ValidChars = "R$€,.1234567890+()[]{}-/* ";
   var isText = true;
   var sText = txt.value;
   if (sText == "") { return isText; }
   var Char;


   for (i = 0; i < sText.length && isText == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
                 isText = false;
         }
      }
   return isText;
}

function IsAlphaNumeric(txt)

{
   var ValidChars = "$€,.1234567890+()[]{}-/*abcdefghijklmnopqrstuvwxyz-'ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
   var isText = true;
   var sText = txt.value;
   if (sText == "") { return isText; }
   var Char;


   for (i = 0; i < sText.length && isText == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
                 isText = false;
         }
      }
   return isText;
}
