function email_popup(language, url)
{
    var name='email_friend';
	var width='370';
	var height='440';
	var urlocation = new String(self.location);
	
	//replce advisor url to public for fundview
	if ( urlocation.indexOf('app/fundview/advisor') != -1 ){
	      urlocation = urlocation.replace('advisor', 'public');
	}
	
	//check if it's a media release
	var isMediaRelease = false;
	var urlocation = new String(self.location);
	if ( urlocation.indexOf('release') != -1 ){
	      isMediaRelease = true;
	}	
	
	//check if there is a TradeMark symbol in the title
	tm = "n";
	tmIndex = "0";
	for (i=0; i<document.title.length; i++) {
		if (document.title.charAt(i) == "™") {
			tm = "y";
			tmIndex = i;
		}
	}
		  
	//add url parameter
	url += '?url='+escape(urlocation);
	
	//add title parameter		
	url += '&title='+document.title;
	
	//add TradeMark flag and TradeMark index parameters
	url += '&tm='+tm;
	url += '&tmIndex='+tmIndex;
		
	//add language parameter
	url += '&language='+language;

	//add app parameter if coming from media release
	if (isMediaRelease) {
		url += '&app=mediarelease';
	}	
	
	var Win = window.open(url, name,'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no,status=no');
	Win.focus();
}

function validate(theform)
{
	var valid=true;
	var errorMsg='';
	
//Regular expression for valid email address & invalid characters
	re = /[a-zA-Z0-9\._-]+@([a-zA-Z0-9-]{2,}\.)+[a-zA-Z0-9]{2,}/; 
//	re2 = /[#\$%&\\/]/;
	re2 = /[\#\$\%\&\\]/;		

//validate recipient email(s)

//validate sender email
	if (!re.test(theform.from.value))
	{
		valid=false;
		if (lang=="E")
		{
			errorMsg+="Please enter valid 'From' e-mail address.\n";
		} else {
			errorMsg+="Introduire l'adresse courriel valide de l'expéditeur.\n";
		}
	}

//split multiple emails by "," and check each one
	var rec_email_arr=theform.rec_email.value.split(",");
	for (i=0;i<rec_email_arr.length;i++)
	{
		if (!re.test(rec_email_arr[i]))
		{
			valid=false;
		}	
	}

	if (!valid)
	{
		if (lang=="E")
		{
			errorMsg+="Please enter valid recipient e-mail address(es).\n";
		} else {
			errorMsg+="Introduire l'adresse courriel valide du destinataire.\n";
		}
	}

//maximum of 20 emails
	if (rec_email_arr.length>20)
	{
		valid=false;
		if (lang=="E")
		{
			errorMsg+="The number of e-mail addresses must be less than 20.\n";
		} else {
			errorMsg+="Le nombre d'adresses courriel doit être inférieur à 20.\n";
		}
	}

//validate subject
	if (re2.test(theform.subject.value))
	{
		valid=false;
		if (lang=="E")
		{
			errorMsg+="The subject must not contain #,$,%,&,/,\\.\n";
		} else {
			errorMsg+="L'objet ne doit pas contenir #,$,%,&,/ ou \\.\n";
		}
	}

//check length of message
	if (theform.note.value.length>255 || re2.test(theform.note.value))
	{
		valid=false;
		if (lang=="E")
		{
		errorMsg+="The message must be shorter than 255 characters and must not contain #,$,%,&,/,\\.\n";
		} else {
			errorMsg+="Le message ne doit pas dépasser 255 caractères et ne doit pas contenir #,$,%,&,/ ou \\.\n";
		}
	}

//inform errors to user
	if (!valid)
	{
		alert(errorMsg);
	}

return valid;
} 

