function validate()
{
	var uname = document.form.username.value;
	var address = document.form.address.value;
	var email = document.form.email.value;
	var contact = document.form.contactno.value;
	var remarks = document.form.remarks.value;
	
	var diff = email.indexOf("@") - email.indexOf(".");
	var diff1 = email.indexOf(".") - email.indexOf("@");
	
	var len = email.length;
	var lchar = email.substring(len-1,len);
	len = len - 1;
	
	if (document.form.username.value == "")
	{
		alert("Name Required");
		document.form.username.select();
		return false;
	}
	else if(uname.indexOf(' ') == 0)
	{
		alert("First character should not be space");
		document.form.username.select();
		return false;
	}
	else if(uname.length > 30)
	{
		alert("Name Length should be less than or equal to 30 character");
		document.form.username.select();
		return false;
	}
	else if(junk_vals(uname) == false)
	{
		alert("Junk characters (#,/\\()-!$%&<>?=+*|~'\";:) not allowed");
   		document.form.username.select();
		return false;
	}
	else if(isNaN(uname) == false)
	{
		alert("Numbers not allowed");
   		document.form.username.select();
		return false;
	}
	else if(address.indexOf(' ') == 0)
	{
		alert("First character should not be space");
		document.form.address.select();
		return false;
	}
	else if(address.indexOf("'") > -1 )
	{
		alert("\' character should not be allowed");
		document.form.address.select();
		return false;
	}
	else if(address.length > 200)
	{
		alert("Address Length should be less than or equal to 200 character");
		document.form.address.select();
		return false;
	}
	else if (document.form.email.value == "")
	{
		alert("Email ID Required");
		document.form.email.select();
		return false;
	}
	else if(junk_vals(email) == false)
	{
		alert("Junk characters (#,/\\()-!$%&<>?=+*|~'\";:) not allowed");
   		document.form.email.select();
		return false;
	}
	else if(email.indexOf(' ') == 0)
	{
		alert("First character should not be space");
		document.form.email.select();
		return false;
	}
	else if(email.length > 50)
	{
		alert("Email ID Length should be less than or equal to 50 character");
		document.form.email.select();
		return false;
	}
	else if( email.indexOf("@") < 1 || email.indexOf(".") < 3 || email.indexOf("@") == len || email.indexOf(".") == len || lchar == "@" || lchar == "." || diff == 1 || diff1 == 1)
	{
	  	alert("Please Enter Valid Email ID"); 
	  	document.form.email.select();
		return false;
	}
	
	else if (document.form.contactno.value == "")
	{
		alert("Contact Number Required");
		document.form.contactno.select();
		return false;
	}
	else if(contact.indexOf(' ') == 0)
	{
		alert("First character should not be space");
		document.form.contactno.select();
		return false;
	}
	else if((contact.length > 15) || (contact.length < 5))
	{
		alert("Contact Number Length should be greater than 5 characters and less than or equal to 15 character");
		document.form.contactno.select();
		return false;
	}
	
	else if(contactOK() == false)  
	{       
		document.form.contactno.select();
		return false;
  	}
	 	
  	else if(remarks.indexOf(' ') == 0)
	{
		alert("First character should not be space");
		document.form.remarks.select();
		return false;
	}
	else if(remarks.indexOf("'") > -1 )
	{
		alert("\' character should not be allowed");
		document.form.remarks.select();
		return false;
	}
	else if(remarks.length > 200)
	{
		alert("Remarks Length should be less than or equal to 200 character");
		document.form.remarks.select();
		return false;
	}
	return true;
}

function junk_vals(val)
{
	if(val.indexOf("#") != -1 || val.indexOf(",") != -1 || val.indexOf("?") != -1 || val.indexOf(">") != -1 || val.indexOf("<") != -1 || val.indexOf("=") != -1 || val.indexOf("*") != -1 || val.indexOf("&") != -1 || val.indexOf("%") != -1 || val.indexOf("$") != -1 || val.indexOf("!") != -1 || val.indexOf("/") != -1 || val.indexOf("\\") != -1 || val.indexOf(")") != -1 || val.indexOf("(") != -1 || val.indexOf("-") != -1 || val.indexOf("|") != -1 || val.indexOf("~") != -1 || val.indexOf("'") != -1 || val.indexOf("\"") != -1 || val.indexOf(";") != -1 || val.indexOf(":") != -1)
	{
		return false;
	}
	else
		return true;
}

function check_email(email)
{
	if ((email.indexOf ('@') == -1) || (email.indexOf ('.') == -1))
	{ 
		return false;
	}
	else
	return true;
}

function isAllDigits(s)
{
	var test =  s;
    	for (var k = 0; k < test.length; k++)
        {
    		var c = test.substring(k, k+1);
    		if (isDigit(c) == false)
            	{
            		return false;
            	}
        }
    	return true;
}
  
function isDigit(c)
{
	var test = "" + c;
    	if (test == "0" || test == "1" || test == "2" || test == "3" || test == "4" 
    	|| test == "5" || test == "6" || test == "7" || test == "8" || test == "9")
        {
    		return true;
        }
    	return false;
}
	
function isAllDigits1(s)
{
	var test =  s;
    	for (var k = 0; k < test.length; k++)
        {
    		var c = test.substring(k, k+1);
    		if (isDigit1(c) == false)
            	{
            		return false;
            	}
        }
    	return true;
}
  
function isDigit1(c)
{
	var test = "" + c;
    	if (test == "0" || test == "1" || test == "2" || test == "3" || test == "4" 
    	|| test == "5" || test == "6" || test == "7" || test == "8" || test == "9")
        {
    		return true;
        }
    	return false;
}
	
function contactOK()
{
	var contact = document.form.contactno.value;
    	if (contact.length <= 15 )
        {
        	var result = isAllDigits1(contact);
	        if (result == false)
            	{
            		alert("Invalid character in contact number");   
            	}
        	return result;
        }
     	else
        return false;
}