function openpopup(popurl){
var winpops=window.open(popurl,"","width=628,height=700,toolbar,scrollbars")
}

/////////////////////////////////////////////////////////////////////////////////

function emailToFriend(){
	var emailBox = document.getElementById("emailFriend");
	
	emailBox.style.display = "block";
	emailBox.style.top = 567 + "px";
	emailBox.style.left = 190 + "px";
}

function goAway(){
	var emailBox = document.getElementById("emailFriend");
	
	emailBox.style.display = "none";
	
	clear();
}

function clear(){
	document.emailForm.emailFrom.value = "";
	document.emailForm.emailName.value = "";
	document.emailForm.emailTo.value = "";
	document.emailForm.emailMessage.value = "";
	document.emailForm.emailCopy.checked = false;
}

/* Email Validator */
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
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   // alert("Invalid E-mail ID")
		    return false
		}

		 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
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function theGatherer(){
	var from = document.emailForm.emailFrom.value;
	var name = document.emailForm.emailName.value;
	var to = document.emailForm.emailTo.value;
	var message = document.emailForm.emailMessage.value;
	var copy = document.emailForm.emailCopy;
	var url = document.location;
	
	var emailID=document.emailForm.emailFrom;
	var emailTO=document.emailForm.emailTo;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email");
		emailID.focus();
		return false
	}
	if ((emailTO.value==null)||(emailTO.value=="")){
		alert("Please Enter the Recipient's Email");
		emailTO.focus();
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		alert("Please Enter a Valid Email Address");
		return false
	}
	if (echeck(emailTO.value)==false){
		emailTO.value="";
		emailTO.focus();
		alert("Please Enter a Valid Email Address");
		return false
	}
	
	
		if(copy.checked == true){
			document.location.href="mailto:"+to+"?cc="+from+"&subject=AARP.org Article from "+name+"&body="+name+" thought you would enjoy this article: "+url+"%0A%0AThis is what they said about it:%0A"+message;
		}else{
			document.location.href="mailto:"+to+"?subject=AARP.org Article from "+name+"&body="+name+" thought you would enjoy this article: "+url+"%0A%0AThis is what they said about it:%0A"+message;
		}
	
		
		goAway();
	
	}
