//Function to trim the string
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function validEmailAddress(email)
{
		invalidChars = " /:,;~"
		if (email == "") 
		{
			return (false);
		}
		for (i=0; i<invalidChars.length; i++) 
		{
			badChar = invalidChars.charAt(i)
			if (email.indexOf(badChar,0) != -1) 
			{
				return (false);
			}
		}
		atPos = email.indexOf("@",1)
		if (atPos == -1) 
		{
			return (false);
		}
		if (email.indexOf("@",atPos+1) != -1) 
		{
			return (false);
		}
		periodPos = email.indexOf(".",atPos)
		if (periodPos == -1) 
		{
			return (false);
		}
		if (periodPos+3 > email.length)	
		{
			return (false);
		}
			
		return (true);
}

//function to check validation of th form objects
function validate(objfrm)
{
	msg="Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	if(trim(objfrm.mail.value)=='' || trim(objfrm.mail.value)=='Enter your e-mail id')	msg+='- Please enter your Email address. \n';		
	
		
	
	else if(!validEmailAddress(trim(objfrm.mail.value)))
	{
		msg +=  "- Please enter valid email address.\n";		
	}	

	if(msg!="Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n")
	{
		alert(msg);
		return false;
	}
	else
	{
		objfrm.method = "POST";
		objfrm.action="newsletter.php";
		objfrm.submit();
		
		return true;
	}
	
}

function clearmail()
{
	if(trim(document.subscribe.mail.value) == 'Enter your e-mail id')
	{
		document.subscribe.mail.value = '';
	}
}
function setmail()
{
	if(trim(document.subscribe.mail.value) == '')
	{
		document.subscribe.mail.value = 'Enter your e-mail id';
	}
}

