//This function is used to trim any string value using javascript.
function trimString (str) {
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


//This function is used for email validation
function isValidEmail(str) {
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(str.match(emailFilter))) { 
        return false;
	}
	else {
		return true;
	}

}

//This function is used for Numeric values
function isNumeric(str) {
	var numFilter=/^[0-9][0-9]*$/;
	if (!(str.match(numFilter))) { 
        return false;
	}
	else {
		return true;
	}
}

function check()
{
	var msg ='';
	var error =  false;
	var name = document.frmCounter.name.value;
	var email = document.frmCounter.email.value;
	var website_title = document.frmCounter.newwebsitetitle.value;
	var username = document.frmCounter.username.value;
	var password = document.frmCounter.password.value;	
	var confirm_password = document.frmCounter.confirm_password.value;	
	var policy = document.frmCounter.policy.checked;
	var startcount = trimString(document.frmCounter.newstartcount.value);	
	var weburl = trimString(document.frmCounter.newwebsite.value);	
	
	if (trimString(name)=="")
	{
		error = true;
		msg = "Please enter the name.\n";
	}

	if (trimString(email)=="")
	{
		error = true;
		msg += "Please enter the email.\n";
	}
	
	if (trimString(email)!=""){
		if (isValidEmail(email)==false)
		{
			error = true;
			msg += "Invalid email address.\n";
		}		
	}

	if (startcount=="")
	{
		error = true;
		msg += "Please enter the start count number.\n";		
	}

	if (startcount!=""){
		if (isNumeric(startcount)==false)
		{
		error = true;
		msg += "Only numbers allowed in starting count field .\n";
		}				
	}	
		
	if (trimString(website_title)=="")
	{
		error = true;
		msg += "Please enter the website title.\n";
	}
	if (weburl != "") 
	{
		var is_protocol_ok=weburl.indexOf('http://');
		if (is_protocol_ok==-1)
	 	{ 
	  		error = true;
			msg += "Web Site URL must start with http://.\n";
	  	}
	}
	if (trimString(username)=="")
	{
		error = true;
		msg += "Please enter the username.\n";
	}
	
	if (trimString(password)=="")
	{
		error = true;
		msg += "Please enter the password.\n";
	}
	
	if (trimString(confirm_password)=="")
	{
		error = true;
		msg += "Please enter the confirm password.\n";
	}
	
	if (password != "" && confirm_password != "" ){
		if (password != confirm_password){
			error = true;
			msg += "Confirm password does not match with the supplied password.\n";
		}	
	}	
	
	
	if (policy == false)
	{
		error = true;
		msg += "Please agree with the policy.\n";
	}
	
	if(error==true){
		alert(msg);
		return false;
	}	 
}	

function validate()
   {
   
   var msg ='';
	var error =  false;
	var name = document.frmCounter.name.value;
	var email = document.frmCounter.email.value;
	var website_title = document.frmCounter.newwebsitetitle.value;
	var password = document.frmCounter.password.value;	
	var confirm_password = document.frmCounter.confirm_password.value;	
	var policy = document.frmCounter.policy.checked;
	var startcount = trimString(document.frmCounter.newstartcount.value);	
	var weburl = trimString(document.frmCounter.newwebsite.value);	
	
	if (trimString(name)=="")
	{
		error = true;
		msg = "Please enter the name.\n";
	}

	if (trimString(email)=="")
	{
		error = true;
		msg += "Please enter the email.\n";
	}
	
	if (trimString(email)!=""){
		if (isValidEmail(email)==false)
		{
			error = true;
			msg += "Invalid email address.\n";
		}		
	}

	if (startcount=="")
	{
		error = true;
		msg += "Please enter the start count number.\n";		
	}

	if (startcount!=""){
		if (isNumeric(startcount)==false)
		{
		error = true;
		msg += "Only numbers allowed in starting count field .\n";
		}				
	}	
		
	if (trimString(website_title)=="")
	{
		error = true;
		msg += "Please enter the website title.\n";
	}
	
	var is_protocol_ok=weburl.indexOf('http://');
	if (is_protocol_ok==-1)
 	{ 
  		error = true;
		msg += "Web Site URL must start with http://.\n";
  	}
	
	if (trimString(password)=="")
	{
		error = true;
		msg += "Please enter the password.\n";
	}
	
	if (trimString(confirm_password)=="")
	{
		error = true;
		msg += "Please enter the confirm password.\n";
	}
	
	if (password != "" && confirm_password != "" ){
		if (password != confirm_password){
			error = true;
			msg += "Confirm password does not match with the supplied password.\n";
		}	
	}	
	
	
	if (policy == false)
	{
		error = true;
		msg += "Please agree with the policy.\n";
	}
	
	if(error==true){
		alert(msg);
		return false;
	}
   }
  