
var has_invt, invt_params, invt_server = 'http://affiliates.investintech.com/'; keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var invt_fts = 1, invt_expires = 365;

if(typeof INVT == 'undefined') 
	var INVT = 'invt';
if(typeof invt_turl == 'undefined') 
	invt_turl = invt_server+'invt.gif';

function encode64(input) {
	input = escape(input);
	var output = '';
	var chr1, chr2, chr3 = '';
	var enc1, enc2, enc3, enc4 = '';
	var i = 0;
	
	do {
	chr1 = input.charCodeAt(i++);
	chr2 = input.charCodeAt(i++);
	chr3 = input.charCodeAt(i++);
	
	enc1 = chr1 >> 2;
	enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	enc4 = chr3 & 63;
	
	if (isNaN(chr2)) {
	enc3 = enc4 = 64;
	} else if (isNaN(chr3)) {
	enc4 = 64;
	}
	
	output = output +
	keyStr.charAt(enc1) +
	keyStr.charAt(enc2) +
	keyStr.charAt(enc3) +
	keyStr.charAt(enc4);
	chr1 = chr2 = chr3 = '';
	enc1 = enc2 = enc3 = enc4 = '';
	} while (i < input.length);
	
	return output;
}

InvtCookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
}

InvtUnparam = function (value) {
	if(!value)
		return false;
    var params = {}, pieces = value.split('&'), pair, i, l, t1;
    for (i = 0, l = pieces.length; i < l; i++) {
        pair = pieces[i].split('=', 2);
        t1 = decodeURIComponent(pair[0]);
        if(t1 == INVT) {
        	params[t1] = (pair.length == 2 ? decodeURIComponent(pair[1].replace(/\+/g, ' ')) : true);
        	break;
        }
    }
    return params;
};

function invtvoid() {return;}

InvtTracker = function () {
	if(!invt_turl || typeof invt_turl == 'undefined')
		return false;
	has_invt = InvtCookie(INVT);
	if(has_invt) {
		var image = new Image(1, 1);
		var invt_referer = document.referrer || '';
		image.src = invt_turl+'?invtx='+Math.random()+'&invtc='+has_invt+'&invtu='+encode64(window.location)+'&invtr='+encode64(invt_referer);
		image.onLoad = function () { invtvoid(); };
	}
};

InvtMain = function () {
	try {
		has_invt = InvtCookie(INVT);
		if(!has_invt || invt_fts == 0) {
			invt_params = InvtUnparam(window.location.search.substring(1));
			InvtCookie(INVT, invt_params[INVT], {'expires':invt_expires,'path':'/'});
		}
		InvtTracker();
	} catch(e) {};
}


