jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { 
        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(); 
        }
        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 { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$(function() {
	var browser = 'Unknown';
    var browserName = navigator.appName;
	var ua = navigator.userAgent;
    var os = 'Unknown';
	if (browserName == 'Microsoft Internet Explorer') {
		if (ua.indexOf('Windows NT 5.1') > -1) {
			os = 'Miscrosoft Windows XP';
		} else if (ua.indexOf('Windows NT 6.0') > -1) {
			os = 'Miscrosoft Windows Vista';
		} else if (ua.indexOf('Windows NT 5.2') > -1) {
			os = 'Miscrosoft Windows Server 2003';
		} else if (ua.indexOf('Windows NT 5.0') > -1) {
			os = 'Miscrosoft Windows 2000';
		} else if (ua.indexOf('Windows 98') > -1) {
			os = 'Miscrosoft Windows 98';
        } else if (ua.indexOf('Windows 98; Win 9x 4.90') > -1) {
            os = 'Miscrosoft Windows Me';
        }

		if (ua.indexOf('MSIE 6.0') > -1) {
			browser = "Microsoft Internet Explorer 6"
        } else if (ua.indexOf('MSIE 7.0') > -1) {
			browser = "Microsoft Internet Explorer 7"
        }
	} else if (browserName == 'Netscape') {
		if (ua.indexOf('Windows NT 5.1') > -1) {
			os = 'Miscrosoft Windows XP';
		} else if (ua.indexOf('Windows NT 5.0') > -1) {
			os = 'Miscrosoft Windows 2000';
		} else if (ua.indexOf('Win98') > -1){
			os = 'Miscrosoft Windows 98';
        } else if (ua.indexOf('Win 9x 4.90') > -1) {
            os = 'Miscrosoft Windows Me';
        } else if (ua.indexOf('Windows NT 6.0') > -1) {
            os = 'Miscrosoft Windows Vista';
        } else if (ua.indexOf('Mac') > -1) {
			os = 'Mac OSX'
        }

		if (ua.indexOf('Firefox/2') > -1) {
			browser = "Firefox 2.0"
        } else if (ua.indexOf('Firefox/1.5') > -1) {
            browser = "Firefox 1.5"
        } else if (ua.indexOf('Firefox/1.0') > -1) {
            browser = "Firefox 1.0"
        } else if (ua.indexOf('AppleWebKit') > -1) {
			browser = "Safari 1.0"
        }
	}
        
    var _ww_eu = window.location.href.replace(window.location.protocol + "//" + window.location.host, "");
    _ww_eu = _ww_eu.replace(":" + window.location.port, "");
	date = new Date();
    date.setTime(date.getTime() + (30 * 60 * 1000));
	var _ww_al = $.cookie('_wwal');
	if(_ww_al == null) {
		$.get("/eBuilder/stat/recordAjax.action", {"al.browser": browser, "al.osType": os, "al.enterUrl": _ww_eu}, function(data) {
			$.cookie('_wwal', data, {expires: date, path: '/'});
		});
	} else {
		$.cookie('_wwal', _ww_al, {expires: date, path: '/'});
	}
	
	$("a[stat]").each(function() {
		$(this).click(function() {
			$.get("/eBuilder/stat/recordClickAjax.action?id=" + $(this).attr("stat"));
		});
	});

	setInterval(function() {$("#updatetime").html(new Date().toLocaleString())}, 900);
});
