function isEmpty(s) {
  return ((s == null) || (s.length == 0));
}

function isAlpha(field) {
var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. "
 var temp;
 for (var i=0; i<field.length; i++) {
 temp = "" + field.substring(i, i+1);
 if (valid.indexOf(temp) == "-1") { 
  return false;
  }
 }
 return true;
}

function isNumeric(c) {
var valid = "0123456789-"
 var temp;
 for (var i=0; i<c.length; i++) {
 temp = "" + c.substring(i, i+1);
 if (valid.indexOf(temp) == "-1") { 
  return false;
  }
 }
 return true;  
}

function email_validate(mail){
  if(mail.indexOf("@") == "-1" || mail.indexOf(".") == "-1" || mail == ""){
   return false;
  }
  return true;
}

function validate() {

if (isEmpty(document.fedbckform.Name.value)){
    alert("Please enter your Name.");
    document.fedbckform.Name.focus();    
   return false;      
   }

if (!isAlpha(document.fedbckform.Name.value)) {    
    alert("Given Name must in alphabets");
    document.fedbckform.Name.focus();    
    return false;     
  }

if (isEmpty(document.fedbckform.Title.value)) {
    alert("Please enter the Title.");
    document.fedbckform.Title.focus();    
   return false;     
  }

if (isEmpty(document.fedbckform.Comp.value)) {
    alert("Please enter your Company Name.");
    document.fedbckform.Comp.focus();    
   return false;     
  }

if (email_validate(document.fedbckform.Email.value)==false){
    alert("Email Address is not correct or empty");
    document.fedbckform.Email.focus();    
   return false;
}

if (isEmpty(document.fedbckform.Tel.value)) {
    alert("Please enter your Telephone Number.");
    document.fedbckform.Tel.focus();    
   return false;
  }

if (!isNumeric(document.fedbckform.Tel.value)) {
    alert("Telephone Number must be in numeric value.");
    document.fedbckform.Tel.focus();    
   return false;
  }

if (isEmpty(document.fedbckform.Fax.value)) {
    alert("Please enter your Fax Number.");
    document.fedbckform.Fax.focus();    
   return false;
  }

if (!isNumeric(document.fedbckform.Fax.value)) {
    alert("Fax Number must be in numeric value.");
    document.fedbckform.Fax.focus();    
   return false;
  }

if (isEmpty(document.fedbckform.Add1.value)) {
    alert("Please enter the Address.");
    document.fedbckform.Add1.focus();    
   return false;     
  }

if (isEmpty(document.fedbckform.Pstcode.value)) {
    alert("Please enter Postcode.");
    document.fedbckform.Pstcode.focus();    
   return false;
  }

if (document.fedbckform.sendtype.selectedIndex == 0) {
   alert("Please select the type of infomation.");
   document.fedbckform.sendtype.focus();
   return false;     
}

if (isEmpty(document.fedbckform.Comment.value)) {
    alert("Please enter your Comments and Queries.");
    document.fedbckform.Comment.focus();    
   return false;     
  }
}

function insertsendtype(infotype){
 
  var a = infotype.options.selectedIndex;
  var itemtype = infotype.options[a].value; 
  var infovalue = "If you like to purchase a set of Development Kit which consist of 1KB SDK \n" + "Smart Reader, 5 pieces of smart cards and documentation at RM1,500.00. \n" + "Please submit through the appropriate box your particulars and we will get in \n" + "touch with you as soon as we can.";

  if (itemtype == "SDK"){
   document.fedbckform.Comment.value = infovalue;
  }else if (itemtype == "other" || itemtype == "website"){
    document.fedbckform.Comment.value = "";
    document.fedbckform.Comment.focus();
  }
  return true;
} 