/***************************************************************
*  uncryptMailToText.js
*  Provides functionality to uncrypt the mailto:-Links [(at) to @]
*
*  Copyright notice
*
*  This script is part of the TYPO3 project. The TYPO3 project 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 2 of the License, or
*  (at your option) any later version.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

//---------------------------------------------------------------------------------
//uncryptMailToText.js
//Provides functionality to uncrypt the mailto:-Links [(at) to @]
//Autor: Patrik Hipp, namics ag
//created: 05.08.2005
//Last Change: 04.09.2006 
//      -> added functionality the for email-link within the FCKEditor
//         (subject and body)
//---------------------------------------------------------------------------------

//---------------------------------------------------------------------------------
function UnCryptMailto(s, shift) {	
// JS function for uncrypting spam-protected emails:
//---------------------------------------------------------------------------------
	var n=0;
	var r="";
	for(var i=0; i < s.length; i++) {
		n=s.charCodeAt(i);
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(shift));
	}
	return r;
}

//---------------------------------------------------------------------------------
function linkTo_UnCryptMailto(s, subjectAndBody, shift)	{
// JS function for uncrypting spam-protected emails:
//---------------------------------------------------------------------------------	
	if(subjectAndBody.indexOf("|") > 0) {
		do{
		   indexOfNextPipeSymbol = subjectAndBody.indexOf("|")
		   subjectAndBody = subjectAndBody.substring(0, indexOfNextPipeSymbol) + "%0D%0A" +
		      subjectAndBody.substring(indexOfNextPipeSymbol+1, subjectAndBody.length)
		} while (subjectAndBody.indexOf("|")>-1)
	}
	var encryptedEmail = UnCryptMailto(s, shift);	
	location.href = encryptedEmail + subjectAndBody;
}

