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("Invalid E-mail ID")
		   return false
		}

		// no @, @ex, ex@
		if (lat==-1 || lat==0 || lat==lstr-1){
		//   alert("Invalid E-mail ID")
		   return false
		}

		// no ., .ex, ex.
		if (ldot==-1 || ldot==0 || ldot==lstr-1){
		 //   alert("Invalid E-mail ID")
		    return false
		}

		// multiple @'s
		 if (str.indexOf(at,(lat+1))!=-1){
		//    alert("Invalid E-mail ID")
		    return false
		 }

		// .@, @.
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//    alert("Invalid E-mail ID")
		    return false
		 }

		// ex@ex - not . after @
		 if (str.indexOf(dot,(lat+2))==-1){
		//    alert("Invalid E-mail ID")
		    return false
		 }
		
		// space in email address
		 if (str.indexOf(" ")!=-1){
		 //   alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}

function trim(str) {
	sp = ' ';
	
	//left trim
	for(i=0;i<str.length;i++)
		if(str.charAt(i)==sp)
			str = str.substring(i+1, str.length);
		else
			break;
			
	//right trim		
	for(i=str.length;i>=0;i--)
		if(str.charAt(i)==sp)
			str = str.substring(0, i);
		else
			break;

	return str;
}

function newsletter()
{
	fld = document.getElementById("name");
	if((trim(fld.value) == "") || fld.value == "Your Name"){
		fld.focus();
		alert("Please enter your Name!");
		return false;
	}
	
	fld = document.getElementById("email");
	if (!echeck(fld.value)){
		fld.focus();
		alert("Please enter a valid Email Address!");
		return false;
	}
	
	if ((!document.getElementById("amudyomiSub").checked)&&(!document.getElementById("mishnaSub").checked)&&(!document.getElementById("rambamSub").checked)&&(!document.getElementById("mastertorahSub").checked)&&(!document.getElementById("allSub").checked)) {
		if(!confirm ("You have not chosen any subscriptions. Are you sure you don't want to receive any newsletters?")) {
			document.getElementById("allSub").focus();
			return false;
		}
	}
return true;
}
