/*********************************************************************************************
*
* eAddressShader.js
* Version: 1.0
* Date: 18.05.2009
* Copyright: (C) 2009 Infotrepid - Tomaz Klemse
* http: www.infotrepid.com
*
**********************************************************************************************
*
* Protect mail address form spam.
*
**********************************************************************************************
*
* How to use:
* 	Place the javascript reference into the head:
* 	<script src="/eAddressShader.js" type="text/javascript"></script>
* 
* 	For encoding or decoding email address for saving into database use following functions:
* 	encAddress or decAddress
* 
* 	For decode the email address into webpage:
*   call the function decLinkText on body or window load
*   Pay attention to naming the tag:
*   the function to decode email search all the tags named eAddressShaded
*   
*   example of link for mailto (jogpAjogp/dpn is an example of encrypted email address):
*   <a href="http:///" onclick="decLinkHref(this);" name="eAddressShaded">jogpAjogp/dpn</a>
* 
**********************************************************************************************/


function encAddress(emailAddress)
{
	var eAddress = emailAddress;
	var encAddress = '';
	for(var i=0; i < eAddress.length; i++)	
	{
		n=eAddress.charCodeAt(i);
		if (n>=8364)
		{
			n = 128;
		}
		encAddress += String.fromCharCode(n+1);
	}
	return encAddress;
}


function decAddress(emailAddress)
{
	var eAddress = emailAddress;
	var encAddress = '';
	for(var i=0; i < eAddress.length; i++)	
	{
		n=eAddress.charCodeAt(i);
		if (n>=8364)
		{
			n = 128;
		}
		encAddress += String.fromCharCode(n-1);
	}
	return encAddress;
}


function decLinkText()
{
	var allElements=document.getElementsByName('eAddressShaded');
	if(allElements.length>0)
	{
		for(i=0;i<=allElements.length-1;i++)
		{
			var thisLink = allElements[i];
			var encLnk = thisLink.firstChild.nodeValue;
			decLnk='';
			for(var j=0; j < encLnk.length; j++)
			{
				n=encLnk.charCodeAt(j);
				if (n>=8364)
				{
					n = 128;
				}
				decLnk += String.fromCharCode(n-1);
			}
			thisLink.firstChild.nodeValue = decLnk;
		}
	}
}


function decLinkHref(link)
{
	s="pdlow";
	r="";
	for(var i=0; i < s.length; i++)
	{
		n=s.charCodeAt(i);
		if (n>=8364)
		{
			n = 128;
		}
		r += String.fromCharCode(n-(3));
	}
	r+='o';
	link.href=r+":"+link.innerHTML;
}
