function checkForm (target)
{
        var name = document.getElementById("name");
        var tel = document.getElementById("tel");
        var fax = document.getElementById("fax");
        var email = document.getElementById("email");
        var description = document.getElementById("description");
        var location = document.getElementById("location");
        var price = document.getElementById("asking_price_per_kg");
        var weight = document.getElementById("approximate_weight");
        var form = document.getElementById("form");

        if (name.value.toString() == "" || tel.value.toString() == "" || email.value.toString() == "" || description.value.toString() == "" || location.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 (description.value.toString() == "") { description.focus(); }
                else if (location.value.toString() == "") { location.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 description1 = false;
                var description2 = false;
                var location1 = false;
                var location2 = 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 < description.value.length; i++)
                      {
                              if (description.value.toString().charAt(i) == "<")
                         {
                                 description1 = true;
                         }
                        else if (description.value.toString().charAt(i) == ">")
                        {
                                description2 = true;
                        }
                      }
                for (i = 0; i < location.value.length; i++)
                      {
                              if (location.value.toString().charAt(i) == "<")
                         {
                                 location1 = true;
                         }
                        else if (location.value.toString().charAt(i) == ">")
                        {
                                location2 = true;
                        }
                      }


                if ((name1 == true && name2 == true) ||
                (email1 == true && email2 == true) ||
                (description1 == true && description2 == true)||
                (location1 == true && location2 == true) ||
                (tel1 == true && tel2 == true) ||
                (fax1 == true && fax2 == 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 || description.value.toString().search("http") != -1 || location.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 || description.value.toString().search("href") != -1 || location.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 || description.value.toString().search("://") != -1 || location.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(location) == false || IsNumeric(price) == false || IsAlphaNumeric(weight) == false)
                                {
                                        alert("Either your name or location is not all text OR your tel, fax, price or weight is 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;
}
