// Form Validation JavaScript Document


function check()
{
	if ( opt_Fname() && opt_email() && opt_Zip()) 
	{
		document.subscribe.submit();
		return true;
	}
	return false;
}


// Name Validation
function opt_Fname() 
{
	var str = document.subscribe.newsletter_name.value;
	if (str == "")
	{
		alert("The First Name field is left blank.\n\nPlease provide an Input.")
		document.subscribe.newsletter_name.focus();
		return false;
	}
	return true;
}

// Email Validation
function opt_email()
{
var str = document.subscribe.newsletter_email.value;
var str1 = document.subscribe.newsletter_email.value.length;
if(str == "")
	{
		alert("The Email ID field is left blank.\n\nPlease provide an Input.")
		document.subscribe.newsletter_email.focus();
		return false;
	}
if (str.indexOf("@")== -1 || str.indexOf(".")== -1)
{
	alert("Please enter the correct E-mail ID.");
	document.subscribe.newsletter_email.select();
	document.subscribe.newsletter_email.focus();
	return false;	
}
if((str.substring(0,1) == "@" || str.substring(0,1)== ".") || str.substring(0,1)=="-" || str.substring(0,1)=="_")
	{
		alert("The Email ID can not begin with @ or . or - or _ ");
		document.subscribe.newsletter_email.select();
		document.subscribe.newsletter_email.focus();
		return false;
	}

if ((str.substring(str1-1,str1)=="@" || str.substring(str1-1,str1)=="."))
{
		alert("The Email ID can not end with @ or . ");
		document.subscribe.newsletter_email.select();
		document.subscribe.newsletter_email.focus();
		return false;
}
var index1 = str.indexOf("@");
var index2 = str.indexOf(".");
var index3=str.indexOf("-");
var index4=str.indexOf("_");

if(str.substring(index1+1,index1+2) ==".")
{
alert(". can not come immidately after @");
document.subscribe.newsletter_email.select();
document.subscribe.newsletter_email.focus();
return false;
}
if ( ( index3==index1+1) || ( index4==index1+1))
{
alert("please enter the correct Email ID as no two special chars can come in sequence.");
document.subscribe.newsletter_email.select();
document.subscribe.newsletter_email.focus();
return false;
}

for (var i = 0; i < str.length; i++) 
{
var ch = str.substring(i, i + 1);
if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_') && ch !='-' && ch !='@' && ch !='.')
		{
			alert("\nThe Email field  accepts letters,numbers & underscore.\n\nPlease re-enter your email.");
			document.subscribe.newsletter_email.select();
			document.subscribe.newsletter_email.focus();
			return false;
		}
	}
return true;
}


// Zip Number Validation
function opt_Zip()
{
var str = document.subscribe.newsletter_zip.value;
if ( isNaN(str) )
{ 
	alert("Sorry this is an Invalid Zip \n\nPlease provide a Numeric value as an Input.");
	document.subscribe.newsletter_zip.select();
	document.subscribe.newsletter_zip.focus();
	return false;
}
if (str == "")
	{
		alert("Zip field is left blank. \n\nPlease provide an Input.")
		document.subscribe.newsletter_zip.focus();
		return false;
	}

if((str.substring(0,1)<"0" || str.substring(0,1)>"9"))
	{
		alert("The Zip should begin with an numeric character.");
		document.subscribe.newsletter_zip.focus();
		return false;
	}
return true; 
}


