function EmailColleague(SectionName,title, url, anchor){
	if (SectionName == "") { var sec = "1"; } else { var sec = SectionName; }
	if (title == "") { var title = "undefined"; } else { var title = title; }
	if (url == "") { var orgurl = ""; } else { var orgurl = url; }	
  var EmailColleague;
  var appstr = "?cat_id="+sec+"&title="+title+"&orgurl="+orgurl+"&anchor="+anchor
	 
	 pictemp2= new Image(1,1); 
	 pictemp2.src = "/en/main/images/546_127052.gif";
	 
	 EmailColleague = window.open("/en/main/SendPageToFriend/sendPage.asp"+appstr, "emailcolleague", "width=500,height=400,scrollbars=no");
}


function check_fromaddr(emailaddr) {
	if (emailaddr.length == "0") {
		alert("You must enter your email address")
		return false;
	} else {
		// check its valid
		if (!validate_emailaddr(emailaddr)) {
			alert("Your email address is invalid - please re-enter");
			return false;
		}
	}
	return true;
}


function check_emailaddr(emaillist) {
	
	// we should receive a comma delimited list of email addresses
	// we will loop through these and validate each one
	var pos = 0;  // first position where to check for the comma
	var comma_count = 0;
	var err_msg = ""
	var badcount = 0;
	var err_count = 0; // will be changed to 1 if there is an error
	
	// first check to make sure something has been entered
	if (emaillist.length == "0") {
		err_msg += "Email address in invalid\n\n- You must enter an email address\n";
		err_count = 1;
	} else {
		// start the loop and see how many we can find
		for (i=0; i < emaillist.length; i++) {
			com = emaillist.charAt(i);
			if (com == ",") {
				comma_count++;
			}
		}
		// if the comma count is greater than 0 then we should have at least 2 email addresses.. validate them
		if (comma_count > 0) {
			emailarray = emaillist.split(",");  // returns an array of email addresses ;)
			//alert(emailarray.length + " email address to be validated");
			for (i in emailarray) {
				// loop through the array and validate each email address
				if (!validate_emailaddr(emailarray[i])) {
					// this is invalid
					err_msg += "- \'"+emailarray[i]+"\' is invalid! \n"
					err_count = 1;
					badcount++;							
				}
			}
			
			if (err_count == 1) { err_msg = "Email address in invalid\n\n" + badcount + " of the " + emailarray.length + " addresses has errors.\n\n" + err_msg; }			
			
		} else {
			// validate what has been put in...

			if (!validate_emailaddr(emaillist)) {
				// this is invalid
				err_msg += "- \'"+emaillist+"\' is invalid! please re-enter\n"
				err_count = 1;
			}
			
			if (err_count == 1) { err_msg = "Email address in invalid\n\n" + err_msg; }			

		} 
	}

	if (err_count == 0) {
		return true;  // if there are no errors, return true
	}
	alert(err_msg);	
	return false; // return false by default
}

function validate_emailaddr(emailaddr) {
// validate a given email address
   if (emailaddr.indexOf("@") < 1)  {
		return false; // checking its @ symbol is not the first character...
   } else {
		if (emailaddr.indexOf(".",emailaddr.indexOf("@")) < emailaddr.indexOf("@")) {
			return false;  // checking that there is a . after the @ symbol
		}
	}		
return true; // if everything is ok then return true
}
