function contactmaildata()
{
msg1 = document.contactmailform.msg.value;
if(msg1 == "")
{
alert("Please enter the message.");
document.contactmailform.msg.focus()
document.contactmailform.msg.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.msg.style.background = "#FFFFFF"
}

var minMsgLength = 20; // Minimum length
var maxMsgLength = 1000; // Maximum length

// check for minimum length
if (document.contactmailform.msg.value.length < minMsgLength) 
{
alert('Message must be at least ' + minMsgLength + ' characters long.');
//document.contactmailform.msg.value=""
document.contactmailform.msg.focus()
document.contactmailform.msg.style.background = "#E9F4F8"
return false;
}
// check for maximum length
if (document.contactmailform.msg.value.length > maxMsgLength) 
{
alert('Message should be ' + maxMsgLength + ' characters long.');
//document.contactmailform.msg.value=""
document.contactmailform.msg.focus()
document.contactmailform.msg.style.background = "#E9F4F8"
return false;
}

wordverification1 = document.contactmailform.wordverification.value;

if(wordverification1 == "")
{
alert("Please enter the word verification.");
document.contactmailform.wordverification.focus()
document.contactmailform.wordverification.style.background = "#E9F4F8"
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.contactmailform.wordverification.value=""
document.contactmailform.wordverification.focus()
document.contactmailform.wordverification.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.wordverification.style.background = "#FFFFFF"
}
}
}

var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var maxLength = 6; // Maximum length
var wf1 = document.contactmailform.wordverification.value;

// check for minimum length
if (document.contactmailform.wordverification.value.length < minLength) 
{
alert('Verification code must be at least ' + minLength + ' characters long.');
document.contactmailform.wordverification.value=""
document.contactmailform.wordverification.focus()
document.contactmailform.wordverification.style.background = "#E9F4F8"
return false;
}

// check for maximum length
if (document.contactmailform.wordverification.value.length > maxLength) 
{
alert('Verification code should be ' + maxLength + ' characters long.');
document.contactmailform.wordverification.value=""
document.contactmailform.wordverification.focus()
document.contactmailform.wordverification.style.background = "#E9F4F8"
return false;
}

if ((document.contactmailform.reg_info[0].checked == false) && (document.contactmailform.reg_info[1].checked == false))
{
alert("Please select one option for field Are you a member?");
document.contactmailform.reg_info[0].focus()
document.contactmailform.reg_info[0].style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.reg_info[0].style.background = "#FFFFFF"
}

if (document.contactmailform.reg_info[0].checked == true)
{
user = document.contactmailform.username.value;
if(user == "")
{
alert("Please enter the username.");
document.contactmailform.username.focus()
document.contactmailform.username.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.username.style.background = "#FFFFFF"
}
pwd1 = document.contactmailform.pwd.value;
if(pwd1 == "")
{
alert("Please enter the password.");
document.contactmailform.pwd.focus()
document.contactmailform.pwd.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.pwd.style.background = "#FFFFFF"
}
}

if (document.contactmailform.reg_info[1].checked == true)
{
username1 = document.contactmailform.username.value;
var iChars = " !@#$%^&*()+=-[]\\\';,./{}|\":<>?";
for (var i = 0; i < document.contactmailform.username.value.length; i++) 
{
if (iChars.indexOf(document.contactmailform.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.contactmailform.username.focus()
document.contactmailform.username.style.background = "#E9F4F8"
return false;
}
}
if(username1 == "")
{
alert("Please enter your username.");
document.contactmailform.username.focus()
document.contactmailform.username.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.username.style.background = "#ffffff"
}

pwd1 = document.contactmailform.pwd.value;
if(pwd1 == "")
{
alert("Please enter your password.");
document.contactmailform.pwd.focus()
document.contactmailform.pwd.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.pwd.style.background = "#ffffff"
}
cpwd1 = document.contactmailform.cpwd.value;
if(cpwd1 == "")
{
alert("Please enter your confirm password.");
document.contactmailform.cpwd.focus()
document.contactmailform.cpwd.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.cpwd.style.background = "#ffffff"
}
if (pwd1 != cpwd1)
{
alert("Entered password does not match with the confirm password. \n Both password shold be the be same.");
document.contactmailform.cpwd.focus()
document.contactmailform.cpwd.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.cpwd.style.background = "#ffffff"
}
name1 = document.contactmailform.fname.value;
if(name1 == "")
{
alert("Please enter the name.");
document.contactmailform.fname.focus()
document.contactmailform.fname.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.fname.style.background = "#FFFFFF"
}
emailname = document.contactmailform.email.value;
if(emailname == "")
{
alert("Please enter a value for the e-mail id.");
document.contactmailform.email.focus()
document.contactmailform.email.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.email.style.background = "#FFFFFF"
if (echeck(document.contactmailform.email.value)==false)
{
document.contactmailform.email.value=""
document.contactmailform.email.focus()
document.contactmailform.email.style.background = "#E9F4F8"
return false
}
}

}
}

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 e-mail id.")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Kindly enter a valid e-mail id.")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Kindly enter a valid e-mail id.")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Kindly enter a valid e-mail id.")
return false
 }
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Kindly enter a valid e-mail id.")
return false
 }
if (str.indexOf(dot,(lat+2))==-1){
alert("Kindly enter a valid e-mail id.")
return false
 }
if (str.indexOf(" ")!=-1){
alert("Kindly enter a valid e-mail id.")
return false
 }
}


function contactdata()
{
msg1 = document.contactmailform.msg.value;
if(msg1 == "")
{
alert("Please enter the message.");
document.contactmailform.msg.focus()
document.contactmailform.msg.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.msg.style.background = "#FFFFFF"
}

var minMsgLength = 20; // Minimum length
var maxMsgLength = 1000; // Maximum length

// check for minimum length
if (document.contactmailform.msg.value.length < minMsgLength) 
{
alert('Message must be at least ' + minMsgLength + ' characters long.');
//document.contactmailform.msg.value=""
document.contactmailform.msg.focus()
document.contactmailform.msg.style.background = "#E9F4F8"
return false;
}
// check for maximum length
if (document.contactmailform.msg.value.length > maxMsgLength) 
{
alert('Message should be ' + maxMsgLength + ' characters long.');
//document.contactmailform.msg.value=""
document.contactmailform.msg.focus()
document.contactmailform.msg.style.background = "#E9F4F8"
return false;
}

wordverification1 = document.contactmailform.wordverification.value;

if(wordverification1 == "")
{
alert("Please enter the word verification.");
document.contactmailform.wordverification.focus()
document.contactmailform.wordverification.style.background = "#E9F4F8"
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.contactmailform.wordverification.value=""
document.contactmailform.wordverification.focus()
document.contactmailform.wordverification.style.background = "#E9F4F8"
return false;
}
else
{
document.contactmailform.wordverification.style.background = "#FFFFFF"
}
}
}

var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var maxLength = 6; // Maximum length
var wf1 = document.contactmailform.wordverification.value;

// check for minimum length
if (document.contactmailform.wordverification.value.length < minLength) 
{
alert('Verification code must be at least ' + minLength + ' characters long.');
document.contactmailform.wordverification.value=""
document.contactmailform.wordverification.focus()
document.contactmailform.wordverification.style.background = "#E9F4F8"
return false;
}

// check for maximum length
if (document.contactmailform.wordverification.value.length > maxLength) 
{
alert('Verification code should be ' + maxLength + ' characters long.');
document.contactmailform.wordverification.value=""
document.contactmailform.wordverification.focus()
document.contactmailform.wordverification.style.background = "#E9F4F8"
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;
}