
/*
Function "echeck" is used to verify if the given value is a possible valid email address. 
This function thus simply makes sure the email address has one (@), atleast one (.). 
It also makes sure that there are no spaces, extra '@'s or a (.) just before or after the @. 
It also makes sure that there is atleast one (.) after the @.

Function "ValidateText" is used to make sure that the email field is not blank 
and that it is a valid email address on form submission. */

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){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			   return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		     return false;
		 }

 		 return true;				
	}

 function Validatesubscriber(objName,objemail,objaddress,objphone){

	var txtName=document.getElementById(objName);
	var txtemail=document.getElementById(objemail);
	var txtaddress=document.getElementById(objaddress);
	var txtphone=document.getElementById(objphone);
	var Message="";
	var beginmessage ="Please correct the following: \n";
	
	if ((txtName.value==null)||(txtName.value=="")){
		Message = Message + "Enter your Name \n";
		txtName.focus();
		}
	if ((txtemail.value==null)||(txtemail.value=="")){
		Message = Message + "Enter your Email \n";
		txtemail.focus();
			}
	if ((txtaddress.value==null)||(txtaddress.value=="")){
		Message = Message + "Enter your address \n";
		txtaddress.focus();
		}
	if ((txtphone.value==null)||(txtphone.value=="")){
		Message = Message + "Enter your phone number \n";
		txtphone.focus();
			}
	if (echeck(txtemail.value)==false){
		Message = Message + "Enter a valid email";
		txtemail.value="";
		txtemail.focus();
			}
	if (Message == ""){
	return true;
		}
    alert(beginmessage + Message);
	return false;
 }
