function checkLogicalInput(obj,typ,fname) {
  if (obj.value.length==0) { return(0) }
  var val = obj.value
  var ch = ""
  switch (typ)
  {
    case "email":
      var ov = obj.value
      var ovl = obj.value.length
      rexp = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
      if(!rexp.test(val)) {
          alert("Email address is not valid!\nExample, info@portnov.net");
          obj.focus()
          return(0)
      }

/*
  xxx      if ( ov.indexOf("@") < 0 || ov.indexOf(".") < 0 ) {
          alert("Email address is not valid!\nExample, info@portnov.net");
          obj.focus()
          return(0)
        }
*/

        var z = ( ov.substring(ov.lastIndexOf(".")+1,ovl) ).toLowerCase()
        if (z !== "com" && z !== "org" && z !== "net" && z !== "us" && z !== "biz" && z !== "COM" && z !== "ORG" && z !== "NET" && z !== "US" && z !== "BIZ") {
          alert("Email Address is not valid.\nAn email address should end with one of the following one com/org/net/us/biz.");
          obj.focus()
        }
      break
    case "phone":
        var cnt = 0
        var r = 0
        var maxlen = 10
        var isChar = false
        for (var r=0;r<obj.value.length;r++ ) {
          //alert(isNaN(obj.value.charAt(r)))
          if (!isNaN(obj.value.charAt(r)) && obj.value.charAt(r) !== " ") {
            cnt++
            if (cnt == 1 && obj.value.charAt(r) == "1") maxlen = 11;
          } else {
            isChar = true
          }
        }
        if (isChar) {
            alert(fname+" number should have digit entry only. Please, correct.");
            obj.focus();
            break;
        }
        if (cnt != maxlen) {
            alert(fname+" Number should be of "+maxlen+" digits. Please, correct.");
//            "Phone Number should be of "+maxlen+" digits. Please, correct."
            obj.focus();
        }

        break
    case "int":
      for (var i = 0; i < val.length; i++) {
        ch = val.substr(i,1)
        if ("0123456789".indexOf(ch) < 0) {
          obj.value = ""
          alert("That field accepts digits only");
          obj.focus();
          return(0)
        }
      }
      break
    case "year":
      if (val.length != 4) {alert("Year should be 4 digital marks");obj.value="";obj.focus();return(0)}
      for (var i = 0; i < val.length; i++) {
        ch = val.substr(i,1)
        if ("0123456789".indexOf(ch) < 0) {
          obj.value = ""
          //alert("Field "+fname+" must be numeric.");
          alert("Field should be 4 digital marks")
          obj.focus();
          return(0)
        }
      }
      break

    case "zip":
      if (val.length !== 5) {
        alert("ZIP code should have 5 digits. Please, correct.");
        obj.value="";
        obj.focus();
        return(0)
      }
      if (val.substring(0,1) !== "9") {
        alert('Invalid California ZIP Code. Please correct.');
        obj.value="";
        obj.focus();return(0)
      }
      for (var i = 0; i < val.length; i++) {
        ch = val.substr(i,1)
        if ("0123456789".indexOf(ch) < 0) {
          obj.value = ""
          //alert("Field "+fname+" must be numeric.");
          alert("ZIP code contains digits only. Please correct.")
          obj.focus();
          return(0)
        }
      }
      break

    case "Miles2Work":
      if (val.length != 2) {alert("Miles To Work should be 2 digital marks");obj.value="";obj.focus();return(0)}
      for (var i = 0; i < val.length; i++) {
        ch = val.substr(i,1)
        if ("0123456789".indexOf(ch) < 0) {
          obj.value = ""
          //alert("Field "+fname+" must be numeric.");
          alert("Field should be 2 digital marks")
          obj.focus();
          return(0)
        }
      }
      break


    case "CoverageLimits":
      for (var i = 0; i < val.length; i++) {
        ch = val.substr(i,1)
        if ("0123456789,.$".indexOf(ch) < 0) {
          obj.value = ""
          alert('That field accepts "0 1 2 3 4 5 6 7 8 9 , . $" only');
          obj.focus();
          return(0)
        }
      }
      break

    case "date":
      rexp = /^([0-9]{2}\/[0-9]{2}\/[0-9]{4})$/
      if(!rexp.test(val)) {
        //obj.value = ""
        alert("Field's format should be mm/dd/yyyy")
        obj.focus();
        return(0)
      }
      var a = val.split("/")
      if (a[0] > 12) {
        //obj.value = ""
        alert("Month is not valid!");
        obj.focus();
        return(0)
      }
      if (a[1] > 31) {
        //obj.value = ""
        alert("Day is not valid!");
        obj.focus();
        return(0)
      }
      break;

   case "text":
      if ((val).length > 0) {
        rexp = /^([a-zA-Z]*)$/
        if(!rexp.test(val)) {
          alert("The field should have only characters mark.")
          obj.focus();
          return(0)
		}
	  }
	  break
  }
}

function testMinSize(obj, n) {
  var val=obj.value
  if (val.length >0 && val.length < n) {
    alert("You have incorrect input, please try again.")
    obj.focus()
    return(0)
  }
}