/**
 * Fix email addresses!
 * @version:	0.2
 * @date: 		23 October 2006
 * @author: 	aluis@corefactor.pt | www.corefactor.pt
 *
 * @description:
 * Independent script that attaches itself to the document (unobtrusively) backing up the window.onLoad function
 * and after executing that, runs through the <a> in the DOM searching for "reversed" links and correcting them. 
 *
 */
 
 function fixEmails() {
	
	var as = window.document.getElementsByTagName( "a" );
	for( i=0;i<as.length;i++ ) {
			if( as[i].href.match( /mailto/ ) && as[i].className.match(/reversed/) ) {
				
					/**if( as[i].className.match( /replace/ ) ) { // replace link text also?
						mail_reversed = as[i].innerHTML;
					} else {
						mail_reversed = as[i].href;
					}*/
					
					mail_reversed = as[i].href.replace( /mailto:/, "" );
						
					mail_ok = "";
					salt ="REVERSETHIS";
					
					for( j = mail_reversed.length - salt.length-1;j>=0;j--) {
						if( mail_ok.charAt)
							mail_ok += ((mail_reversed.charAt( j )=='@')?"@":mail_reversed.charAt( j ));
						else
							mail_ok += ((mail_reversed[j]=='@')?"@":mail_reversed[j]);
					}

					if( as[i].className.match( /replace/ ) ) { // replace link text also?
						as[i].innerHTML = mail_ok;
						as[i].href = "mailto:" + mail_ok;
					} else {
						as[i].href ="mailto:" + mail_ok;
					}

			}
	}
	
 }
 
 var backupOnload = false;
 if ( typeof( window.onload ) == "function" ) {
	 core_old_onload = window.onload;
	 backupOnload = true;
 }

	 
 window.onload = function() {

	if( backupOnload)
		core_old_onload();
	fixEmails();	
 }
