// ********* Search functionality code start here...**************

// Display search in the text field and shows the alert message after click search button

function searchI()
{
	alert("Search feature will be added soon ");
}

function resetsearchI()
{}


// ********* Field Validation code start here...**************

var focusflag=0;
function IsEmptyF(k)
{ 
   
	var  arr=document.frmRegistration.firstName.value;
	arr=arr.split("");

	for(var i = 0;i<arr.length;i++)
	{
		if(arr[0]==' ')
		{
			alert("Blank space not allowed ");
			document.frmRegistration.firstName.value="";
			document.frmRegistration.firstName.focus();
			return 0;
		} 
	}
}

function IsEmptyL(k)
{ 
	var  arr=document.frmRegistration.surname.value;
	arr=arr.split("");

    for(var i = 0;i<arr.length;i++)
	{
		 if(arr[0]==' ')
		 {
			 alert("Blank space not allowed ");
			 document.frmRegistration.surname.value="";
			 document.frmRegistration.surname.focus();
			 return 0;
		 } 
 	}
}
function IsEmptyJT(k)
{ 
	var  arr=document.frmRegistration.jobTitle.value;
	arr=arr.split("");

    for(var i = 0;i<arr.length;i++)
    {
		 if(arr[0]==' ')
		 {
			 alert("Blank space not allowed ");
			 document.frmRegistration.jobTitle.value="";
			 document.frmRegistration.jobTitle.focus();
			 return 0;
		} 
 	}
}
function IsEmptyP(k)
{ 
	var  arr=document.frmRegistration.phone.value;
	arr=arr.split("");

    for(var i = 0;i<arr.length;i++)
    {
		 if(arr[0]==' ')
		 {
			 alert("Blank space not allowed ");
			 document.frmRegistration.phone.value="";
			 document.frmRegistration.phone.focus();
			 return 0;
		} 
 	}
}



function verifyRegistration() 
{
	var ckflag=0;

	var themessage = "Following fields are required: ";
	var frmName    = document.frmRegistration;
	var objRegExpName = /^([a-zA-Z'.\s]+)$/;
	var objRegExpEAddress = /^([_&amp;#@0-9a-zA-Z-\/\s,'"().-]+)$/;
	var objRegExpEmail = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
	var objRegExpZip = /^([0-9-]+)$/;
	//First Name
	if (frmName.firstName.value== "" || frmName.firstName.value==null ) 
	{
		themessage = themessage + "\n - First Name";
		frmName.firstName.focus();
		ckflag=1;
	}
	else if(!objRegExpName.test(frmName.firstName.value)){
		themessage = themessage + "\n - Enter the valid First Name, only a-z A-Z . ' and space allowed";
		frmName.firstName.focus();
		ckflag=1;
	}
	//SurName
	if (frmName.surname.value == "" || frmName.surname.value==null ) 
	{
		themessage = themessage + "\n - Surname";
		frmName.surname.focus();
		ckflag=1;
	}
	else if(!objRegExpName.test(frmName.surname.value)){
		themessage = themessage + "\n - Enter the valid Surname, only a-z A-Z . ' and space allowed";
		frmName.surname.focus();
		ckflag=1;
	}
	
	//Job Title
	if (frmName.jobTitle.value == "" ) 
	{
		themessage = themessage + "\n - Job Title";
		frmName.jobTitle.focus();
		ckflag=1;
	}
	else if(!objRegExpName.test(frmName.jobTitle.value)){
		themessage = themessage + "\n - Enter the valid Job Title, only a-z A-Z . ' and space allowed";
		frmName.jobTitle.focus();
		ckflag=1;
	}
	
	//Company
	if (frmName.company.value != "" ) {
		if(!objRegExpName.test(frmName.company.value)){
			themessage = themessage + "\n - Enter the valid Company, only a-z A-Z . ' and space allowed";
			frmName.company.focus();
			ckflag=1;
		}
	}
	
	// Email Address
	if ( frmName.email.value == "" )
	{
		themessage = themessage + "\n - Valid Email ID";
		frmName.email.focus();
		ckflag=1;
	}
	else if (!objRegExpEmail.test(frmName.email.value))
	{
		themessage = themessage + "\n - Valid Email ID";
		frmName.email.focus();
		ckflag=1;
	}
	//Street address
	if (frmName.address.value != "" ) {
		if(!objRegExpEAddress.test(frmName.address.value)){
			themessage = themessage + "\n - Enter the valid Street Address, only 0-9 a-z A-Z , ' ( ) , . & # @ / - _ \" and space allowed.";
			frmName.address.focus();
			ckflag=1;
		}
	}
	//City
	if (frmName.city.value != "" ) {
		if(!objRegExpName.test(frmName.city.value)){
			themessage = themessage + "\n - Enter the valid City, only a-z A-Z . ' and space allowed";
			frmName.city.focus();
			ckflag=1;
		}
	}
	//ZIP Postal code
	if (frmName.zip.value != "" ) {
		if (!objRegExpZip.test(frmName.zip.value)) 
		{
			themessage = themessage + "\n - Enter the valid Zip/Postal Code, only 0-9 - allowed.";
			frmName.zip.focus();
			ckflag=1;
		}
	}

	if(frmName.phone.value== "" )
	{
		themessage = themessage + "\n - Telephone";
		frmName.phone.focus();
		ckflag=1;
	}
	else if(frmName.phone.value.length < 6)
	{	
		themessage = themessage + "\n - Telephone length should not be less than 6";
		frmName.phone.focus();
		ckflag=1;
	}
	else if (isNaN(frmName.phone.value)) 
	{
		themessage = themessage + "\n - Enter the valid Telephone, only 0-9 allowed.";
		frmName.phone.focus();
		ckflag=1;
	}

	
	
	
	//alert if fields are empty and cancel form submit

	if (ckflag==0)
	{
		
		//frmName.target="_self";
		//frmName.action="thankyouRegistration.php";
		//document.frmRegistration.submit();
	}
	else 
	{
		alert(themessage);
		return false;
	}
}
function load()
{
	document.frmRegistration.firstName.focus();
}



function emailCheck (emailStr) 
{


	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	var emailPat=/^(.+)@(.+)$/;

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	var validChars="\[^\\s" + specialChars + "\]";

	var quotedUser="(\"[^\"]*\")";

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;


	var atom=validChars + '+';

	var word="(" + atom + "|" + quotedUser + ")";

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) 
	{
		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			//alert("Ths username contains invalid characters.");
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) {
		//alert("Ths domain name contains invalid characters.");
		return false;
		   }
	}


	if (user.match(userPat)==null) 
	{
		//alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{

		// this is an IP address

		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
		//alert("Destination IP address is invalid!");
		return false;
		   }
		}
		return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
		//alert("The domain name does not seem to be valid.");
		return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	if (len<2) 
	{
		//alert("This address is missing a hostname!");
		return false;
	}

	return true;
}


// ********* Field Validation code End here...**************