﻿// JavaScript Document

function validateFormOnSubmit() {
 var reason ="";
 var fname2=document.getElementById('ctl00_ContentPlaceHolder3_contus_fname2').value;
  var tele2=document.getElementById('ctl00_ContentPlaceHolder3_contus_tele2').value;
  var com2=document.getElementById('ctl00_ContentPlaceHolder3_contus_com2').value;
  reason += validateGefirstname(fname2);
  reason += validateGemobilenumber(tele2);
  reason += validateQuery(com2);
      
  	 
  if (reason != null) {
    alert("Some fields need correction:\n\n" + reason);
    return false;
  }
else
	alert("Thank you for your interest.We will contact you soon.")
      

  return true;
}


function validateQuery(fld) {
    var error = "";

    if (fld.length == 0) {
       document.getElementById('ctl00_ContentPlaceHolder3_contus_com2').style.background = '#3f362b';
		document.getElementById('ctl00_ContentPlaceHolder3_contus_com2').style.color = '#FFFFFF';
        error = "Please enter your Enquiry.\n"
    } else {
       document.getElementById('ctl00_ContentPlaceHolder3_contus_com2').style.background = '#b2aaa3;';
    }
    return error;
}


function validateGefirstname(fld) {
    var error = "";
    var illegalChars = /[A-Za-z]/; // allow letters, numbers, and underscores

    if (fld ==null) {
        document.getElementById('ctl00_ContentPlaceHolder3_contus_fname2').style.background = '#3f362b';
		document.getElementById('ctl00_ContentPlaceHolder3_contus_fname2').style.color = '#FFFFFF';
        error = "You didn't enter a First name.\n";
    } else if ((fld.length < 5) || (fld.value.length > 15)) {
        document.getElementById('ctl00_ContentPlaceHolder3_contus_fname2').style.background = '#3f362b';
		document.getElementById('ctl00_ContentPlaceHolder3_contus_fname2').style.color = '#FFFFFF';
        error = "The First name is the wrong length.\n";
    } else if (!(illegalChars.test(fld.value))) {
       document.getElementById('ctl00_ContentPlaceHolder3_contus_fname2').style.background = '#3f362b';
		document.getElementById('ctl00_ContentPlaceHolder3_contus_fname2').style.color = '#FFFFFF';
        error = "The First name contains illegal characters.\n";
    } else {
        document.getElementById('ctl00_ContentPlaceHolder3_contus_fname2').style.background = '#b2aaa3;';
    }
    return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}


    
function validateGelastname(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#3f362b';
		fld.style.color = '#FFFFFF';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#3f362b';
		fld.style.color = '#FFFFFF';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#3f362b';
		fld.style.color = '#FFFFFF';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = '#b2aaa3;';
    }
    return error;
}
function validateGemobilenumber(fld) {
    var error = "";
    var stripped = fld.replace(/[\(\)\.\-\ ]/g, '');

   if (fld ==null) {
        error = "You didn't enter a Telephone number.\n";
     document.getElementById('ctl00_ContentPlaceHolder3_contus_tele2').style.background = '#3f362b';
	document.getElementById('ctl00_ContentPlaceHolder3_contus_tele2').style.color = '#FFFFFF';
    } else if (isNaN(parseInt(stripped))) {
        error = "The Telephone number contains illegal characters.\n";
    document.getElementById('ctl00_ContentPlaceHolder3_contus_tele2').style.background = '#3f362b';
	document.getElementById('ctl00_ContentPlaceHolder3_contus_tele2').style.color = '#FFFFFF';
		
    }else {
       document.getElementById('ctl00_ContentPlaceHolder3_contus_tele2').style.background = '#b2aaa3;';
		
		}
    return error;
}
function checkIt(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
}

function checknum(e) 
{
           var key = window.event ? e.keyCode : e.which;
         var keychar = String.fromCharCode(key);
         reg = /\d/;
         return !reg.test(keychar);
    
}

//function sucmsg()
//{
//alert("Thank you for your interest.We will contact you soon.")
//}


