
// Written by Dmitry Zhemchuzhin

// This script is designed to make email-collecting robots' task harder.

//**************** START DATA SECTION ********************

//info
function EMCodec_start1() {
	EMCodec_startFullLink("gjgogggpeagogphggpgfcnhagpglgpgmgfgogjgfcohchf");
}

//***************** END DATA SECTION *********************

var EMCodec_endTag;

// If this is going to be a full link, then HTML between start and end EMCodec tags
// (which supposed to be an image) is hidden and a link is created, otherwise,
// a link is created over existing HTML

function EMCodec_startFullLink(code) {
	var address = EMCodec_decodeString(code);
	document.write('<a href="mailto:' + address + '">' + address + '</a>');
	document.write('<span style="display:none">');
	EMCodec_endTag = '</span>';
}

function EMCodec_startOverLink(code) {
	var address = EMCodec_decodeString(code);
	document.write('<a href="mailto:' + address + '">');
	EMCodec_endTag = '</a>';
}

function EMCodec_end() {
	document.write(EMCodec_endTag);
}

// This should be called to generate an encoded string
function EMCodec_showEncoded(string) {
	document.write(EMCodec_encodeString(string));
}

function EMCodec_encodeString(string) {
	var result = "";
	for(var i=0; i<string.length; i++) {
		result += EMCodec_encodeCharacter(string.charAt(i));
	}
	return result;
}

function EMCodec_decodeString(string) {
	var result = "";
	for(var i=0; i<string.length; i+=2) {
		result += EMCodec_decodeCharacter(string.substring(i,i + 2));
	}
	return result;
}

function EMCodec_encodeCharacter(ch) {
	var num = EMCodec_getCharCode(ch);
	var c1 = String.fromCharCode((num & 0xF0) / 0x10 + 0x61);
	var c2 = String.fromCharCode((num & 0xF) + 0x61);
	return c1 + c2;
}

function EMCodec_decodeCharacter(char_pair) {
	var num1 = EMCodec_getCharCode(char_pair.charAt(0)) - 0x61;
	var num2 = EMCodec_getCharCode(char_pair.charAt(1)) - 0x61;
	return String.fromCharCode(num1 * 0x10 + num2);
}

function EMCodec_getCharCode(ch) {
	for(var i=0x20; i<0x80; i++) {
		if(ch == String.fromCharCode(i)) return i;
	}
	return 0;
}

