// JavaScript Document
function validate() {
        var box = document.form1.customer_name;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 3) )
                 {
                  alert("Please enter full customer name.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.contact_person;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 3) )
                 {
                  alert("Please enter full name of the contact person.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.address;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 3) )
                 {
                  alert("Please enter address.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.street;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2) )
                 {
                  alert("Please enter your street/block.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.state;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2) )
                 {
                  alert("Please enter your state.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.city;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2) )
                 {
                  alert("Please enter your city name.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.area_code;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2)  )
                 {
                  alert("Please enter a valid area code.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.country;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2) )
                 {
                  alert("Please enter your country's name.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.phone;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2) || (isNaN(box.value)) )
                 {
                  alert("Please enter a valid phone number. Only numbers are allowed.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.fax;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2) || (isNaN(box.value)) )
                 {
                  alert("Please enter a valid fax number. Use your phone number if you do not have fax. Only numbers are allowed.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.cell;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2) || (isNaN(box.value)) )
                 {
                  alert("Please enter your cell number. Use your phone number if you do not have fax. Only numbers are allowed.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var box = document.form1.email;
        var new_value = trimAll(box.value);
        box.value = new_value;
        var string = box.value;
        if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {/* nothing*/ }
        else {
                alert("Please enter a valid email address.");
                box.value = "";
                box.focus();
                return false;
        }

        var box = document.form1.others_product;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 1) )
                 {
                  box.value = "";
                  var product = "no";

                }
        var g =  document.form1.g
        if( (g.checked) && (product == "no") ) {
               box.value = "";
               alert("Please specify some other product.");
               box.focus();
               return false;

        }
        var a = document.form1.a;
        var b = document.form1.b;
        var c = document.form1.c;
        var d = document.form1.d;
        var e = document.form1.e;
        var f = document.form1.f;


        if( (!a.checked) && (!b.checked) &&(!c.checked) &&(!d.checked) &&(!e.checked) &&(!f.checked) &&(!g.checked) )
                                {
                                        alert("You must select one of the products or specify some other product.");
                                        a.focus();
                                        return false;
                                }

        var box = document.form1.quantity_required;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 1) || (isNaN(box.value)) )
                 {
                  alert("Please enter the quantity required. Only numbers are allowed.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

        var a = document.form1.FOB;
        var b = document.form1.CF;
        var c = document.form1.CIF;
        if( (!a.checked) && (!b.checked) &&(!c.checked) )
                                {
                                        alert("Please select a value for Basis of Shipment.");
                                        a.focus();
                                        return false;
                                }


        //////////////////////////
         var box = document.form1.others_shipment;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 1) )
                 {
                  box.value = "";
                  var shipment = "no";

                }
        var c =  document.form1.ship_other;
        if( (c.checked) && (shipment == "no") ) {
               box.value = "";
               alert("Please specify some other shipment method.");
               box.focus();
               return false;

        }
         var a = document.form1.break_bulk;
        var b = document.form1.container;


        if( (!a.checked) && (!b.checked) && (!c.checked) )
                                {
                                        alert("You must select one of the shipment types or specify some other type. ");
                                        a.focus();
                                        return false;
                                }

         //////////////////////////////
         var box = document.form1.others_packing;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 1) )
                 {
                  box.value = "";
                  var packing = "no";

                }
        var c = document.form1.packaging_other;
        if( (c.checked) && (packing == "no") ) {
               box.value = "";
               alert("Please specify some other packaging type.");
               box.focus();
               return false;

        }
        var a = document.form1.packaging_poly;
        var b = document.form1.packaging_paper;

        if( (!a.checked) && (!b.checked) && (!c.checked) )
                                {
                                        alert("Please select a value for Packaging or specify some other value.");
                                        a.focus();
                                        return false;
                                }


        var box = document.form1.date_of_shipment;
        var new_value = trimAll(box.value);
        box.value = new_value;
                if(  (box.value=="") || (box.value==null) || (box.value=='\r') || (box.value.length < 2) )
                 {
                  alert("Please enter the approximate date of submission.");
                  box.value = "";
                  box.focus();
                  indicator = 0;
                  return false;
                }

}// end of validate function



function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

