// antispam.js
// IN THE FIGHT AGAINST SPAM...

var _DEFAULT_DOMAIN	= 'silverfoxbc.co.uk';
var _DEFAULT_ID		= 'webmaster';
var _IMGDIR = '/imgtxt/';

// EASIER VERSION...
// <A HREF="javascript:
function sendMail(domain,id) {
  //var at = '&#64;';	// ONLY GETS PROSESSED CORRECTLY WITH IE, NOT FIREFOX!
  var at = '@';

  // DEFAULT
  if ((typeof(id) == 'undefined') || (id < ' ')) id = _DEFAULT_ID;
  if ((typeof(domain) == 'undefined') || (domain < ' ')) domain = _DEFAULT_DOMAIN;

  // .navigate METHOD IS MSIE 3.02+ ONLY
  //window.navigate('mailto:' + id + '&#64;' + domain);
  window.location.href = 'mailto:' + id + at + domain;
}

// Returns <img> tag
// width, height - optional
function imgTag(filename,width,height) {
	var t;
	
	t = '<img src="' + _IMGDIR + filename + '" ';
	if (width > ' ') {
		t += 'width="' + width + '" ';
	}
	if (height > ' ') {	
		t += 'height="' + height + '" ';
	}
	//t += 'alt="' + filename + '" ';
	t += '/>';
	
	return t;
}

// Converts string of email address to string including subst <img> tags
// Assumed that email parts like '@' and '.co.uk' only occur once.
// 28/APR/2006 - Does not convert to img if not online!
function emailToImg(addrstr) {
	if (!_ONLINE) return addrstr;
	addrstr = addrstr.replace(/@/,imgTag('at.gif'));
	addrstr = addrstr.replace(/silverfoxbc/,imgTag('silverfoxbc.gif'));
	addrstr = addrstr.replace(/ntlworld/,imgTag('ntlworld.gif'));
	addrstr = addrstr.replace(/tiscali/,imgTag('tiscali.gif'));
	addrstr = addrstr.replace(/btinternet/,imgTag('btinternet.gif'));
	addrstr = addrstr.replace(/hotmail/,imgTag('hotmail.gif'));
	addrstr = addrstr.replace(/aol/,imgTag('aol.gif'));
	addrstr = addrstr.replace(/freeserve/,imgTag('freeserve.gif'));
	addrstr = addrstr.replace(/demon/,imgTag('demon.gif'));						
	addrstr = addrstr.replace(/\.co\.uk/,imgTag('co-uk.gif'));
	addrstr = addrstr.replace(/\.ac\.uk/,imgTag('ac-uk.gif'));	
	addrstr = addrstr.replace(/\.com/,imgTag('com.gif'));
	addrstr = addrstr.replace(/\.net/,imgTag('net.gif'));	
	addrstr = addrstr.replace(/\.uk/,imgTag('uk.gif'));		
		
	return addrstr;
}

// CONSTRUCTS EMAIL ADDRESS - NO ANCHOR
// NEARLY ALWAYS AN EMAIL ADDRESS, NOT MY OWN
// ALTHOUGH BOTH id AND domain WILL BE DEFAULTED IF NOT SPECIFIED
// *NEW* Converts email address to <img>
function antiSpam(domain,id) {
  var em = '';

  // ID
  if (id > ' ') {
    em = id;
  } else {
    em = _DEFAULT_ID;
  }
  //em += '&#64;';
	em += '@';

  // DOMAIN
  if (domain > ' ') {
    em += domain;
  } else {
    em += _DEFAULT_DOMAIN;
  }
	
	// convert email string to <img>'s
	em = emailToImg(em);

  // DONE
  //document.write(em);
  return em;
}

// ** OLD VERSION - SEE BELOW **
// CONSTRUCTS EMAIL ADDRESS - WITH ANCHOR
// display, subject, addclass AND domain ARE OPTIONAL
// NB: IF display NOT SPECIFIED, THEN EMAIL ADDY IS SHOWN
function OLD_antiSpamA(domain,id,display,subject,addclass) {
  var em = '';
  var anchor = '<A';

  // ID?
  if (id > ' ') {
    em = id;
  } else {
    em = _DEFAULT_ID;
  }
  em += '&#64;';

  // DOMAIN?
  if (domain > ' ') {
    em += domain;
  } else {
    em += _DEFAULT_DOMAIN;
  }

  // CLASS?
  if (addclass > ' ') {
    anchor += ' CLASS="' + addclass + '"';
  }

  // HREF
  anchor += ' HREF="mail';
  anchor += 'to:%20' + em;	// BROWSER CONVERTS %20 TO A SPACE

  // SUBJECT?
  if (subject > '') {
    anchor += '?subject=' + subject;
  }
  anchor += '">'

  // WHAT TO DISPLAY IN ANCHOR
  // IF DISPLAY NOT SPECIFIED, THEN EMAIL ADDY IS SHOWN
  if (display > '') {
    anchor += display;
  } else {
    anchor += em;
  }

  // FINISH
  anchor += '</A>';
  document.write(anchor);
}

// CONSTRUCTS EMAIL ADDRESS - WITH ANCHOR - NEW VERSION, USES sendMail() ABOVE
// -- USE HREF="javascript:sendMail('domain','id');" DIRECTLY IN HREF LINK
// -- ALTHOUGH antiSpamA() ALSO HIDES DISPLAYED EMAIL A LITTLE IF SHOWING FULL EMAIL ADDRESS
// display, (subject), addclass AND domain ARE OPTIONAL
// NB: DON'T KNOW WAY OF SPECIFYING subject USING sendMail() FUNCTION
// NB: IF display NOT SPECIFIED, THEN EMAIL ADDY IS SHOWN
function antiSpamA(domain,id,display,addclass) {
  var anchor = '<A';

  // DEFAULT (COULD LET sendMail() SET DEFAULTS)
  if ((typeof(id) == 'undefined') || (id < ' ')) id = _DEFAULT_ID;
  if ((typeof(domain) == 'undefined') || (domain < ' ')) domain = _DEFAULT_DOMAIN;
  if ((typeof(display) == 'undefined') || (display < ' ')) display = id + '&#64;' + domain;

  // CLASS?
  if (typeof(addclass) != 'undefined') {
    anchor += ' CLASS="' + addclass + '"';
  }

  // HREF
  anchor += ' HREF="javascript:sendMail(\'' + domain + '\',\'' + id + '\');"';

  // SUBJECT?
  //if (subject > ' ') anchor += '?subject=' + subject;
  anchor += '">';

  // WHAT TO DISPLAY IN ANCHOR
  // IF DISPLAY NOT SPECIFIED, THEN EMAIL ADDY IS SHOWN (DEFUALTED ABOVE)
  anchor += display;

  // FINISH
  anchor += '</A>';
  //document.write(anchor);
  return anchor;
}