$(document).ready(function(){
	// global ajax csrf fix
    function getCookie(name) {
        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]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
	$(document).ajaxSend(function(b, c){
		c.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
	});
	// disable datepicker animation
	if ($.datepicker)
		$.datepicker.setDefaults({
			showAnim: '',
			showOn: 'both',
			buttonImageOnly: true,
			buttonImage: '/static/images/datepicker/calendar.gif',
			buttonText: '选择日期'
		});
	if ($.fn.tipsy){
		$.fn.tipsy.defaults = {
			delayIn: 0,      // delay before showing tooltip (ms)
			delayOut: 0,     // delay before hiding tooltip (ms)
			fade: false,     // fade tooltips in/out?
			fallback: '',    // fallback text to use when no tooltip text
			gravity: 's',    // gravity
			html: true,     // is tooltip content HTML?
			live: false,     // use live event support?
			offset: 0,       // pixel offset of tooltip from element
			opacity: 0.8,    // opacity of tooltip
			title: 'tip',  // attribute/callback containing tooltip text
			useCache: true,  // used in ajax load
			indicator: '/static/images/jtip/loader.gif',
			trigger: 'hover' // how tooltip is triggered - hover | focus | manual
		};
		$('.jtip').click(function(){ if(!$(this).attr('tip')) return false; }).tipsy();
	}
	if ($.fn.placeholder)
		$('input[placeholder]').placeholder();
	//CSS Hack
	(function(){
		if ($.browser.msie && $.browser.version == '6.0') {
			//Min Windth
			var min = $(document.body).hasClass('auto') ? 802 : 922;
			var topbar = $('#topbar');
			var Min = function() {
				document.body.style.width = document.documentElement.clientWidth <= min ? min + 'px' : '';
			}
			Min();
			$(window).resize(Min);
			// ie6 upgrade notify
			setTimeout(function(){
				$('<div class="pa bc tc w none pb10 pt10 f12" style="top:0;background:#ffc;color:#333;z-index:98;cursor:default;">您还在使用旧版本的IE浏览器，可能会无法正常使用本系统某些功能。建议您升级到 <a href="http://windows.microsoft.com/zh-CN/internet-explorer/products/ie/home">新版本的IE</a>，或者换用 <a href="http://www.google.com/chrome/">Google Chrome浏览器</a>&nbsp;&nbsp;<a class="red" href="#" onclick="javascript:void($(this.parentNode).remove());">X</a></div>').appendTo(document.body).slideDown('normal');
			}, 2000);
		}
	})();

});

