function contactdata()
{
	sname1 = document.contactform.sname.value;
	if(sname1 == "")
	{
		alert("Please enter your name.");
		document.contactform.sname.focus()
		document.contactform.sname.style.background = "#F7F7F7"
		return false;
	}
	else
	{
		document.contactform.sname.style.background = "#FFFFFF"
	}

	semailname = document.contactform.semail.value;
	if(semailname == "")
	{
		alert("Please enter your e-mail.");
		document.contactform.semail.focus()
		document.contactform.semail.style.background = "#F7F7F7"
		return false;
	}
	else
	{
		document.contactform.semail.style.background = "#FFFFFF"		
		if (echeck(document.contactform.semail.value)==false)
		{
			document.contactform.semail.value=""
			document.contactform.semail.focus()
			document.contactform.semail.style.background = "#F7F7F7"
			return false
		}
	}

	subject1 = document.contactform.subject.value;
	if(subject1 == "")
	{
		alert("Please enter the subject.");
		document.contactform.subject.focus()
		document.contactform.subject.style.background = "#F7F7F7"
		return false;
	}
	else
	{
		document.contactform.subject.style.background = "#FFFFFF"
	}

	msg1 = document.contactform.msg.value;
	if(msg1 == "")
	{
		alert("Please enter the message.");
		document.contactform.msg.focus()
		document.contactform.msg.style.background = "#F7F7F7"
		return false;
	}
	else
	{
		document.contactform.msg.style.background = "#FFFFFF"
	}



	var minMsgLength = 20; // Minimum length
	var maxMsgLength = 1000; // Maximum length

	if (document.contactform.msg.value.length < minMsgLength) 
	{
		alert('Message must be at least ' + minMsgLength + ' characters long.');
		//document.contactForm.msg.value=""
		document.contactform.msg.focus()
		document.contactform.msg.style.background = "#F7F7F7"
		return false;
	}
	if (document.contactform.msg.value.length > maxMsgLength) 
	{
		alert('Message should be ' + maxMsgLength + ' characters long.');
		//document.contactForm.msg.value=""
		document.contactform.msg.focus()
		document.contactform.msg.style.background = "#F7F7F7"
		return false;
	}

	wordverification1 = document.contactform.wordverification.value;

	if(wordverification1 == "")
	{
		alert("Please enter the word verification.");
		document.contactform.wordverification.focus()
		document.contactform.wordverification.style.background = "#F7F7F7"
		return false;
	}
	else
	{
		j=wordverification1.length;
		for(i=0;i<j;i++)
		{
			if(wordverification1.charAt(i)< "0" || wordverification1.charAt(i)> "9")
			{
				alert("Please enter a 'numeric' word verification.");
				document.contactform.wordverification.value=""
				document.contactform.wordverification.focus()
				document.contactform.wordverification.style.background = "#F7F7F7"
				return false;
			}
			else
			{
				document.contactform.wordverification.style.background = "#FFFFFF"
			}
		}
	}

	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var maxLength = 6; // Maximum length
	var wf1 = document.contactform.wordverification.value;

	if (document.contactform.wordverification.value.length < minLength) 
	{
	alert('Verification code must be at least ' + minLength + ' characters long.');
	document.contactform.wordverification.value=""
	document.contactform.wordverification.focus()
	document.contactform.wordverification.style.background = "#F7F7F7"
	return false;
	}

	if (document.contactform.wordverification.value.length > maxLength) 
	{
	alert('Verification code should be ' + maxLength + ' characters long.');
	document.contactform.wordverification.value=""
	document.contactform.wordverification.focus()
	document.contactform.wordverification.style.background = "#F7F7F7"
	return false;
	}

	if ((document.contactform.reg_info[0].checked == false) && (document.contactform.reg_info[1].checked == false))
	{
		alert("Please select one option for field Are you a member?");
		document.contactform.reg_info[0].focus()
		document.contactform.reg_info[0].style.background = "#F7F7F7"
		return false;
	}
	else
	{
		document.contactform.reg_info[0].style.background = "#FFFFFF"
	}

	if (document.contactform.reg_info[0].checked == true)
	{
		user = document.contactform.username.value;
		if(user == "")
		{
			alert("Please enter the username.");
			document.contactform.username.focus()
			document.contactform.username.style.background = "#F7F7F7"
			return false;
		}
		else
		{
			document.contactform.username.style.background = "#FFFFFF"
		}

		pwd1 = document.contactform.pwd.value;
		if(pwd1 == "")
		{
			alert("Please enter the password.");
			document.contactform.pwd.focus()
			document.contactform.pwd.style.background = "#F7F7F7"
			return false;
		}
		else
		{
			document.contactform.pwd.style.background = "#FFFFFF"
		}
	}

	if (document.contactform.reg_info[1].checked == true)
	{
		category1 = document.contactform.category.value;
		if(category1 == "Select")
		{
			alert("Please select the category.");
			document.contactform.category.focus()
			document.contactform.category.style.background = "#F7F7F7"
			return false;
		}
		else
		{
			document.contactform.category.style.background = "#FFFFFF"
		}

		username1 = document.contactform.username.value;
		var iChars = " !@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		for (var i = 0; i < document.contactform.username.value.length; i++) 
		{
			if (iChars.indexOf(document.contactform.username.value.charAt(i)) != -1)
			{
				alert ("Your username has special characters or in-between spaces. \nThese are not allowed.\n Please remove them and try again.");
				document.contactform.username.focus()
				document.contactform.username.style.background = "#F7F7F7"
				return false;
			}
		}
		if(username1 == "")
		{
			alert("Please enter your username.");
			document.contactform.username.focus()
			document.contactform.username.style.background = "#F7F7F7"
			return false;
		}
		else
		{
			document.contactform.username.style.background = "#ffffff"
		}

		pwd1 = document.contactform.pwd.value;
		if(pwd1 == "")
		{
			alert("Please enter your password.");
			document.contactform.pwd.focus()
			document.contactform.pwd.style.background = "#F7F7F7"
			return false;
		}
		else
		{
			document.contactform.pwd.style.background = "#ffffff"
		}

		emailname = document.contactform.email.value;
		if(emailname == "")
		{
			alert("Please enter a value for the email.");
			document.contactform.email.focus()
			document.contactform.email.style.background = "#F7F7F7"
			return false;
		}
		else
		{
			document.contactform.email.style.background = "#FFFFFF"		
			if (echeck(document.contactform.email.value)==false)
			{
				document.contactform.email.value=""
				document.contactform.email.focus()
				document.contactform.email.style.background = "#F7F7F7"
				return false
			}
		}
	
	
		fname1 = document.contactform.fname.value;
		if(fname1 == "")
		{
			alert("Please enter the first name.");
			document.contactform.fname.focus()
			document.contactform.fname.style.background = "#F7F7F7"
			return false;
		}
		else
		{
			document.contactform.fname.style.background = "#FFFFFF"		
		}

		lname1 = document.contactform.lname.value;
		if(lname1 == "")
		{
			alert("Please enter the last name.");
			document.contactform.lname.focus()
			document.contactform.lname.style.background = "#F7F7F7"
			return false;
		}
		else
		{
			document.contactform.lname.style.background = "#FFFFFF"		
		}

	}
}


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){
	   alert("Kindly enter a valid email.")
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Kindly enter a valid email.")
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Kindly enter a valid email.")
	    return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Kindly enter a valid email.")
	    return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Kindly enter a valid email.")
	    return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Kindly enter a valid email.")
	    return false
	 }
	 if (str.indexOf(" ")!=-1){
	    alert("Kindly enter a valid email.")
	    return false
	 }
}

function textCounter(field, countfield, maxlimit) 
{
if (field.value.length > maxlimit)
	field.value = field.value.substring(0, maxlimit);
else 
	countfield.value = maxlimit - field.value.length;
}
