// CopyLeft 2003 Lauri Kasvandik [http://zone.ee/internetu/lauri_k.php]

function dec2hex(number_, length_)
{
	var hexval;
	hexval="";

	while (number_>0) 
	{
		remainder=number_%16;
		if (remainder<10)
			hexval=remainder + hexval;
		else if (remainder==10)
			hexval="a"+hexval;
		else if (remainder==11)
			hexval="b"+hexval;
		else if (remainder==12)
			hexval="c"+hexval;
		else if (remainder==13)
			hexval="d"+hexval;
		else if (remainder==14)
			hexval="e"+hexval;
		else if (remainder==15)
			hexval="f"+hexval;
		number_=Math.floor(number_/16);
	}

	while (hexval.length<length_) hexval="0".hexval;

	return hexval; 
}

function nospam1(email_aadress, link_name)
{
	var encoded;
	var str;
	var x;

	encoded = '';
	str = email_aadress;
	for(i = 0; i < str.length; i++)
	{
		x= '%' + dec2hex(str.charCodeAt(i))
		encoded = encoded + x;
		//alert (email_aadress.charCodeAt(i));
	}

	return '<a href="mailto:' + encoded + '">' + link_name + '</a>';
}

function nospam2(email_aadress, link_name)
{
	var str;
	var encoded;
	encoded ='';
	str = 'mailto:'+email_aadress;
	for(i = 0; i < str.length; i++)
	{
		encoded = encoded + '&#'+str.charCodeAt(i)+';';
	}

	return '<a href="' + encoded + '">' + link_name + '</a>';

}

// didnt work at the moment...
function nospam3(email_aadress, at, point)
{
	
	email_aadress.Replace('@',at);
	email_aadress.Replace('.',point);
	return '<a href="mailto:' + email_aadress + '">' + link_name + '</a>';

}

//prompt('here it is: ', nospam1('mina@kuskil.ee','maili mulle'))
//prompt('here it is: ', nospam3('mina@kuskil.ee',' (at) ', ' (point) '))

function chk()
{
	eml = document.forms.nspm.eml.value
	lnk = document.forms.nspm.lnk.value
	//if (isNaN(eml) || isNaN(lnk)) return false;
	prompt('...and here is hex version of your email address!', nospam1(eml,lnk))
	prompt('...and here is decimal version!', nospam2(eml,lnk))
}

