/* This script and many more are available free online at The JavaScript Source :: http://javascript.internet.com Created by: Shaun Bailey :: http://www.sbwebdevelopment.co.uk */function validate() {  if(!document.getElementById) return;  // get form variables  var first_name = document.getElementById("first_name").value;  var surname = document.getElementById("surname").value;  var company_name = document.getElementById("company_name").value;  var Email = document.getElementById("Email").value;  var telephone = document.getElementById("telephone").value;  var incorrect = new Array();  var no = 0;  var regExp = /[A-Za-z]{2,6}/;  	   var first_nameID=document.frmSample.first_name     if(regExp.test(first_name)) {   	first_name = first_name.charAt(0).toUpperCase() + first_name.substring(1,first_name.length).toLowerCase();  }   else {   	incorrect[no] = "1";   	no++;   	first_name = "";   	first_nameID.value="";   	// alert("Please Enter your First Name")   	// return false  }   var surnameID=document.frmSample.surname regExp = /[A-Za-z]{3,}-?[A-Za-z]?/;if(regExp.test(surname)) {	surname = capWords(surname);}else {	incorrect[no] = "2";	no++;	surname = "";	surnameID.value="";}  var company_nameID=document.frmSample.company_name    if(company_name.length < 2) {   	incorrect[no] = "3";   	no++;   	company_name = "";   	company_nameID.value="";  }          function echeck(str) {		var at="@"		var dot="."		var lat=str.indexOf(at)		var lstr=str.length		var ldot=str.indexOf(dot)		if (str.indexOf(at)==-1){			incorrect[no] = "4";   	no++;   	Email = "";		   // alert("Invalid E-mail ID")		   return false		}		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr || str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.indexOf(at,(lat+1))!=-1 || str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot || str.indexOf(dot,(lat+2))==-1 || str.indexOf(" ")!=-1){			incorrect[no] = "4";   	no++;   	Email = "";		//   alert("Invalid E-mail ID")		   return false		} 								}	var emailID=document.frmSample.Email		if ((emailID.value==null)||(emailID.value=="") || (echeck(emailID.value)==false)){		incorrect[no] = "4";   	no++;   	Email = "";   	emailID.value="";		// alert("Please Enter your Email Address")					}	      var telephoneID=document.frmSample.telephone   regExp = /\(?\d{5}\)?\s?\d{6}/;  if(regExp.test(telephone))   {   	if(telephone.indexOf("(") < 0)    	{  	  	telephone = "(" + telephone.substring(0,5) + ") " + telephone.substring(telephone.length-6,telephone.length);    } else if(telephone.indexOf(" ") < 0)     {   	 	telephone = telephone.substring(0,7) + " " + telephone.substring(telephone.length-6,telephone.length);incorrect[no] = "5";   	}  } else {    incorrect[no] = "5";    no++;    telephone = "";    telephoneID.value="";    // alert("Please Enter your Phone No")      }    for(i=1;i<6;i++) {  		document.getElementById(i).style.color="#000000";  }  for(j=0;j<no;j++) {  		document.getElementById(incorrect[j]).style.color="#FF0000";  }    //   for(j=0;j<no;j++) {  //		document.getElementById(incorrect[j]).style.background="#FF6600"; }  if(no > 0) {   	document.getElementById("errors").innerHTML = "<span style=\"font-family: Verdana, Arial, Tahoma, Geneva, sans-serif; line-height: 1.5em; font-weight:bold;font-size:10px\" class=\"error\">There was an error with your form submission. Please fill in the required fields shown in red:</span><br />";    return false;  }  document.getElementById("first_name").value = first_name;  document.getElementById("surname").value = surname;  document.getElementById("company_name").value = company_name;  document.getElementById("Email").value = Email;  document.getElementById("telephone").value = telephone;}function capWords(word) {	// capitalise words	var lower = word.toLowerCase();	var capWord = lower.split(" ");	noWords = capWord.length;	for(i=0;i<noWords;i++) {		capWord[i] = capWord[i].charAt(0).toUpperCase() + capWord[i].substring(1,capWord[i].length);	}	return capWord.join(" ");}