/*
 * $Id: marketruler.js 6 2009-09-28 19:49:37Z kent $
 *
 * Copyright (C) 2006, Market Acumen, Inc. All rights reserved.
 *
 * http://www.marketacumen.com/
 */
var offset = parseInt(Math.random() * 10) + 1;

function bleeto(x,y) 
{
	var i,p='';for(i=0;i<x.length;i++){p+=String.fromCharCode((x.charCodeAt(i)-32)%240+y+32);}return escape(p);
}

var e_shake;

function encryptjs(we,qs,hr,nos) 
{
	if (!Email_Valid(we.value)) {
		if (typeof e_shake == "object") {
			e_shake.cancel();
		}
		e_shake = new Effect.Shake('email-address',{delay:1, duration: 0.5});
		return "Please enter a valid email address.";
	}
	if (typeof e_shake == "object") {
		e_shake.cancel();
	}
	var e = Email_Clean(we.value.toLowerCase());
	if (e != we.value) {
		we.value = e;
	}
	e = e + qs;
	var j = "";
	var doff = 32 + offset;
	var ec = (we.form.elements['class'].value.length > 0) ? (" class=\"" + we.form.elements['class'].value + "\"") : "";
	if (hr == "") { 
		hr = e; 
	}
	e = '<a'+ec+' href="mailto:' + e + '">' + hr + '</a>';
	j += '<scri'+'pt type="text/javascript">\n';
	j += 'var e = unescape("' + bleeto(e,offset) + '");\n';
	j += "var i,p='';for(i=0;i<e.length;i++){p+=String.fromCharCode(((e.charCodeAt(i)-"+doff+")%240)+32);}\n";
	j += 'document.write(p);\n';
	j += '</scr' + 'ipt>';
	if (nos) {
		e = we.value.split("@");
		j += '<nosc'+'ript'+ec+'>' + e[0] + ' <em>-at-</em> ';
		e = e[1].split(".");
		j += e.join(" <em>dot</em> ");
		j += '</nosc'+'ript>';
	}
	return j;
}

function updatejs(form) 
{
	var qs = '';
	var s = form.subject.value.trim();
	var b = form.body.value.trim();
	if ((s + b).length > 0) {
		qs = "?subject=" + escape(s) + "&body=" + escape(b);
	}
	var js = encryptjs(form.email, qs, form.href.value, form.noscr.checked);
	form.js.value=js;
}

function toggle_help(id)
{
	new Effect[Element.visible(id) ? 'BlindUp' : 'BlindDown'](id, {duration: 0.25});
}
