/*
 *  etumlib
 *  Copyright (C) 20007  J. Middag <j.middag@etum.nl>
 *
 *  This file is part of etumlib.
 *
 *  etumlib is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Retourneert een veilige mailto link
 * @param text De inhoud van het href attribuut na de mailto
 * @param name De naam van de link (als die leeg is wordt het adres er neer gezet met de @ vervangen door een plaatje)
 * @return String De html-code
 */

function printEPostLink(text, name) {
	var link;
	var i;

	if (name == "") {
		link = "";
		for (i = 0; i < text.length; i += 2) {
			number = parseInt("0x" + text.substr(i, 2));
			link += String.fromCharCode(number);
		}
		name = link.replace(/@/, ' AT ');
	}
	link = "<a href=\"http://localhost\" onMouseOver=\"return epostMouseOver(this, '" + text + "');\" onMouseOut=\"return epostMouseOut(this);\">" + name + "</a>";
	document.write(link);
}

/**
 * Zet het a element de echte link
 * @param DOM-element aElm Het a element die beveiligd is
 * @param String text De inhoud van het href attribuut na de mailto:
 */
function epostMouseOver(aElm, text) {
	var link;
	var i;

	link = "";
	for (i = 0; i < text.length; i += 2) {
		number = parseInt("0x" + text.substr(i, 2));
		link += String.fromCharCode(number);
	}
	aElm.href = "mailto:" + link;
	return false;
}

/**
 * Zet het a element de niet echte link
 * @param DOM-element aElm Het a element die beveiligd is
 */
function epostMouseOut(aElm) {
	aElm.href = "#";
	return false;
}