Rot13 = {
    map: null,

    convert: function(a) {
        Rot13.init();

        var s = "";
        for (i=0; i < a.length; i++) {
            var b = a.charAt(i);
            s += ((b>='A' && b<='Z') || (b>='a' && b<='z') ? Rot13.map[b] : b);
        }
        return s;
    },

    init: function() {
        if (Rot13.map != null)
            return;
              
        var map = new Array();
        var s   = "abcdefghijklmnopqrstuvwxyz";

        for (i=0; i<s.length; i++)
            map[s.charAt(i)] = s.charAt((i+13)%26);
        for (i=0; i<s.length; i++)
            map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
            
        Rot13.map = map;
    },

    write: function(a) {
        document.write(Rot13.convert(a));
    }
}


var MailAddress = {

 	encrypt: function(string){
    	return Rot13.convert(string);
	},
	
	decrypt: function(string){
    	return Rot13.convert(string);
	}
}

var urlUtils = {
	getFileName: function(url){
		var idx = url.lastIndexOf('/');
		if (idx == -1)
		{
			return null;
		}
		return url.substr(idx+1);
	}
}

jQuery(function($) {
	$("a.mailer").each(function(index){
		var mail = $(this).attr('href');
		$(this).attr('href', 'mailto:'+MailAddress.decrypt(mail.substr(7, mail.length)));
	}); 
	$("a.download").each(function(index){
		var url = $(this).attr('href');
		$(this).attr('onclick', "$.ajax({async:false, cache:false, url:'downloadLog.php', data:{name: '" + urlUtils.getFileName(url) +"'}, dataType:'text'});");
	}); 
});

