

function isNumberKey(evt) {
  var charCode = (evt.which) ? evt.which : event.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57))
  return false;
}
function message() {

  var name = document.getElementById("name");
  document.getElementById("rtrmessage").style.display = "none";

}
function Clear() {
  document.getElementById("name").value = "";
  document.getElementById("email").value = "";
  document.getElementById("phone").value = "";
  document.getElementById("society").value = "";
  document.getElementById("brand").value = "";
  document.getElementById("location").value = "";
  document.getElementById("affiliation").value = "";
  document.getElementById("number").value = "";
  document.getElementById("type").value = "";
  document.getElementById("constitution").value = "";
  document.getElementById("students").value = "";
  document.getElementById("grades").value = "";
  document.getElementById("current").value = "";
  document.getElementById("last").value = "";
  document.getElementById("previous").value = "";
  document.getElementById("old").value = "";
  document.getElementById("existing").value = "";
  document.getElementById("who").value = "";
  document.getElementById("purpose").value = "";
  document.getElementById("institution").value = "";
   document.getElementById("tenure").value = "";


}
function trim(stringToTrim) {

  return stringToTrim.replace(/^\s+|\s+$/g, "");

}

function ltrim(stringToTrim) {

  return stringToTrim.replace(/^\s+/, "");

}

function rtrim(stringToTrim) {

  return stringToTrim.replace(/\s+$/, "");

}
function validate(Email) {

  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;


  if (reg.test(Email) == false) {

    return false;
  }
  else {
    return true;
  }
}
function MobileValidate(MobileNo) {
  var reg = /^([7-9]{1})([0-9]{9})$/;
  if (reg.test(MobileNo) == false)
  { return false; }
  else {
    return true;
  }
}
function sendmail() {

  var varname = document.getElementById("name").value;
  var varemail = document.getElementById("email").value;
  var varmobileNo = document.getElementById("phone").value;
  var varsociety = document.getElementById("society").value;
  var varbrand = document.getElementById("brand").value;
  var varlocation = document.getElementById("location").value;
  var e = document.getElementById("affiliation");
  var affiliation = e.options[e.selectedIndex].value;
  var varnumber = document.getElementById("number").value;
  var e = document.getElementById("type");
  var type = e.options[e.selectedIndex].value;
   var e = document.getElementById("constitution");
  var constitution = e.options[e.selectedIndex].value;
  var varstudents = document.getElementById("students").value;
  var e = document.getElementById("grades");
  var grades = e.options[e.selectedIndex].value;

  var varcurrent = document.getElementById("current").value;
  var varlast = document.getElementById("last").value;
  var varprevious = document.getElementById("previous").value;
  var varold = document.getElementById("old").value;
  var varexisting = document.getElementById("existing").value;
  var varwho = document.getElementById("who").value;
  var varpurpose = document.getElementById("purpose").value;
  var varinstitution = document.getElementById("institution").value;
  var vartenure = document.getElementById("tenure").value;

  


  if(trim(varname)=="") {

    sweetAlert("Oops...", "Please enter Name!", "error");
    return false;
  }

  if (trim(varemail) == "") {
    sweetAlert("Oops...", "Please enter Email ID!", "error");
    return false;
  }

  if (!validate(varemail)) {

    sweetAlert("Oops...", "Please enter valid Email ID!", "error");
    return false;
  }

  if (trim(varmobileNo) == "") {
    sweetAlert("Oops...", "Please enter Mobile No.!", "error");
    return false;
  }
  if (!MobileValidate(varmobileNo)) {
    sweetAlert("Oops...", "Please enter valid Mobile No.!", "error");
    return false;
  }
   if(trim(varsociety)=="") {

    sweetAlert("Oops...", "Please enter Name of the Society or Trust or Company!", "error");
    return false;
  }
   if(trim(varbrand)=="") {

    sweetAlert("Oops...", "Please enter Brand Name of the School(s)!", "error");
    return false;
  }
   if(trim(varlocation)=="") {

    sweetAlert("Oops...", "Please enter your location", "error");
    return false;
  }
  if (affiliation == "-1") {
        sweetAlert("Oops...", "Select Affiliation of School(s)!", "error");
        return false;
    }
if(trim(varnumber)=="") {

    sweetAlert("Oops...", "Please enter Number of Affiliated Schools/ Institutions/ Branches!", "error");
    return false;
  }
   
   if (type == "-1") {
        sweetAlert("Oops...", "Select Type of School!", "error");
        return false;
    }
	 if (constitution == "-1") {
        sweetAlert("Oops...", "Select Constitution of the applicant school!", "error");
        return false;
    }
   
   
   if(trim(varstudents)=="") {

    sweetAlert("Oops...", "Please enter No. of students!", "error");
    return false;
  }
  if (grades == "-1") {
        sweetAlert("Oops...", "Select Grades Coverage!", "error");
        return false;
    }
   
  if(trim(varcurrent)=="") {

    sweetAlert("Oops...", "Please enter Fee receipts expected in current financial year!", "error");
    return false;
  }
  if(trim(varlast)=="") {

    sweetAlert("Oops...", "Please enter Fee Receipts in last financial year (2016-17)!", "error");
    return false;
  }
  if(trim(varprevious)=="") {

    sweetAlert("Oops...", "Fee Receipts in previous financial year (2015-16) !", "error");
    return false;
  }
   if(trim(varold)=="") {

    sweetAlert("Oops...", "Please enter How old is the School - no. of years!", "error");
    return false;
  }
   if(trim(varexisting)=="") {

    sweetAlert("Oops...", "Please enter Any existing loans (insert amount in INR lacs)!", "error");
    return false;
  }
  if(trim(varwho)=="") {

    sweetAlert("Oops...", "Please enter Who have you taken a loan from currently!", "error");
    return false;
  }
   if(trim(varpurpose)=="") {

    sweetAlert("Oops...", "Please enter your purpose!", "error");
    return false;
  }

if(trim(varinstitution)=="") {

    sweetAlert("Oops...", "Please enter Amount Sought by Institution (Rs. Lacs)!", "error");
    return false;
  }
  if(trim(vartenure)=="") {

    sweetAlert("Oops...", "Please enter Tenure Sought (in Years)!", "error");
    return false;
  }

  var xmlhttp;

  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari

    xmlhttp = new XMLHttpRequest();

  }

  else {// code for IE6, IE5

    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

  }
  swal("Email Sent!", "Thank You for contacting us, we will get back to you soon...!!!", "success")

  xmlhttp.onreadystatechange = function () {

    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

      var varMaxQuestion = xmlhttp.responseText;

      Clear();

    }

  }

  xmlhttp.open("POST", "enquiry-mail.php?Name=" + varname + "&Email=" + varemail + "&Mobile=" + varmobileNo + "&Society=" + varsociety + "&Brand=" + varbrand + "&Location=" + varlocation + "&Affiliation=" + affiliation + "&Number=" + varnumber + "&Type=" + type + "&Constitution=" + constitution + "&Students=" + varstudents + "&Grades=" + grades + "&Current=" + varcurrent + "&Last=" + varlast + "&Previous=" + varprevious + "&Old=" + varold + "&Existing=" + varexisting + "&Who=" + varwho + "&Purpose=" + varpurpose + "&Institution=" + varinstitution + "&Tenure="+vartenure,  true);

  xmlhttp.send();


}
