/*********************************************************************************
Application: 		CapeVerdeImports Web Site
Author:				John Abbott
Creation Date:		27 Jan 2008
Amendment Date:		N/A
Version:			1.0
Page:				Included in the Contacts Page
Purpose:			Allows for the encoding of the email address
Overview			The email address is hidden by encoding the address using
					SSS to produce an index/letter combination that can be
					decoded in JavaScript to produce the plain text.  To make
					the routine compatible with XML the text must be placed
					in the document by manipulating the DOM.
********************************************************************************/


/*--------------------Create a DOM Element for XML or HTML----------------------*/
function createElement(element) {
/*Purpose:	Creates a DOM element either compatible with XML or html.
Inputs:		element.  String representing the html tag element to create
					ie.  'div'.
Outputs:	None
Return:		Object representing the Element created.
Date:		27 Jan 2008
Version:	1.0
Note:		
Reference:	This script is taken from:
			http://simonwillison.net/2003/Jun/15/javascriptWithXML/
			visited Jan 2008.
********************************************************************/

	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}


/*-------------------------- Decode Text  -------------------------------------*/

function decodeText(strIndexes, strLetters) {
/*Purpose:	Decodes text that has been encoded into an index/letters
			pair of strings.
Inputs:		strIndexes - String of indexes
			strLetters - String of letters
Outputs:	None
Return:		Plain Text string of the decoded data.
Date:		27 Jan 2008
Version:	1.0
Note:		The encoded text is produced by SS scripting.
			It is not meant to be secure.  Only to hide the
			text from spambots and the like.
Reference:	This code based on a algorythm by Tyler Akins 
			http://rumkin.com/tools/mailto_encoder/example.phps
********************************************************************/

	var strOutput ='';
	
	for (var i=0; i<strIndexes.length; i++) {
		strOutput += strLetters.charAt(strIndexes.charCodeAt(i)-48);
	}
	return strOutput;
}
